Compare commits

...

2 Commits

Author SHA1 Message Date
Silvan Mosberger
f0726dcd69 modules/direnv: init
nix-direnv is surprisingly annoying to configure correctly, due to it
needing both system-wide adjustments (`nix.conf` changes), but also
user-wide adjustments (telling direnv to load nix-direnv using
~/.config/direnv/direnvrc).

This module puts an end to that, allowing a direnv + nix-direnv
installation with just

  programs.direnv.enable = true;
2022-09-23 22:37:28 +02:00
Silvan Mosberger
7b4b779ead direnv: Also install to /share/direnv/lib/nix-direnv.sh
This allows setting DIRENV_CONFIG to (nix-profile)/share/direnv and have
it find the nix-direnv script, while also allowing other direnv
integrations to coexist.

Old path kept for backwards compat.
2022-09-23 22:14:46 +02:00
2 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
{ lib, config, pkgs, ... }: {
options.programs.direnv.enable = lib.mkOption {
type = lib.types.bool;
default = false;
example = true;
description = ''
Whether to enable direnv integration. Takes care of both installation and
setting up the sourcing of the shell. Additionally enables nix-direnv
integration. Note that you need to logout and login for this change to apply.
'';
};
config = lib.mkIf config.programs.direnv.enable {
environment.systemPackages = with pkgs; [
direnv
nix-direnv
];
environment.pathsToLink = [
"/share/direnv"
];
environment.sessionVariables.DIRENV_CONFIG = "/run/current-system/sw/share/direnv";
programs.bash.interactiveShellInit = ''
eval "$(direnv hook bash)"
'';
programs.zsh.interactiveShellInit = ''
eval "$(direnv hook zsh)"
'';
programs.fish.interactiveShellInit = ''
direnv hook fish | source
'';
# nix options for derivations to persist garbage collection
nix.settings.keep-outputs = true;
nix.settings.keep-derivations = true;
};
}

View File

@@ -26,6 +26,9 @@ stdenv.mkDerivation rec {
installPhase = ''
runHook preInstall
install -m500 -D direnvrc $out/share/nix-direnv/direnvrc
# Allows NixOS to set DIRENV_CONFIG to /run/current-system/sw/share/direnv and have direnv load this
install -m500 -D direnvrc $out/share/direnv/lib/nix-direnv.sh
runHook postInstall
'';