From 3b91f038e6e8574c2c020df4bdf1dae439367c65 Mon Sep 17 00:00:00 2001 From: foglar Date: Fri, 14 Mar 2025 13:14:22 +0100 Subject: [PATCH] nix lang explain --- prezentace.md | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/prezentace.md b/prezentace.md index 418e911..7231cd5 100644 --- a/prezentace.md +++ b/prezentace.md @@ -250,7 +250,7 @@ foo.bar let foo = { bar = "test" - }; + }; in foo.bar ``` @@ -276,7 +276,74 @@ foo.bar --- +## Funkce +```nix +# Jednoduchá funkce +let + bar = eggs: eggs + 1; +in + bar 3 # -> 4 + +# Funkce s více parametry +let + bar = eggs: bacon: (eggs+1) * bacon; +in +bar 3 7 # -> 28 +``` + +--- + +```nix +let + bar = { bacon, eggs }: bacon + eggs; +in + bar { bacon = 10; eggs = 15; } +``` + +* konfigurační soubory jsou funkce + +```nix +# configuration.nix +{inputs, pkgs}: +{ + environment.systemPackages = [ + inputs.zen-browser.packages.${system}.default + pkgs.gcc + ]; +} +``` + +--- + +```nix +let + bar = { bacon ? 10, eggs, ... }: bacon + eggs; +in + bar { eggs = 15; bread = 30 } +``` + +```nix +let + bar = { bacon ? 10, ... }@arguments: + bacon + arguments.eggs; +in + bar { eggs = 15; bread = 30; } +``` + +--- + +```nix + outputs = inputs @ { + nixpkgs, + home-manager, + zen-browser, + ... + }: { + nixosConfigurations = { + nixos = nixpkgs.lib.nixosSystem { +... +``` ---