Skip to content

Commit 001c4e7

Browse files
committed
add wip verity
1 parent d32f2d1 commit 001c4e7

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

lib/types/verity.nix

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
{ config, options, lib, diskoLib, parent, device, ... }:
2+
{
3+
options = {
4+
type = lib.mkOption {
5+
type = lib.types.enum [ "luks" ];
6+
internal = true;
7+
description = "Type";
8+
};
9+
device = lib.mkOption {
10+
type = lib.types.str;
11+
description = "Device to encrypt";
12+
default = device;
13+
};
14+
name = lib.mkOption {
15+
type = lib.types.str;
16+
description = "Name of the LUKS";
17+
};
18+
keyFile = lib.mkOption {
19+
type = lib.types.nullOr diskoLib.optionTypes.absolute-pathname;
20+
default = null;
21+
description = "DEPRECATED use passwordFile or settings.keyFile. Path to the key for encryption";
22+
example = "/tmp/disk.key";
23+
};
24+
settings = lib.mkOption {
25+
type = lib.types.attrsOf lib.types.anything;
26+
default = { };
27+
description = "veritysetup settings (as defined in configuration.nix in boot.initrd.luks.devices.<name>)";
28+
example = ''{
29+
};'';
30+
};
31+
additionalKeyFiles = lib.mkOption {
32+
type = lib.types.listOf diskoLib.optionTypes.absolute-pathname;
33+
default = [ ];
34+
description = "Path to additional key files for encryption";
35+
example = [ "/tmp/disk2.key" ];
36+
};
37+
extraFormatArgs = lib.mkOption {
38+
type = lib.types.listOf lib.types.str;
39+
default = [ ];
40+
description = "Extra arguments to pass to `cryptsetup luksFormat` when formatting";
41+
example = [ "--pbkdf argon2id" ];
42+
};
43+
extraOpenArgs = lib.mkOption {
44+
type = lib.types.listOf lib.types.str;
45+
default = [ ];
46+
description = "Extra arguments to pass to `cryptsetup luksOpen` when opening";
47+
example = [ "--timeout 10" ];
48+
};
49+
content = diskoLib.deviceType { parent = config; device = "/dev/mapper/${config.name}"; };
50+
_parent = lib.mkOption {
51+
internal = true;
52+
default = parent;
53+
};
54+
_meta = lib.mkOption {
55+
internal = true;
56+
readOnly = true;
57+
type = lib.types.functionTo diskoLib.jsonType;
58+
default = dev:
59+
lib.optionalAttrs (config.content != null) (config.content._meta dev);
60+
description = "Metadata";
61+
};
62+
_create = diskoLib.mkCreateOption {
63+
inherit config options;
64+
default = lib.optionalString (config.content != null) config.content._create;
65+
};
66+
_mount = diskoLib.mkMountOption {
67+
inherit config options;
68+
default = lib.optionalString (config.content != null) config.content._mount;
69+
};
70+
_unmount = diskoLib.mkMountOption {
71+
inherit config options;
72+
default = lib.optionalAttrs (config.content != null) config.content._unmount;
73+
};
74+
_config = lib.mkOption {
75+
internal = true;
76+
readOnly = true;
77+
default = [
78+
({config, ...}: {
79+
# TODO: upstream this.
80+
assertions = [
81+
{
82+
assertion = config.boot.inird.systemd.enable;
83+
message = ''
84+
veritysetup with disko requires systemd in the initrd to be enabled.
85+
'';
86+
}
87+
];
88+
boot.initrd = {
89+
availableKernelModules = [
90+
"dm_mod"
91+
"dm_verity"
92+
];
93+
# We need LVM for dm-verity to work.
94+
services.lvm.enable = true;
95+
96+
systemd = {
97+
additionalUpstreamUnits = [
98+
"veritysetup-pre.target"
99+
"veritysetup.target"
100+
"remote-veritysetup.target"
101+
];
102+
storePaths = [
103+
"${config.boot.initrd.systemd.package}/lib/systemd/systemd-veritysetup"
104+
"${config.boot.initrd.systemd.package}/lib/systemd/system-generators/systemd-veritysetup-generator"
105+
];
106+
};
107+
};
108+
})
109+
] ++ (lib.optional (config.content != null) config.content._config);
110+
description = "NixOS configuration";
111+
};
112+
_pkgs = lib.mkOption {
113+
internal = true;
114+
readOnly = true;
115+
type = lib.types.functionTo (lib.types.listOf lib.types.package);
116+
default = pkgs: [ pkgs.veritysetup ] ++ (lib.optionals (config.content != null) (config.content._pkgs pkgs));
117+
description = "Packages";
118+
};
119+
};
120+
config = {
121+
postUnmountHook = ''
122+
veritysetup format ${config.device} ${config.name} ${lib.concatStringsSep " " config.extraFormatArgs}
123+
'';
124+
};
125+
}

0 commit comments

Comments
 (0)