I had a different problem, but this is in the top DDG results for nix store reference
so I'll leave this here. My problem wasn't so much that I needed to reference a specific file from another package in my package, I just needed my package to have a rundep (buildInputs
) on particular store paths so I could install it to my profile and they wouldn't be GC'd. (I was sick of constantly re-downloading paths when using nix-shell
, and while nix-env -iA nixpkgs.stdenv
worked, nix-env -iA nixpkgs.bash
is apparently a different copy.)
Just putting the store paths into a text file in $out
doesn't work, they need to be passed through builtins.storePath
first:
writeTextDir "share/nix-shell-nogc" (builtins.concatStringsSep "\n" (builtins.map builtins.storePath [
"/nix/store/2r4gr92p49kpx48s0hxxxv04cqbx4d6c-bash-interactive-5.1-p16-dev"
"/nix/store/76yin93c7c0jv29kq2hr39d5rzd0v6dg-bash-interactive-5.1-p16-doc"
"/nix/store/d2m4s6bm6gxpwd22pv20cbhl3ikbhhpb-bash-interactive-5.1-p16-man"
"/nix/store/p5fqinp9r82fr92rncwxmhd8nsk3igjy-bash-interactive-5.1-p16-info"
]))
Or alternatively, use path literals (doesn't build unless the paths exist, while the above method downloads them during build if necessary):
writeTextDir "share/nix-shell-nogc" ''
${/nix/store/2r4gr92p49kpx48s0hxxxv04cqbx4d6c-bash-interactive-5.1-p16-dev}
${/nix/store/76yin93c7c0jv29kq2hr39d5rzd0v6dg-bash-interactive-5.1-p16-doc}
${/nix/store/d2m4s6bm6gxpwd22pv20cbhl3ikbhhpb-bash-interactive-5.1-p16-man}
${/nix/store/p5fqinp9r82fr92rncwxmhd8nsk3igjy-bash-interactive-5.1-p16-info}
'';
I don't like that I had to hardcode the paths, but it gets the job done.