[Nix-dev] string vs path hell

Sergey Mironov grrwlf at gmail.com
Tue Jun 10 08:41:31 CEST 2014


OK, you are right. My code snippet really works fine. So I feel I must
post a part of my real code which still doesn't work for me. It is a
bit long, but maybe you will be able to help me find a mistake. Here
it is (below). This expression takes a set of paths to the executables
(exe // setuids) and builds the initrd image. Every attribute of (exe
// setuids) is either a string like [adduser =
"${busybox}/sbin/adduser";] or the result of mkDerivation producing
the single binary in it's $out.

Note the "dummy" expression. If I uncomment "builtins.trace dummy"
line, it will show me the expected result (string "dummy" for every
list item). But in the same time, "builtins.trace fn" shows that fn is
evaluated incorrectly. Every time it contains full Nix path
("/nix/strote/...", see example at the end of the letter) instead of
the filename part. It looks like 'splitString' doesn't recognize it's
argument as a string.

Please, comment!
Sergey


--
the code

      ...

      img = makeInitrd {

        compressor = "${gzip}/bin/gzip --fast";

        contents = with all.ipkgs;
          [{ symlink = "/init";
            object = exe.init;
          }
          { symlink = "/bin/sh";
            object = exe.shell;
          }] ++
          map (v :

            let

              takeFileName = p : let
                  fl = lib.splitString "/" p;
                in lib.last fl;

              fn = takeFileName "${v}";

              dummy = takeFileName "/a/string/encoded/path/dummy";

            in

            # builtins.trace fn   # <---------------- see example output below
            # builtins.trace dummy

            {
              symlink = "/bin/${fn}";
              object = v;
            }) (lib.attrValues (exe // setuids));
      };

--
example output of "builtins.trace fn":

trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/sbin/addgroup
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/sbin/adduser
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/bin/false
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/bin/true
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/bin/awk
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/bin/cat
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/bin/chmod
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/bin/chown
trace: /nix/store/sx19dvnv3wi2j8pvyra8npl9vdwdbmrk-busybox-1.21.1/bin/cp
trace: /nix/store/h8rs91fjivsh6wakmwmpkca31wfp38g0-msr-tools-1.3/bin/cpuid


More information about the nix-dev mailing list