@@ -5,6 +5,52 @@ with lib;
55
66let
77
8+ randomEncryptionCoerce = enable: { inherit enable; };
9+
10+ randomEncryptionOpts = { ... }: {
11+
12+ options = {
13+
14+ enable = mkOption {
15+ default = false;
16+ type = types.bool;
17+ description = ''
18+ Encrypt swap device with a random key. This way you won't have a persistent swap device.
19+
20+ WARNING: Don't try to hibernate when you have at least one swap partition with
21+ this option enabled! We have no way to set the partition into which hibernation image
22+ is saved, so if your image ends up on an encrypted one you would lose it!
23+
24+ WARNING #2: Do not use /dev/disk/by-uuid/… or /dev/disk/by-label/… as your swap device
25+ when using randomEncryption as the UUIDs and labels will get erased on every boot when
26+ the partition is encrypted. Best to use /dev/disk/by-partuuid/…
27+ '';
28+ };
29+
30+ cipher = mkOption {
31+ default = "aes-xts-plain64";
32+ example = "serpent-xts-plain64";
33+ type = types.str;
34+ description = ''
35+ Use specified cipher for randomEncryption.
36+
37+ Hint: Run "cryptsetup benchmark" to see which one is fastest on your machine.
38+ '';
39+ };
40+
41+ source = mkOption {
42+ default = "/dev/urandom";
43+ example = "/dev/random";
44+ type = types.str;
45+ description = ''
46+ Define the source of randomness to obtain a random key for encryption.
47+ '';
48+ };
49+
50+ };
51+
52+ };
53+
854 swapCfg = {config, options, ...}: {
955
1056 options = {
@@ -45,12 +91,19 @@ let
4591 '';
4692 };
4793
48− randomEncryption.enable = mkOption {
94+ randomEncryption = mkOption {
4995 default = false;
50− type = types.bool;
96+ example = {
97+ enable = true;
98+ cipher = "serpent-xts-plain64";
99+ source = "/dev/random";
100+ };
101+ type = types.coercedTo types.bool randomEncryptionCoerce (types.submodule randomEncryptionOpts);
51102 description = ''
52103 Encrypt swap device with a random key. This way you won't have a persistent swap device.
53104
105+ HINT: run "cryptsetup benchmark" to test cipher performance on your machine.
106+
54107 WARNING: Don't try to hibernate when you have at least one swap partition with
55108 this option enabled! We have no way to set the partition into which hibernation image
56109 is saved, so if your image ends up on an encrypted one you would lose it!
@@ -61,26 +114,6 @@ let
61114 '';
62115 };
63116
64− randomEncryption.cipher = mkOption {
65− default = "aes-xts-plain64";
66− example = "serpent-xts-plain64";
67− type = types.str;
68− description = ''
69− Use specified cipher for randomEncryption.
70−
71− Hint: Run "cryptsetup benchmark" to see which one is fastest on your machine.
72− '';
73− };
74−
75− randomEncryption.source = mkOption {
76− default = "/dev/urandom";
77− example = "/dev/random";
78− type = types.str;
79− description = ''
80− Define the source of randomness to obtain a random key for encryption.
81− '';
82− };
83−
84117 deviceName = mkOption {
85118 type = types.str;
86119 internal = true;