[Nix-dev] truly persistent nix-shell

Ruben Astudillo ruben.astud at gmail.com
Sun Nov 20 20:44:15 CET 2016


On 20/11/16 16:30, Andreas Herrmann wrote:
> Is there any reason why it is not mentioned in the man-page, yet?

Probably because is a combination of two independent tricks that don't
only concern nix-shell. For protection against updates in the
nix-channel, you have to craft a default.nix/shell.nix (as cabal2nix
does) and force the derivation be an environment (irrespective of
nix-shell)

    ... common cabal2nix output
      drv = haskellPackages.callPackage f {};
    in
      ## if pkgs.lib.inNixShell then drv.env else drv
      drv.env  # this change

then you instantiate such derivation (really an environment)

    $ nix-instantiate ./shell.nix --indirect --add-root $PWD/shell.drv

Now this .drv will persist between channel updates. Yet still remains
how to persist between garbage collection, for this you make the
nix-shell trick described above in the thread

    $ mkdir gcroots
    $ nix-shell $(pwd)/shell-main.drv --indirect --add-root gcroots/dep

For the complete trick.

Admittedly as a combination of two hacks, it shouldn't belong on a
single manpage, yet it should be in the manual (as the wiki is getting
deprecated). I would like this for now remain on record on this mailing
list and investigate possibly edge cases (or maybe hacking nix-shell for
a persistent flag) and submit this to the manual.

-- 
-- Ruben


More information about the nix-dev mailing list