2024-10-21 16:24:42 +02:00
|
|
|
# shellcheck shell=bash
|
2022-04-13 09:51:13 +02:00
|
|
|
|
|
|
|
use_pkgs() {
|
|
|
|
if ! has nix; then
|
|
|
|
# shellcheck disable=2016
|
|
|
|
log_error 'use_pkgs: `nix` is not in PATH'
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
|
2022-04-13 10:04:38 +02:00
|
|
|
# Use user-provided default value, or fallback to nixpkgs
|
|
|
|
local DEFAULT_FLAKE="${DIRENV_DEFAULT_FLAKE:-nixpkgs}"
|
2023-09-05 13:15:33 +02:00
|
|
|
# Additional args that should be forwarded to `nix`
|
|
|
|
local args=()
|
2022-04-13 09:51:13 +02:00
|
|
|
|
|
|
|
# Allow changing the default flake through a command line switch
|
2023-09-05 13:10:01 +02:00
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2023-09-05 18:20:27 +02:00
|
|
|
-b|--broken)
|
|
|
|
args+=(--impure)
|
|
|
|
export NIXPKGS_ALLOW_BROKEN=1
|
|
|
|
shift
|
|
|
|
;;
|
2023-09-05 13:10:01 +02:00
|
|
|
-f|--flake)
|
|
|
|
DEFAULT_FLAKE="$2"
|
|
|
|
shift 2
|
|
|
|
;;
|
2023-09-05 13:15:33 +02:00
|
|
|
-i|--impure)
|
|
|
|
args+=(--impure)
|
|
|
|
shift
|
|
|
|
;;
|
2023-09-05 18:20:20 +02:00
|
|
|
-s|--insecure)
|
|
|
|
args+=(--impure)
|
|
|
|
export NIXPKGS_ALLOW_INSECURE=1
|
|
|
|
shift
|
|
|
|
;;
|
2023-09-05 18:20:03 +02:00
|
|
|
-u|--unfree)
|
|
|
|
args+=(--impure)
|
|
|
|
export NIXPKGS_ALLOW_UNFREE=1
|
|
|
|
shift
|
|
|
|
;;
|
2023-09-05 13:10:01 +02:00
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
2022-04-13 09:51:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Allow specifying a full installable, or just a package name and use the default flake
|
|
|
|
local packages=()
|
|
|
|
for pkg; do
|
|
|
|
if [[ $pkg =~ .*#.* ]]; then
|
|
|
|
packages+=("$pkg")
|
|
|
|
else
|
|
|
|
packages+=("$DEFAULT_FLAKE#$pkg")
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# shellcheck disable=2154
|
2023-09-05 13:15:33 +02:00
|
|
|
direnv_load nix shell "${args[@]}" "${packages[@]}" --command "$direnv" dump
|
2023-09-05 18:20:03 +02:00
|
|
|
|
|
|
|
# Clean-up after ourselves (assumes the user does not set them before us)
|
2023-09-05 18:20:27 +02:00
|
|
|
unset NIXPKGS_ALLOW_BROKEN
|
2023-09-05 18:20:20 +02:00
|
|
|
unset NIXPKGS_ALLOW_INSECURE
|
2023-09-05 18:20:03 +02:00
|
|
|
unset NIXPKGS_ALLOW_UNFREE
|
2022-04-13 09:51:13 +02:00
|
|
|
}
|