Search code examples
nix

How to set multiple attribute sets' values to the same in Nix?


I've got the following code:

extraGroups = {
  realtime.members = [ config.users.users.default.name ];
  wireshark.members = [ config.users.users.default.name ];
}

Ideally I'd simply shorten the inner part to one of the following:

realtime.members = wireshark.members = [ config.users.users.default.name ];
{realtime, wireshark}.members = [ config.users.users.default.name ];
map (entry: entry.members = [ config.users.users.default.name ]) [realtime, wireshark]

None of those are valid Nix syntax. How do I do the equivalent, without pulling out a new variable?


Solution

  • The language does not support such syntax, because the functionality is already covered by other language features like let bindings. Saving a few keystrokes is not worth a complicated language, especially for a language that most people shouldn't need to write very often.

    However, you can do this in your specific case:

    users.users.default.extraGroups = ["realtime" "wireshark"];