Thanks, looks like I didn't notice this possibility! Works just how I expected.
Sergey 2014-04-14 13:13 GMT+04:00 Cameron Turner <[email protected]>: > The implementation of this would be: > > users = { > root = { name = "root"; group = groups.root; }; > ssh = { name = "ssh" ; group = groups.nogroup ; severity = 33; }; > }; > userList = (map (key: getAttr key users) (attrNames users)); > > Roughly based on some code in Disnix's lib.nix. I'm sure you could split this > out into a library function (maybe that's already been done), but there's no > need for it to be a built-in. > > Shell > > Sergey Mironov <[email protected]> wrote: > Hi. Nix language has a built-in function builtins.listToAttrs which > converts list to the Attrs. I'm searching a way to make an opposite > thing - convert attrs to a list. Say, I'd like to convert > > users = { > root = { name = "root"; group = groups.root; }; > ssh = { name = "ssh" ; group = groups.nogroup ; severity = 33; }; > }; > > to a list like this: > > [ > { name = "root"; group = groups.root; } > { name = "ssh" ; group = groups.nogroup ; severity = 33; } > ]; > > to use it later both in shell scripting, as list > > lib.map (toList users) (u: '' > adduser ${u.name} ${u.group} > ''); > > .. and in derivations, by reference > > stdenv.mkDerivation "ssh" { > user = users.ssh; > }; > > In order to workaround the problem I have to add additional field > `list' (like below) but this way I have to duplicate field names which > is not good (easy to forget). So Is it possible to do the > transformation in a more > safe way? > > Regards, > Sergey > > # A workaround > > users = rec { > root = { name = "root"; group = groups.root; }; > ssh = { name = "ssh" ; group = groups.nogroup ; severity = 33; }; > list = [ root ssh ]; > }; > _______________________________________________ > nix-dev mailing list > [email protected] > http://lists.science.uu.nl/mailman/listinfo/nix-dev > _______________________________________________ > nix-dev mailing list > [email protected] > http://lists.science.uu.nl/mailman/listinfo/nix-dev _______________________________________________ nix-dev mailing list [email protected] http://lists.science.uu.nl/mailman/listinfo/nix-dev
