From d69f6effd4bea0c8b1d84a3b7ba199ab81af747e Mon Sep 17 00:00:00 2001 From: chn Date: Tue, 25 Jul 2023 23:33:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86services?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 7 +++- modules/boot/chn-PC.nix | 43 ----------------------- modules/services/default.nix | 68 ++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 44 deletions(-) delete mode 100644 modules/boot/chn-PC.nix create mode 100644 modules/services/default.nix diff --git a/flake.nix b/flake.nix index fce09bac..91796239 100644 --- a/flake.nix +++ b/flake.nix @@ -149,6 +149,7 @@ ./modules/boot ./modules/system ./modules/virtualization + ./modules/services (inputs: { config = { nixos = @@ -233,6 +234,11 @@ kvmGuest.enable = true; nspawn = [ "arch" "ubuntu-22.04" ]; }; + services = + { + impermanence.enable = true; + snapper = { enable = true; configs.persistent = "/nix/persistent"; }; + }; }; boot.kernelParams = [ "i915.force_probe=46a6" ]; }; }) @@ -240,7 +246,6 @@ ./modules/basic.nix ./modules/fonts.nix ./modules/sops.nix - ./modules/boot/chn-PC.nix [ ./modules/hardware/nvidia-prime.nix { intelBusId = "PCI:0:2:0"; nvidiaBusId = "PCI:1:0:0"; } ] ./modules/hardware/chn-PC.nix ./modules/networking/samba.nix diff --git a/modules/boot/chn-PC.nix b/modules/boot/chn-PC.nix deleted file mode 100644 index 670b4c04..00000000 --- a/modules/boot/chn-PC.nix +++ /dev/null @@ -1,43 +0,0 @@ -inputs: -{ - config = - { - # impermanence - environment.persistence."/nix/persistent" = - { - hideMounts = true; - directories = - [ - "/etc/NetworkManager/system-connections" - "/home" - "/root" - "/var" - ]; - files = - [ - "/etc/machine-id" - "/etc/ssh/ssh_host_ed25519_key.pub" - "/etc/ssh/ssh_host_ed25519_key" - "/etc/ssh/ssh_host_rsa_key.pub" - "/etc/ssh/ssh_host_rsa_key" - ]; - }; - - # services - services = - { - snapper.configs.persistent = - { - SUBVOLUME = "/nix/persistent"; - TIMELINE_CREATE = true; - TIMELINE_CLEANUP = true; - TIMELINE_MIN_AGE = 1800; - TIMELINE_LIMIT_HOURLY = "10"; - TIMELINE_LIMIT_DAILY = "7"; - TIMELINE_LIMIT_WEEKLY = "1"; - TIMELINE_LIMIT_MONTHLY = "0"; - TIMELINE_LIMIT_YEARLY = "0"; - }; - }; - }; -} diff --git a/modules/services/default.nix b/modules/services/default.nix new file mode 100644 index 00000000..c301508a --- /dev/null +++ b/modules/services/default.nix @@ -0,0 +1,68 @@ +inputs: +{ + options.nixos.services = let inherit (inputs.lib) mkOption types; in + { + impermanence = + { + enable = mkOption { type = types.bool; default = false; }; + persistence = mkOption { type = types.nonEmptyStr; default = "/nix/persistent"; }; + }; + snapper = + { + enable = mkOption { type = types.bool; default = false; }; + configs = mkOption { type = types.attrsOf types.nonEmptyStr; default = {}; }; + }; + }; + config = let inherit (inputs.lib) mkMerge mkIf; inherit (inputs.localLib) stripeTabs attrsToList; in mkMerge + [ + ( + mkIf inputs.config.nixos.services.impermanence.enable + { + environment.persistence."${inputs.config.nixos.services.impermanence.persistence}" = + { + hideMounts = true; + directories = + [ + "/etc/NetworkManager/system-connections" + "/home" + "/root" + "/var" + ]; + files = + [ + "/etc/machine-id" + "/etc/ssh/ssh_host_ed25519_key.pub" + "/etc/ssh/ssh_host_ed25519_key" + "/etc/ssh/ssh_host_rsa_key.pub" + "/etc/ssh/ssh_host_rsa_key" + ]; + }; + } + ) + ( + mkIf inputs.config.nixos.services.snapper.enable + { + services.snapper.configs = + let + f = (config: + { + inherit (config) name; + value = + { + SUBVOLUME = config.value; + TIMELINE_CREATE = true; + TIMELINE_CLEANUP = true; + TIMELINE_MIN_AGE = 1800; + TIMELINE_LIMIT_HOURLY = "10"; + TIMELINE_LIMIT_DAILY = "7"; + TIMELINE_LIMIT_WEEKLY = "1"; + TIMELINE_LIMIT_MONTHLY = "0"; + TIMELINE_LIMIT_YEARLY = "0"; + }; + }); + in + builtins.listToAttrs (builtins.map f (attrsToList inputs.config.nixos.services.snapper.configs)); + } + ) + ]; +}