From b9361dada469fdb797625bd0e0c55a44ab942f87 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 13 Apr 2022 09:51:13 +0200 Subject: [PATCH] home: direnv: add 'nix' library file --- home/direnv/lib/nix.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 home/direnv/lib/nix.sh diff --git a/home/direnv/lib/nix.sh b/home/direnv/lib/nix.sh new file mode 100644 index 0000000..9fbd73d --- /dev/null +++ b/home/direnv/lib/nix.sh @@ -0,0 +1,31 @@ +#shellcheck shell=bash + +use_pkgs() { + if ! has nix; then + # shellcheck disable=2016 + log_error 'use_pkgs: `nix` is not in PATH' + return 1 + fi + + local DEFAULT_FLAKE="pkgs" + + # Allow changing the default flake through a command line switch + if [ "$1" = "-f" ] || [ "$1" = "--flake" ]; then + DEFAULT_FLAKE="$2" + shift 2 + fi + + + # 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 "${packages[@]}" --command "$direnv" dump +}