Oops, at some point I missed that this is all about nix-shell.

So, by looking into nix-shell, we see that packages names are evaluated here https://github.com/NixOS/nix/blob/master/scripts/nix-build.in#L226. This means that the package names used with "-p" must exist within "<nixpkgs>", which you just shown do not...

This is all a misunderstanding. When trying to resolve <nixpkgs>, nix-shell looks at yout NIX_PATH.
Your nix-path contains something like this :
/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels
So, the first place where nixpkgs is looked for is /nix/var/nix/profiles/per-user/root/channels/nixos, and as the nixos channel comes with a folder named nixpkgs, this is the one selected.

To work around this, you have one solution: override nixpkgs location.
You can either use
NIX_PATH=nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs nix-shell -p letsencrypt, or nix-shell -p letsencrypt -I nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixpkgs

Other variations may also work, like
NIX_PATH=/nix/var/nix/profiles/per-user/root/channels/ nix-shell -p letsencrypt, or
nix-shell -p letsencrypt -I /nix/var/nix/profiles/per-user/root/channels/

Now, this happens because nixos defines NIX_PATH to be the nixos pkgs tree, and therefore <nixpkgs> always resolves to nixos packages. As to why this package is listed in nix-env, this is because nix-env gets its default expression from ~/.nix-defexpr, which behaves more sanely, not looking at NIX_PATH. If you want to know more about the future unification of nix-*commands, https://github.com/NixOS/nix/issues/779 (and referenced pages) are a good start.

It appears that the nice channel.package is very specific to nix-env, and not used by the other tools. In particular, nix-shell provides no way to use packages from different channels at the same time.

Regards,
-- Layus.

On 31/03/16 15:30, Dmitry Malikov wrote:
> What's the output of (normal user)
> $ nix-channel --list

Well, it's empty.

>To inspect your system state, try to run

>> nix-instantiate --eval --expr --strict "<nixpkgs>"
/nix/store/bc71r4k7bms0ykfl5zxgww1fi3kb0jdw-nixos-15.09.1180.e8e1cb8/nixos/nixpkgs
>> nix-instantiate --eval --expr --strict "<nixos>"
/nix/store/bc71r4k7bms0ykfl5zxgww1fi3kb0jdw-nixos-15.09.1180.e8e1cb8/nixos/nixos
>> sudo nix-instantiate --eval --expr --strict "<nixpkgs>"
/nix/store/bc71r4k7bms0ykfl5zxgww1fi3kb0jdw-nixos-15.09.1180.e8e1cb8/nixos/nixpkgs
>> sudo nix-instantiate --eval --expr --strict "<nixos>"
/nix/store/bc71r4k7bms0ykfl5zxgww1fi3kb0jdw-nixos-15.09.1180.e8e1cb8/nixos/nixos

><nixpkgs> gets evaluated in the context of the current user, so you will get very different results when using sudo.
Nah, they look pretty much the same.

>Now, there is no reason for the attribute returned by `nix-env -f "<nixpkgs>" -qaP` to be missing when calling `nix-shell "<nixpkgs>" -p` because the nixpkgs are exactly the same.

Yep, probably this explains something.
>> nix-env -qaP -f "<nixpkgs>" | grep letsencrypt
>>

So, what are the best practices of having nixos and nixpkgs-unstable channels? Should root user be subscribed to nixos and the normal user to nixpkgs one?

On 31 March 2016 at 11:46, Guillaume Maudoux (Layus) <[email protected] <mailto:[email protected]>> wrote:

    Hmm.. could it be that your system is confused by multiple channels ?

    What's the output of (normal user)
    $ nix-channel --list

    I think your best bet is `nix-shell "<nixpkgs>" -p letsencrypt`
    where nixpkgs is your channel name.

    You can even go further and set the nixpkgs path directly using
    nix-shell
    
/nix/store/7kxsv9svwcaxzkxxjg0zxcb151mic8vw-nixos-16.03pre76756.885acea/nixos/nixpkgs
    -p letsencrypt

    nix-env can also take such a path

    To inspect your system state, try to run
    $ nix-instantiate --eval --expr --strict "<nixpkgs>"
    $ nix-instantiate --eval --expr --strict "<nixos>"
    $ sudo nix-instantiate --eval --expr --strict "<nixpkgs>"
    $ sudo nix-instantiate --eval --expr --strict "<nixos>"

    <nixpkgs> gets evaluated in the context of the current user, so
    you will get very different results when using sudo.

    To ensure a consistent result, you can also pass the nixpkg tree
    to nix-env with option -f.
    $ nix-env -qaP -f "<nixpkgs>"

    Now, there is no reason for the attribute returned by `nix-env -f
    "<nixpkgs>" -qaP` to be missing when calling `nix-shell
    "<nixpkgs>" -p` because the nixpkgs are exactly the same.

    All this highlights the inconsistency between (and within) the tools.
    But that's another story :-).

    Layus.

    Le 31/03/16 11:25, Dmitry Malikov a écrit :
    >> nix-shell -p nixpkgs.pkgs.letsencrypt
    error: undefined variable ‘nixpkgs’ at (string):1:66
    (use ‘--show-trace’ to show detailed location information)

    Any other ideas?

    On 31 March 2016 at 10:37, Arseniy Seroka <[email protected]
    <mailto:[email protected]>> wrote:

        nix-shell -p nixpkgs.pkgs.letsencrypt

-- Sincerely,
        Arseniy Seroka

        On 31 March 2016 02:21:40 Dmitry Malikov
        <[email protected] <mailto:[email protected]>> wrote:

        >> sudo nix-channel --list
        nixpkgs https://nixos.org/channels/nixpkgs-unstable
        nixos https://nixos.org/channels/nixos-15.09

        >> nixos-version
        15.09.1180.e8e1cb8 (Dingo)

        >> nix-env --version
        nix-env (Nix) 1.10

        Anything else?

        On 31 Mar 2016, at 00:45, Jonn Mostovoy <[email protected]
        <mailto:[email protected]>> wrote:

        Just worked for me, exactly the same command.
        My version of nixpkgs is way older though.

        On Mar 31, 2016 12:40 AM, "Dmitry Malikov"
        <[email protected] <mailto:[email protected]>> wrote:

            >>
            nix-env -qaP '*' | grep letsencrypt
            nixpkgs.letsencrypt
            letsencrypt-0.4.0

            >> nix-shell -p letsencrypt
            error: undefined variable ‘letsencrypt’ at (string):1:66
            (use ‘--show-trace’ to show detailed location information)


            What am I missing here?

            _______________________________________________
            nix-dev mailing list
            [email protected]
            <mailto:[email protected]>
            http://lists.science.uu.nl/mailman/listinfo/nix-dev


        _______________________________________________
        nix-dev mailing list
        [email protected]
        <mailto:nix-dev%40lists.science.uu.nl>
        http://lists.science.uu.nl/mailman/listinfo/nix-dev




    _______________________________________________
    nix-dev mailing list
    [email protected] <mailto:[email protected]>
    http://lists.science.uu.nl/mailman/listinfo/nix-dev


    _______________________________________________
    nix-dev mailing list
    [email protected] <mailto:[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

Reply via email to