From f90f7cf8a4e36103f50a83cecf4ee2fa7ff46455 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 17 May 2024 00:37:19 +0100 Subject: [PATCH] working btrfs impermanence & added lvm to disko --- hosts/common/disks/std-disk-config.nix | 29 +++++++++++++---- hosts/common/optional/btrfs-impermanence.nix | 9 +++--- hosts/media/default.nix | 1 + hosts/media/hardware-configuration.nix | 34 +------------------- 4 files changed, 29 insertions(+), 44 deletions(-) diff --git a/hosts/common/disks/std-disk-config.nix b/hosts/common/disks/std-disk-config.nix index 1f30607..cf44fb6 100644 --- a/hosts/common/disks/std-disk-config.nix +++ b/hosts/common/disks/std-disk-config.nix @@ -19,23 +19,38 @@ mountpoint = "/boot"; }; }; - root = { - size = "100%"; - content = { - type = "btrfs"; - extraArgs = [ "-f" ]; # Override existing partition + root = { + name = "root"; + size = "100%"; + content = { + type = "lvm_pv"; + vg = "root_vg"; + }; + }; + }; + }; + }; + lvm_vg = { + root_vg = { + type = "lvm_vg"; + lvs = { + root = { + size = "100%FREE"; + content = { + type = "btrfs"; + extraArgs = ["-f"]; subvolumes = { "/root" = { mountpoint = "/"; }; "/persist" = { - mountOptions = [ "compress=zstd" ]; + mountOptions = [ "subvol=persist" ]; mountpoint = "/persist"; }; "/nix" = { - mountOptions = [ "compress=zstd" "noatime" ]; + mountOptions = [ "subvol=nix" "noatime" ]; mountpoint = "/nix"; }; diff --git a/hosts/common/optional/btrfs-impermanence.nix b/hosts/common/optional/btrfs-impermanence.nix index 9e7fb46..3fdb60f 100644 --- a/hosts/common/optional/btrfs-impermanence.nix +++ b/hosts/common/optional/btrfs-impermanence.nix @@ -1,11 +1,12 @@ +{lib, ...}: { boot.initrd.postDeviceCommands = lib.mkAfter '' - mkdir /btrfs_tmp - mount / /btrfs_tmp + mkdir /btrfs_tmp + mount /dev/root_vg/root /btrfs_tmp if [[ -e /btrfs_tmp/root ]]; then mkdir -p /btrfs_tmp/old_roots - timestamp=$(date --date="@$(stat -c %Y /btrfs_tmp)" "+%Y-%m-%-d_%H:%M:%S") - mv /btrfs_tmp "/btrfs_tmp/old_roots/$timestamp" + 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() { diff --git a/hosts/media/default.nix b/hosts/media/default.nix index d24cbb4..3fdaa34 100644 --- a/hosts/media/default.nix +++ b/hosts/media/default.nix @@ -6,6 +6,7 @@ # Disk configuration inputs.disko.nixosModules.disko (import ../common/disks/std-disk-config.nix { device = "/dev/vda"; }) + ../common/optional/btrfs-impermanence.nix # Import core options ./hardware-configuration.nix diff --git a/hosts/media/hardware-configuration.nix b/hosts/media/hardware-configuration.nix index 42455ba..f9c2647 100644 --- a/hosts/media/hardware-configuration.nix +++ b/hosts/media/hardware-configuration.nix @@ -10,41 +10,9 @@ boot.initrd.availableKernelModules = [ "ahci" "xhci_pci" "virtio_pci" "sr_mod" "virtio_blk" ]; boot.initrd.kernelModules = [ ]; - boot.kernelModules = [ "kvm-intel" ]; + boot.kernelModules = [ "kvm-amd" ]; boot.extraModulePackages = [ ]; - fileSystems."/" = - { device = "/dev/disk/by-uuid/debf250f-70e6-46ef-85b4-c47752bd5ba4"; - fsType = "btrfs"; - options = [ "subvol=root" ]; - }; - - fileSystems."/nix" = - { device = "/dev/disk/by-uuid/debf250f-70e6-46ef-85b4-c47752bd5ba4"; - fsType = "btrfs"; - options = [ "subvol=nix" ]; - }; - - fileSystems."/.swapvol" = - { device = "/dev/disk/by-uuid/debf250f-70e6-46ef-85b4-c47752bd5ba4"; - fsType = "btrfs"; - options = [ "subvol=swap" ]; - }; - - fileSystems."/persist" = - { device = "/dev/disk/by-uuid/debf250f-70e6-46ef-85b4-c47752bd5ba4"; - fsType = "btrfs"; - options = [ "subvol=persist" ]; - }; - - fileSystems."/boot" = - { device = "/dev/disk/by-uuid/A9BB-DDED"; - fsType = "vfat"; - options = [ "fmask=0022" "dmask=0022" ]; - }; - - swapDevices = [ ]; - # 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