Types and flakes

This commit is contained in:
2025-07-16 21:33:27 +02:00
parent 2b89e01d9a
commit 8a59799d04
6 changed files with 45 additions and 7 deletions

View File

@ -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 ];
};
};
}
```

View File

@ -1 +0,0 @@
# Functions

View File

@ -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)

View File

@ -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)