Skip to content

Commit

Permalink
flakes: Don't run shellHook on cached dev shells
Browse files Browse the repository at this point in the history
This makes the behavior of `use flake` consistent with that of `use
nix`.

Resolve #90.
  • Loading branch information
ryneeverett committed Jun 8, 2021
1 parent 4cb1aa4 commit 7b86b7f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions direnvrc
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ use_flake() {

log_status renewed cache
else
sed -i '/eval \"\$shellHook\"/d' "$profile_rc"
log_status using cached dev shell
fi

Expand Down
4 changes: 4 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def test_nix_shell(self) -> None:
)
sys.stderr.write(out1.stderr)
self.assertIn("renewed cache and derivation link", out1.stderr)
self.assertIn("Executing shellHook.", out1.stderr)
self.assertEqual(out1.returncode, 0)

run(["nix-collect-garbage"], check=True)
Expand All @@ -67,6 +68,7 @@ def test_nix_shell(self) -> None:
)
sys.stderr.write(out2.stderr)
self.assertIn("using cached derivation", out2.stderr)
self.assertNotIn("Executing shellHook.", out2.stderr)
self.assertEqual(out2.returncode, 0)

@unittest.skipUnless(support_flakes(), "requires flakes")
Expand All @@ -86,6 +88,7 @@ def test_nix_flake(self) -> None:
)
sys.stderr.write(out1.stderr)
self.assertIn("renewed cache", out1.stderr)
self.assertIn("Executing shellHook.", out1.stderr)
self.assertEqual(out1.returncode, 0)

run(["nix-collect-garbage"], check=True)
Expand All @@ -107,6 +110,7 @@ def test_nix_flake(self) -> None:
for symlink in inputs:
self.assertTrue(symlink.is_dir())
self.assertIn("using cached dev shell", out2.stderr)
self.assertNotIn("Executing shellHook.", out2.stderr)

self.assertEqual(out2.returncode, 0)

Expand Down
3 changes: 3 additions & 0 deletions tests/testenv/shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
nativeBuildInputs = [ pkgs.hello ];
shellHook = ''
echo "Executing shellHook."
'';
}

0 comments on commit 7b86b7f

Please sign in to comment.