nix lang explain

This commit is contained in:
foglar 2025-03-14 13:14:22 +01:00
parent 88db5fdb43
commit 3b91f038e6

View File

@ -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 {
...
```
---