From 373fb458319ba13f0945cac2451eb0d6ef812449 Mon Sep 17 00:00:00 2001 From: Jack O'Sullivan Date: Mon, 4 Dec 2023 23:00:25 +0000 Subject: [PATCH] nixos: Switch to systemd initrd --- nixos/boxes/tower/default.nix | 3 --- nixos/modules/common.nix | 9 +++++++++ nixos/modules/containers.nix | 8 +++++++- nixos/modules/tmproot.nix | 5 +++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/nixos/boxes/tower/default.nix b/nixos/boxes/tower/default.nix index 98f686c..c192b88 100644 --- a/nixos/boxes/tower/default.nix +++ b/nixos/boxes/tower/default.nix @@ -31,17 +31,14 @@ initrd = { availableKernelModules = [ "nvme" "xhci_pci" "usb_storage" "usbhid" "thunderbolt" ]; luks = { - reusePassphrases = true; devices = { persist = { device = "/dev/disk/by-uuid/27840c6f-445c-4b95-8c39-e69d07219f33"; allowDiscards = true; - preLVM = false; }; home = { device = "/dev/disk/by-uuid/c16c5038-7883-42c3-960a-a085a99364eb"; allowDiscards = true; - preLVM = false; }; }; }; diff --git a/nixos/modules/common.nix b/nixos/modules/common.nix index f12d56c..44ff590 100644 --- a/nixos/modules/common.nix +++ b/nixos/modules/common.nix @@ -94,6 +94,7 @@ in "net.ipv6.route.max_size" = mkDefault 16384; }; }; + loader = { efi = { efiSysMountPoint = mkDefault "/boot"; @@ -111,6 +112,14 @@ in memtest86.enable = mkDefault true; }; }; + + initrd = { + systemd = { + enable = mkDefault true; + emergencyAccess = mkDefault true; + }; + services.lvm.enable = mkDefault true; + }; }; environment.systemPackages = with pkgs; mkMerge [ diff --git a/nixos/modules/containers.nix b/nixos/modules/containers.nix index 4701609..23ca463 100644 --- a/nixos/modules/containers.nix +++ b/nixos/modules/containers.nix @@ -208,7 +208,13 @@ in mkdir -p -m 0755 "$root"/sbin "$root"/etc touch "$root"/etc/os-release - ln -sf "${containerSystem}"/init "$root"/sbin/init + + if [ -e "${containerSystem}"/prepare-root ]; then + initSource="${containerSystem}"/prepare-root + else + initSource="${containerSystem}"/init + fi + ln -sf "$initSource" "$root"/sbin/init ''; postStop = '' diff --git a/nixos/modules/tmproot.nix b/nixos/modules/tmproot.nix index 347c6a3..7d71b59 100644 --- a/nixos/modules/tmproot.nix +++ b/nixos/modules/tmproot.nix @@ -224,8 +224,9 @@ in # Catch non-existent source directories that are needed for boot (see `pathsNeededForBoot` in # nixos/lib/util.nix). We do this by monkey-patching the `waitDevice` function that would otherwise hang. - boot.initrd.postDeviceCommands = - '' + # Seems like systemd initrd doesn't care because it uses the systemd.mount units + # ("If this mount is a bind mount and the specified path does not exist yet it is created as directory.") + boot.initrd.postDeviceCommands = mkIf (!config.boot.initrd.systemd.enable) '' ensurePersistSource() { [ -e "/mnt-root$1" ] && return echo "Persistent source directory $1 does not exist, creating..."