This commit is contained in:
2025-07-16 19:55:50 +02:00
parent 988c09fdb1
commit 808e843d2d
7 changed files with 109 additions and 5 deletions

View File

@ -1 +0,0 @@
# Attributes

13
src/nixbasics/flakes.md Normal file
View File

@ -0,0 +1,13 @@
# Flakes
Flakes are as of writing this guide still an experimental feature.
However, flakes provide concepts that I feel are fundamental to the concepts of Nix.
What flakes does is similar to `package-lock.json` from **npm**.
It makes sure that the inputs that are used, for example **nixpkgs**, are kept to a specific version.
To enable flakes to your config, add the following
```nix
nix.settings.experimental-features = "nix-command flakes";
```
This enables `nix-command` and `flakes`, where nix-command is needed for flakes.

View File

@ -0,0 +1 @@
# Functions

86
src/nixbasics/types.md Normal file
View File

@ -0,0 +1,86 @@
# Types
There are several types that can be used withing Nix, most of them are as one would expect, but I will go through some of them that are a bit more special.
- Integer
- Float
- Boolean
- String
- Path
- Null
- Attribute set
- List
- Function
- External
Functions will be covered in [Functions](./functions.md).
## Attribute set
One of the core
Attribute set can be seen as a record, or a key value map.
They are written as the following:
``` nix
foo = {
bar = true;
baz = {
name = "Jane";
}
}
```
However, the same can be written as:
``` nix
foo.bar = true;
foo.baz.name = "Jane";
```
and indexing can be done by:
``` nix
foo.bar # foo.bar == true
```
## String
Strings works like one would expect, using `"`.
There are multiline strings however, that are written like the following:
``` nix
foo = ''
gtk-application-prefer-dark-theme=0
gtk-dialogs-use-header=false
'';
```
The leading white space will be trimmed, as long as the same amount is trimmed.
Further, one can escape into Nix again, using `${}`, as can be seen in:
```nix
let homeDir = "/home/pingu"; in
path = "${homeDir}/coolstuffs"; # "/home/pingu/coolstuffs"
```
## Path
Paths are first class citizen.
This allows for easy imports of files.
They are relative to the directory of the source file that uses it.
For example, the following code would set `symbolsFile` to the file that is placed in the relative file `files/selayout`.
```nix
symbolsFile = ./files/selayout;
```
One can specify an absolute path, but that shouldn't be done, since that makes less guarantees.
Usually, when writing configurations or similar, one keeps the files in git, and such this would make it untenable.
What is recommended, if a global path is needed, is to encode it as a string instead.[^global]
## List
Lists are lazy, for some reason strict in length.[^strict?]
They are written with spaces as separators, as can be seen in:
```nix
foo = [ 123 "abc" { bar = false; } ];
```
[^global]: [Nix Reference Manual: Path](https://nix.dev/manual/nix/2.26/language/syntax#path-literal)
[^strict?]: [Nix Reference Manual: List](https://nix.dev/manual/nix/2.26/language/syntax#list-literal)