From 2bdbbafbb00b9955eca80d29ef68e9017e2cd5c0 Mon Sep 17 00:00:00 2001 From: chayleaf Date: Sat, 13 Jul 2024 06:05:08 +0700 Subject: [PATCH] server: switch to systemd initrd --- flake.lock | 6 +-- flake.nix | 1 + system/devices/radxa-rock5a-server.nix | 54 ++++++++++++++++++++------ 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/flake.lock b/flake.lock index 3a1a086..8975cb5 100644 --- a/flake.lock +++ b/flake.lock @@ -629,11 +629,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1720722856, - "narHash": "sha256-vTD9PK8X0rVrOkcRetSpTacRNbH/qZi8YdKBXxAC8GQ=", + "lastModified": 1720888318, + "narHash": "sha256-s5Pf3Es1reWTvHiz0YNuVknH/0RGo2vu+8MyeKT7VWo=", "owner": "chayleaf", "repo": "nixpkgs", - "rev": "06bfe30652b5d4b56a800a09c29ada61adcede65", + "rev": "81b52fd15be6a3331668cc7bbaab4aec7c654472", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index b4448b3..e221dd2 100644 --- a/flake.nix +++ b/flake.nix @@ -71,6 +71,7 @@ # mobile-nixos = true; # nixos-router = true; # notnft = true; + # nixpkgs = true; }; # IRL-related stuff I'd rather not put into git priv = diff --git a/system/devices/radxa-rock5a-server.nix b/system/devices/radxa-rock5a-server.nix index e818be9..c108321 100644 --- a/system/devices/radxa-rock5a-server.nix +++ b/system/devices/radxa-rock5a-server.nix @@ -1,8 +1,9 @@ { config -, lib +, pkgs , router-config , hardware -, ... }: +, ... +}: let uuids.enc = "15945050-df48-418b-b736-827749b9262a"; @@ -60,16 +61,39 @@ in }; boot.initrd = { - # eth0 on some kernels - # end0 on other kernels - # sometimes even version dependent - preLVMCommands = lib.mkOrder 499 '' - ip link set end0 address ${router-config.router-settings.serverInitrdMac} || ip link set eth0 address ${router-config.router-settings.serverInitrdMac} || true - ''; - network.enable = true; + systemd = { + services.unlock-bcachefs-persist.enable = false; + enable = true; + network = { + enable = true; + links."10-mac" = { + matchConfig.OriginalName = "e*"; + linkConfig = { + MACAddressPolicy = "none"; + MACAddress = router-config.router-settings.serverInitrdMac; + }; + }; + networks."10-dhcp" = { + DHCP = "yes"; + name = "e*"; + networkConfig = { + IPv6AcceptRA = "yes"; + }; + dhcpV4Config = { + ClientIdentifier = "mac"; + DUIDType = "link-layer"; + }; + dhcpV6Config = { + DUIDType = "link-layer"; + }; + }; + }; + }; + network.enable = false; network.flushBeforeStage2 = true; - network.udhcpc.enable = true; - network.udhcpc.extraArgs = [ "-t100" ]; + systemd.initrdBin = [ pkgs.iproute2 pkgs.vim pkgs.bashInteractive pkgs.util-linux ]; + systemd.storePaths = [ pkgs.vim pkgs.busybox ]; + systemd.users.root.shell = "/bin/bash"; network.ssh = { enable = true; port = 22; @@ -102,7 +126,13 @@ in options = [ "defaults" "size=2G" "mode=755" ]; }; "/persist" = { device = "UUID=${uuids.bch}"; fsType = "bcachefs"; inherit neededForBoot; - options = [ "errors=ro" ]; }; + options = [ + "errors=ro" + "x-systemd.device-timeout=0" + "x-systemd.requires=dev-mapper-bch0.device" + "x-systemd.requires=dev-mapper-bch1.device" + "x-systemd.requires=dev-mapper-bch2.device" + ]; }; "/boot" = { device = parts.boot; fsType = "vfat"; inherit neededForBoot; }; };