nix language

This commit is contained in:
foglar 2025-03-14 12:51:11 +01:00
parent 8f3a1b443b
commit 88db5fdb43
2 changed files with 72 additions and 13 deletions

View File

@ -1,7 +1,8 @@
# Nix
- [ ] Nix scripts
- [ ] Nix home-manager
- [ ] Nix home-manager, standalone vs sysconfig module
- [ ] Plasma manager
- [ ] Stylix
- [ ] NixOS Everywhere, NixOS Anywhere
- [x] Inputs in Nix
@ -12,7 +13,7 @@
- [ ] Impermanence
- [x] Own nixos ISO
- [ ] NixOS helper
- [ ] NixOS builders and writers
- [x] NixOS builders and writers
- [ ] Ovverrides and overlays
- [ ] Nix Shell
- [x] Nix writers

View File

@ -4,6 +4,7 @@ class: invert
paginate: true
footer: "Albert Vala, Filip Kohout, Nix flakes & Nix command"
---
<style>
@import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital,wght@0,300;0,400;0,500;0,700;1,300;1,400;1,500;1,700&display=swap');
:root {
@ -69,16 +70,22 @@ nix run nixpkgs#cowsay #New
* Cokoliv.
---
# Nix command + flakes
- temp shell
```shell
nix shell nixpkgs#alejandra
nix shell github:kamadorueda/alejandra
```
- Show output attr
```shell
nix flake show github:kamadorueda/alejandra
```
```
---
# Jak použít flakes na systémovou configuraci?
@ -145,7 +152,9 @@ nix flake show github:kamadorueda/alejandra
programs.home-manager.enable = true;
}
```
---
```nix
#configuration.nix
{
@ -179,11 +188,11 @@ nix flake show github:kamadorueda/alejandra
* `nix flake update [home-manager]` - aktualizace jednoho vstupu
```nix
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-current = "github:nixos/nixpkgs?ref=3058cf84bce1aba7b1820cb24319a171572217ba-dirty";
}
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-stable.url = "github:nixos/nixpkgs/nixos-24.11";
nixpkgs-current = "github:nixos/nixpkgs?ref=3058cf84bce1aba7b1820cb24319a171572217ba-dirty";
}
```
---
@ -212,23 +221,72 @@ nix build /etc/nixos#nixosConfigurations.nixos.config.system.build.toplevel
* `--build-host` - konfigurace tady
* `--target-host` - konfigurace tam
* `nix.settings.trusted-users`
---
# Virtual machine
* `nix run github:nix-community/nixos-generators -- -c ./flake.nix --flake '#default' -f vm --disk-size 20480`
* možnost generovat pro různé platformy (Amazon E2C, Docker, ISO, Proxmox, VMware, vagrant, qcow, ...)
* [https://github.com/nix-community/nixos-generators](https://github.com/nix-community/nixos-generators)
---
# Nix language
* `nix-repl` nebo `nix-instantiate --eval foo.nix`
```nix
# Deklarace setu
foo = {
bar = "test"
}
# "Čtení" setu (evaluation)
foo.bar
# Let-In syntaxe
let
foo = {
bar = "test"
};
in
foo.bar
```
---
```nix
# Rekurze
foo = rec {
bar = 10;
ham = 5;
eggs = bar + ham;
}
```
```nix
# Použití with
environment.systemPackages = with pkgs; [
neovim
wireshark
];
```
---
---
# Nix writers
* Jednoduchý způsob přidávání skriptů v různých programovacích jazycích do
systému ve flake konfiguraci
systému
* Rozdíl oproti klasickému `pkgs.writeShellScriptBin`
* [nixpkgs](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/writers/scripts.nix) -
pro všechny možnosti konfigurace skriptů
* [https://nixos.wiki/wiki/Nix-writers](https://nixos.wiki/wiki/Nix-writers) -
osekaná wiki
* [nixpkgs](https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/writers/scripts.nix) - pro všechny možnosti konfigurace skriptů
* [https://nixos.wiki/wiki/Nix-writers](https://nixos.wiki/wiki/Nix-writers) - osekaná wiki
---