NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.19k stars 14.19k forks source link

nix does not clean the remaining files #266858

Open KCynk opened 1 year ago

KCynk commented 1 year ago

Describe the bug

nix does not clean the remaining files

Steps To Reproduce

Steps to reproduce the behavior:

  1. vim /etc/nixos/configuration.conf
  2. Content of the config file
    
    { config, pkgs, ... }:

{ services.freshrss = { enable = true; defaultUser = "kcynk"; passwordFile = "/run/secrets/freshrss"; dataDir = "/var/lib/freshrss"; baseUrl = "https://freshrss.localhost"; database = { type = "sqlite"; }; };

3. sudo nixos-rebuild switch
4. Reboot
5. Delete content related to freshrss service
6. sudo nixos-rebuild switch
7. Reboot
8. Files are still there

[kcynk@nixos:/var/lib/freshrss] sudo find / -name 'freshrss' [sudo] password for kcynk: /var/lib/freshrss /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos/nixos/pkgs/servers/web-apps/freshrss**

[kcynk@nixos:/var/lib/freshrss] cd /var/lib/freshrss/ [kcynk@nixos:/var/lib/freshrss] ll total 36 -rw-rw---- 1 992 990 0 11-10 18:49 applied_migrations.txt drwxrwx--- 2 992 990 4096 11-10 20:59 cache -rw-rw---- 1 992 990 1688 11-10 19:11 config.php -rw-rw---- 1 992 990 1688 11-10 19:04 config.php.bak.php drwxrwx--- 2 992 990 4096 11-10 18:49 extensions-data drwxrwx--- 2 992 990 4096 11-10 20:59 favicons drwxrwx--- 2 992 990 4096 11-10 18:49 fever -rw-rw---- 1 992 990 0 11-10 21:55 index.html -rw-r--r-- 1 992 990 0 11-10 19:39 last_update.txt drwxrwx--- 4 992 990 4096 11-10 18:49 PubSubHubbub drwxrwx--- 2 992 990 4096 11-10 18:49 tokens drwxrwx--- 4 992 990 4096 11-10 18:49 users

9. Executing following commands:
- nix-collect-garbage -d
- nix-collect-garbage
- nix-store --gc
10. Files still there
11. 

[kcynk@nixos:/var/lib/freshrss] sudo nix-store --query --roots /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos/nixos/pkgs/servers/web-apps/freshrss/ /nix/var/nix/profiles/per-user/root/channels-3-link -> /nix/store/18ic13fhdq5mgdnhym22pz2a20pci571-user-environment /proc/13969/environ -> /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos /proc/13971/environ -> /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos


### Expected behavior
Old files should be deleted after rebuild or after one of mentioned command

### Metadata

[kcynk@nixos:/var/lib/freshrss] nix-shell -p nix-info --run "nix-info -m" these 6 paths will be fetched (0.75 MiB download, 10.18 MiB unpacked): /nix/store/h5pshzq92r2xcv6w1p10cmkar4nyv0xp-file-5.45 /nix/store/azkk9647ivcaa29fpb8viwj879q7yjw4-gnu-config-2023-07-31 /nix/store/9dh2csn531by6b1vr9jv85v4k17xwkid-gnumake-4.4.1 /nix/store/znqwpxy9jlxcgi2ms2hga0ch87bbbr9g-patchelf-0.15.0 /nix/store/bbxdw4rgwwl3gnajri82yidr1nlsfskf-stdenv-linux /nix/store/6g3mnziija245czxdqvs4k4sc6lad0sw-update-autotools-gnu-config-scripts-hook copying path '/nix/store/azkk9647ivcaa29fpb8viwj879q7yjw4-gnu-config-2023-07-31' from 'https://cache.nixos.org'... copying path '/nix/store/h5pshzq92r2xcv6w1p10cmkar4nyv0xp-file-5.45' from 'https://cache.nixos.org'... copying path '/nix/store/znqwpxy9jlxcgi2ms2hga0ch87bbbr9g-patchelf-0.15.0' from 'https://cache.nixos.org'... copying path '/nix/store/9dh2csn531by6b1vr9jv85v4k17xwkid-gnumake-4.4.1' from 'https://cache.nixos.org'... copying path '/nix/store/6g3mnziija245czxdqvs4k4sc6lad0sw-update-autotools-gnu-config-scripts-hook' from 'https://cache.nixos.org'... copying path '/nix/store/bbxdw4rgwwl3gnajri82yidr1nlsfskf-stdenv-linux' from 'https://cache.nixos.org'...

Related issue: https://github.com/NixOS/nix/issues/6141

KCynk commented 1 year ago
[kcynk@nixos:~] nix-store --query --referrers /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos/nixos/pkgs/servers/web-apps/freshrss
/nix/store/5bbvjnhpkzgmb2piay1002ajnlgd1yva-env-manifest.nix
/nix/store/18ic13fhdq5mgdnhym22pz2a20pci571-user-environment

sudo nix-store --query --referrers /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos/nixos/pkgs/servers/web-apps/freshrss | xargs nix-store --delete
[sudo] password for kcynk: 
finding garbage collector roots...
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/18ic13fhdq5mgdnhym22pz2a20pci571-user-environment' since it is still alive. To find out why, use: nix-store --query --roots
KCynk commented 1 year ago
grep nix /etc/nixos/configuration.conf
nix.settings.experimental-features = [ "nix-command" ];
sudo nixos-rebuild switch

[kcynk@nixos:~] sudo nix store delete --ignore-liveness /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos/nixos/pkgs/servers/web-apps/freshrss
0 store paths deleted, 0.00 MiB freed
error: Cannot delete path '/nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos' since it is still alive. To find out why, use: nix-store --query --roots

[kcynk@nixos:~] sudo nix-store --query --roots /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos/nixos/pkgs/servers/web-apps/freshrss
removing stale link from '/nix/var/nix/gcroots/auto/9g1mgvqfhlgw56vjanjsc96pznafm0c3' to '/tmp/nixos-rebuild.BZ6w8a/nix'
removing stale link from '/nix/var/nix/gcroots/auto/v1ychyhf92phfq3q30h1aqscw191hyi1' to '/tmp/nix-build-18502-0/result'
removing stale link from '/nix/var/nix/gcroots/auto/rm0qjaxlggkzdwnsmsdfk521qw0ld493' to '/tmp/nix-build-18475-0/result'
removing stale link from '/nix/var/nix/gcroots/auto/zr57fvv42ysai0xgnd1p5jhny9i9c10d' to '/tmp/nixos-rebuild.BZ6w8a/nix.drv'
/proc/20282/environ -> /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos
/proc/20284/environ -> /nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos
/nix/var/nix/profiles/per-user/root/channels-3-link -> /nix/store/18ic13fhdq5mgdnhym22pz2a20pci571-user-environment

[kcynk@nixos:~] find /nix/store -name freshrss
/nix/store/sw8kbzmalpiq4kmlrp5s1zg9cjkr43rp-nixos/nixos/pkgs/servers/web-apps/freshrss

[kcynk@nixos:~/Downloads] printenv -0 > env
[kcynk@nixos:~/Downloads] grep -i freshrss env 
[kcynk@nixos:~/Downloads] 

[root@nixos:~] printenv -0 > env
[root@nixos:~] grep -i fresh env 
[root@nixos:~]