This commit is contained in:
2026-04-22 20:34:53 +02:00
parent a2d976591b
commit c226044528
7 changed files with 309 additions and 52 deletions
+68 -49
View File
@@ -1,108 +1,127 @@
# NixOS-konfiguration # NixOS-konfiguration
Det här förrådet innehåller en flake-baserad NixOS-konfiguration för mina Det här förrådet innehåller flake-baserade NixOS-konfigurationer.
maskiner.
Just nu finns värden `kronos`. ## Värdar
Punktfiler förväntas att finns under `~/dotfiles`, och hanteras med home manager - `daidalos`: Raspberry Pi 4, `aarch64-linux`, ZFS-root, `extlinux`
- `hermes`: x86_64-server
- `kronos`: x86_64-desktop
## Flakes ## Ny installation: `daidalos`
Vi lever i framtiden, därför används flakes exklusivt. De här stegen utgår från en helt ren maskin. Du behöver inte installera Nix
innan du börjar. NixOS-installationsmediet innehåller redan `nix`,
`nixos-install` och `nixos-generate-config`.
## För att installera ### Krav
1. Kontrollera att rätt disk (`installDisk`) är vald i `hosts/kronos/default.nix` - En Raspberry Pi 4
2. Generera en `hardware-configuration.nix`. Tag dock bort all information om filsystem. Disko sköter redan det åt oss. - Ett separat microSD-kort med NixOS generiska `aarch64` SD-image
3. Kontrollera `networking.hostId`. Bör vara unikt för nätverket. - En separat måldisk för systemet, helst en USB-SSD eller NVMe-adapter som
syns under `/dev/disk/by-id`
- Nätverksanslutning under installationen
- All data på måldisken raderas under installationen
### Applicera konfiguration `daidalos` använder ZFS och refererar diskar via `/dev/disk/by-id`. Installera
inte på samma medium som du har bootat installationsmiljön från.
Sedan: ### 1. Boota installationsmediet
1. Ladda ned NixOS generiska `aarch64` SD-image.
2. Skriv den till ett microSD-kort.
3. Starta Raspberry Pi 4 från kortet.
4. Om nätverket inte kommer upp automatiskt, kör `nmtui`.
### 2. Hämta förrådet och välj måldisk
```bash ```bash
sudo -i sudo -i
export NIX_CONFIG='experimental-features = nix-command flakes' export NIX_CONFIG='experimental-features = nix-command flakes'
cd /tmp cd /tmp
git clone <repo-url> nixcfg nix shell nixpkgs#git -c git clone <repo-url> nixcfg
cd nixcfg cd /tmp/nixcfg
ls -l /dev/disk/by-id
nix shell nixpkgs#openssl -c openssl rand -hex 4
nix shell nixpkgs#nvim -c nvim modules/hosts/daidalos/configuration.nix
``` ```
Applicera disk-layouten: Ändra sedan i `modules/hosts/daidalos/configuration.nix`:
- Ersätt `REPLACE_ME` i `installDisk` med rätt disk från `/dev/disk/by-id`
- Sätt `networking.hostId` till en unik sträng med 8 hextecken, till exempel
värdet från `openssl rand -hex 4`
### 3. Partitionera, formatera och montera måldisken
```bash ```bash
nix run github:nix-community/disko -- --mode disko .#kronos nix run github:nix-community/disko -- --mode destroy,format,mount --flake .#daidalos
``` ```
Generera hårdvarufilen och kopiera in den i förrådet: Kommandot raderar all data på måldisken och monterar systemet under `/mnt`.
### 4. Generera `hardware.nix` för just den här maskinen
```bash ```bash
nixos-generate-config --root /mnt mkdir -p /tmp/hw
cp /mnt/etc/nixos/hardware-configuration.nix ./hosts/kronos/hardware-configuration.nix nixos-generate-config --root /mnt --dir /tmp/hw --no-filesystems
cp /tmp/hw/hardware-configuration.nix modules/hosts/daidalos/hardware.nix
``` ```
Kom ihåg att ta bort alla filesystemkonfiguration från `hardware-configuration.nix`. `--no-filesystems` är viktigt här. Disklayouten hanteras redan av `disko`.
Disko sköter ju redan det.
Kopiera också över konfigurationen till målenheten ### 5. Kopiera konfigurationen och installera systemet
```bash ```bash
rm -rf /mnt/etc/nixos mkdir -p /mnt/etc
cp -r /tmp/nixcfg /mnt/etc/nixos cp -a /tmp/nixcfg /mnt/etc/nixos
nixos-install --root /mnt --flake /mnt/etc/nixos#daidalos
``` ```
Installera systemet: `nixos-install` frågar efter ett root-lösenord för den installerade maskinen.
```bash ### 6. Starta om
nixos-install --flake .#kronos
```
Registrera TPM-nyckeln: Ta bort installationskortet och starta om:
```bash
nixos-enter --root /mnt
./systemd-cryptenroll.sh
```
Starta om:
```bash ```bash
reboot reboot
``` ```
## Efter första uppstart Om Pi:n inte bootar från måldisken efter installationen är firmware troligen
inte inställd för USB-boot ännu. Då behöver Raspberry Pi EEPROM uppdateras innan
```bash systemet kan starta från en USB-disk.
git clone <dotfiles-repo> ~/dotfiles
```
## Vanligt underhåll ## Vanligt underhåll
När systemet väl är installerat jobbar man oftast så här. På en installerad maskin ligger konfigurationen under `/etc/nixos`.
Uppdatera flake-låset: Uppdatera flake-låset:
```bash ```bash
cd /etc/nixos
nix flake update nix flake update
``` ```
Bygg och applicera ändringar på den lokala maskinen: Bygg och aktivera konfigurationen:
```bash ```bash
sudo nixos-rebuild switch --flake .#kronos cd /etc/nixos
sudo nixos-rebuild switch --flake .#daidalos
``` ```
Testa en konfiguration utan att göra den permanent vid nästa boot: Testa utan att göra ändringen permanent över reboot:
```bash ```bash
sudo nixos-rebuild test --flake .#kronos cd /etc/nixos
sudo nixos-rebuild test --flake .#daidalos
``` ```
Bygg bara, utan att byta system direkt: Bygg bara:
```bash ```bash
sudo nixos-rebuild build --flake .#kronos cd /etc/nixos
sudo nixos-rebuild build --flake .#daidalos
``` ```
Rensa gamla generationer och oanvända paket: Rensa gamla generationer och oanvända paket:
@@ -111,7 +130,7 @@ Rensa gamla generationer och oanvända paket:
sudo nix-collect-garbage -d sudo nix-collect-garbage -d
``` ```
Kontrollera `ZFS`-snapshots: Visa ZFS-snapshots:
```bash ```bash
zfs list -t snapshot zfs list -t snapshot
+4 -2
View File
@@ -14,10 +14,11 @@ in
disko, disko,
lolcat, lolcat,
nixosModules, nixosModules,
system ? "x86_64-linux",
hostModules ? [ ], hostModules ? [ ],
}: }:
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; inherit system;
specialArgs = { specialArgs = {
inputs = inputs // { inputs = inputs // {
"lolcat++" = lolcat; "lolcat++" = lolcat;
@@ -33,10 +34,11 @@ in
disko, disko,
lolcat, lolcat,
nixosModules, nixosModules,
system ? "x86_64-linux",
hostModules ? [ ], hostModules ? [ ],
}: }:
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
system = "x86_64-linux"; inherit system;
specialArgs = { specialArgs = {
inputs = inputs // { inputs = inputs // {
"lolcat++" = lolcat; "lolcat++" = lolcat;
+80
View File
@@ -0,0 +1,80 @@
{
lib,
pkgs,
nixosModules,
...
}:
let
userName = "root";
hostName = "Daidalos";
installDisk = "/dev/disk/by-id/REPLACE_ME";
in
{
_module.args = {
inherit
userName
hostName
installDisk
;
};
imports = [
./disko.nix
./hardware.nix
nixosModules.base
nixosModules.binBashWrapper
];
my.binBashWrapper.enable = true;
boot = {
kernelPackages = pkgs.linuxPackages_rpi4;
supportedFilesystems = [ "zfs" ];
zfs.devNodes = "/dev/disk/by-id";
extraModprobeConfig = ''
options zfs zfs_arc_min=67108864
options zfs zfs_arc_max=134217728
'';
loader = {
grub.enable = lib.mkForce false;
systemd-boot.enable = lib.mkForce false;
generic-extlinux-compatible.enable = true;
};
};
services.zfs = {
autoScrub.enable = true;
trim.enable = false;
autoSnapshot.enable = false;
};
services.fstrim.enable = false;
hardware.enableRedistributableFirmware = true;
hardware.deviceTree = {
enable = true;
filter = "*rpi-4-*.dtb";
};
environment.systemPackages = with pkgs; [
libraspberrypi
raspberrypi-eeprom
];
networking.hostName = hostName;
networking.hostId = "69aaeea1";
systemd.network.networks."10-wired".matchConfig.Name = lib.mkForce [
"en*"
"eth*"
"end0"
];
zramSwap = {
enable = true;
memoryPercent = 50;
algorithm = "zstd";
};
system.stateVersion = "25.05";
}
+20
View File
@@ -0,0 +1,20 @@
{
inputs,
mkHost,
nixosModules,
...
}:
let
host = mkHost {
nixpkgs = inputs.nixpkgs-stable;
disko = inputs.disko-stable;
lolcat = inputs."lolcat++-stable";
system = "aarch64-linux";
inherit nixosModules;
hostModules = [ ./configuration.nix ];
};
in
{
Daidalos = host;
daidalos = host;
}
+116
View File
@@ -0,0 +1,116 @@
{ installDisk, ... }:
{
disko.devices = {
disk.main = {
type = "disk";
device = installDisk;
content = {
type = "gpt";
partitions = {
firmware = {
label = "FIRMWARE";
size = "1G";
type = "0700";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot/firmware";
mountOptions = [ "umask=0077" ];
};
};
zfs = {
label = "zfs";
size = "100%";
content = {
type = "zfs";
pool = "rpool";
};
};
};
};
};
zpool.rpool = {
type = "zpool";
options = {
ashift = "12";
autotrim = "on";
};
rootFsOptions = {
acltype = "posixacl";
atime = "off";
compression = "lz4";
dnodesize = "auto";
mountpoint = "none";
xattr = "sa";
};
datasets = {
root = {
type = "zfs_fs";
options.mountpoint = "none";
};
"root/nixos" = {
type = "zfs_fs";
mountpoint = "/";
options = {
canmount = "noauto";
mountpoint = "legacy";
};
postCreateHook = ''
zfs list -t snapshot -H -o name | grep -E '^rpool/root/nixos@blank$' \
|| zfs snapshot rpool/root/nixos@blank
'';
};
home = {
type = "zfs_fs";
mountpoint = "/home";
options.mountpoint = "legacy";
};
nix = {
type = "zfs_fs";
mountpoint = "/nix";
options = {
mountpoint = "legacy";
"com.sun:auto-snapshot" = "false";
primarycache = "metadata";
};
};
persist = {
type = "zfs_fs";
mountpoint = "/persist";
options.mountpoint = "legacy";
};
var = {
type = "zfs_fs";
options.mountpoint = "none";
};
"var/log" = {
type = "zfs_fs";
mountpoint = "/var/log";
options.mountpoint = "legacy";
};
"var/lib" = {
type = "zfs_fs";
mountpoint = "/var/lib";
options.mountpoint = "legacy";
};
reserved = {
type = "zfs_volume";
size = "1G";
};
};
};
};
}
+20
View File
@@ -0,0 +1,20 @@
{ lib, modulesPath, ... }:
{
imports = [
(modulesPath + "/installer/scan/not-detected.nix")
];
boot.initrd.availableKernelModules = [
"pcie_brcmstb"
"reset-raspberrypi"
"usbhid"
"usb_storage"
"vc4"
"xhci_pci"
];
boot.initrd.kernelModules = [ ];
boot.kernelModules = [ ];
boot.extraModulePackages = [ ];
nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux";
}
+1 -1
View File
@@ -1 +1 @@
args: (import ./hermes args) // (import ./kronos args) args: (import ./daidalos args) // (import ./hermes args) // (import ./kronos args)