From 3d642e2320184d95fee224cd75defafc66a086bf Mon Sep 17 00:00:00 2001 From: Jake Hillion Date: Fri, 9 Aug 2024 23:08:35 +0100 Subject: [PATCH] boron: move postgresqlBackup to disk to reduce ram pressure --- hosts/boron.cx.ts.hillion.co.uk/default.nix | 9 +++- .../hardware-configuration.nix | 7 +++ hosts/sodium.pop.ts.hillion.co.uk/default.nix | 8 ++-- modules/impermanence.nix | 44 +++++++++++++------ 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/hosts/boron.cx.ts.hillion.co.uk/default.nix b/hosts/boron.cx.ts.hillion.co.uk/default.nix index a434d94..95baa71 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/system + btrfs subvolume snapshot /cache/empty_snapshot /cache/system + ''; ## 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..15b8a0a 100644 --- a/hosts/sodium.pop.ts.hillion.co.uk/default.nix +++ b/hosts/sodium.pop.ts.hillion.co.uk/default.nix @@ -22,12 +22,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 - chmod 0777 /cache/tmp - chmod +t /cache/tmp + chmod 1777 /cache/tmp ''; ## CA server diff --git a/modules/impermanence.nix b/modules/impermanence.nix index 49a661d..84e468d 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"; + }; + }; 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