nh
nh copied to clipboard
`nh clean all` using home-manager on arch removes everything
When i run nh clean I get this weird error:
❯ nh clean all -k 5 -K 3d
sudo: nh: command not found
When I run any other nh command it works, I needed to run it in fakeroot, sudo wont work because it checks the root account's profile, when it does work it removes home-manager and anything installed by it
I'll fix it asap
Please run the command with --verbose and paste the output.
Not the same person but I am running the same setup:
❯ nh clean all --verbose
TRACE nh::logging:86: Logging OK
DEBUG nh:32: Main {
verbose: true,
command: Clean(
CleanProxy {
command: All(
CleanArgs {
keep: 1,
keep_since: Duration(
0ns,
),
dry: false,
ask: false,
nogc: false,
nogcroots: false,
},
),
},
),
}
DEBUG nh:33: NH_VERSION=4.0.0-beta.5 NH_REV=Some("6a69a14")
DEBUG nh:49: "sudo" "nh" "clean" "all" "--verbose"
[sudo] password for skylar:
sudo: nh: command not found
My guess is that this has to do with the program being installed in my user profile. Running readlink $(which nh) and running the binary directly does get past the sudo issue but instead I am met with an error:
❯ /nix/store/wfg7csq178khs2p640vpycgl7qrdc861-nh-4.0.0-beta.5-6a69a14/bin/nh clean all --verbose
TRACE nh::logging:86: Logging OK
DEBUG nh:32: Main {
verbose: true,
command: Clean(
CleanProxy {
command: All(
CleanArgs {
keep: 1,
keep_since: Duration(
0ns,
),
dry: false,
ask: false,
nogc: false,
nogcroots: false,
},
),
},
),
}
DEBUG nh:33: NH_VERSION=4.0.0-beta.5 NH_REV=Some("6a69a14")
! nh 4.0.0-beta.5 now uses NH_FLAKE instead of FLAKE, please modify your configuration (nh/src/main.rs:36)
DEBUG nh:49: "sudo" "/nix/store/wfg7csq178khs2p640vpycgl7qrdc861-nh-4.0.0-beta.5-6a69a14/bin/nh" "clean" "all" "--verbose"
TRACE nh::logging:86: Logging OK
DEBUG nh:32: Main {
verbose: true,
command: Clean(
CleanProxy {
command: All(
CleanArgs {
keep: 1,
keep_since: Duration(
0ns,
),
dry: false,
ask: false,
nogc: false,
nogcroots: false,
},
),
},
),
}
DEBUG nh:33: NH_VERSION=4.0.0-beta.5 NH_REV=Some("6a69a14")
DEBUG profiles_in_dir: nh::clean:240: return=[] dir="/nix/var/nix/profiles"
DEBUG profiles_in_dir: nh::clean:240: return=["/nix/var/nix/profiles/per-user/root/profile"] dir="/nix/var/nix/profiles/per-user/root"
DEBUG nh::clean:64: Scanning XDG profiles for users 0, $1000-$1100
DEBUG nh::clean:67: Adding XDG profiles for user user=User(0, root)
! Failed to read profiles directory dir="/root/.local/state/nix/profiles" error=Os { code: 2, kind: NotFound, message: "No such file or directory" } (nh/src/clean.rs:272)
DEBUG profiles_in_dir: nh::clean:240: return=[] dir="/root/.local/state/nix/profiles"
DEBUG nh::clean:67: Adding XDG profiles for user user=User(1000, skylar)
DEBUG profiles_in_dir: nh::clean:240: return=["/home/skylar/.local/state/nix/profiles/home-manager", "/home/skylar/.local/state/nix/profiles/profile"] dir="/home/skylar/.local/state/nix/profiles"
DEBUG cleanable_generations: nh::clean:341: {
Generation {
number: 2,
last_modified: SystemTime {
tv_sec: 1734814738,
tv_nsec: 501387808,
},
path: "/nix/var/nix/profiles/per-user/root/profile-2-link",
}: false,
} profile="/nix/var/nix/profiles/per-user/root/profile" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:341: {
Generation {
number: 45,
last_modified: SystemTime {
tv_sec: 1735588276,
tv_nsec: 255411177,
},
path: "/home/skylar/.local/state/nix/profiles/home-manager-45-link",
}: false,
} profile="/home/skylar/.local/state/nix/profiles/home-manager" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:341: {
Generation {
number: 31,
last_modified: SystemTime {
tv_sec: 1735588277,
tv_nsec: 392070676,
},
path: "/home/skylar/.local/state/nix/profiles/profile-31-link",
}: false,
} profile="/home/skylar/.local/state/nix/profiles/profile" keep=1 keep_since=Duration(0ns)
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/v73nmmh5d8van4ja5c8jn0gjlwhxbz3a" dst="/nix/var/nix/profiles/per-user/root/profile-2-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/nix/var/nix/profiles/per-user/root/profile-2-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/za3i593wy63jx69igv2kd596mzaj7n96" dst="/home/skylar/nixfiles/.devenv/gc/shell-30-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/home/skylar/nixfiles/.devenv/gc/shell-30-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/gkd5mn5f9x4rga3s81gd84v72wgrkcp4" dst="/home/skylar/.local/state/home-manager/gcroots/current-home"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/home/skylar/.local/state/home-manager/gcroots/current-home"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/10f9vwvjjybiwaymbryc251mns6zzg5j" dst="/home/skylar/.cache/nix/flake-registry.json"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/home/skylar/.cache/nix/flake-registry.json"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/g15qw8gvikc1qsz6hdq0lmi2cqvxpsfb" dst="/home/skylar/.local/state/nix/profiles/home-manager-45-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/home/skylar/.local/state/nix/profiles/home-manager-45-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/169phrhd10k7bz8sjnlzdr1qhdvadk8w" dst="/home/skylar/.local/state/nix/profiles/profile-30-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/home/skylar/.local/state/nix/profiles/profile-30-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/srpyams1lbyyrg4f1lxbbi3rxrjgq9qi" dst="/tmp/nh-os16Ds66/result"
DEBUG gcroot detection: nh::clean:159: dst doesn't exist or is not writable, skipping dst="/tmp/nh-os16Ds66/result"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/pf9wwmskhs5j5xafncd8vqnjjsaldzi4" dst="/home/skylar/.local/state/nix/profiles/home-manager-44-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/home/skylar/.local/state/nix/profiles/home-manager-44-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/szg4qhas6niv59c6rkh0bsywigllbnm9" dst="/home/skylar/.local/state/nix/profiles/profile-31-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/home/skylar/.local/state/nix/profiles/profile-31-link"
Welcome to nh clean
Keeping 1 generation(s)
Keeping paths newer than 0s
legend:
OK: path to be kept
DEL: path to be removed
/nix/var/nix/profiles/per-user/root/profile
- OK /nix/var/nix/profiles/per-user/root/profile-2-link
/home/skylar/.local/state/nix/profiles/home-manager
- OK /home/skylar/.local/state/nix/profiles/home-manager-45-link
/home/skylar/.local/state/nix/profiles/profile
- OK /home/skylar/.local/state/nix/profiles/profile-31-link
> Performing garbage collection on the nix store
DEBUG nh::commands:97: cmd=Exec { nix store gc }
Error:
0: Performing garbage collection on the nix store
1: No such file or directory (os error 2)
2: No such file or directory (os error 2)
Location:
src/commands.rs:101
However my guess is that this second problem is related to how I've installed nix and the default root environment not having nix on PATH.
Yeah I'd agree you have a path issue to sort out.
I'd like to point out the failure to read /root/.local/state/nix/profiles similar to #202 helping to show that isn't a Darwin specific issue
Please run the command with
--verboseand paste the output.
sorry for the late response, (this was run in fakeroot btw)
~
# ❯ nh clean all --verbose
TRACE nh::logging:86: Logging OK
DEBUG nh:23: args=NHParser { verbose: true, command: Clean(CleanProxy { command: All(CleanArgs { keep: 1, keep_since: Duration(0ns), dry: false, ask: false, nogc: false, nogcroots: false }) }) }
DEBUG nh:24: NH_VERSION=3.6.0
DEBUG profiles_in_dir: nh::clean:235: return=[] dir="/nix/var/nix/profiles"
DEBUG profiles_in_dir: nh::clean:235: return=["/nix/var/nix/profiles/per-user/root/profile"] dir="/nix/var/nix/profiles/per-user/root"
DEBUG nh::clean:58: Scanning XDG profiles for users 0, 1000-1100
DEBUG nh::clean:61: Adding XDG profiles for user user=User(0, root)
! Failed to read profiles directory dir="/root/.local/state/nix/profiles" error=Os { code: 13, kind: PermissionDenied, message: "Permission denied" } @ src/clean.rs:267
DEBUG profiles_in_dir: nh::clean:235: return=[] dir="/root/.local/state/nix/profiles"
DEBUG nh::clean:61: Adding XDG profiles for user user=User(1000, cinnamon)
DEBUG profiles_in_dir: nh::clean:235: return=["/home/cinnamon/.local/state/nix/profiles/profile", "/home/cinnamon/.local/state/nix/profiles/channels", "/home/cinnamon/.local/state/nix/profiles/home-manager"] dir="/home/cinnamon/.local/state/nix/profiles"
DEBUG cleanable_generations: nh::clean:336: {
Generation {
number: 1,
last_modified: SystemTime {
tv_sec: 1735403653,
tv_nsec: 996627176,
},
path: "/nix/var/nix/profiles/per-user/root/profile-1-link",
}: true,
Generation {
number: 2,
last_modified: SystemTime {
tv_sec: 1735403654,
tv_nsec: 86627172,
},
path: "/nix/var/nix/profiles/per-user/root/profile-2-link",
}: false,
} profile="/nix/var/nix/profiles/per-user/root/profile" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:336: {
Generation {
number: 28,
last_modified: SystemTime {
tv_sec: 1735935658,
tv_nsec: 929910519,
},
path: "/home/cinnamon/.local/state/nix/profiles/profile-28-link",
}: true,
Generation {
number: 29,
last_modified: SystemTime {
tv_sec: 1736001751,
tv_nsec: 111085530,
},
path: "/home/cinnamon/.local/state/nix/profiles/profile-29-link",
}: true,
Generation {
number: 30,
last_modified: SystemTime {
tv_sec: 1736001751,
tv_nsec: 147752197,
},
path: "/home/cinnamon/.local/state/nix/profiles/profile-30-link",
}: false,
} profile="/home/cinnamon/.local/state/nix/profiles/profile" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:336: {
Generation {
number: 1,
last_modified: SystemTime {
tv_sec: 1735470556,
tv_nsec: 799886128,
},
path: "/home/cinnamon/.local/state/nix/profiles/channels-1-link",
}: false,
} profile="/home/cinnamon/.local/state/nix/profiles/channels" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:336: {
Generation {
number: 13,
last_modified: SystemTime {
tv_sec: 1735935659,
tv_nsec: 26577188,
},
path: "/home/cinnamon/.local/state/nix/profiles/home-manager-13-link",
}: false,
} profile="/home/cinnamon/.local/state/nix/profiles/home-manager" keep=1 keep_since=Duration(0ns)
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/ak9698wzcgmg7jidjax3isb6r423p81z" dst="/home/cinnamon/.local/state/nix/profiles/profile-28-link"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/home/cinnamon/.local/state/nix/profiles/profile-28-link"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/d41417n6i4nbci08n7xxa1kmkadr8has" dst="/home/cinnamon/.local/state/nix/profiles/channels-1-link"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/home/cinnamon/.local/state/nix/profiles/channels-1-link"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/xzsaf5bcijc8kr84srapk1j7cil6v9rv" dst="/home/cinnamon/.local/state/home-manager/gcroots/current-home"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/home/cinnamon/.local/state/home-manager/gcroots/current-home"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/ajbv2slxp8lsnm0bdni7h64gzxkfxc4z" dst="/home/cinnamon/.local/state/nix/profiles/home-manager-13-link"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/home/cinnamon/.local/state/nix/profiles/home-manager-13-link"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/k9d5vvcmfkfsnxwv7ac4frrd9y07lh4r" dst="/home/cinnamon/.cache/nix/flake-registry.json"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/home/cinnamon/.cache/nix/flake-registry.json"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/d9lddacv5m59m7azjl8nq31wms23rvaq" dst="/home/cinnamon/.local/state/nix/profiles/profile-29-link"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/home/cinnamon/.local/state/nix/profiles/profile-29-link"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/lzjbmb2ry0z7lma2fvpqprb12921pnb5" dst="/nix/var/nix/profiles/per-user/root/profile-1-link"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/nix/var/nix/profiles/per-user/root/profile-1-link"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/0hdpv1mlaymcmjrir5s8m79vl8mzf9wy" dst="/home/cinnamon/.local/state/nix/profiles/profile-30-link"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/home/cinnamon/.local/state/nix/profiles/profile-30-link"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/x25ab52fcq5q68wlfk8185nl7w7jbc9h" dst="/tmp/home-manager-build.noYfNSJuxw/news.json"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/tmp/home-manager-build.noYfNSJuxw/news.json"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/v73nmmh5d8van4ja5c8jn0gjlwhxbz3a" dst="/nix/var/nix/profiles/per-user/root/profile-2-link"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/nix/var/nix/profiles/per-user/root/profile-2-link"
DEBUG gcroot detection: nh::clean:109: src="/nix/var/nix/gcroots/auto/knrjv6hmwf7lbrdrg5a71wqh5mbwr5vd" dst="/tmp/home-manager-build.noYfNSJuxw/generation"
DEBUG gcroot detection: nh::clean:115: dst doesn't match any gcroot regex, skipping dst="/tmp/home-manager-build.noYfNSJuxw/generation"
Welcome to nh clean
Keeping 1 generation(s)
Keeping paths newer than 0s
legend:
OK: path to be kept
DEL: path to be removed
/nix/var/nix/profiles/per-user/root/profile
- OK /nix/var/nix/profiles/per-user/root/profile-2-link
- DEL /nix/var/nix/profiles/per-user/root/profile-1-link
/home/cinnamon/.local/state/nix/profiles/channels
- OK /home/cinnamon/.local/state/nix/profiles/channels-1-link
/home/cinnamon/.local/state/nix/profiles/home-manager
- OK /home/cinnamon/.local/state/nix/profiles/home-manager-13-link
/home/cinnamon/.local/state/nix/profiles/profile
- OK /home/cinnamon/.local/state/nix/profiles/profile-30-link
- DEL /home/cinnamon/.local/state/nix/profiles/profile-29-link
- DEL /home/cinnamon/.local/state/nix/profiles/profile-28-link
> Removing /nix/var/nix/profiles/per-user/root/profile-1-link
! Failed to remove path path="/nix/var/nix/profiles/per-user/root/profile-1-link" err=Os { code: 13, kind: PermissionDenied, message: "Permission denied" } @ src/clean.rs:343
> Removing /home/cinnamon/.local/state/nix/profiles/profile-29-link
> Removing /home/cinnamon/.local/state/nix/profiles/profile-28-link
> Performing garbage collection on the nix store
DEBUG nh::commands:53: cmd=Exec { nix store gc }
7727 store paths deleted, 8655.86 MiB freed
Wierd, it know doesnt remove home-manager