Skip to content

Commit

Permalink
alias: use a proper derivation for nix-shell
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentbernat committed Nov 28, 2021
1 parent 5e07f0f commit e543bf8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
25 changes: 10 additions & 15 deletions rc/alias.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -127,25 +127,20 @@ mkcd() { command mkdir -p -- $1 && cd -- $1 }
# Make nix-shell use zsh
# Source: https://ianthehenry.com/posts/how-to-learn-nix/nix-zshell/
(( $+commands[nix-shell] )) && nix-shell() {
local NIX_BUILD_SHELL="$(mktemp -t nix-build-shell-XXXXXXX)"
{
local bash=$(nix-build --no-out-link -E '(import <nixpkgs>{}).bashInteractive')
local zsh=$(nix-build --no-out-link -E '(import <nixpkgs>{}).zsh')
cat <<EOF > $NIX_BUILD_SHELL
#!${bash}/bin/bash
case \$#,"\$1" in
local wrapper
read -d '' wrapper <<"EOF"
with import <nixpkgs> {};
writeShellScriptBin "_nix-shell-wrap" ''
case $#,"$1" in
2,--rcfile) : ;;
*) >&2 echo "[!] Wrong invocation (\$@)" ; exit 1 ;;
*) >&2 echo "[!] Wrong invocation ($@)" ; exit 1 ;;
esac
source "\$2"
source "$2"
exec -a zsh ${zsh}/bin/zsh
''
EOF
chmod +x $NIX_BUILD_SHELL
NIX_BUILD_SHELL=$NIX_BUILD_SHELL =nix-shell "$@"
} always {
rm -f $NIX_BUILD_SHELL
}
local nix_build_shell=$(nix-store --no-gc-warning -r $(nix-instantiate --no-gc-warning -E $wrapper))
NIX_BUILD_SHELL=${nix_build_shell}/bin/_nix-shell-wrap =nix-shell "$@"
}

# Setting up less colors
Expand Down
2 changes: 1 addition & 1 deletion zshenv
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fi
path=()
# First, put paths from savedpaths not in the wanted list
for p in $savedpath; do
[[ $p == /tmp ]] \
(( 0 )) \
|| (( ${${wanted[(r)$p]}:+1} )) \
|| (( ${${wanted[(r)${p:A}]}:+1} )) \
|| (( ${${path[(r)${p}]}:+1} )) \
Expand Down

0 comments on commit e543bf8

Please sign in to comment.