dotfiles/hm/shell/direnv.nix
Geoffrey “Frogeye” Preud'homme 65817f4e70 Do not sync direnv
It will only add the the cache to gcroots on the first computer that
built it, so everyone else has to re-fetch it.
2025-05-19 21:48:48 +02:00

59 lines
1.5 KiB
Nix

# Allow switching to a specific environment when going into a directory
{
config,
lib,
pkgs,
...
}:
{
config = {
programs = {
direnv = {
enable = true;
enableBashIntegration = true;
enableZshIntegration = true;
nix-direnv.enable = true;
};
git.ignores = [
".envrc"
".direnv"
];
};
systemd.user.services.direnv_ignore = {
Service = {
Type = "oneshot";
ExecStart = lib.getExe (
pkgs.writeShellApplication {
name = "direnv_ignore";
text =
''
ignore_direnv() {
dir="$1"
if [ ! -f "$dir/.stignore" ]
then
touch "$dir/.stignore"
fi
rule="**/.direnv"
if ! grep -qFx "$rule" "$dir/.stignore"
then
echo "$rule" >> "$dir/.stignore"
fi
}
''
+ (lib.trivial.pipe config.frogeye.folders [
builtins.attrValues
(builtins.filter (folder: folder.syncthing.enable))
(builtins.map (folder: ''
ignore_direnv ${lib.strings.escapeShellArg folder.fullPath}
''))
lib.strings.concatLines
]);
}
);
};
Install = {
WantedBy = [ "default.target" ];
};
};
};
}