Skip to content

nix-build --run-env with --add-root not working as expected (or at all?) #86

Closed

Description

@cillianderoiste

(this issue replaces NixOS/nixpkgs#250)

With Nix 1.3

~/Projects/MyEnv $ nix-build --run-env '<nixpkgs>' -A irssi

works fine but when I try it with add-root I get surprising results:

~/Projects/MyEnv $ nix-build --run-env '<nixpkgs>' -A irssi --add-root myroot error: creating a garbage collector root (/nix/store/27irakzga2m3wiv7977hafjr8kaa3plb-stdenv.drv) in the Nix store is forbidden (are you running nix-build inside the store?) /run/current-system/sw/bin/nix-build: failed to build all dependencies

with --indirect

~/Projects/MyEnv $  nix-build --run-env '<nixpkgs>' -A irssi --add-root  myroot --indirect  
error: path `/home/goibhniu/Projects/MyEnv/--indirect' is not a valid garbage collector root; it's not in the directory `/nix/var/nix/gcroots'
/run/current-system/sw/bin/nix-build: failed to build all dependencies

By accident I ran:

~/Projects/MyEnv $  nix-build --run-env '<nixpkgs>' -A irssi --indirect --add-root  ./myroot --indirect

which did something interesting:

~/Projects/MyEnv $ ls -l                                                 
total 4
lrwxrwxrwx 1 goibhniu users 50 Jan  8 23:12 --indirect -> /nix/store/b48470bj4b8d4x6z5rr62924n30cwsiq-stdenv
lrwxrwxrwx 1 goibhniu users 55 Jan  8 23:12 --indirect-2 -> /nix/store/ahg5mlj2mlp7yfl3x875pq95ar763vgj-ncurses-5.9
lrwxrwxrwx 1 goibhniu users 56 Jan  8 23:12 --indirect-3 -> /nix/store/043zrsanirjh8nbc5vqpjn93hhrf107f-bash-4.2-p24
lrwxrwxrwx 1 goibhniu users 58 Jan  8 23:12 --indirect-4 -> /nix/store/h0q955qx57zck3b73mg6f4x3951qhs5p-openssl-1.0.0i
lrwxrwxrwx 1 goibhniu users 55 Jan  8 23:12 --indirect-5 -> /nix/store/v4m3gahx1iz53v51rdinh0lcmipn1p4j-perl-5.14.2
lrwxrwxrwx 1 goibhniu users 64 Jan  8 23:12 --indirect-6 -> /nix/store/xy74fdawwpyfzag4m8sgm63x2k9lkagk-irssi-0.8.15.tar.bz2
lrwxrwxrwx 1 goibhniu users 59 Jan  8 23:12 --indirect-7 -> /nix/store/w6bwp1sq5w24n3vnmx0yifiqdq696fyf-pkg-config-0.23
lrwxrwxrwx 1 goibhniu users 55 Jan  8 23:12 --indirect-8 -> /nix/store/jsjfzx23rz1vz03wh3x23ryr54c08nb1-glib-2.34.0

Perhaps I'm just using it wrong?

Activity

  1. chaoflow commented on Jan 11, 2013

    @chaoflow
    Member
    ~/dev/nixos/nixpkgs/
    % nix-build default.nix --run-env -A irssi
    warning: you did not specify `--add-root'; the result might be removed by the garbage collector
    /nix/store/b48470bj4b8d4x6z5rr62924n30cwsiq-stdenv/setup:93: command not found: shopt
    exitHandler:4: command not found: closeNest
    runHook:2: bad option: -t
    runHook:6: bad substitution
    

    nix-build (Nix) 1.3

    NixOS/nixpkgs@6f1aad7

  2. chaoflow commented on Jan 11, 2013

    @chaoflow
    Member

    @cillianderoiste: Where did you find documentation for the parameters you used? nix-build --help only says: [--run-env [--command cmd] [--exclude regexp]] paths...

  3. cillianderoiste commented on Jan 12, 2013

    @cillianderoiste
    MemberAuthor

    @chaoflow IIUC it doesn't work correctly on zsh: NixOS/nixpkgs#79

  4. cillianderoiste commented on Jan 12, 2013

    @cillianderoiste
    MemberAuthor

    The only documentation I've found which mentions --run-env with --add-root is:

    http://nixos.org/wiki/GIT_workflow

    @qknight If I remember correctly, you were using this at the hackfest. Do you still use it?

    $ nix-build ~/code/nixpkgs --run-env -A irssi --add-root
    error: creating a garbage collector root (/nix/store/27irakzga2m3wiv7977hafjr8kaa3plb-stdenv.drv) in the Nix store is forbidden (are you running nix-build inside the store?)
    /run/current-system/sw/bin/nix-build: failed to build all dependencies
    
  5. edolstra commented on Jan 14, 2013

    @edolstra
    Member

    Since "nix-build --run-env" doesn't actually build the top-level package (just its dependencies), the "--add-root" flag doesn't really make sense. But I guess it shouldn't print that weird error message.

  6. cillianderoiste commented on Jan 15, 2013

    @cillianderoiste
    MemberAuthor

    Aha! No wonder it isn't documented then! I was under the impression that --run-env with --add-root could replace buildEnv to provide a persistent development environment, so I was obviously wrong. Thanks for clearing that up.

  7. CMCDragonkai commented on Jul 28, 2014

    @CMCDragonkai
    Member

    Does nix-shell replace nix-build --run-env?

  8. edolstra commented on Jul 28, 2014

    @edolstra
    Member

    Yes.

  9. added a commit that references this issue on Feb 26, 2025
    31d509f
  10. added a commit that references this issue on Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions