From b99fff4723667e942f79d828eeaea5565f2d5739 Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Sat, 27 Jul 2024 15:32:31 -0400 Subject: [PATCH 1/5] nixos/direnv: format with nixfmt --- nixos/modules/programs/direnv.nix | 38 +++++++++++++++++++------------ 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/nixos/modules/programs/direnv.nix b/nixos/modules/programs/direnv.nix index 6061de58eb8e..e7956e1b4bd6 100644 --- a/nixos/modules/programs/direnv.nix +++ b/nixos/modules/programs/direnv.nix @@ -3,9 +3,11 @@ config, pkgs, ... -}: let +}: +let cfg = config.programs.direnv; -in { +in +{ options.programs.direnv = { enable = lib.mkEnableOption '' @@ -14,7 +16,7 @@ in { integration. Note that you need to logout and login for this change to apply ''; - package = lib.mkPackageOption pkgs "direnv" {}; + package = lib.mkPackageOption pkgs "direnv" { }; direnvrcExtra = lib.mkOption { type = lib.types.lines; @@ -61,7 +63,11 @@ in { }; imports = [ - (lib.mkRemovedOptionModule ["programs" "direnv" "persistDerivations"] "persistDerivations was removed as it is no longer necessary") + (lib.mkRemovedOptionModule [ + "programs" + "direnv" + "persistDerivations" + ] "persistDerivations was removed as it is no longer necessary") ]; config = lib.mkIf cfg.enable { @@ -91,17 +97,19 @@ in { environment = { systemPackages = - if cfg.loadInNixShell then [cfg.package] - else [ - #direnv has a fish library which sources direnv for some reason - (cfg.package.overrideAttrs (old: { - installPhase = - (old.installPhase or "") - + '' - rm -rf $out/share/fish - ''; - })) - ]; + if cfg.loadInNixShell then + [ cfg.package ] + else + [ + #direnv has a fish library which sources direnv for some reason + (cfg.package.overrideAttrs (old: { + installPhase = + (old.installPhase or "") + + '' + rm -rf $out/share/fish + ''; + })) + ]; variables = { DIRENV_CONFIG = "/etc/direnv"; From 9183b7d82b45d9bead4e7656b73ebbf3873bad55 Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Sat, 27 Jul 2024 15:33:39 -0400 Subject: [PATCH 2/5] nixos/direnv: add gerg-l to maintainers --- nixos/modules/programs/direnv.nix | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/modules/programs/direnv.nix b/nixos/modules/programs/direnv.nix index e7956e1b4bd6..8b2b6f7aa95a 100644 --- a/nixos/modules/programs/direnv.nix +++ b/nixos/modules/programs/direnv.nix @@ -149,4 +149,5 @@ in }; }; }; + meta.maintainers = with lib.maintainers; [ gerg-l ]; } From c6f73686d6c7968acfd7b880235bacccf711f94d Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Sat, 27 Jul 2024 15:36:24 -0400 Subject: [PATCH 3/5] nixos/direnv: stop uneccesary build --- nixos/modules/programs/direnv.nix | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nixos/modules/programs/direnv.nix b/nixos/modules/programs/direnv.nix index 8b2b6f7aa95a..7aeeb9db2065 100644 --- a/nixos/modules/programs/direnv.nix +++ b/nixos/modules/programs/direnv.nix @@ -102,13 +102,13 @@ in else [ #direnv has a fish library which sources direnv for some reason - (cfg.package.overrideAttrs (old: { - installPhase = - (old.installPhase or "") - + '' - rm -rf $out/share/fish - ''; - })) + (pkgs.symlinkJoin { + inherit (cfg.package) name; + paths = [ cfg.package ]; + postBuild = '' + rm -rf $out/share/fish + ''; + }) ]; variables = { From 008173588b9ad455bb67fe57ef8d746542d4f733 Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Sat, 27 Jul 2024 15:37:11 -0400 Subject: [PATCH 4/5] nixos/direnv: remove old option removal error --- nixos/modules/programs/direnv.nix | 8 -------- 1 file changed, 8 deletions(-) diff --git a/nixos/modules/programs/direnv.nix b/nixos/modules/programs/direnv.nix index 7aeeb9db2065..f0932c413f15 100644 --- a/nixos/modules/programs/direnv.nix +++ b/nixos/modules/programs/direnv.nix @@ -62,14 +62,6 @@ in }; }; - imports = [ - (lib.mkRemovedOptionModule [ - "programs" - "direnv" - "persistDerivations" - ] "persistDerivations was removed as it is no longer necessary") - ]; - config = lib.mkIf cfg.enable { programs = { From ee3da00d592822e508ee4c0e1b6a5ec1bf3051bd Mon Sep 17 00:00:00 2001 From: Gerg-L Date: Sat, 27 Jul 2024 15:52:07 -0400 Subject: [PATCH 5/5] nixos/direnv: add enable{Bash,Fish,Zsh}Integrations use shorthand function for enabled by default options --- nixos/modules/programs/direnv.nix | 68 +++++++++++++++++-------------- 1 file changed, 37 insertions(+), 31 deletions(-) diff --git a/nixos/modules/programs/direnv.nix b/nixos/modules/programs/direnv.nix index f0932c413f15..f127e959ef01 100644 --- a/nixos/modules/programs/direnv.nix +++ b/nixos/modules/programs/direnv.nix @@ -6,6 +6,13 @@ }: let cfg = config.programs.direnv; + enabledOption = + x: + lib.mkEnableOption x + // { + default = true; + example = false; + }; in { options.programs.direnv = { @@ -18,6 +25,16 @@ in package = lib.mkPackageOption pkgs "direnv" { }; + enableBashIntegration = enabledOption '' + Bash integration + ''; + enableZshIntegration = enabledOption '' + Zsh integration + ''; + enableFishIntegration = enabledOption '' + Fish integration + ''; + direnvrcExtra = lib.mkOption { type = lib.types.lines; default = ""; @@ -34,22 +51,14 @@ in the hiding of direnv logging ''; - loadInNixShell = - lib.mkEnableOption '' - loading direnv in `nix-shell` `nix shell` or `nix develop` - '' - // { - default = true; - }; + loadInNixShell = enabledOption '' + loading direnv in `nix-shell` `nix shell` or `nix develop` + ''; nix-direnv = { - enable = - (lib.mkEnableOption '' - a faster, persistent implementation of use_nix and use_flake, to replace the built-in one - '') - // { - default = true; - }; + enable = enabledOption '' + a faster, persistent implementation of use_nix and use_flake, to replace the builtin one + ''; package = lib.mkOption { default = pkgs.nix-direnv.override { nix = config.nix.package; }; @@ -65,7 +74,7 @@ in config = lib.mkIf cfg.enable { programs = { - zsh.interactiveShellInit = '' + zsh.interactiveShellInit = lib.mkIf cfg.enableZshIntegration '' if ${lib.boolToString cfg.loadInNixShell} || printenv PATH | grep -vqc '/nix/store'; then eval "$(${lib.getExe cfg.package} hook zsh)" fi @@ -73,13 +82,13 @@ in #$NIX_GCROOT for "nix develop" https://github.com/NixOS/nix/blob/6db66ebfc55769edd0c6bc70fcbd76246d4d26e0/src/nix/develop.cc#L530 #$IN_NIX_SHELL for "nix-shell" - bash.interactiveShellInit = '' + bash.interactiveShellInit = lib.mkIf cfg.enableBashIntegration '' if ${lib.boolToString cfg.loadInNixShell} || [ -z "$IN_NIX_SHELL$NIX_GCROOT$(printenv PATH | grep '/nix/store')" ] ; then eval "$(${lib.getExe cfg.package} hook bash)" fi ''; - fish.interactiveShellInit = '' + fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration '' if ${lib.boolToString cfg.loadInNixShell}; or printenv PATH | grep -vqc '/nix/store'; ${lib.getExe cfg.package} hook fish | source @@ -88,20 +97,17 @@ in }; environment = { - systemPackages = - if cfg.loadInNixShell then - [ cfg.package ] - else - [ - #direnv has a fish library which sources direnv for some reason - (pkgs.symlinkJoin { - inherit (cfg.package) name; - paths = [ cfg.package ]; - postBuild = '' - rm -rf $out/share/fish - ''; - }) - ]; + systemPackages = [ + # direnv has a fish library which automatically sources direnv for some reason + # I don't see any harm in doing this if we're sourcing it with fish.interactiveShellInit + (pkgs.symlinkJoin { + inherit (cfg.package) name; + paths = [ cfg.package ]; + postBuild = '' + rm -rf $out/share/fish + ''; + }) + ]; variables = { DIRENV_CONFIG = "/etc/direnv";