Other than:
- repeating the entire list of submodules
- ignoring the warning and modifying
hardware-configuration.nix
anyway
is there another / better(?) way for me to modify an attribute of a list of submodules defined in another file?
In this case, I’m specifically looking at adding e.g. discardPolicy = "both";
to config.swapDevices.*
, but I’m currently doing my first NixOS + ZFS on mirrored root setup, so I’m also looking at adding "nofail"
to my mirrored EFI filesystems and hoping to find a general approach.
Initially, I was really hoping that I had missed a language feature somewhere and could just literally put swapDevices.*.discardPolicy = "both";
that obviously didn’t work.
Next, I was really thinking that I could use the let cfg = config...
trick to work around infinite recursion issues (as is common to see in modules):
swapDevices = let devs = config.swapDevices; in
builtins.map (dev: dev // {discardPolicy = "both";}) devs;
(where config.swapDevices is defined in hardware-configuration.nix
, which I thought I’d try not to modify for once.)
This seems to work in the repl:
nix-repl> builtins.map (dev: dev // {discardPolicy = "both";}) nixosConfigurations.nas.config.swapDevices
[ { ... } { ... } ]
But when I try I get infinite recursion:
# nixos-rebuild switch --flake .#nas
building the system configuration...
error: infinite recursion encountered
at /nix/store/15q3niqkdvkyf7mvbyh1r8szp4xwk9nz-source/lib/modules.nix:728:9:
727| in warnDeprecation opt //
728| { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
729| inherit (res.defsFinal') highestPrio;
(use '--show-trace' to show detailed location information)
Is duplicating everything my only / best option if I’m trying not to change hardware-configuration.nix
?
TIA!