Skip to content

swap: allow randomEncryption to take an attrset for extra config - #1285

Open
yottanami wants to merge 2 commits into
nix-community:masterfrom
yottanami:agent/52-randomEncryption-extra-config
Open

swap: allow randomEncryption to take an attrset for extra config#1285
yottanami wants to merge 2 commits into
nix-community:masterfrom
yottanami:agent/52-randomEncryption-extra-config

Conversation

@yottanami

Copy link
Copy Markdown

randomEncryption on the swap partition type was typed as a plain bool, which only ever built { enable = ...; allowDiscards = ...; } for NixOS's swapDevices.*.randomEncryption submodule — there was no way to reach its other options (cipher, sectorSize, etc.), as noted in the issue.

Per the maintainer's suggestion in the issue thread, this widens the type to lib.types.either lib.types.bool (lib.types.attrsOf lib.types.anything):

  • A plain true/false keeps the exact old behavior (backwards compatible — verified both existing in-repo usages, example/swap.nix and tests/mdadm-btrfs-wipe.nix, still use a bare bool and are unaffected).
  • An attrset enables encryption by default (enable = true, overridable by setting enable in the attrset), and is merged over the enable/allowDiscards defaults so any extra NixOS randomEncryption options (cipher, sectorSize, ...) pass straight through.

Also introduced a randomEncryptionEnabled derived boolean (config.randomEncryption when it's a bool, else .enable or true) since the rest of the module (_create/_mount/_unmount) branches on whether random encryption is active at all, and ! doesn't work on an attrset.

I don't have a local Nix environment to run nix flake check / the test suite against this change — flagging that so a maintainer/CI can verify directly.

Fixes #438

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 nix-community#438
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

randomEncryption does not support extended configuration from NixOS module

1 participant