From 379831e348e0c7b07a47945cbd9e95e0bef79caf Mon Sep 17 00:00:00 2001 From: William Date: Sun, 18 Feb 2024 21:26:36 -0300 Subject: [PATCH] io is now ephermal --- hosts/desktops/io/default.nix | 2 +- hosts/desktops/io/ephermal.nix | 44 +++++++++++++ hosts/desktops/io/hardware-configuration.nix | 69 +++++++++++++------- 3 files changed, 89 insertions(+), 26 deletions(-) create mode 100644 hosts/desktops/io/ephermal.nix diff --git a/hosts/desktops/io/default.nix b/hosts/desktops/io/default.nix index 704aaf0..3b3c6ee 100644 --- a/hosts/desktops/io/default.nix +++ b/hosts/desktops/io/default.nix @@ -1,5 +1,5 @@ { ... }: { - imports = [ ./hardware-configuration.nix ]; + imports = [ ./ephermal.nix ./hardware-configuration.nix ]; } diff --git a/hosts/desktops/io/ephermal.nix b/hosts/desktops/io/ephermal.nix new file mode 100644 index 0000000..7bfc484 --- /dev/null +++ b/hosts/desktops/io/ephermal.nix @@ -0,0 +1,44 @@ +{ 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/ef1916a9-e15c-450e-8100-4b2af9f6e1a5 /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 + ''; + }; +} \ No newline at end of file diff --git a/hosts/desktops/io/hardware-configuration.nix b/hosts/desktops/io/hardware-configuration.nix index c2497a1..d1939c1 100644 --- a/hosts/desktops/io/hardware-configuration.nix +++ b/hosts/desktops/io/hardware-configuration.nix @@ -1,40 +1,59 @@ -# 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" "usb_storage" "sd_mod" "sdhci_pci" ]; - boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; - boot.extraModulePackages = [ ]; - - fileSystems."/" = { - device = "/dev/disk/by-uuid/2321ee32-a952-4a4b-bba0-bb25f616a4a5"; - fsType = "ext4"; + boot = { + initrd = { + availableKernelModules = + [ "xhci_pci" "ahci" "usb_storage" "sd_mod" "sdhci_pci" ]; + luks.devices."cryptroot".device = + "/dev/disk/by-uuid/37c930c5-2b31-4d18-a1c4-7f13e0412656"; + }; + kernelModules = [ "kvm-intel" ]; }; - boot.initrd.luks.devices."luks-008bb7cb-917c-4dda-93fe-542c2285bafb".device = - "/dev/disk/by-uuid/008bb7cb-917c-4dda-93fe-542c2285bafb"; - - fileSystems."/boot/efi" = { - device = "/dev/disk/by-uuid/36B4-C473"; - fsType = "vfat"; + fileSystems = { + "/" = { + device = "/dev/disk/by_uuid/ef1916a9-e15c-450e-8100-4b2af9f6e1a5"; + fsType = "btrfs"; + options = [ "subvol=@root" "noatime" "compress=zstd" ]; + }; + "/home" = { + device = "/dev/disk/by_uuid/ef1916a9-e15c-450e-8100-4b2af9f6e1a5"; + fsType = "btrfs"; + options = [ "subvol=@home" "noatime" "compress=zstd" ]; + }; + "/boot/efi" = { + device = "/dev/disk/by-uuid/36B4-C473"; + fsType = "vfat"; + options = [ "noatime" "fmask=0077" "dmask=0077" ]; + }; + "/nix" = { + device = "/dev/disk/by_uuid/ef1916a9-e15c-450e-8100-4b2af9f6e1a5"; + fsType = "btrfs"; + options = [ "subvol=@nix" "noatime" "compress=zstd" ]; + }; + "/persistent" = { + device = "/dev/disk/by_uuid/ef1916a9-e15c-450e-8100-4b2af9f6e1a5"; + fsType = "btrfs"; + options = [ "subvol=@persistent" "noatime" "compress=zstd" ]; + }; + "/swap" = { + device = "/dev/disk/by_uuid/ef1916a9-e15c-450e-8100-4b2af9f6e1a5"; + fsType = "btrfs"; + options = [ "subvol=@swap" "noatime" ]; + }; }; - swapDevices = [ ]; + swapDevices = [{ "/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.wlp0s20f3.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64"; powerManagement.cpuFreqGovernor = lib.mkDefault "powersave"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; }