toraritte
toraritte

Reputation: 8243

What is the `nix-shell` equivalent of `nix-env -f <path-to-my-local-nixpkgs-repo> -iA ...`?

Or is this only possible by writing a custom shell.nix?

Where path-to-my-local-nixpkgs-repo is a directory with a default.nix file containing a valid Nix expression. This directory may hold one's personal collection of Nix packages or a local clone of the Nixpkgs repo. I think this is the part in the Nix manual where default.nix is introduced, but this SO thread seems to be better.

For example:

let
  nixpkgs_commit = "f4593ab";
  nixpkgs_sha256 = "01bmiqndp1czwjw87kp21dvxs0zwv7yypqlyp713584iwncxjv0r";
  pinnedNixpkgsGithubURL = "https://github.com/NixOS/nixpkgs/archive/${nixpkgs_commit}.tar.gz";

  fetchedPinnedTarball =
    builtins.fetchTarball
      { name = "nixpkgs";
        url = pinnedNixpkgsGithubURL;
        sha256 = nixpkgs_sha256;
      }
  ;
in
  { pkgs ? import fetchedPinnedTarball {} }:

  pkgs.mkShell
    { buildInputs = [ pkgs.tor-browser-bundle-bin ]; 
    }

One might argue that this question is off-topic here, because it asks about command line options, but the solution may only be the above Nix expression (or one provided with -E). Anyway, if my argument is flawed, please let me know. Thanks!

Upvotes: 4

Views: 925

Answers (3)

James Williams
James Williams

Reputation: 29

e.g. to create a nix-shell that includes perl using the nixpkgs in /path/to/your/nixpkgs:

nix-shell -E 'with import (builtins.filterSource (p: t: baseNameOf p != ".git") /path/to/your/nixpkgs) {}; mkShell { buildInputs = [ perl ]; }'

Upvotes: 2

toraritte
toraritte

Reputation: 8243

$ nix-shell -E 'with import path-to-my-local-nixpkgs-clone/default.nix {}; runCommand "dummy" { buildInputs = [ tor-browser-bundle-bin ]; } ""'

(Credit goes to Stackoverflow thread. Thanks a lot @potong for doing this research!)

Upvotes: 2

AleXoundOS
AleXoundOS

Reputation: 446

$ nix-shell -E 'with import path-to-my-local-nixpkgs-repo {}; mkShell { buildInputs = [ tor-browser-bundle-bin PKG2 PKGS3 ]; }'

Compared to simple nix-shell -p '(import path-to-my-local-nixpkgs-repo {}).tor-browser-bundle-bin' this has the benefit of presenting more than one package.


Also, I suggest to replace import path-to-my-local-nixpkgs-repo {} with builtins.filterSource (p: t: baseNameOf p != ".git") path-to-my-local-nixpkgs-repo to save space from copying .git (2 GiB full git clone) for no reason on every change.

Upvotes: 3

Related Questions