diff options
| author | Silvan Mosberger <contact@infinisil.com> | 2022-09-23 22:17:05 +0200 |
|---|---|---|
| committer | Silvan Mosberger <contact@infinisil.com> | 2022-09-23 22:37:28 +0200 |
| commit | f0726dcd69ba30feafd88606882c317c7e9bd093 (patch) | |
| tree | 1d89b2ce5aade52ebba3a439281bf328885392dc | |
| parent | direnv: Also install to /share/direnv/lib/nix-direnv.sh (diff) | |
| download | nixpkgs-f0726dcd69ba30feafd88606882c317c7e9bd093.tar.gz | |
modules/direnv: initorigin/direnv-module
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;
| -rw-r--r-- | nixos/modules/programs/direnv.nix | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/nixos/modules/programs/direnv.nix b/nixos/modules/programs/direnv.nix new file mode 100644 index 000000000000..0e182052d3d3 --- /dev/null +++ b/nixos/modules/programs/direnv.nix @@ -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; + }; + +} |
