direnv: add nix-direnv to lib instead of sourcing

Also removes use of `with lib`.
This commit is contained in:
Joaquín Triñanes 2024-04-29 00:30:45 +02:00 committed by GitHub
parent c002bc08c8
commit 9fe79591c1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 13 additions and 15 deletions

View file

@ -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

View file

@ -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
'';
};
}

View file

@ -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}'

View file

@ -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 \