mirror of
https://github.com/CHN-beta/nixpkgs.git
synced 2026-01-12 10:50:30 +08:00
Compare commits
2 Commits
update-git
...
direnv-mod
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f0726dcd69 | ||
|
|
7b4b779ead |
44
nixos/modules/programs/direnv.nix
Normal file
44
nixos/modules/programs/direnv.nix
Normal 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;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -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
|
||||
'';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user