8000 nix-shell: add additional packages to the environment · Issue #278 · NixOS/nix · GitHub
[go: up one dir, main page]

Skip to content

nix-shell: add additional packages to the environment #278

Closed

Description

@bennofs

Currently, I can use nix-shell to create an environment with just the particular packages I want:

$ nix-shell -p foo bar

I can also load the dependencies of a package:

$ nix-shell .

However, I want to combine the two, to load the dependencies of a package plus some additional packages:

$ nix-shell . -p foo
error: syntax error, unexpected '.', at (string):1:66

Is this possible?

Activity

  1. edolstra commented on Jun 10, 2014

    @edolstra
    Member

    No, combining is not possible. That's because -p is implemented by generating a Nix expression on the fly. So here it generates an expression with buildInputs = [ . foo ];.

  2. waxlamp commented on Jun 2, 2017

    @waxlamp

    Surely it's possible, it's just not what nix-shell currently does right? I'd also like to be able to load the deps in a shell.nix file and also add in other incidental packages I may need (such as my preferred editor, etc.).

    If we shouldn't be using nix-shell this way, what's the recommended way to create a shell environment that reflects a project's shell.nix file, plus a few selected packages?

  3. willjp commented on Aug 16, 2020

    @willjp

    I figured out a way to achieve what you're looking for from nix repl .

    nix-repl> pkgs = import <nixpkgs> {}
    nix-repl> pkg = import ./default.nix {}
    nix-repl> pkg-dev = pkgs.stdenv.mkDerivation { name="${pkg.name}-vim"; buildInputs=pkg.buildInputs ++ [pkgs.vim]; }
    nix-repl> :s pkg-dev
    

    Using nix-shell -E (which evaluates a nix expression) you can achieve essentially same behaviour:

    nix-shell -E 'with import <nixpkgs> {}; runCommand "foo" { buildInputs=(import ./default.nix {}).buildInputs ++ [vim]; } "" '

    This is probably too much information, but I plan to create a derivation in ~/.config/nixpkgs/config.nix that encapsulates my vim config requirements. I'll assign this to a bash alias so that I can quickly produce an environment for vim in addition to my package's requirements.

  4. steinybot commented on Jan 28, 2022

    @steinybot

    This worked for me:

    nix-shell -p foo bar --run 'nix-shell'
    
  5. waxlamp commented on Feb 3, 2022

    @waxlamp

    image

  6. Pitometsu commented on May 23, 2023

    @Pitometsu

    I figured out a way to achieve what you're looking for from nix repl .

    nix-repl> pkgs = import <nixpkgs> {}
    nix-repl> pkg = import ./default.nix {}
    nix-repl> pkg-dev = pkgs.stdenv.mkDerivation { name="${pkg.name}-vim"; buildInputs=pkg.buildInputs ++ [pkgs.vim]; }
    nix-repl> :s pkg-dev
    

    Using nix-shell -E (which evaluates a nix expression) you can achieve essentially same behaviour:

    nix-shell -E 'with import <nixpkgs> {}; runCommand "foo" { buildInputs=(import ./default.nix {}).buildInputs ++ [vim]; } "" '

    This is probably too much information, but I plan to create a derivation in ~/.config/nixpkgs/config.nix that encapsulates my vim config requirements. I'll assign this to a bash alias so that I can quickly produce an environment for vim in addition to my package's requirements.

    But that doesn't work for nix-shell https://whatever.tgz

    This worked for me:

    nix-shell -p foo bar --run 'nix-shell'
    

    Doesn't have sense in case of pure shell.

  7. added a commit that references this issue on Feb 26, 2025
  8. added a commit that references this issue on Dec 8, 2025
  9. kaddkaka commented on Nov 13, 2026

    @kaddkaka

    @edolstra why was this closed? Is there no way to add the feature to nix-shell? It would be very convenient.

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

      0