From ff9eb3b6facd8818dbc7b67263c9ee63d573cfcc Mon Sep 17 00:00:00 2001 From: William Date: Sun, 3 Aug 2025 20:44:23 -0300 Subject: [PATCH] ephermal systemd unit is now for host agnostic; moved io to disko disk management --- hosts/modules/ephermal.nix | 64 +++++++++ hosts/modules/io/ephermal.nix | 44 ------- hosts/modules/io/hardware-configuration.nix | 139 +++++++++++++------- hosts/modules/rotterdam/ephermal.nix | 45 ------- 4 files changed, 152 insertions(+), 140 deletions(-) create mode 100644 hosts/modules/ephermal.nix delete mode 100644 hosts/modules/io/ephermal.nix delete mode 100644 hosts/modules/rotterdam/ephermal.nix diff --git a/hosts/modules/ephermal.nix b/hosts/modules/ephermal.nix new file mode 100644 index 0000000..ff22557 --- /dev/null +++ b/hosts/modules/ephermal.nix @@ -0,0 +1,64 @@ +{ + hostType, + lib, + ... +}: + +{ + config = lib.mkMerge [ + # Common configuration + { + } + + # Server specific configuration + (lib.mkIf hostType.isServer { + }) + + # Workstation specific configuration + (lib.mkIf hostType.isWorkstation { + boot.initrd.systemd.services.recreate-root = { + description = "Rolling over and creating new filesystem root"; + requires = [ "initrd-root-device.target" ]; + after = [ + "local-fs-pre.target" + "initrd-root-device.target" + ]; + requiredBy = [ "initrd-root-fs.target" ]; + before = [ "sysroot.mount" ]; + unitConfig = { + AssertPathExists = "/etc/initrd-release"; + DefaultDependencies = false; + }; + serviceConfig = { + Type = "oneshot"; + RemainAfterExit = true; + }; + script = '' + mkdir /btrfs_tmp + mount /dev/mapper/cryptroot /btrfs_tmp + + if [[ -e /btrfs_tmp/@root ]]; then + mkdir -p /btrfs_tmp/old_roots + timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S") + mv /btrfs_tmp/@root "/btrfs_tmp/old_roots/$timestamp" + fi + + delete_subvolume_recursively() { + IFS=$'\n' + for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do + delete_subvolume_recursively "/btrfs_tmp/$i" + done + btrfs subvolume delete "$1" + } + + for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do + delete_subvolume_recursively "$i" + done + + btrfs subvolume create /btrfs_tmp/@root + umount /btrfs_tmp + ''; + }; + }) + ]; +} diff --git a/hosts/modules/io/ephermal.nix b/hosts/modules/io/ephermal.nix deleted file mode 100644 index 9ab97f2..0000000 --- a/hosts/modules/io/ephermal.nix +++ /dev/null @@ -1,44 +0,0 @@ -{ - boot.initrd.systemd.services.recreate-root = { - description = "Rolling over and creating new filesystem root"; - requires = [ "initrd-root-device.target" ]; - after = [ - "local-fs-pre.target" - "initrd-root-device.target" - ]; - requiredBy = [ "initrd-root-fs.target" ]; - before = [ "sysroot.mount" ]; - unitConfig = { - AssertPathExists = "/etc/initrd-release"; - DefaultDependencies = false; - }; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - }; - script = '' - mkdir /btrfs_tmp - mount /dev/disk/by-uuid/3638cea6-5503-43cc-aa4f-3d37ebedad2f /btrfs_tmp - if [[ -e /btrfs_tmp/@root ]]; then - mkdir -p /btrfs_tmp/old_roots - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S") - mv /btrfs_tmp/@root "/btrfs_tmp/old_roots/$timestamp" - fi - - delete_subvolume_recursively() { - IFS=$'\n' - for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do - delete_subvolume_recursively "/btrfs_tmp/$i" - done - btrfs subvolume delete "$1" - } - - for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do - delete_subvolume_recursively "$i" - done - - btrfs subvolume create /btrfs_tmp/@root - umount /btrfs_tmp - ''; - }; -} diff --git a/hosts/modules/io/hardware-configuration.nix b/hosts/modules/io/hardware-configuration.nix index 020240f..7d73811 100644 --- a/hosts/modules/io/hardware-configuration.nix +++ b/hosts/modules/io/hardware-configuration.nix @@ -17,59 +17,10 @@ "sd_mod" "sdhci_pci" ]; - luks.devices."enc" = { - device = "/dev/disk/by-uuid/8018720e-42dd-453c-b374-adaa02eb48c9"; - keyFile = "/dev/disk/by-partuuid/cbc7e305-d32d-4250-b6ae-6a8264ea096e"; - }; }; kernelModules = [ "kvm-intel" ]; - }; - - fileSystems = { - "/" = { - device = "/dev/disk/by-uuid/3638cea6-5503-43cc-aa4f-3d37ebedad2f"; - fsType = "btrfs"; - options = [ - "subvol=@root" - "noatime" - "compress=zstd" - ]; - }; - "/home" = { - device = "/dev/disk/by-uuid/3638cea6-5503-43cc-aa4f-3d37ebedad2f"; - fsType = "btrfs"; - options = [ - "subvol=@home" - "noatime" - "compress=zstd" - ]; - }; - "/nix" = { - device = "/dev/disk/by-uuid/3638cea6-5503-43cc-aa4f-3d37ebedad2f"; - fsType = "btrfs"; - options = [ - "subvol=@nix" - "noatime" - "compress=zstd" - ]; - }; - "/persistent" = { - device = "/dev/disk/by-uuid/3638cea6-5503-43cc-aa4f-3d37ebedad2f"; - fsType = "btrfs"; - options = [ - "subvol=@persistent" - "noatime" - "compress=zstd" - ]; - }; - "/boot/efi" = { - device = "/dev/disk/by-uuid/31C9-08FF"; - fsType = "vfat"; - options = [ - "noatime" - "fmask=0077" - "dmask=0077" - ]; + luks.devices.cryptroot = { + device = "/dev/mmcblk1p3"; }; }; @@ -85,4 +36,90 @@ nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + + disko.devices = { + disk = { + main = { + type = "disk"; + device = "/dev/mmcblk1"; + content = { + type = "gpt"; + partitions = { + ESP = { + priority = 1; + name = "ESP"; + start = "1MiB"; + end = "1GiB"; + type = "EF00"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot/efi"; + mountOptions = [ + "noatime" + "fmask=0077" + "dmask=0077" + ]; + }; + }; + swap = { + priority = 2; + name = "swap"; + size = "12G"; + content = { + type = "swap"; + }; + }; + cryptroot = { + priority = 3; + name = "root"; + size = "100%"; + content = { + type = "luks"; + name = "cryptroot"; + content = { + type = "btrfs"; + extraArgs = [ "-f" ]; + subvolumes = { + "@root" = { + mountpoint = "/"; + mountOptions = [ + "noatime" + "compress=zstd" + "subvol=@root" + ]; + }; + "@home" = { + mountpoint = "/home"; + mountOptions = [ + "noatime" + "compress=zstd" + "subvol=@home" + ]; + }; + "@nix" = { + mountpoint = "/nix"; + mountOptions = [ + "noatime" + "compress=zstd" + "subvol=@nix" + ]; + }; + "@persistent" = { + mountpoint = "/persistent"; + mountOptions = [ + "noatime" + "compress=zstd" + "subvol=@persistent" + ]; + }; + }; + }; + }; + }; + }; + }; + }; + }; + }; } diff --git a/hosts/modules/rotterdam/ephermal.nix b/hosts/modules/rotterdam/ephermal.nix deleted file mode 100644 index 8e9c708..0000000 --- a/hosts/modules/rotterdam/ephermal.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ - boot.initrd.systemd.services.recreate-root = { - description = "Rolling over and creating new filesystem root"; - requires = [ "initrd-root-device.target" ]; - after = [ - "local-fs-pre.target" - "initrd-root-device.target" - ]; - requiredBy = [ "initrd-root-fs.target" ]; - before = [ "sysroot.mount" ]; - unitConfig = { - AssertPathExists = "/etc/initrd-release"; - DefaultDependencies = false; - }; - serviceConfig = { - Type = "oneshot"; - RemainAfterExit = true; - }; - script = '' - mkdir /btrfs_tmp - mount /dev/disk/by-uuid/3287dbc3-c0fa-4096-a0b3-59b017cfecc8 /btrfs_tmp - - if [[ -e /btrfs_tmp/@root ]]; then - mkdir -p /btrfs_tmp/old_roots - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp/@root)" "+%Y-%m-%-d_%H:%M:%S") - mv /btrfs_tmp/@root "/btrfs_tmp/old_roots/$timestamp" - fi - - delete_subvolume_recursively() { - IFS=$'\n' - for i in $(btrfs subvolume list -o "$1" | cut -f 9- -d ' '); do - delete_subvolume_recursively "/btrfs_tmp/$i" - done - btrfs subvolume delete "$1" - } - - for i in $(find /btrfs_tmp/old_roots/ -maxdepth 1 -mtime +30); do - delete_subvolume_recursively "$i" - done - - btrfs subvolume create /btrfs_tmp/@root - umount /btrfs_tmp - ''; - }; -}