!tDnwWRNkmmYtMXfaZl:nixos.org

Nix Language

1518 Members
Nix programming language267 Servers

Load older messages


SenderMessageTime
12 Aug 2024
@kyub:matrix.orgkyub left the room.16:59:10
@kyub:matrix.orgkyub joined the room.17:00:44
13 Aug 2024
@atagen:imagisphe.reatagen

how would I enumerate attrs? for example, if I have:

foo = {
 bar = { baz = false; };
 rab = { zab = true; };
};

how can I process this to get

foo = {
 bar = { n = 0; baz = false; };
 rab = { n = 1; zab = true; };
};
```?
02:18:12
@atagen:imagisphe.reatagen *

how would I enumerate attrs? for example, if I have:

foo = {
 bar = { baz = false; };
 rab = { zab = true; };
};

how can I process this to get

foo = {
 bar = { n = 0; baz = false; };
 rab = { n = 1; zab = true; };
};
```
?
02:18:26
@atagen:imagisphe.reatagen *

how would I enumerate attrs? for example, if I have:

foo = {
 bar = { baz = false; };
 rab = { zab = true; };
};

how can I process this to get

foo = {
 bar = { n = 0; baz = false; };
 rab = { n = 1; zab = true; };
};

?

02:18:42
@atagen:imagisphe.reatagen I don't care about the order of evaluation, only that n is unique for each member 02:19:01
@infinisil:matrix.orginfinisil atagen: There's a PR proposing imapAttrs: https://github.com/NixOS/nixpkgs/pull/270049 02:20:59
@emilazy:matrix.orgemily
nix-repl> :p lib.listToAttrs (lib.imap0 (n: {name, value}: {inherit name; value = value // { inherit n; }; }) (lib.attrsToList {a = {}; b = {};}))
{
  a = { n = 0; };
  b = { n = 1; };
}
02:21:56
@emilazy:matrix.orgemily(why do you want this?)02:21:58
@atagen:imagisphe.reatagen
In reply to @emilazy:matrix.org
(why do you want this?)
I have a home-manager option that generates firefox profiles w userchrome removed, unique .desktop files etc to make pseudo-PWAs - the IDs need to be unique and sequential for firefox to respect all entries in the profile ini
02:24:54
@emilazy:matrix.orgemilyI see02:25:20
@emilazy:matrix.orgemily you might want to skip the listToAttrs part depending on your usecase 02:25:28
@emilazy:matrix.orgemilyalso, since there's no ordering guarantees, if renumbering would matter at all you might just want it to be a list to begin with02:25:54
@atagen:imagisphe.reatagenI appreciate the help, I'll have a poke around at it02:25:55
@atagen:imagisphe.reatagenanything beats setting them manually at each site02:26:32
@atagen:imagisphe.reatagen
In reply to @emilazy:matrix.org
also, since there's no ordering guarantees, if renumbering would matter at all you might just want it to be a list to begin with
though hmm yeah
02:26:36
@adis:blad.is@adis:blad.isAttrsets are sorted02:27:03
@atagen:imagisphe.reatagennow I think about it, if I remove one and the number decrements, firefox will probably start using the data of the old profile from the wrong app02:27:08
@adis:blad.is@adis:blad.isSo you'll get numbering in lexicographical order02:27:20
@atagen:imagisphe.reatagen * now I think about it, if I remove one and the number decrements, firefox will probably start using the data of the old profile from the wrong app.. perhaps I can do some symlink crimes based on app names and some stateful stuff in home dir02:29:21
@emilazy:matrix.orgemily
In reply to @adis:blad.is
Attrsets are sorted
uh, TIL
02:30:38
@emilazy:matrix.orgemily
In reply to @atagen:imagisphe.re
now I think about it, if I remove one and the number decrements, firefox will probably start using the data of the old profile from the wrong app.. perhaps I can do some symlink crimes based on app names and some stateful stuff in home dir
I'm confused, surely the reason Firefox profile directories are named after key mashes is to avoid this?
02:31:15
@emilazy:matrix.orgemilyare you sure the ordering is not just to determine the list some UI presents or something?02:31:37
@atagen:imagisphe.reatagenI honestly have no idea02:31:50
@atagen:imagisphe.reatagen hmm, they do have a Path key in the INI, but I don't know if I have simple access to that part of the hm firefox machinery lol 02:32:51
@atagen:imagisphe.reatagenyou may well be right that it's just for UI/selections. either way, no longer a Nix lang problem 👍️02:33:58
@atagen:imagisphe.reatagen * hmm, they do have a Path key in the INI, but I don't know if I have simple access to that part of the hm firefox machinery lol. but if that's all it is then I guess it's fine until I literally reuse an app name 02:34:25
@aloisw:kde.org@aloisw:kde.org
In reply to @adis:blad.is
Attrsets are sorted
However the order is inconsistent between operations; most user-facing things (like attrNames or printing) use lexicographic order, but comparison uses symbol table order.
07:43:03
@emilazy:matrix.orgemily: (09:23:49
@emilazy:matrix.orgemilyI wish you hadn't said that09:23:54

Show newer messages


Back to Room ListRoom Version: 6