From 808e843d2d2ecb9de0235b19bf80d05a4d508efc Mon Sep 17 00:00:00 2001 From: pingu Date: Wed, 16 Jul 2025 19:55:50 +0200 Subject: [PATCH] Types --- src/SUMMARY.md | 5 ++- src/configuration/users.md | 1 - src/installation/index.md | 7 ++- src/nixbasics/attributes.md | 1 - src/nixbasics/flakes.md | 13 ++++++ src/nixbasics/functions.md | 1 + src/nixbasics/types.md | 86 +++++++++++++++++++++++++++++++++++++ 7 files changed, 109 insertions(+), 5 deletions(-) delete mode 100644 src/configuration/users.md delete mode 100644 src/nixbasics/attributes.md create mode 100644 src/nixbasics/flakes.md create mode 100644 src/nixbasics/functions.md create mode 100644 src/nixbasics/types.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 7da5722..fcab18d 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -4,9 +4,10 @@ - [Installation](./installation/index.md) - [Nix basics](./nixbasics/index.md) - - [Attributes](./nixbasics/attributes.md) + - [Types](./nixbasics/types.md) + - [Functions](./nixbasics/functions.md) + - [Flakes](./nixbasics/flakes.md) - [Configuration](./configuration/index.md) - - [Users](./configuration/users.md) - [Drivers](./configuration/drivers.md) - [GUI](./configuration/GUI.md) - [Home-manager](./configuration/hm.md) diff --git a/src/configuration/users.md b/src/configuration/users.md deleted file mode 100644 index 76e7c23..0000000 --- a/src/configuration/users.md +++ /dev/null @@ -1 +0,0 @@ -# Users diff --git a/src/installation/index.md b/src/installation/index.md index 7e922ea..98448e3 100644 --- a/src/installation/index.md +++ b/src/installation/index.md @@ -84,6 +84,11 @@ For more hardware-specific settings, see https://github.com/NixOS/nixos-hardware ... ``` -With this you have an installed system, with a root user, but not much more. +# Post install + +TODO: adding a user and git. + +# Further reading +With this you have an installed system, with a user, but not much more. How to configure the system, to add users, software, drivers and such, will be covered in [Configuration](../configuration/index.md). But, you might need to understand some aspects of the nix language in order to fully understand how to do configuration, so that will be covered in [Nix basics](../nixbasics/index.md). diff --git a/src/nixbasics/attributes.md b/src/nixbasics/attributes.md deleted file mode 100644 index 78a7385..0000000 --- a/src/nixbasics/attributes.md +++ /dev/null @@ -1 +0,0 @@ -# Attributes diff --git a/src/nixbasics/flakes.md b/src/nixbasics/flakes.md new file mode 100644 index 0000000..fc2785b --- /dev/null +++ b/src/nixbasics/flakes.md @@ -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. diff --git a/src/nixbasics/functions.md b/src/nixbasics/functions.md new file mode 100644 index 0000000..0c5faf5 --- /dev/null +++ b/src/nixbasics/functions.md @@ -0,0 +1 @@ +# Functions diff --git a/src/nixbasics/types.md b/src/nixbasics/types.md new file mode 100644 index 0000000..f210570 --- /dev/null +++ b/src/nixbasics/types.md @@ -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)