ITADN

Refresh gc roots timestamp when loading from cache

#669OpenGuillaumeLagrange 创建于 2026-01-14
Hello, I use `nh clean all --keep-since 7d --keep 3` for my garbage collection, but this tends to remove flakes that are evaluated through direnv. For those not aware, this `nh clean all` command keeps at least 3 generations for nixos, home manager, and user profiles, as well as remove any path that is older than seven days. I would like for this not to remove gcroots that are used in flakes of projects I actively visit. My workflow generally involves `nix-direnv` and a very simple envrc file ``` # .envrc use flake <path/to/flake ``` During the initial flake evaluation, this creates files - multiple `./.direnv/flake-inputs/<hash>-source` files - one `./direnv/flake-profile-<hash>` file Which are registered as gcroots for nix ``` $ ls -al /nix/var/nix/gcroots/auto lrwxrwxrwx 1 root root 85 Jan 14 13:52 68vrkig6b764sgkjxpd0v279khs4nyac -> /home/guillaume/my_project/.direnv/flake-inputs/hq5y1148qpc2msay1prbj2d2wz7dqzs5-source lrwxrwxrwx 1 root root 85 Jan 14 13:52 9dvbckqq0i586j6vrbbwncl8zp010rim -> /home/guillaume/my_project/.direnv/flake-inputs/01x5k4nlxcpyd85nnr0b9gm89rm8ff4x-source lrwxrwxrwx 1 root root 85 Jan 14 13:52 c80nqx4vyqijmvw7wfp6ivhwh2n32z9h -> /home/guillaume/my_project/.direnv/flake-inputs/wdqrnd6fkxdsf4xn2kkfa8f42shfw0i3-source lrwxrwxrwx 1 root root 64 Jan 14 13:52 mid36gnlv6wzxw2d6yh5agx1f5fpp0d0 -> /home/guillaume/my_project/.direnv/flake-tmp-profile.641224-1-link lrwxrwxrwx 1 root root 87 Jan 14 13:52 rzfp8qss5rwj3adchjnxgaayk4ph96x8 -> /home/guillaume/my_project/.direnv/flake-profile-4d80ff801b67b847faa9281e5c6824ae0732da81 lrwxrwxrwx 1 root root 85 Jan 14 13:52 va5gs26a1hfbbqkya42lz7668aldnv6w -> /home/guillaume/my_project/.direnv/flake-inputs/lbh16p3bgamgp6dzakwshc070fa640d6-source lrwxrwxrwx 1 root root 85 Jan 14 13:52 zb3dsjcavi8dydkl1na45nj5xklf3yyi -> /home/guillaume/my_project/.direnv/flake-inputs/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source ``` However, on subsequent loads of the direnv, when I cd into the project for example, it uses the cached devshell ``` $ cdc direnv: loading ~/my_project/.envrc direnv: using flake ./flake direnv: nix-direnv: Using cached dev shell # ... ``` This is really nice, however the timestamp of the gc root is never updated, which means that at some point this flake evaluation is going to be garbage collected. I'm looking for a way to prevent this, does anyone has any idea? Either by using some direnv options, proposing a PR for either direnv or nix-direnv, or even nh/nix? The best thing I've got for now is from time to time running `direnv reload`, but I'd like to either find an alternative, or automate this so that I do not have to think about it, and still have the flakes I have not used in a certain timeframe be auto gc-ed
1 条评论