1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-11-27 05:29:46 +01:00

direnv: add support for nix-direnv

PR #1297
This commit is contained in:
Damien Cassou 2020-06-01 09:56:48 +02:00 committed by Robert Helgesson
parent 575cd4b8ba
commit b33802ca7f
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89
4 changed files with 53 additions and 2 deletions

View file

@ -70,6 +70,11 @@ in {
Whether to enable Fish integration.
'';
};
enableNixDirenvIntegration = mkEnableOption ''
<link
xlink:href="https://github.com/nix-community/nix-direnv">nix-direnv</link>,
a fast, persistent use_nix implementation for direnv'';
};
config = mkIf cfg.enable {
@ -78,8 +83,11 @@ in {
xdg.configFile."direnv/config.toml" =
mkIf (cfg.config != { }) { source = configFile cfg.config; };
xdg.configFile."direnv/direnvrc" =
mkIf (cfg.stdlib != "") { text = cfg.stdlib; };
xdg.configFile."direnv/direnvrc" = let
text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib
++ optional cfg.enableNixDirenvIntegration
"source ${pkgs.nix-direnv}/share/nix-direnv/direnvrc");
in mkIf (text != "") { inherit text; };
programs.bash.initExtra = mkIf cfg.enableBashIntegration (
# Using mkAfter to make it more likely to appear after other

View file

@ -1,4 +1,6 @@
{
direnv-bash = ./bash.nix;
direnv-nix-direnv = ./nix-direnv.nix;
direnv-stdlib = ./stdlib.nix;
direnv-stdlib-and-nix-direnv = ./stdlib-and-nix-direnv.nix;
}

View file

@ -0,0 +1,18 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.bash.enable = true;
programs.direnv.enable = true;
programs.direnv.enableNixDirenvIntegration = true;
nmt.script = ''
assertFileExists home-files/.bashrc
assertFileRegex \
home-files/.config/direnv/direnvrc \
'source /nix/store/.*nix-direnv.*/share/nix-direnv/direnvrc'
'';
};
}

View file

@ -0,0 +1,23 @@
{ config, lib, pkgs, ... }:
with lib;
let expectedContent = "something important";
in {
config = {
programs.bash.enable = true;
programs.direnv.enable = true;
programs.direnv.enableNixDirenvIntegration = true;
programs.direnv.stdlib = expectedContent;
nmt.script = ''
assertFileExists home-files/.bashrc
assertFileRegex \
home-files/.config/direnv/direnvrc \
'source /nix/store/.*nix-direnv.*/share/nix-direnv/direnvrc'
assertFileRegex \
home-files/.config/direnv/direnvrc \
'${expectedContent}'
'';
};
}