From ac93cb0ac8cd2ff4c0194bb0cf2d9aca1c34f758 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 5 Sep 2023 11:10:01 +0000 Subject: [PATCH 1/5] home: direnv: refactor option handling This will make it easier to add more options. --- home/direnv/lib/nix.sh | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/home/direnv/lib/nix.sh b/home/direnv/lib/nix.sh index 2d40b20..b0c2dae 100644 --- a/home/direnv/lib/nix.sh +++ b/home/direnv/lib/nix.sh @@ -11,10 +11,21 @@ use_pkgs() { local DEFAULT_FLAKE="${DIRENV_DEFAULT_FLAKE:-nixpkgs}" # Allow changing the default flake through a command line switch - if [ "$1" = "-f" ] || [ "$1" = "--flake" ]; then - DEFAULT_FLAKE="$2" - shift 2 - fi + while true; do + case "$1" in + -f|--flake) + DEFAULT_FLAKE="$2" + shift 2 + ;; + --) + shift + break + ;; + *) + break + ;; + esac + done # Allow specifying a full installable, or just a package name and use the default flake From 5926cd356d28a6652934a2fdae111f71bddb6246 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 5 Sep 2023 11:15:33 +0000 Subject: [PATCH 2/5] home: direnv: allow impure 'use pkgs' This makes it easier to use non-free or insecure packages. --- home/direnv/lib/nix.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/home/direnv/lib/nix.sh b/home/direnv/lib/nix.sh index b0c2dae..e05025b 100644 --- a/home/direnv/lib/nix.sh +++ b/home/direnv/lib/nix.sh @@ -9,6 +9,8 @@ use_pkgs() { # 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 @@ -17,6 +19,10 @@ use_pkgs() { DEFAULT_FLAKE="$2" shift 2 ;; + -i|--impure) + args+=(--impure) + shift + ;; --) shift break @@ -39,5 +45,5 @@ use_pkgs() { done # shellcheck disable=2154 - direnv_load nix shell "${packages[@]}" --command "$direnv" dump + direnv_load nix shell "${args[@]}" "${packages[@]}" --command "$direnv" dump } From d060978b65b510b3da2f81c9d6e8a66197cdf2d5 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 5 Sep 2023 16:20:03 +0000 Subject: [PATCH 3/5] home: direnv: allow unfree 'use pkgs' --- home/direnv/lib/nix.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/home/direnv/lib/nix.sh b/home/direnv/lib/nix.sh index e05025b..ec8fa88 100644 --- a/home/direnv/lib/nix.sh +++ b/home/direnv/lib/nix.sh @@ -23,6 +23,11 @@ use_pkgs() { args+=(--impure) shift ;; + -u|--unfree) + args+=(--impure) + export NIXPKGS_ALLOW_UNFREE=1 + shift + ;; --) shift break @@ -46,4 +51,7 @@ use_pkgs() { # shellcheck disable=2154 direnv_load nix shell "${args[@]}" "${packages[@]}" --command "$direnv" dump + + # Clean-up after ourselves (assumes the user does not set them before us) + unset NIXPKGS_ALLOW_UNFREE } From 96a2c62e947f66a7d9c8c1501ba56c1ea60f4a41 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 5 Sep 2023 16:20:20 +0000 Subject: [PATCH 4/5] home: direnv: allow insecure 'use pkgs' --- home/direnv/lib/nix.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/home/direnv/lib/nix.sh b/home/direnv/lib/nix.sh index ec8fa88..de86dac 100644 --- a/home/direnv/lib/nix.sh +++ b/home/direnv/lib/nix.sh @@ -23,6 +23,11 @@ use_pkgs() { args+=(--impure) shift ;; + -s|--insecure) + args+=(--impure) + export NIXPKGS_ALLOW_INSECURE=1 + shift + ;; -u|--unfree) args+=(--impure) export NIXPKGS_ALLOW_UNFREE=1 @@ -53,5 +58,6 @@ use_pkgs() { direnv_load nix shell "${args[@]}" "${packages[@]}" --command "$direnv" dump # Clean-up after ourselves (assumes the user does not set them before us) + unset NIXPKGS_ALLOW_INSECURE unset NIXPKGS_ALLOW_UNFREE } From f0e387b943ddf059147259ad0345bb582f7ae00f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 5 Sep 2023 16:20:27 +0000 Subject: [PATCH 5/5] home: direnv: allow broken 'use pkgs' --- home/direnv/lib/nix.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/home/direnv/lib/nix.sh b/home/direnv/lib/nix.sh index de86dac..a65eb31 100644 --- a/home/direnv/lib/nix.sh +++ b/home/direnv/lib/nix.sh @@ -15,6 +15,11 @@ use_pkgs() { # Allow changing the default flake through a command line switch while true; do case "$1" in + -b|--broken) + args+=(--impure) + export NIXPKGS_ALLOW_BROKEN=1 + shift + ;; -f|--flake) DEFAULT_FLAKE="$2" shift 2 @@ -58,6 +63,7 @@ use_pkgs() { direnv_load nix shell "${args[@]}" "${packages[@]}" --command "$direnv" dump # Clean-up after ourselves (assumes the user does not set them before us) + unset NIXPKGS_ALLOW_BROKEN unset NIXPKGS_ALLOW_INSECURE unset NIXPKGS_ALLOW_UNFREE }