From 1ea4104d3af12fc5729ab511eedfa0033527f4da Mon Sep 17 00:00:00 2001 From: William Date: Thu, 7 Dec 2023 13:26:36 -0300 Subject: [PATCH] we are not ephemeral --- hosts/common/boot.nix | 2 +- hosts/desktops/rotterdam/default.nix | 2 +- hosts/desktops/rotterdam/ephermal.nix | 45 ++++++++++++++ .../rotterdam/hardware-configuration.nix | 61 +++++++++++-------- 4 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 hosts/desktops/rotterdam/ephermal.nix diff --git a/hosts/common/boot.nix b/hosts/common/boot.nix index 9d4c57f..21dfa9f 100644 --- a/hosts/common/boot.nix +++ b/hosts/common/boot.nix @@ -4,7 +4,7 @@ boot = { loader = { timeout = 1; - efi.canTouchEfiVariables = true; + # efi.canTouchEfiVariables = true; systemd-boot = { enable = true; editor = false; diff --git a/hosts/desktops/rotterdam/default.nix b/hosts/desktops/rotterdam/default.nix index 704aaf0..7627914 100644 --- a/hosts/desktops/rotterdam/default.nix +++ b/hosts/desktops/rotterdam/default.nix @@ -1,5 +1,5 @@ { ... }: { - imports = [ ./hardware-configuration.nix ]; + imports = [ ./hardware-configuration.nix ./ephermal.nix ]; } diff --git a/hosts/desktops/rotterdam/ephermal.nix b/hosts/desktops/rotterdam/ephermal.nix new file mode 100644 index 0000000..f794ba1 --- /dev/null +++ b/hosts/desktops/rotterdam/ephermal.nix @@ -0,0 +1,45 @@ +{ config, lib, pkgs, ... }: + +{ + 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 + rmdir btrfs_tmp + ''; + }; +} diff --git a/hosts/desktops/rotterdam/hardware-configuration.nix b/hosts/desktops/rotterdam/hardware-configuration.nix index f24b973..4a68d06 100644 --- a/hosts/desktops/rotterdam/hardware-configuration.nix +++ b/hosts/desktops/rotterdam/hardware-configuration.nix @@ -1,37 +1,50 @@ -# Do not modify this file! It was generated by ‘nixos-generate-config’ -# and may be overwritten by future invocations. Please make changes -# to /etc/nixos/configuration.nix instead. -{ config, pkgs, lib, modulesPath, ... }: +{ config, lib, modulesPath, ... }: { imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; - boot.initrd.availableKernelModules = - [ "xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-amd" ]; - boot.extraModulePackages = [ ]; - - fileSystems."/" = { - device = "/dev/disk/by-uuid/9ccbb9e3-addc-42a3-b5d8-1e81eed37548"; - fsType = "ext4"; + boot = { + initrd = { + availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usbhid" "sd_mod" ]; + luks.devices."cryptroot".device = + "/dev/disk/by-uuid/f7dd4142-7109-4493-834d-4a831777f08d"; + }; + kernelModules = [ "kvm-amd" ]; }; - fileSystems."/boot/efi" = { - device = "/dev/disk/by-uuid/7707-0E25"; - fsType = "vfat"; + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/3287dbc3-c0fa-4096-a0b3-59b017cfecc8"; + fsType = "btrfs"; + options = [ "subvol=@root" "noatime" "compress=zstd" ]; + }; + "/boot/efi" = { + device = "/dev/disk/by-uuid/1F5A-8945"; + fsType = "vfat"; + options = [ "noatime" "fmask=0077" "dmask=0077" ]; + }; + "/nix" = { + device = "/dev/disk/by-uuid/3287dbc3-c0fa-4096-a0b3-59b017cfecc8"; + fsType = "btrfs"; + options = [ "subvol=@nix" "noatime" "compress=zstd" ]; + }; + "/persistent" = { + device = "/dev/disk/by-uuid/3287dbc3-c0fa-4096-a0b3-59b017cfecc8"; + fsType = "btrfs"; + options = [ "subvol=@persistent" "noatime" "compress=zstd" ]; + }; + "/swap" = { + device = "/dev/disk/by-uuid/3287dbc3-c0fa-4096-a0b3-59b017cfecc8"; + fsType = "btrfs"; + options = [ "subvol=@swap" "noatime" ]; + }; }; - swapDevices = - [{ device = "/dev/disk/by-uuid/39005453-0ac9-4fee-bdd3-7ea9bb6f9ca6"; }]; + swapDevices = [{ device = "/swap/swapfile"; }]; - # Enables DHCP on each ethernet and wireless interface. In case of scripted networking - # (the default) this is the recommended approach. When using systemd-networkd it's - # still possible to use this option, but it's recommended to use it in conjunction - # with explicit per-interface declarations with `networking.interfaces..useDHCP`. networking.useDHCP = lib.mkDefault true; - # networking.interfaces.enp34s0.useDHCP = lib.mkDefault true; - # networking.interfaces.wlo1.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;