From e0f2949c981a636ff1a75bd075e2a614af3bafb1 Mon Sep 17 00:00:00 2001 From: Josh Holland Date: Tue, 15 Jun 2021 17:11:26 +0100 Subject: [PATCH] direnv: add enableFlakes option for enableNixDirenvIntegration (#2089) NixOS/nixpkgs@03310df843a344215b45b2e8aef11ae9402a40e2 disabled flake support by default, so we now need to build a custom package and use it if the user wants to `use flake` successfully. This should fix #2087. --- modules/programs/direnv.nix | 26 ++++++++++++++----- tests/modules/programs/direnv/nix-direnv.nix | 2 +- .../programs/direnv/stdlib-and-nix-direnv.nix | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/modules/programs/direnv.nix b/modules/programs/direnv.nix index 63436d172..383cff3af 100644 --- a/modules/programs/direnv.nix +++ b/modules/programs/direnv.nix @@ -9,6 +9,14 @@ let tomlFormat = pkgs.formats.toml { }; in { + imports = [ + (mkRenamedOptionModule [ + "programs" + "direnv" + "enableNixDirenvIntegration" + ] [ "programs" "direnv" "nix-direnv" "enable" ]) + ]; + meta.maintainers = [ maintainers.rycee ]; options.programs.direnv = { @@ -63,10 +71,14 @@ in { ''; }; - enableNixDirenvIntegration = mkEnableOption '' - nix-direnv, - a fast, persistent use_nix implementation for direnv''; + nix-direnv = { + enable = mkEnableOption '' + nix-direnv, + a fast, persistent use_nix implementation for direnv''; + enableFlakes = mkEnableOption "Flake support in nix-direnv"; + }; + }; config = mkIf cfg.enable { @@ -77,9 +89,11 @@ in { }; xdg.configFile."direnv/direnvrc" = let + package = + pkgs.nix-direnv.override { inherit (cfg.nix-direnv) enableFlakes; }; text = concatStringsSep "\n" (optional (cfg.stdlib != "") cfg.stdlib - ++ optional cfg.enableNixDirenvIntegration - "source ${pkgs.nix-direnv}/share/nix-direnv/direnvrc"); + ++ optional cfg.nix-direnv.enable + "source ${package}/share/nix-direnv/direnvrc"); in mkIf (text != "") { inherit text; }; programs.bash.initExtra = mkIf cfg.enableBashIntegration ( diff --git a/tests/modules/programs/direnv/nix-direnv.nix b/tests/modules/programs/direnv/nix-direnv.nix index 57b3907dd..4c1730977 100644 --- a/tests/modules/programs/direnv/nix-direnv.nix +++ b/tests/modules/programs/direnv/nix-direnv.nix @@ -6,7 +6,7 @@ with lib; config = { programs.bash.enable = true; programs.direnv.enable = true; - programs.direnv.enableNixDirenvIntegration = true; + programs.direnv.nix-direnv.enable = true; nmt.script = '' assertFileExists home-files/.bashrc diff --git a/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix b/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix index 1dc224317..4e5efb873 100644 --- a/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix +++ b/tests/modules/programs/direnv/stdlib-and-nix-direnv.nix @@ -7,7 +7,7 @@ in { config = { programs.bash.enable = true; programs.direnv.enable = true; - programs.direnv.enableNixDirenvIntegration = true; + programs.direnv.nix-direnv.enable = true; programs.direnv.stdlib = expectedContent; nmt.script = ''