feat: remote generations support and centralized sudo handling#23
feat: remote generations support and centralized sudo handling#23yeoldegrove wants to merge 1 commit intoarnarg:mainfrom
Conversation
|
I'll wait to do a full review once #22 has been completed but testing this locally, it looks like it does not elevate permissions with sudo when deleting a generation symlink on a remote target. >> ./result/bin/nilla-os gen clean -k 1 -t <host>
> Plan
Generation Build date NixOS version Kernel version
* 70 2026-01-07 16:10:41 25.11pre-git 6.18.3
69 2025-12-01 23:50:18 25.11pre-git 6.17.9
2026/01/07 16:28:21 ERRO failed to delete generation 69: Process exited with status 1 |
df51422 to
fe25808
Compare
|
Yes, I need to have a look at the permission elevation again... Will update the PR once I manged to get it running. |
- Add remote support for generation listing and cleaning operations - Add CommandWithSudoIfNeeded and IsRootOnExecutor for centralized sudo logic - Refactored shared copy and executor logic to eliminate code duplication
fe25808 to
bb8b862
Compare
|
@arnarg I guess you can give it a test if it works for you now. |
arnarg
left a comment
There was a problem hiding this comment.
I apologize for leaving this PR hanging for so long. It's quite big and I haven't had the time to review it properly.
I've added one comment that I'd like you to look at before continuing.
| func getStatCommand(path string) (string, []string) { | ||
| // Try to detect platform, default to Linux | ||
| if runtime.GOOS == "darwin" { | ||
| return "stat", []string{"-f", "%m", path} | ||
| } | ||
| // Default to Linux format | ||
| return "stat", []string{"-c", "%Y", path} | ||
| } |
There was a problem hiding this comment.
I might be misunderstanding the flow but this won't behave correctly if nilla-utils is run on linux and the target is darwin (or vice versa).
This may have to run uname or the target. Or statCmd could just be ls -l --time-style=+%s <path> which afaict is portable between linux and darwin, but requires extra parsing.
Summary
Adds support for remote generation operations and adds centralized sudo handling.
New Features
IsRootOnExecutor()andCommandWithSudoIfNeeded()tointernal/exec/exec.gosudoprefix when neededCode Quality Improvements
nix.CopyToTarget()to eliminate duplicated copy logic betweennilla-osandnilla-homeUsage
NixOS Generations
Home Manager Generations
Implementation
Needs remote build code from #22.
NixOS Generation Retrieval
NixOS generations are stored in
/nix/var/nix/profiles/system-<id>-linksymlinks:/nix/var/nix/profiles/systemsymlink to find the current generationsystem-<id>-linkentries in/nix/var/nix/profilesnixos-versionfile and kernel version fromkernel-modules/lib/modulesdirectoryHome Manager Generation Retrieval
Home Manager generations can be in two locations:
/nix/var/nix/profiles/per-user/<user>/(system-wide)~/.local/state/nix/profiles/(user-specific)Two layouts are supported:
profile -> profile-<id>-link(takes precedence)home-manager -> home-manager-<id>-linkThe retrieval process:
hm-versionfor standalone, or marks as "from NixOS" for module integrationFor remote operations, home directory resolution uses:
getent passwd <user>(if available) to get home directoryeval echo ~<user>shell expansion