mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
Merge pull request #15 from nix-community/gc
fix persistent derivation link
This commit is contained in:
commit
5498c5404a
3 changed files with 36 additions and 5 deletions
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
|
|
@ -8,5 +8,9 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: cachix/install-nix-action@v7
|
- uses: cachix/install-nix-action@v7
|
||||||
|
- name: Prevent garbage collections of gcroots
|
||||||
|
run:
|
||||||
|
printf "keep-outputs = true\nkeep-derivations = true\n" | sudo tee -a /etc/nix/nix.conf;
|
||||||
|
sudo systemctl restart nix-daemon
|
||||||
- run:
|
- run:
|
||||||
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixpkgs-unstable.tar.gz ci.nix --run 'true'
|
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixpkgs-unstable.tar.gz ci.nix --run 'true'
|
||||||
|
|
|
||||||
2
direnvrc
2
direnvrc
|
|
@ -84,7 +84,7 @@ use_nix() {
|
||||||
local escaped_pwd=${stripped_pwd//-/--}
|
local escaped_pwd=${stripped_pwd//-/--}
|
||||||
local escaped_pwd=${escaped_pwd//\//-}
|
local escaped_pwd=${escaped_pwd//\//-}
|
||||||
ln -fs "$drv" "$drv_link"
|
ln -fs "$drv" "$drv_link"
|
||||||
ln -fs "$PWD/$drv_link" "/nix/var/nix/gcroots/per-user/$LOGNAME/$escaped_pwd"
|
ln -fs "$drv_link" "/nix/var/nix/gcroots/per-user/$USER/$escaped_pwd"
|
||||||
log_status renewed cache and derivation link
|
log_status renewed cache and derivation link
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,22 @@
|
||||||
|
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import shutil
|
import shutil
|
||||||
import unittest
|
import unittest
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
TEST_ROOT = Path(__file__).resolve().parent
|
TEST_ROOT = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
|
||||||
|
def run(cmd: List[str], **kwargs) -> subprocess.CompletedProcess:
|
||||||
|
print("$ " + " ".join(cmd))
|
||||||
|
return subprocess.run(cmd, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class IntegrationTest(unittest.TestCase):
|
class IntegrationTest(unittest.TestCase):
|
||||||
def setUp(self) -> None:
|
def setUp(self) -> None:
|
||||||
self.env = os.environ.copy()
|
self.env = os.environ.copy()
|
||||||
|
|
@ -24,12 +31,32 @@ class IntegrationTest(unittest.TestCase):
|
||||||
f.write(f"use nix")
|
f.write(f"use nix")
|
||||||
|
|
||||||
def test_direnv(self) -> None:
|
def test_direnv(self) -> None:
|
||||||
subprocess.run(
|
run(["direnv", "allow"], cwd=str(self.testenv), env=self.env, check=True)
|
||||||
["direnv", "allow"], cwd=str(self.testenv), env=self.env, check=True
|
|
||||||
|
run(["nix-collect-garbage"], check=True)
|
||||||
|
|
||||||
|
out1 = run(
|
||||||
|
["direnv", "exec", str(self.testenv), "hello"],
|
||||||
|
env=self.env,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
)
|
)
|
||||||
subprocess.run(
|
sys.stderr.write(out1.stderr)
|
||||||
["direnv", "exec", str(self.testenv), "hello"], env=self.env, check=True
|
self.assertIn("renewed cache and derivation link", out1.stderr)
|
||||||
|
self.assertEqual(out1.returncode, 0)
|
||||||
|
|
||||||
|
run(["nix-collect-garbage"], check=True)
|
||||||
|
run(["sh", "-c", "realpath /nix/var/nix/gcroots/per-user/$USER/*"], check=True)
|
||||||
|
|
||||||
|
out2 = run(
|
||||||
|
["direnv", "exec", str(self.testenv), "hello"],
|
||||||
|
env=self.env,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
text=True,
|
||||||
)
|
)
|
||||||
|
sys.stderr.write(out2.stderr)
|
||||||
|
self.assertIn("using cached derivation", out2.stderr)
|
||||||
|
self.assertEqual(out2.returncode, 0)
|
||||||
|
|
||||||
def tearDown(self) -> None:
|
def tearDown(self) -> None:
|
||||||
self.dir.cleanup()
|
self.dir.cleanup()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue