diff --git a/hosts/boron.cx.ts.hillion.co.uk/default.nix b/hosts/boron.cx.ts.hillion.co.uk/default.nix index a434d94..7c703b2 100644 --- a/hosts/boron.cx.ts.hillion.co.uk/default.nix +++ b/hosts/boron.cx.ts.hillion.co.uk/default.nix @@ -41,7 +41,14 @@ fileSystems."/nix".options = [ "compress=zstd" ]; ## Impermanence - custom.impermanence.enable = true; + custom.impermanence = { + enable = true; + cache.enable = true; + }; + boot.initrd.postDeviceCommands = lib.mkAfter '' + btrfs subvolume delete /cache/tmp + btrfs subvolume snapshot /cache/empty_snapshot /cache/tmp + ''; ## Custom Services custom = { diff --git a/hosts/boron.cx.ts.hillion.co.uk/hardware-configuration.nix b/hosts/boron.cx.ts.hillion.co.uk/hardware-configuration.nix index 3d22afe..0bdb02d 100644 --- a/hosts/boron.cx.ts.hillion.co.uk/hardware-configuration.nix +++ b/hosts/boron.cx.ts.hillion.co.uk/hardware-configuration.nix @@ -35,6 +35,13 @@ options = [ "subvol=data" ]; }; + fileSystems."/cache" = + { + device = "/dev/disk/by-uuid/9aebe351-156a-4aa0-9a97-f09b01ac23ad"; + fsType = "btrfs"; + options = [ "subvol=cache" ]; + }; + fileSystems."/nix" = { device = "/dev/disk/by-uuid/9aebe351-156a-4aa0-9a97-f09b01ac23ad"; diff --git a/hosts/sodium.pop.ts.hillion.co.uk/default.nix b/hosts/sodium.pop.ts.hillion.co.uk/default.nix index 0abd12d..f7a975d 100644 --- a/hosts/sodium.pop.ts.hillion.co.uk/default.nix +++ b/hosts/sodium.pop.ts.hillion.co.uk/default.nix @@ -22,12 +22,13 @@ fileSystems."/nix".options = [ "compress=zstd" ]; ## Impermanence - custom.impermanence.enable = true; + custom.impermanence = { + enable = true; + cache.enable = true; + }; boot.initrd.postDeviceCommands = lib.mkAfter '' btrfs subvolume delete /cache/tmp btrfs subvolume snapshot /cache/empty_snapshot /cache/tmp - chmod 0777 /cache/tmp - chmod +t /cache/tmp ''; ## CA server diff --git a/modules/impermanence.nix b/modules/impermanence.nix index 49a661d..fd8343f 100644 --- a/modules/impermanence.nix +++ b/modules/impermanence.nix @@ -11,6 +11,13 @@ in type = lib.types.str; default = "/data"; }; + cache = { + enable = lib.mkEnableOption "impermanence.cache"; + path = lib.mkOption { + type = lib.types.str; + default = "/cache/tmp"; + }; + }; users = lib.mkOption { type = with lib.types; listOf str; @@ -39,20 +46,31 @@ in gitea.stateDir = "${cfg.base}/system/var/lib/gitea"; }; - environment.persistence."${cfg.base}/system" = { - hideMounts = true; + environment.persistence = lib.mkMerge [ + { + "${cfg.base}/system" = { + hideMounts = true; - directories = [ - "/etc/nixos" - ] ++ (lib.lists.optional config.services.tailscale.enable "/var/lib/tailscale") ++ - (lib.lists.optional config.services.zigbee2mqtt.enable config.services.zigbee2mqtt.dataDir) ++ - (lib.lists.optional config.services.postgresql.enable config.services.postgresql.dataDir) ++ - (lib.lists.optional config.hardware.bluetooth.enable "/var/lib/bluetooth") ++ - (lib.lists.optional config.custom.services.unifi.enable "/var/lib/unifi") ++ - (lib.lists.optional (config.virtualisation.oci-containers.containers != { }) "/var/lib/containers") ++ - (lib.lists.optional config.services.tang.enable "/var/lib/private/tang") ++ - (lib.lists.optional config.services.step-ca.enable "/var/lib/step-ca/db"); - }; + directories = [ + "/etc/nixos" + ] ++ (lib.lists.optional config.services.tailscale.enable "/var/lib/tailscale") ++ + (lib.lists.optional config.services.zigbee2mqtt.enable config.services.zigbee2mqtt.dataDir) ++ + (lib.lists.optional config.services.postgresql.enable config.services.postgresql.dataDir) ++ + (lib.lists.optional config.hardware.bluetooth.enable "/var/lib/bluetooth") ++ + (lib.lists.optional config.custom.services.unifi.enable "/var/lib/unifi") ++ + (lib.lists.optional (config.virtualisation.oci-containers.containers != { }) "/var/lib/containers") ++ + (lib.lists.optional config.services.tang.enable "/var/lib/private/tang") ++ + (lib.lists.optional config.services.step-ca.enable "/var/lib/step-ca/db"); + }; + } + (lib.mkIf cfg.cache.enable { + "${cfg.cache.path}/system" = { + hideMounts = true; + + directories = (lib.lists.optional config.services.postgresqlBackup.enable config.services.postgresqlBackup.location); + }; + }) + ]; home-manager.users = let