ITADN

Options for Nix garbage collection in other-useful-tips are incorrect

#262ClosedEason20000 创建于 2025-11-24
E
Eason20000commented
In https://nixos-and-flakes.thiscute.world/nixos-with-flakes/other-useful-tips#reducing-disk-usage: > ```nix > { lib, pkgs, ... }: > > { > # ... > > # Limit the number of generations to keep > boot.loader.systemd-boot.configurationLimit = 10; > # boot.loader.grub.configurationLimit = 10; > > # Perform garbage collection weekly to maintain low disk usage > nix.gc = { > automatic = true; > dates = "weekly"; > options = "--delete-older-than 1w"; > }; > > # Optimize storage > # You can also manually optimize the store via: > # nix-store --optimise > # Refer to the following link for more details: > # https://nixos.org/manual/nix/stable/command-ref/conf-file.html#conf-auto-optimise-store > nix.settings.auto-optimise-store = true; > } > ``` Causes: ``` × nix-gc.service - Nix Garbage Collector Loaded: loaded (/etc/systemd/system/nix-gc.service; linked; preset: ignored) Active: failed (Result: exit-code) since Mon 2025-11-24 00:00:03 CST; 1 day 3h ago Invocation: 27244a8e96514ad1be4a5fdbfd441ac1 TriggeredBy: ● nix-gc.timer Process: 34711 ExecStart=/nix/store/n7hlfhd5sgyq993pgh24zhf6x49ccba1-unit-script-nix-gc-start/bin/nix-gc-start (code=exited, status=1/FAILURE) Main PID: 34711 (code=exited, status=1/FAILURE) IP: 0B in, 0B out IO: 900K read, 0B written Mem peak: 6.3M CPU: 32ms 11月 24 00:00:03 ESN20-Z390 systemd[1]: Starting Nix Garbage Collector... 11月 24 00:00:03 ESN20-Z390 nix-gc-start[34711]: removing old generations of profile /nix/var/nix/profiles/per-user/root/channels 11月 24 00:00:03 ESN20-Z390 nix-gc-start[34711]: error: invalid number of days specifier '1w', expected something like '14d' 11月 24 00:00:03 ESN20-Z390 nix-gc-start[34711]: Try '/nix/store/rqn7v98b071xg19iyrz3qzlby8nwmqh3-nix-2.31.2/bin/nix-collect-garbage --help' for more information. 11月 24 00:00:03 ESN20-Z390 systemd[1]: nix-gc.service: Main process exited, code=exited, status=1/FAILURE 11月 24 00:00:03 ESN20-Z390 systemd[1]: nix-gc.service: Failed with result 'exit-code'. 11月 24 00:00:03 ESN20-Z390 systemd[1]: Failed to start Nix Garbage Collector. ``` Setting `nix.gc.options` to `"--delete-older-than 7d"` seems to fix this.
关闭于 2025-11-25 0 条评论