nix-config/home/direnv/lib/nix.sh
Bruno BELANYI 5926cd356d home: direnv: allow impure 'use pkgs'
This makes it easier to use non-free or insecure packages.
2023-09-05 16:11:11 +00:00

50 lines
1.2 KiB
Bash

#shellcheck shell=bash
use_pkgs() {
if ! has nix; then
# shellcheck disable=2016
log_error 'use_pkgs: `nix` is not in PATH'
return 1
fi
# Use user-provided default value, or fallback to nixpkgs
local DEFAULT_FLAKE="${DIRENV_DEFAULT_FLAKE:-nixpkgs}"
# Additional args that should be forwarded to `nix`
local args=()
# Allow changing the default flake through a command line switch
while true; do
case "$1" in
-f|--flake)
DEFAULT_FLAKE="$2"
shift 2
;;
-i|--impure)
args+=(--impure)
shift
;;
--)
shift
break
;;
*)
break
;;
esac
done
# 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
direnv_load nix shell "${args[@]}" "${packages[@]}" --command "$direnv" dump
}