Skip to content

Commit ea04f9b

Browse files
authored
Restore stable Nix compatibility (#8)
Stable Nix doesn't have nix shell, which means the most recent update broke any-nix-shell for people using the defaults. Here, I've added a simple version check to restore the old behaviour on Nix versions that don't have nix shell.
1 parent e6b86e6 commit ea04f9b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

bin/.any-nix-wrapper

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@ fns () {
55
which_shell="$1"
66
shift
77
pos=0
8+
9+
subcommand=shell
10+
if nix --version | grep -q ' 2\.[0-3][^0-9]'; then
11+
subcommand=run
12+
fi
13+
814
for arg in "$@"; do
915
if [[ $pos != 0 ]]; then
1016
pos=$((pos-1))
1117
elif [[ $arg == -* ]]; then
1218
if [[ $arg == -c ]] || [[ $arg == --command ]]; then
13-
command nix shell "$@"
19+
command nix "$subcommand" "$@"
1420
return
1521
elif [[ $arg == --arg ]] || [[ $arg == --argstr ]]; then
1622
pos=2
@@ -27,6 +33,6 @@ fns () {
2733
if [[ -n $name ]] && [[ $name != shell ]]; then
2834
pkgs+=" "$name
2935
fi
30-
env ANY_NIX_SHELL_PKGS="$pkgs" IN_NIX_RUN=1 nix shell "$@" --command $which_shell
36+
env ANY_NIX_SHELL_PKGS="$pkgs" IN_NIX_RUN=1 nix "$subcommand" "$@" --command $which_shell
3137
}
3238
fns "$@"

0 commit comments

Comments
 (0)