diff --git a/spotlight_courses/HS24_NixOS/main.typ b/spotlight_courses/HS24_NixOS/main.typ index 98435f675c43cdb46e1ecf191608ea97ac247712..3b7712151ab43f72808a7902512ccbbde8b665a5 100644 --- a/spotlight_courses/HS24_NixOS/main.typ +++ b/spotlight_courses/HS24_NixOS/main.typ @@ -59,7 +59,7 @@ - Easier to change, manage and maintain the configuration - Easier to back up and share with people - Easy to deploy machines and their configuration - - Out of the box Rollbacks. + - Out of the box Rollbacks - Configuration options for many programs & services - Free of side effects - Actually uninstalls packages and their dependencies - Easy to set up VMs @@ -103,16 +103,38 @@ a true ``` ]) +=== let ... in +assign values and use them in a single expression +```nix +> let +a = 4; +in + a + a; +8 +``` === Attribute sets: - collection of name-value pairs +#columns(2, [ ```nix > {a = 1; b = "2"; c = 3.0;} { a = 1; b = "2"; c = 3; -}``` +} +``` +#colbreak() +access values in an attribute set: +```nix +> let +a ={b = 2; c = "a";} +in +toString a.b + a.c + +"2a" +``` +]) === Nix is lazy! ```nix > {a = {lazy = 5;}; b = "2"; c = 3.0;} @@ -174,6 +196,8 @@ addtwo 3 ``` ]) === Functions, a bit more in depth: +#columns(2, [ + Function which returns a function: ```nix > add = a: b: a + b @@ -184,6 +208,16 @@ Function which returns a function: b: 3 + b ``` `a` is being replaced by 3. +#colbreak() +They can take attribute sets too! +```nix +> let +f = {a, b, c ? 3, ...}: a + b + c; +in +f {a =1; b = 2; d = "Hi!"} +6 +``` +]) = Nix derivations == A simple bash script #columns(2, [ @@ -469,7 +503,6 @@ in - have what-is-my-ip installed! ])]) ]) -// https://fzakaria.com/2024/07/05/learn-nix-the-fun-way.html = NixOS == What is NixOS? @@ -673,7 +706,7 @@ flake.lock flake.nix result what-is-my-ip.nix total 16 -rw-r--r-- 1 cr users 567 Oct 30 18:34 flake.lock -rw-r--r-- 1 cr users 312 Oct 30 18:34 flake.nix -lrwxrwxrwx 1 cr users 57 Oct 30 18:35 result -> /nix/store/hysmspp11fxnkgjsp032q9zinl1gdk5n-what-is-my-ip/ +lrwxrwxrwx 1 cr users 57 Oct 30 18:35 result -> /nix/store/5jf23xp5nmqw8vhrjpgvbimrvd086v6z-what-is-my-ip/ -rw-r--r-- 1 cr users 247 Oct 30 18:34 what-is-my-ip.nix ``` - Symlink to the location of the build package in the nix store @@ -718,9 +751,8 @@ size: 15pt, - Keep track of all inputs, lock them - version-control your dependencies - something broken after a `nix flake update`? \ - switch back to the latest commit + $==>$ go back back a commit - provide packages easily - - I can expose my sys == NixOS flake structure #columns(1)[ @@ -1227,3 +1259,8 @@ content = { == Sources - https://cohost.org/leftpaddotpy/post/798893-rechosting-a-banger +- https://nix.dev/tutorials/nix-language +- https://github.com/danth/stylix +- https://github.com/nix-community/disko +- https://github.com/NotAShelf/nvf +- https://fzakaria.com/2024/07/05/learn-nix-the-fun-way