mirror of
https://github.com/nix-community/disko.git
synced 2026-12-04 23:13:28 +01:00
swap: allow randomEncryption to take an attrset for extra config
randomEncryption was typed as a plain bool, which just passed enable/allowDiscards down to NixOS's swapDevices.*.randomEncryption submodule, with no way to reach its other options (cipher, sectorSize, etc). Widen the type to bool or an attrset. A bool keeps the old behavior unchanged. An attrset enables encryption by default (overridable via its own enable key) and is merged over the enable/allowDiscards defaults, so extra NixOS randomEncryption options pass through. Fixes #438
This commit is contained in:
1 parent
7fdf779611
commit
9d88a40600
1 file changed
+23
-7
+23
-7
@@ -7,6 +7,13 @@
|
|||||||
device,
|
device,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
let
|
||||||
|
randomEncryptionEnabled =
|
||||||
|
if builtins.isBool config.randomEncryption then
|
||||||
|
config.randomEncryption
|
||||||
|
else
|
||||||
|
config.randomEncryption.enable or true;
|
||||||
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@@ -58,9 +65,17 @@
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
randomEncryption = lib.mkOption {
|
randomEncryption = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.either lib.types.bool (lib.types.attrsOf lib.types.anything);
|
||||||
default = false;
|
default = false;
|
||||||
description = "Whether to randomly encrypt the swap";
|
description = ''
|
||||||
|
Whether to randomly encrypt the swap.
|
||||||
|
|
||||||
|
Can be a plain boolean to just enable/disable it, or an attribute set
|
||||||
|
to pass through additional options to NixOS's
|
||||||
|
`swapDevices.*.randomEncryption` (e.g. `cipher`, `sectorSize`). When
|
||||||
|
given as an attribute set, encryption is enabled unless `enable` is
|
||||||
|
explicitly set to `false`.
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
resumeDevice = lib.mkOption {
|
resumeDevice = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
@@ -81,7 +96,7 @@
|
|||||||
_create = diskoLib.mkCreateOption {
|
_create = diskoLib.mkCreateOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
# TODO: we don't support encrypted swap yet
|
# TODO: we don't support encrypted swap yet
|
||||||
default = lib.optionalString (!config.randomEncryption) ''
|
default = lib.optionalString (!randomEncryptionEnabled) ''
|
||||||
if ! blkid "${config.device}" -o export | grep -q '^TYPE='; then
|
if ! blkid "${config.device}" -o export | grep -q '^TYPE='; then
|
||||||
mkswap \
|
mkswap \
|
||||||
${toString config.extraArgs} \
|
${toString config.extraArgs} \
|
||||||
@@ -92,7 +107,7 @@
|
|||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
# TODO: we don't support encrypted swap yet
|
# TODO: we don't support encrypted swap yet
|
||||||
default = lib.optionalAttrs (!config.randomEncryption) {
|
default = lib.optionalAttrs (!randomEncryptionEnabled) {
|
||||||
fs.${config.device} = ''
|
fs.${config.device} = ''
|
||||||
if test "''${DISKO_SKIP_SWAP:-}" != 1 && ! swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
|
if test "''${DISKO_SKIP_SWAP:-}" != 1 && ! swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
|
||||||
swapon ${
|
swapon ${
|
||||||
@@ -107,7 +122,7 @@
|
|||||||
};
|
};
|
||||||
_unmount = diskoLib.mkUnmountOption {
|
_unmount = diskoLib.mkUnmountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = lib.optionalAttrs (!config.randomEncryption) {
|
default = lib.optionalAttrs (!randomEncryptionEnabled) {
|
||||||
fs.${config.device} = ''
|
fs.${config.device} = ''
|
||||||
if swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
|
if swapon --show | grep -q "^$(readlink -f "${config.device}") "; then
|
||||||
swapoff "${config.device}"
|
swapoff "${config.device}"
|
||||||
@@ -125,10 +140,11 @@
|
|||||||
device = config.device;
|
device = config.device;
|
||||||
inherit (config) discardPolicy priority;
|
inherit (config) discardPolicy priority;
|
||||||
randomEncryption = {
|
randomEncryption = {
|
||||||
enable = config.randomEncryption;
|
enable = randomEncryptionEnabled;
|
||||||
# forward discard/TRIM attempts through dm-crypt
|
# forward discard/TRIM attempts through dm-crypt
|
||||||
allowDiscards = config.discardPolicy != null;
|
allowDiscards = config.discardPolicy != null;
|
||||||
};
|
}
|
||||||
|
// lib.optionalAttrs (!builtins.isBool config.randomEncryption) config.randomEncryption;
|
||||||
options = config.mountOptions;
|
options = config.mountOptions;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in new issue
Block a user