summaryrefslogtreecommitdiff
path: root/sys/boot/impermanence.nix
blob: 632094b384f9c53c7f032fe9cc2869b1f621a5b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
  config,
  lib,
  ...
}:
with lib; let
  cfg = config.local.boot.impermanence;
in {
  options.local.boot.impermanence = {
    enable = mkEnableOption "root fs impermanence";

    #TODO: type correcto de files, directories?

    directories = mkOption {
      type = with lib.types; listOf (either str attrs);
      default = [];
    };

    files = mkOption {
      type = with lib.types; listOf (either str attrs);
      default = [];
    };
  };

  config = mkMerge [
    {
      local.boot.impermanence = {
        directories = [
          "/etc/lvm"
          "/var/lib/nixos"
          "/var/log"
        ];

        files = [
          "/etc/machine-id"
          "/var/lib/logrotate.status"
        ];
      };
    }
    (mkIf cfg.enable {
      assertions = [
        {
          assertion = (config.fileSystems ? "/persist") && config.fileSystems."/persist".neededForBoot;
          message = "Impermanence requires /persist to be a neededForBoot mountpoint";
        }
      ];

      environment.persistence."/persist" = {
        hideMounts = true;

        files = cfg.files;
        directories = cfg.directories;
      };
    })
  ];
}