[Nix-dev] Multiple stores

Roland Koebler rk-list at simple-is-better.org
Fri Aug 26 23:36:40 CEST 2016


Hi,

> My understanding is that whenever a file is needed it is copied in the
> store.
by default, yes.

I do not yet have much experience with Nix, and I don't know if it's a good
idea, but it is possible to symlink files. (I'm pretty sure that it isn't
a good idea to do this in normal cases, but I think it could be reasonable
in your case).

I tested it with the GNU hello program, which is used as example in the
documentation:

./custom-packages.nix:

    { system ? builtins.currentSystem }:
    
    let
        pkgs = import <nixpkgs> { inherit system; };
        callPackage = pkgs.lib.callPackageWith (pkgs);
    in
    rec {
        symlink-test = callPackage ./pkgs/symlink-test {};
    }

./pkgs/symlink-test/default.nix:

    { stdenv, fetchurl }:
    
    stdenv.mkDerivation rec {
      name = "symlink-test";
    
      src = fetchurl {
        url = "mirror://gnu/hello/${name}.tar.gz";
        sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i";
      };
    
      doCheck = false;
    
      meta = {
        description = "Symlink test, derived from GNU hello.";
        license = stdenv.lib.licenses.gpl3Plus;
        platforms = stdenv.lib.platforms.all;
      };

      #### MOVE FILE TO OTHER PLACE AND SYMLINK IT
      postInstall = "mv $out/bin/hello /tmp/hello && ln -s /tmp/hello $out/bin/hello";
    }

$ nix-env -f custom-packages.nix -iA symlink-test

Then:

$ ll /nix/store/*symlink-test*/bin
total 0
lrwxrwxrwx 1 user user 10 Jan  1  1970 hello -> /tmp/hello

$ ll /tmp/hello
-rwxr-xr-x 1 user user 99400 Aug 26 23:21 /tmp/hello

$ which hello
/home/user/.nix-profile/bin/hello

$ ll /home/user/.nix-profile/bin/hello
lrwxrwxrwx 1 rk rk 66 Jan  1  1970 /home/rk/.nix-profile/bin/hello -> /nix/store/dmgrr42asbq121z3kd03z33d1hs7kpx5-symlink-test/bin/hello

$ ll /nix/store/dmgrr42asbq121z3kd03z33d1hs7kpx5-symlink-test/bin/hello
/nix/store/dmgrr42asbq121z3kd03z33d1hs7kpx5-symlink-test/bin/hello -> /tmp/hello


Roland



More information about the nix-dev mailing list