[Nix-dev] Checksum of an attrset?

Marc Weber marco-oweber at gmx.de
Thu Jul 19 19:23:29 CEST 2012


Excerpts from Rickard Nilsson's message of Thu Jul 19 17:21:58 +0200 2012:
> > Adding a md5sum primop function to the nix language should be straight
> > forward.

There is a eval.c(c) file in nix. If you have a look at the substring
implementations it should be easy to copy paste that function and
introduce a md5sum like hash function.

> > let attrs = [a,b,c]
> > turn into attrs
> I'm not sure I'm following you here.

I didn't quite understand what you try to do. I can think about several
use cases. Eg if you create upstart jobs they all have to have a unique
name. Thus instead of worrying about a name:

  "job-1" = {
    name = "job-1";
    ...
  }
  "job-2" = {
    name = "job-2";
    ...
  }

you can also do it this way:

  add_names = list: count:
    let h = builtins.head list;
        t = builtins.tail list;
    in [ ( h // { name = "name${builtins.toString count}"; } ) ]
    ++ add_names t (builtins.add 1 count)

  and pass your job like list to that function. When its done the jobs
  will have incrementing naming.

  turning the list into attrs can be done by listToAttrs primop easily.

It may or may not be what you need. Its the same way as IPs are assigned
to virtual machines in the test cases.

Marc Weber


More information about the nix-dev mailing list