Daidalos
This commit is contained in:
@@ -1,108 +1,127 @@
|
||||
# NixOS-konfiguration
|
||||
|
||||
Det här förrådet innehåller en flake-baserad NixOS-konfiguration för mina
|
||||
maskiner.
|
||||
Det här förrådet innehåller flake-baserade NixOS-konfigurationer.
|
||||
|
||||
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`
|
||||
2. Generera en `hardware-configuration.nix`. Tag dock bort all information om filsystem. Disko sköter redan det åt oss.
|
||||
3. Kontrollera `networking.hostId`. Bör vara unikt för nätverket.
|
||||
- En Raspberry Pi 4
|
||||
- Ett separat microSD-kort med NixOS generiska `aarch64` SD-image
|
||||
- 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
|
||||
sudo -i
|
||||
export NIX_CONFIG='experimental-features = nix-command flakes'
|
||||
cd /tmp
|
||||
git clone <repo-url> nixcfg
|
||||
cd nixcfg
|
||||
nix shell nixpkgs#git -c git clone <repo-url> 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
|
||||
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
|
||||
nixos-generate-config --root /mnt
|
||||
cp /mnt/etc/nixos/hardware-configuration.nix ./hosts/kronos/hardware-configuration.nix
|
||||
mkdir -p /tmp/hw
|
||||
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`.
|
||||
Disko sköter ju redan det.
|
||||
`--no-filesystems` är viktigt här. Disklayouten hanteras redan av `disko`.
|
||||
|
||||
Kopiera också över konfigurationen till målenheten
|
||||
### 5. Kopiera konfigurationen och installera systemet
|
||||
|
||||
```bash
|
||||
rm -rf /mnt/etc/nixos
|
||||
cp -r /tmp/nixcfg /mnt/etc/nixos
|
||||
mkdir -p /mnt/etc
|
||||
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
|
||||
nixos-install --flake .#kronos
|
||||
```
|
||||
### 6. Starta om
|
||||
|
||||
Registrera TPM-nyckeln:
|
||||
|
||||
```bash
|
||||
nixos-enter --root /mnt
|
||||
./systemd-cryptenroll.sh
|
||||
```
|
||||
|
||||
Starta om:
|
||||
Ta bort installationskortet och starta om:
|
||||
|
||||
```bash
|
||||
reboot
|
||||
```
|
||||
|
||||
## Efter första uppstart
|
||||
|
||||
```bash
|
||||
git clone <dotfiles-repo> ~/dotfiles
|
||||
```
|
||||
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
|
||||
systemet kan starta från en USB-disk.
|
||||
|
||||
## 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:
|
||||
|
||||
```bash
|
||||
cd /etc/nixos
|
||||
nix flake update
|
||||
```
|
||||
|
||||
Bygg och applicera ändringar på den lokala maskinen:
|
||||
Bygg och aktivera konfigurationen:
|
||||
|
||||
```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
|
||||
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
|
||||
sudo nixos-rebuild build --flake .#kronos
|
||||
cd /etc/nixos
|
||||
sudo nixos-rebuild build --flake .#daidalos
|
||||
```
|
||||
|
||||
Rensa gamla generationer och oanvända paket:
|
||||
@@ -111,7 +130,7 @@ Rensa gamla generationer och oanvända paket:
|
||||
sudo nix-collect-garbage -d
|
||||
```
|
||||
|
||||
Kontrollera `ZFS`-snapshots:
|
||||
Visa ZFS-snapshots:
|
||||
|
||||
```bash
|
||||
zfs list -t snapshot
|
||||
|
||||
@@ -14,10 +14,11 @@ in
|
||||
disko,
|
||||
lolcat,
|
||||
nixosModules,
|
||||
system ? "x86_64-linux",
|
||||
hostModules ? [ ],
|
||||
}:
|
||||
nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
inherit system;
|
||||
specialArgs = {
|
||||
inputs = inputs // {
|
||||
"lolcat++" = lolcat;
|
||||
@@ -33,10 +34,11 @@ in
|
||||
disko,
|
||||
lolcat,
|
||||
nixosModules,
|
||||
system ? "x86_64-linux",
|
||||
hostModules ? [ ],
|
||||
}:
|
||||
nixpkgs.lib.nixosSystem {
|
||||
system = "x86_64-linux";
|
||||
inherit system;
|
||||
specialArgs = {
|
||||
inputs = inputs // {
|
||||
"lolcat++" = lolcat;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -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 @@
|
||||
args: (import ./hermes args) // (import ./kronos args)
|
||||
args: (import ./daidalos args) // (import ./hermes args) // (import ./kronos args)
|
||||
|
||||
Reference in New Issue
Block a user