all repos — nixfiles @ d2711022cde38d2e0035edd917d7f17f2b7c9ff2

System and user configuration, managed by nix and home-manager

Enable automatic per-project nix development shells with direnv
Alan Pearce alan@alanpearce.eu
Tue, 11 Apr 2023 15:12:03 +0200
commit

d2711022cde38d2e0035edd917d7f17f2b7c9ff2

parent

aa43b171944d5393f23e6e2902ceb7191714ab03

2 files changed, 19 insertions(+), 1 deletions(-)

jump to
M system/settings/darwin.nixsystem/settings/darwin.nix
@@ -18,6 +18,8 @@ };     settings.extra-platforms = "aarch64-darwin x86_64-darwin";
     settings.experimental-features = "nix-command flakes";
     settings.warn-dirty = false;
+    settings.keep-outputs = true;
+    settings.keep-derivations = true;
   };
 
   nixpkgs.config = {
M user/settings/development/base.nixuser/settings/development/base.nix
@@ -2,7 +2,13 @@ { config , lib
 , pkgs
 , ...
-}: {
+}:
+let
+  direnvHook = pkgs.runCommandLocal "direnv_hook" { } ''
+    ${pkgs.direnv}/bin/direnv hook zsh > $out
+  '';
+in
+{
   home.packages = with pkgs;
     [
       shellcheck
@@ -31,4 +37,14 @@ (self: super: {       ripgrep = super.ripgrep.override { withPCRE2 = true; };
     })
   ];
+
+  programs.direnv = {
+    enable = true;
+    nix-direnv = {
+      enable = true;
+    };
+  };
+  programs.zsh.initExtra = ''
+    source ${direnvHook}
+  '';
 }