You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.9 KiB
114 lines
2.9 KiB
6 years ago
|
{ config, lib, pkgs, ... }:
|
||
|
|
||
|
with lib;
|
||
|
|
||
|
let
|
||
|
|
||
|
cfg = config.programs.direnv;
|
||
4 years ago
|
|
||
|
tomlFormat = pkgs.formats.toml { };
|
||
6 years ago
|
|
||
4 years ago
|
in {
|
||
3 years ago
|
imports = [
|
||
|
(mkRenamedOptionModule [
|
||
|
"programs"
|
||
|
"direnv"
|
||
|
"enableNixDirenvIntegration"
|
||
|
] [ "programs" "direnv" "nix-direnv" "enable" ])
|
||
|
];
|
||
|
|
||
6 years ago
|
meta.maintainers = [ maintainers.rycee ];
|
||
|
|
||
|
options.programs.direnv = {
|
||
|
enable = mkEnableOption "direnv, the environment switcher";
|
||
|
|
||
6 years ago
|
config = mkOption {
|
||
4 years ago
|
type = tomlFormat.type;
|
||
4 years ago
|
default = { };
|
||
6 years ago
|
description = ''
|
||
|
Configuration written to
|
||
|
<filename>~/.config/direnv/config.toml</filename>.
|
||
|
</para><para>
|
||
|
See
|
||
|
<citerefentry>
|
||
|
<refentrytitle>direnv.toml</refentrytitle>
|
||
|
<manvolnum>1</manvolnum>
|
||
|
</citerefentry>.
|
||
|
for the full list of options.
|
||
|
'';
|
||
|
};
|
||
|
|
||
6 years ago
|
stdlib = mkOption {
|
||
|
type = types.lines;
|
||
|
default = "";
|
||
|
description = ''
|
||
6 years ago
|
Custom stdlib written to
|
||
|
<filename>~/.config/direnv/direnvrc</filename>.
|
||
6 years ago
|
'';
|
||
|
};
|
||
|
|
||
6 years ago
|
enableBashIntegration = mkOption {
|
||
|
default = true;
|
||
|
type = types.bool;
|
||
|
description = ''
|
||
|
Whether to enable Bash integration.
|
||
|
'';
|
||
|
};
|
||
|
|
||
|
enableZshIntegration = mkOption {
|
||
|
default = true;
|
||
|
type = types.bool;
|
||
|
description = ''
|
||
|
Whether to enable Zsh integration.
|
||
|
'';
|
||
|
};
|
||
6 years ago
|
|
||
|
enableFishIntegration = mkOption {
|
||
|
default = true;
|
||
|
type = types.bool;
|
||
3 years ago
|
readOnly = true;
|
||
6 years ago
|
description = ''
|
||
3 years ago
|
Whether to enable Fish integration. Note, enabling the direnv module
|
||
|
will always active its functionality for Fish since the direnv package
|
||
|
automatically gets loaded in Fish.
|
||
6 years ago
|
'';
|
||
|
};
|
||
4 years ago
|
|
||
3 years ago
|
nix-direnv = {
|
||
|
enable = mkEnableOption ''
|
||
|
<link
|
||
|
xlink:href="https://github.com/nix-community/nix-direnv">nix-direnv</link>,
|
||
|
a fast, persistent use_nix implementation for direnv'';
|
||
|
enableFlakes = mkEnableOption "Flake support in nix-direnv";
|
||
|
};
|
||
|
|
||
6 years ago
|
};
|
||
|
|
||
|
config = mkIf cfg.enable {
|
||
|
home.packages = [ pkgs.direnv ];
|
||
|
|
||
4 years ago
|
xdg.configFile."direnv/config.toml" = mkIf (cfg.config != { }) {
|
||
|
source = tomlFormat.generate "direnv-config" cfg.config;
|
||
|
};
|
||
6 years ago
|
|
||
4 years ago
|
xdg.configFile."direnv/direnvrc" = let
|
||
3 years ago
|
package =
|
||
|
pkgs.nix-direnv.override { inherit (cfg.nix-direnv) enableFlakes; };
|
||
4 years ago
|
text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib
|
||
3 years ago
|
++ optional cfg.nix-direnv.enable
|
||
|
"source ${package}/share/nix-direnv/direnvrc");
|
||
4 years ago
|
in mkIf (text != "") { inherit text; };
|
||
6 years ago
|
|
||
4 years ago
|
programs.bash.initExtra = mkIf cfg.enableBashIntegration (
|
||
4 years ago
|
# Using mkAfter to make it more likely to appear after other
|
||
|
# manipulations of the prompt.
|
||
4 years ago
|
mkAfter ''
|
||
|
eval "$(${pkgs.direnv}/bin/direnv hook bash)"
|
||
|
'');
|
||
6 years ago
|
|
||
|
programs.zsh.initExtra = mkIf cfg.enableZshIntegration ''
|
||
|
eval "$(${pkgs.direnv}/bin/direnv hook zsh)"
|
||
|
'';
|
||
|
};
|
||
|
}
|