From 8a59799d044d863729b2ba3a51c0bb133396bf31 Mon Sep 17 00:00:00 2001 From: pingu Date: Wed, 16 Jul 2025 21:33:27 +0200 Subject: [PATCH] Types and flakes --- src/SUMMARY.md | 3 +-- src/installation/index.md | 4 ++-- src/nixbasics/flakes.md | 21 +++++++++++++++++++++ src/nixbasics/functions.md | 1 - src/nixbasics/index.md | 3 +++ src/nixbasics/types.md | 20 ++++++++++++++++++-- 6 files changed, 45 insertions(+), 7 deletions(-) delete mode 100644 src/nixbasics/functions.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index fcab18d..c29bdb3 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -4,9 +4,8 @@ - [Installation](./installation/index.md) - [Nix basics](./nixbasics/index.md) - - [Types](./nixbasics/types.md) - - [Functions](./nixbasics/functions.md) - [Flakes](./nixbasics/flakes.md) + - [Types](./nixbasics/types.md) - [Configuration](./configuration/index.md) - [Drivers](./configuration/drivers.md) - [GUI](./configuration/GUI.md) diff --git a/src/installation/index.md b/src/installation/index.md index 80bbd5d..5ecc8bc 100644 --- a/src/installation/index.md +++ b/src/installation/index.md @@ -125,5 +125,5 @@ After fixing a good setup, please setup a remote for git, so that you are able t # 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). +How to configure the system, software, drivers and such, will be covered in [Configuration](../configuration/index.md). +But, you might need to understand some aspects of the nix language, and how the rebuilding with flakes works, 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/flakes.md b/src/nixbasics/flakes.md index fc2785b..b250b3b 100644 --- a/src/nixbasics/flakes.md +++ b/src/nixbasics/flakes.md @@ -11,3 +11,24 @@ nix.settings.experimental-features = "nix-command flakes"; ``` This enables `nix-command` and `flakes`, where nix-command is needed for flakes. + +## Systems +Flakes also handles systems a bit a bit different. +Below is the auto generated flake file for a system. +When running `nixos-rebuild switch --flake .#nixos -L`, the `nixos` parts comes from this file. +If `nixosConfiguration.nixostwo` existed, then you could run that instead to build that system. + +```nix +{ + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + outputs = inputs@{ self, nixpkgs, ... }: { + # NOTE: 'nixos' is the default hostname + nixosConfigurations.nixos = nixpkgs.lib.nixosSystem { + inherit pkgs; + modules = [ ./configuration.nix ]; + }; + }; +} +``` diff --git a/src/nixbasics/functions.md b/src/nixbasics/functions.md deleted file mode 100644 index 0c5faf5..0000000 --- a/src/nixbasics/functions.md +++ /dev/null @@ -1 +0,0 @@ -# Functions diff --git a/src/nixbasics/index.md b/src/nixbasics/index.md index e6642e5..3e273dd 100644 --- a/src/nixbasics/index.md +++ b/src/nixbasics/index.md @@ -1 +1,4 @@ # Nix basics + +The basics of Nix will be covered here. +Flakes are covered in [Flakes](./flakes.md), and the types are covered in [Types](./types.md) diff --git a/src/nixbasics/types.md b/src/nixbasics/types.md index f210570..a0b08ac 100644 --- a/src/nixbasics/types.md +++ b/src/nixbasics/types.md @@ -13,8 +13,6 @@ There are several types that can be used withing Nix, most of them are as one wo - Function - External -Functions will be covered in [Functions](./functions.md). - ## Attribute set One of the core @@ -82,5 +80,23 @@ They are written with spaces as separators, as can be seen in: foo = [ 123 "abc" { bar = false; } ]; ``` +## Functions +Functions in nix only take one argument, however, they can be a set. +What they return however, can be a function themselves, so that is how one says there are multiple arguments. +You are also able to clump a set into one argument, while still expanding parts of it, while hiding the rest with `...`. + +```nix +f = x: !x; # negate x +g = x: y: x + y # add x and y +h = { x, y}: x + y # add x and y from a set +i = w@{ x, y, ...}: x + y + w.z # add x, y and z from the same set +j = { x, y, ...}@w: x + y + w.z # add x, y and z from the same set +``` + +You are also able to set default values to arguments, if they weren't supplied. +```nix +foo = {a, b ? 23}: a + b # add a and b, where b is 23 by default +``` + [^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)