Hi,
I have a home-manager
setup with elixir_1_14
as a package.
I also have a nix flake that looks like this:
{
description = "Flake with elixir";
inputs = {
nixpkgs.url = "nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let pkgs = import nixpkgs {
inherit system;
};
in
{
devShells.default = pkgs.mkShell {
packages = with pkgs; [
elixir_1_15
];
};
}
);
}
When I run nix develop
and check the elixir version, I get the correct 1.15.2
version.
But when I run nix develop --command fish
, I get the incorrect 1.14.5
version (the package installed by home-manager).
What’s going on here? How can I get the correct package inside the fish
shell?
I’m not sure if this work but try:
nix develop --command 'fish -C "fish_add_path --path $PATH"'
or
nix develop --command 'fish -C "set -x --unpath PATH $PATH"'
The idea (if it works) is:
nix develop changes your PATH, before executing fish, and fish will use nix develop PATH
1 Like
This almost works. The arguments to nix develop
are a bit different as seen here: Docs: Add nix develop --command entry by jonringer · Pull Request #7008 · NixOS/nix · GitHub
and only the first command works (with fish_add_path), so the solution is: nix develop --command fish -C "fish_add_path --path $PATH"
Thank you!
1 Like
It works with double quotes?
I was expecting $PATH to be resolved when fish runs, that’s why I was using single quotes.
Ie:
nix develop --command fish -C "fish_add_path --path $PATH"
To be:
- nix
- develop
- –command
- fish
- -C
- “fish_add --path /old/elixir/bin:/usr/bin”
- fish
- -C
- “fish_add --path /old/elixir/bin:/usr/bin”
And
nix develop --command fish -C 'fish_add_path --path $PATH'
To be:
- nix
- develop
- –command
- fish
- -C
- ‘fish_add --path $PATH’
- fish
- -C
- ‘fish_add --path /new/elixir/bin:/usr/bin’
you’ve added single quotes around --command 'fish -C ...'
and that doesn’t work. The PR I’ve linked shows it with double quotes and that works. I haven’t actual tried to do nix develop -c fish -C 'fish_add_path --path $PATH'
but I would expect that to work as well.
this suddenly stopped working and I have no idea why.
If I do: nix develop
, the nix develop path is the first entry in the path and works correctly
If I do: nix develop -c bash
, the first entries are .nix-profile
entries:
> nix develop -c bash
[thomas@honor elixir]$ echo $PATH
/home/thomas/.nix-profile/bin:/nix/var/nix/profiles/default/bin:/nix/store/4w22z1kl60hd8z6c50skc58bhbinxqn5-elixir-1.15.2/bin:/nix/store/sprx92b3v49if4m7wi7iahclfsi4nwvn-patchelf-0.15.0/bin:...
and thus this fails.
If I run:
> nix develop -c bash -C 'echo $PATH'
bash: echo $PATH: No such file or directory
which I don’t really understand, with fish
I get:
> nix develop -c fish -C 'echo $PATH'
/home/thomas/.local/bin /home/thomas/.nix-profile/bin /nix/var/nix/profiles/default/bin /home/thomas/.bin /nix/store/4w22z1kl60hd8z6c50skc58bhbinxqn5-elixir-1.15.2/bin /nix/store/sprx92b3v49if4m7wi7iahclfsi4nwvn-patchelf-0.
the elixir
path is placed after the nix-profile
paths, so it doesn’t get precedence.
so I’m now doing this: nix develop -c fish -C 'fish_add_path $nativeBuildInputs/bin'
but I’m not sure if this is ok or not. It works though