From 9fe79591c1005ce6f93084ae7f7dab0a2891440d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joaqu=C3=ADn=20Tri=C3=B1anes?= Date: Mon, 29 Apr 2024 00:30:45 +0200 Subject: [PATCH] direnv: add nix-direnv to lib instead of sourcing Also removes use of `with lib`. --- modules/programs/direnv.nix | 19 ++++++++++--------- tests/modules/programs/direnv/nix-direnv.nix | 4 +--- .../programs/direnv/stdlib-and-nix-direnv.nix | 4 +--- tests/modules/programs/direnv/stdlib.nix | 1 + 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/modules/programs/direnv.nix b/modules/programs/direnv.nix index fcbc4634..add2c8fc 100644 --- a/modules/programs/direnv.nix +++ b/modules/programs/direnv.nix @@ -1,8 +1,8 @@ { config, lib, pkgs, ... }: - -with lib; - let + inherit (lib) + mkOption mkRenamedOptionModule mkRemovedOptionModule mkEnableOption types + mkPackageOption mkIf mkAfter getExe; cfg = config.programs.direnv; @@ -19,7 +19,7 @@ in { "Flake support is now always enabled.") ]; - meta.maintainers = [ maintainers.rycee ]; + meta.maintainers = [ lib.maintainers.rycee ]; options.programs.direnv = { enable = mkEnableOption "direnv, the environment switcher"; @@ -104,11 +104,12 @@ in { source = tomlFormat.generate "direnv-config" cfg.config; }; - xdg.configFile."direnv/direnvrc" = let - text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib - ++ optional cfg.nix-direnv.enable - "source ${cfg.nix-direnv.package}/share/nix-direnv/direnvrc"); - in mkIf (text != "") { inherit text; }; + xdg.configFile."direnv/lib/hm-nix-direnv.sh" = mkIf cfg.nix-direnv.enable { + source = "${cfg.nix-direnv.package}/share/nix-direnv/direnvrc"; + }; + + xdg.configFile."direnv/direnvrc" = + lib.mkIf (cfg.stdlib != "") { text = cfg.stdlib; }; programs.bash.initExtra = mkIf cfg.enableBashIntegration ( # Using mkAfter to make it more likely to appear after other diff --git a/tests/modules/programs/direnv/nix-direnv.nix b/tests/modules/programs/direnv/nix-direnv.nix index 4c173097..588cd6ed 100644 --- a/tests/modules/programs/direnv/nix-direnv.nix +++ b/tests/modules/programs/direnv/nix-direnv.nix @@ -10,9 +10,7 @@ with lib; nmt.script = '' assertFileExists home-files/.bashrc - assertFileRegex \ - home-files/.config/direnv/direnvrc \ - 'source /nix/store/.*nix-direnv.*/share/nix-direnv/direnvrc' + assertFileExists home-files/.config/direnv/lib/hm-nix-direnv.sh ''; }; } diff --git a/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix b/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix index 4e5efb87..3bfd768c 100644 --- a/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix +++ b/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix @@ -12,9 +12,7 @@ in { nmt.script = '' assertFileExists home-files/.bashrc - assertFileRegex \ - home-files/.config/direnv/direnvrc \ - 'source /nix/store/.*nix-direnv.*/share/nix-direnv/direnvrc' + assertFileExists home-files/.config/direnv/lib/hm-nix-direnv.sh assertFileRegex \ home-files/.config/direnv/direnvrc \ '${expectedContent}' diff --git a/tests/modules/programs/direnv/stdlib.nix b/tests/modules/programs/direnv/stdlib.nix index 1d06a0bc..2a859132 100644 --- a/tests/modules/programs/direnv/stdlib.nix +++ b/tests/modules/programs/direnv/stdlib.nix @@ -10,6 +10,7 @@ in { programs.direnv.stdlib = expectedContent; nmt.script = '' + assertPathNotExists home-files/.config/direnv/lib/hm-nix-direnv.sh assertFileExists home-files/.bashrc assertFileRegex \ home-files/.config/direnv/direnvrc \