From 6530af39d8a04356300d571f8f278af237af1817 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 13 Apr 2022 10:04:38 +0200 Subject: [PATCH] home: direnv: allow specifying default flake --- home/direnv/default.nix | 18 ++++++++++++++++-- home/direnv/lib/nix.sh | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/home/direnv/default.nix b/home/direnv/default.nix index 666f572..93a1f3b 100644 --- a/home/direnv/default.nix +++ b/home/direnv/default.nix @@ -3,8 +3,18 @@ let cfg = config.my.home.direnv; in { - options.my.home.direnv = with lib.my; { - enable = mkDisableOption "direnv configuration"; + options.my.home.direnv = with lib; { + enable = my.mkDisableOption "direnv configuration"; + + defaultFlake = mkOption { + type = types.str; + default = "pkgs"; + example = "nixpkgs"; + description = '' + Which flake from the registry should be used for + use pkgs by default. + ''; + }; }; config = lib.mkIf cfg.enable { @@ -28,5 +38,9 @@ in { source = libDir + "/${name}"; }; in lib.my.genAttrs' files linkLibFile; + + home.sessionVariables = { + DIRENV_DEFAULT_FLAKE = cfg.defaultFlake; + }; }; } diff --git a/home/direnv/lib/nix.sh b/home/direnv/lib/nix.sh index 9fbd73d..2d40b20 100644 --- a/home/direnv/lib/nix.sh +++ b/home/direnv/lib/nix.sh @@ -7,7 +7,8 @@ use_pkgs() { return 1 fi - local DEFAULT_FLAKE="pkgs" + # Use user-provided default value, or fallback to nixpkgs + local DEFAULT_FLAKE="${DIRENV_DEFAULT_FLAKE:-nixpkgs}" # Allow changing the default flake through a command line switch if [ "$1" = "-f" ] || [ "$1" = "--flake" ]; then