diff --git a/flake.lock b/flake.lock index 0c27ced..178720e 100644 --- a/flake.lock +++ b/flake.lock @@ -192,6 +192,21 @@ "type": "github" } }, + "impermanence": { + "locked": { + "lastModified": 1737831083, + "narHash": "sha256-LJggUHbpyeDvNagTUrdhe/pRVp4pnS6wVKALS782gRI=", + "owner": "nix-community", + "repo": "impermanence", + "rev": "4b3e914cdf97a5b536a889e939fb2fd2b043a170", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "impermanence", + "type": "github" + } + }, "nixos-hardware": { "locked": { "lastModified": 1756750488, @@ -280,6 +295,7 @@ "firefox-addons": "firefox-addons", "flake-parts": "flake-parts", "home-manager": "home-manager", + "impermanence": "impermanence", "nixos-hardware": "nixos-hardware", "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", diff --git a/flake.nix b/flake.nix index e09b15d..0a37437 100644 --- a/flake.nix +++ b/flake.nix @@ -8,6 +8,8 @@ nixos-hardware.url = "github:NixOS/nixos-hardware/master"; + impermanence.url = "github:nix-community/impermanence"; + home-manager = { url = "github:nix-community/home-manager/release-25.05"; inputs.nixpkgs.follows = "nixpkgs"; @@ -68,6 +70,7 @@ ./flake/dev-shell.nix ./flake/formatter.nix ./flake/hosts.nix + ./flake/install-anywhere.nix ./flake/modules.nix ./flake/sops.nix ]; diff --git a/modules/system/impermanence.nix b/modules/system/impermanence.nix new file mode 100644 index 0000000..b544219 --- /dev/null +++ b/modules/system/impermanence.nix @@ -0,0 +1,39 @@ +{ + config, + inputs, + lib, + ... +}: +let + cfg = config.custom.impermanence; + + inherit (config.custom) services; +in +{ + imports = [ inputs.impermanence.nixosModules.impermanence ]; + + options.custom.impermanence.enable = lib.mkEnableOption ""; + + config = lib.mkIf cfg.enable { + fileSystems."/persist".neededForBoot = true; + + environment.persistence."/persist" = { + hideMounts = true; + + # See https://nixos.org/manual/nixos/stable/#ch-system-state + directories = [ + "/var/lib/nixos" + "/var/lib/systemd" + "/var/log/journal" + + (lib.optionalString services.tailscale.enable "/var/lib/tailscale") + ]; + + files = [ + "/etc/machine-id" + "/etc/ssh/ssh_host_ed25519_key" + "/etc/ssh/ssh_host_ed25519_key.pub" + ]; + }; + }; +}