[Nix-dev] string vs path hell

Kirill Elagin kirelagin at gmail.com
Tue Jun 10 11:04:15 CEST 2014


Oh yeah, I've managed to reproduce this:

~~~~~
nix-repl> :l <nixpkgs>
Added 3863 variables.

nix-repl> lib.splitString "/" "${pkgs.busybox}/foo/bar"
[ "/nix/store/nn00kn1fa0154qa1szszijw825cha8ps-busybox-1.22.1/foo/bar" ]

nix-repl> lib.splitString "/" (toString "${pkgs.busybox}/foo/bar")
[ "/nix/store/nn00kn1fa0154qa1szszijw825cha8ps-busybox-1.22.1/foo/bar" ]

nix-repl> lib.splitString "/"
"/nix/store/nn00kn1fa0154qa1szszijw825cha8ps-busybox-1.22.1/foo/bar"
[ "" "nix" "store" "nn00kn1fa0154qa1szszijw825cha8ps-busybox-1.22.1" "foo"
"bar" ]
~~~~~

Total weirdness.


--
Кирилл Елагин


On Tue, Jun 10, 2014 at 12:58 PM, Kirill Elagin <kirelagin at gmail.com> wrote:

> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> let lib = (import <nixpkgs> {}).lib;
>     exe = {
>       foo = "/some/path/to/foo";
>       bar = "/other/path/to/bar";
>     };
> in
> {
>   contents =
>
>     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
>         #builtins.trace dummy
>
>
>         {
>           symlink = "/bin/${fn}";
>           object = v;
>         }) (lib.attrValues exe);
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> ~~~~~~~~~~~~~~~~
> nix-repl> :l test.nix
> Added 1 variables.
>
> nix-repl> :p contents
> [ { object = "/other/path/to/bar"; symlink = "/bin/bar"; } { object =
> "/some/path/to/foo"; symlink = "/bin/foo"; } ]
> ~~~~~~~~~~~~~~~~~
>
> Dunno, you should probably inspect your `exe` set closer in case
> something's wrong with values there.
>
>
> --
> Кирилл Елагин
>
>
> On Tue, Jun 10, 2014 at 10:41 AM, Sergey Mironov <grrwlf at gmail.com> wrote:
>
>> 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
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20140610/4b437173/attachment.html 


More information about the nix-dev mailing list