diff --git a/modules/programs/direnv.nix b/modules/programs/direnv.nix index fcbc46346..add2c8fca 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 4c1730977..588cd6ed6 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 4e5efb873..3bfd768c4 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 1d06a0bc2..2a859132f 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 \