summaryrefslogtreecommitdiffstats
path: root/nixos/modules/system/boot/stratisroot.nix
blob: 349133ab540c352e6a6c1512cfdcf1073f53469f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
{
  config,
  lib,
  pkgs,
  utils,
  ...
}:
let
  requiredStratisFilesystems = lib.attrsets.filterAttrs (
    _: x: utils.fsNeededForBoot x && x.stratis.poolUuid != null
  ) config.fileSystems;
in
{
  options = { };
  config = lib.mkIf (requiredStratisFilesystems != { }) {
    assertions = [
      {
        assertion = config.boot.initrd.systemd.enable;
        message = "stratis root fs requires systemd stage 1";
      }
    ];
    boot.initrd = {
      systemd = {
        storePaths = [
          "${pkgs.stratisd}/lib/udev/stratis-base32-decode"
          "${pkgs.stratisd}/lib/udev/stratis-str-cmp"
          "${pkgs.lvm2.bin}/bin/dmsetup"
          "${pkgs.stratisd}/libexec/stratisd-min"
          "${pkgs.stratisd.initrd}/bin/stratis-rootfs-setup"
        ];
        packages = [ pkgs.stratisd.initrd ];
        extraBin = {
          thin_check = "${pkgs."thin-provisioning-tools"}/bin/thin_check";
          thin_repair = "${pkgs."thin-provisioning-tools"}/bin/thin_repair";
          thin_metadata_size = "${pkgs."thin-provisioning-tools"}/bin/thin_metadata_size";
          stratis-min = "${pkgs.stratisd}/bin/stratis-min";
        };
        services = lib.attrsets.mapAttrs' (mountPoint: fileSystem: {
          name = "stratis-setup-${fileSystem.stratis.poolUuid}";
          value = {
            description = "setup for Stratis root filesystem";
            unitConfig.DefaultDependencies = "no";
            conflicts = [
              "shutdown.target"
              "initrd-switch-root.target"
            ];
            onFailure = [ "emergency.target" ];
            unitConfig.OnFailureJobMode = "isolate";
            wants = [
              "stratisd-min.service"
              "plymouth-start.service"
            ];
            wantedBy = [ "initrd.target" ];
            after = [
              "paths.target"
              "plymouth-start.service"
              "stratisd-min.service"
            ];
            before = [
              "initrd.target"
              "shutdown.target"
              "initrd-switch-root.target"
            ];
            environment.STRATIS_ROOTFS_UUID = fileSystem.stratis.poolUuid;
            serviceConfig = {
              Type = "oneshot";
              ExecStart = "${pkgs.stratisd.initrd}/bin/stratis-rootfs-setup";
              RemainAfterExit = "yes";
            };
          };
        }) requiredStratisFilesystems;
      };
      availableKernelModules = [
        "dm-thin-pool"
        "dm-crypt"
      ]
      ++ [
        "aes"
        "blowfish"
        "twofish"
        "serpent"
        "cbc"
        "xts"
        "lrw"
        "sha1"
        "sha256"
        "sha512"
        "af_alg"
        "algif_skcipher"
      ];
      services.udev.packages = [
        pkgs.stratisd.initrd
        pkgs.lvm2
      ];
    };
  };
}