nh icon indicating copy to clipboard operation
nh copied to clipboard

nh clean all on darwin

Open gigamonster256 opened this issue 1 year ago • 9 comments

Same behavior as https://github.com/ToyVo/nh_plus/issues/5 during nh clean all. I believe

https://github.com/viperML/nh/blob/6a69a145b0c7dbd5616bbded512b8bf8b5d2f8a4/src/main.rs#L44-L50

may need some massaging similar to

https://github.com/viperML/nh/blob/6a69a145b0c7dbd5616bbded512b8bf8b5d2f8a4/src/commands.rs#L68-L84

gigamonster256 avatar Dec 28 '24 18:12 gigamonster256

Hmm I know I've gotten a commit in that uses the set-home sudo flag on Darwin. https://github.com/viperML/nh/blob/master/src/commands.rs#L66-L81 which fixed it on that original issue

ToyVo avatar Dec 28 '24 18:12 ToyVo

Paste the output with --verbose

viperML avatar Dec 28 '24 19:12 viperML

nh clean all -v

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" "-v"
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=["/nix/var/nix/profiles/system"] dir="/nix/var/nix/profiles"
DEBUG profiles_in_dir: nh::clean:240: return=["/nix/var/nix/profiles/per-user/root/profile", "/nix/var/nix/profiles/per-user/root/channels"] dir="/nix/var/nix/profiles/per-user/root"
DEBUG nh::clean:64: Scanning XDG profiles for users 0, $501-$601
DEBUG nh::clean:67: Adding XDG profiles for user user=User(501, caleb)
DEBUG profiles_in_dir: nh::clean:240: return=["/Users/caleb/.local/state/nix/profiles/home-manager", "/Users/caleb/.local/state/nix/profiles/profile", "/Users/caleb/.local/state/nix/profiles/channels"] dir="/Users/caleb/.local/state/nix/profiles"
DEBUG nh::clean:67: Adding XDG profiles for user user=User(0, root)
! Failed to read profiles directory dir="/var/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="/var/root/.local/state/nix/profiles"
DEBUG nh::clean:67: Adding XDG profiles for user user=User(0, root)
! Failed to read profiles directory dir="/var/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="/var/root/.local/state/nix/profiles"
DEBUG cleanable_generations: nh::clean:341: {
    Generation {
        number: 176,
        last_modified: SystemTime {
            tv_sec: 1735427412,
            tv_nsec: 874421128,
        },
        path: "/nix/var/nix/profiles/system-176-link",
    }: false,
} profile="/nix/var/nix/profiles/system" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:341: {
    Generation {
        number: 2,
        last_modified: SystemTime {
            tv_sec: 1716005930,
            tv_nsec: 890011595,
        },
        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: 1,
        last_modified: SystemTime {
            tv_sec: 1716005961,
            tv_nsec: 220760859,
        },
        path: "/nix/var/nix/profiles/per-user/root/channels-1-link",
    }: false,
} profile="/nix/var/nix/profiles/per-user/root/channels" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:341: {
    Generation {
        number: 268,
        last_modified: SystemTime {
            tv_sec: 1734666178,
            tv_nsec: 980974749,
        },
        path: "/Users/caleb/.local/state/nix/profiles/home-manager-268-link",
    }: false,
} profile="/Users/caleb/.local/state/nix/profiles/home-manager" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:341: {
    Generation {
        number: 175,
        last_modified: SystemTime {
            tv_sec: 1734666178,
            tv_nsec: 816775090,
        },
        path: "/Users/caleb/.local/state/nix/profiles/profile-175-link",
    }: false,
} profile="/Users/caleb/.local/state/nix/profiles/profile" keep=1 keep_since=Duration(0ns)
DEBUG cleanable_generations: nh::clean:341: {
    Generation {
        number: 2,
        last_modified: SystemTime {
            tv_sec: 1716317891,
            tv_nsec: 341288520,
        },
        path: "/Users/caleb/.local/state/nix/profiles/channels-2-link",
    }: false,
} profile="/Users/caleb/.local/state/nix/profiles/channels" keep=1 keep_since=Duration(0ns)
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/shnp9f301qfcwx3v5si3zbr8qk6fr2dk" dst="/nix/var/nix/profiles/system-176-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/nix/var/nix/profiles/system-176-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/b1f694mwixg3gcphvjabzjpmd4f2m6m8" dst="/Users/caleb/projects/csce662/.pre-commit-config.yaml"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/Users/caleb/projects/csce662/.pre-commit-config.yaml"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/2hi0nw73qzh4qf8svbhcjpqrkaz8xkcn" dst="/Users/caleb/.local/state/nix/profiles/channels-2-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/Users/caleb/.local/state/nix/profiles/channels-2-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/0b6f5n57w98f16i7sfkmrw1dqr4biam0" dst="/var/root/.cache/nix/flake-registry.json"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/var/root/.cache/nix/flake-registry.json"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/n2fwfr4nkwpp12bavaqryba17qgagavj" dst="/Users/caleb/projects/nix-config/.pre-commit-config.yaml"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/Users/caleb/projects/nix-config/.pre-commit-config.yaml"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/9p7q7h68bbjw18c0bgss4pbifwwni7m6" dst="/Users/caleb/.local/state/home-manager/gcroots/current-home"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/Users/caleb/.local/state/home-manager/gcroots/current-home"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/lvi04m7mn76ymzgzcx5rrifj5019psvd" dst="/nix/var/nix/profiles/per-user/root/channels-1-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/nix/var/nix/profiles/per-user/root/channels-1-link"
DEBUG gcroot detection: nh::clean:115: src="/nix/var/nix/gcroots/auto/q4j8zmv579j2apqjljryfxf6yv5s5746" dst="/Users/caleb/.local/state/nix/profiles/profile-175-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/Users/caleb/.local/state/nix/profiles/profile-175-link"
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/c49qm8ndml7p2jvjz6vcsd09jn1q65np" dst="/Users/caleb/.local/state/nix/profiles/home-manager-268-link"
DEBUG gcroot detection: nh::clean:121: dst doesn't match any gcroot regex, skipping dst="/Users/caleb/.local/state/nix/profiles/home-manager-268-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

/Users/caleb/.local/state/nix/profiles/home-manager
- OK  /Users/caleb/.local/state/nix/profiles/home-manager-268-link

/Users/caleb/.local/state/nix/profiles/profile
- OK  /Users/caleb/.local/state/nix/profiles/profile-175-link

/Users/caleb/.local/state/nix/profiles/channels
- OK  /Users/caleb/.local/state/nix/profiles/channels-2-link

/nix/var/nix/profiles/per-user/root/profile
- OK  /nix/var/nix/profiles/per-user/root/profile-2-link

/nix/var/nix/profiles/per-user/root/channels
- OK  /nix/var/nix/profiles/per-user/root/channels-1-link

/nix/var/nix/profiles/system
- OK  /nix/var/nix/profiles/system-176-link

> Performing garbage collection on the nix store
DEBUG nh::commands:97: cmd=Exec { nix store gc }
warning: $HOME ('/Users/caleb') is not owned by you, falling back to the one defined in the 'passwd' file ('/var/root')
0 store paths deleted, 0.00 MiB freed

gigamonster256 avatar Dec 29 '24 01:12 gigamonster256

nh is not crashing there

viperML avatar Dec 29 '24 07:12 viperML

nh is not crashing there

Correct, nh just outputs a warning (second to last line of the verbose output) The warning is printed in non-verbose mode.

gigamonster256 avatar Dec 29 '24 07:12 gigamonster256

If it's a darwin issue I have no idea then

viperML avatar Dec 29 '24 09:12 viperML

After finally taking a look at it I can confirm that the issue happens on my end as well. I now see the more detailed initial commend pointing out the code block differences. Testing now and plan to make a PR shortly, but I'm essentially removing self_elevate in favor of the elevate function on the Command.

nevermind that doesn't actually work because self elevate is needed to gather the list of profiles, still going to extract out the flag function to not repeat it

ToyVo avatar Dec 29 '24 16:12 ToyVo

I've updated some code to ensure the the --set-home --preserve-env=PATH env is added to self_elevate, but I still get the same error output lines and thats because at least on my end /var/root/.local/state/nix/profiles genuinely doesn't exist

ToyVo avatar Dec 29 '24 17:12 ToyVo

After testing a bunch of devices, Some linux boxes not running nixos, nixos machines, and a bunch of macs, none of the root users have ~/.local/state/nix, so I think its probably safe to remove the condition user.uid == 0

https://github.com/viperML/nh/blob/6a69a145b0c7dbd5616bbded512b8bf8b5d2f8a4/src/clean.rs#L66

ToyVo avatar Dec 29 '24 20:12 ToyVo