2

Adding a runtime dependency to a package through override buildInputs causes the package to rebuild. Is there a simple way to inject runtime dependencies into a package without recompiling?

So basically adding package/bin to PATH and package/lib to LD_LIBRARY_PATH

dvc
  • 124
  • 1
  • 9
  • That would defeat the whole purpose of being purely functional, wouldn't it? (-> NO) – Daniel Jour Jun 16 '16 at 21:55
  • actually I think there is a way, looking at cc-wrapper, it swaps out binutils for example without having to rebuild gcc, so you could also use it to add a runtime dependency. `echo ${toString extraPackages} > $out/nix-support/propagated-native-build-inputs` – dvc Jun 16 '16 at 22:19
  • but I like that you cited me =P – dvc Jun 17 '16 at 00:47
  • So you mean to change the environment used when a Nix-installed app is *run*, not the one used when it is *built*, right? – akavel Jul 21 '16 at 18:27

1 Answers1

2

If I understand correctly that you want to tweak the environment used when a Nix-installed app is run, not the one used when it is built, then a method I know of is as follows below. By using it, you essentially create a wrapper script, which overrides the "default command". So, something similar like creating e.g. a custom ~/bin/vim script, which adds some options/env overrides to the default vim binary, which is called with a "hardcoded original path" inside the script.

One example of it in nixpkgs is how vimutils.vimWithRC overrides vim command with a custom script. For your own use, you could write more or less something like below:

with import <nixpkgs> {};

writeScriptBin "vim" ''
  #!/usr/bin/env bash
  export PATH=package/bin:$PATH   # whatever you like; I've added what you asked for
  export LD_LIBRARY_PATH=package/lib:$LD_LIBRARY_PATH
  ${vim}/bin/vim --my-options "$@"
'';

If you put it in my-vim.nix, you should be able to install it with:

$ nix-env -e vim   # REMOVE NORMAL VIM. I think this should be done first to avoid conflict
$ nix-env -i -f my-vim.nix

And hopefully it'll work and "override" the default vim for you.

DISCLAIMER: I haven't actually tested it in this exact form, sorry. Don't have a Nix console handy at this moment, unfortunately.

akavel
  • 4,789
  • 1
  • 35
  • 66