way too overcomplicated!
This commit is contained in:
@@ -1,16 +1,83 @@
|
||||
function ns() {
|
||||
args=()
|
||||
for pkg in $@; do
|
||||
local args=()
|
||||
for pkg in "$@"; do
|
||||
args+=(nixpkgs#"$pkg")
|
||||
done
|
||||
>&2 echo + exec nix shell "${args[@]}"
|
||||
local tmp=$(
|
||||
local outpaths="$(
|
||||
export NIXPKGS_ALLOW_BROKEN
|
||||
export NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM
|
||||
export NIXPKGS_ALLOW_UNFREE
|
||||
export NIXPKGS_ALLOW_INSECURE
|
||||
nix --extra-experimental-features "nix-command flakes" shell --impure "${args[@]}" -c sh -c 'echo $PATH'
|
||||
)
|
||||
[[ $? -eq 0 && -n "$tmp" ]] || return 1
|
||||
export PATH="$tmp"
|
||||
nix --extra-experimental-features "nix-command flakes" build --impure "${args[@]}" --print-out-paths --no-link
|
||||
)"
|
||||
if [[ $? -ne 0 || -z "$outpaths" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
local -a storepaths_native=()
|
||||
local -a storepaths_build=()
|
||||
readarray -d $'\n' -t storepaths_native <<<"$outpaths"
|
||||
readarray -d $'\n' -t storepaths_build <<<"$outpaths"
|
||||
|
||||
# traverse propagated inputs
|
||||
local -i idx=-1
|
||||
while [[ $((++idx)) -lt "${#storepaths_native[@]}" ]]; do
|
||||
if [[ -f "${storepaths_native[$idx]}"/nix-support/propagated-native-build-inputs ]]; then
|
||||
storepaths_native+=($(cat "${storepaths_native[$idx]}"/nix-support/propagated-native-build-inputs))
|
||||
fi
|
||||
if [[ -f "${storepaths_native[$idx]}"/nix-support/propagated-build-inputs ]]; then
|
||||
storepaths_build+=($(cat "${storepaths_native[$idx]}"/nix-support/propagated-build-inputs))
|
||||
fi
|
||||
done
|
||||
local -i idx=-1
|
||||
while [[ $((++idx)) -lt "${#storepaths_build[@]}" ]]; do
|
||||
if [[ -f "${storepaths_build[$idx]}"/nix-support/propagated-build-inputs ]]; then
|
||||
storepaths_build+=($(cat "${storepaths_build[$idx]}"/nix-support/propagated-build-inputs))
|
||||
fi
|
||||
done
|
||||
|
||||
# find things to add to env
|
||||
local -a add_to_path=()
|
||||
local -a add_to_libs=()
|
||||
local -a add_to_share=()
|
||||
local -a add_to_include=()
|
||||
local -a add_to_pythonpath=()
|
||||
|
||||
# for storepath in "${storepaths_native[@]}"; do
|
||||
for storepath in "${storepaths_build[@]}"; do
|
||||
if [[ -d "$storepath/bin" ]]; then
|
||||
add_to_path+=("$storepath/bin")
|
||||
fi
|
||||
if >/dev/null compgen -G "$storepath/lib/*.so"; then
|
||||
add_to_libs+=("$storepath"/lib/*.so)
|
||||
fi
|
||||
if >/dev/null compgen -G "$storepath/lib/*.so.*"; then
|
||||
add_to_libs+=("$storepath"/lib/*.so.*)
|
||||
fi
|
||||
if [[ -d "$storepath/share" ]]; then
|
||||
add_to_share+=("$storepath/share")
|
||||
fi
|
||||
if >/dev/null compgen -G "$storepath/lib/python*/site-packages"; then
|
||||
add_to_pythonpath+=("$storepath"/lib/python*/site-packages)
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ "${#add_to_path[@]}" -gt 0 ]]; then
|
||||
export PATH="$(IFS=: ; printf "%s" "${add_to_path[*]}")${PATH:+":$PATH"}"
|
||||
fi
|
||||
if [[ "${#add_to_libs[@]}" -gt 0 ]]; then
|
||||
export NIX_LDFLAGS="$(IFS=" " ; printf "-L%s" "${add_to_libs[*]}")${NIX_LDFLAGS:+" $NIX_LDFLAGS"}"
|
||||
export LD_LIBRARY_PATH="$(IFS=: ; printf "%s" "${add_to_libs[*]}")${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"}"
|
||||
fi
|
||||
if [[ "${#add_to_share[@]}" -gt 0 ]]; then
|
||||
export XDG_DATA_DIRS="$(IFS=: ; printf "%s" "${add_to_share[*]}")${XDG_DATA_DIRS:+":$XDG_DATA_DIRS"}"
|
||||
fi
|
||||
if [[ "${#add_to_include[@]}" -gt 0 ]]; then
|
||||
export CPATH="$(IFS=: ; printf "%s" "${add_to_include[*]}")${CPATH:+":$CPATH"}"
|
||||
fi
|
||||
if [[ "${#add_to_pythonpath[@]}" -gt 0 ]]; then
|
||||
export PYTHONPATH="$(IFS=: ; printf "%s" "${add_to_pythonpath[*]}")${PYTHONPATH:+":$PYTHONPATH"}"
|
||||
# export PYTHONNOUSERSITE=1
|
||||
fi
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user