Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --user flag to the home-manager cli #5878

Open
SpiderUnderUrBed opened this issue Sep 22, 2024 · 8 comments
Open

Add a --user flag to the home-manager cli #5878

SpiderUnderUrBed opened this issue Sep 22, 2024 · 8 comments
Assignees

Comments

@SpiderUnderUrBed
Copy link

SpiderUnderUrBed commented Sep 22, 2024

Description

I want to run the home-manager switch command in my /etc/nixos or files which i am very restrictive of because of permissions, I would like to be able to specify the user when running a home-manager command so i dont get any situations like:
error: flake 'git+file:///etc/nixos' does not provide attribute 'packages.x86_64-linux.homeConfigurations."root".activationPackage', 'legacyPackages.x86_64-linux.homeConfigurations."root".activationPackage' or 'homeConfigurations."root".activationPackage' .
This can be done with a --user flag where you specify the user

I know this isnt the way you usually do things with home-manager but I have a place in my flake where home-manager is run, and the thing is, i usually have to do alot of hoop jumping to first initilize home-manager, before it can become aware of my config in my flake

@loicreynier
Copy link
Contributor

I'm not sure I fully understand your situation, but couldn't you specify the user in the flake URI when invoking home-manager, as in

home-manager switch --flake <path/to/flake>#<user>

@SpiderUnderUrBed
Copy link
Author

Wait I still get a error:

[spiderunderurbed@daspidercave:~/home-manager]$ sudo home-manager switch --flake .#spiderunderurbed --impure
warning: Git tree '/home/spiderunderurbed/home-manager' is dirty
Starting Home Manager activation
Error: USER is set to "root" but we expect "spiderunderurbed"

@rennsax
Copy link
Contributor

rennsax commented Oct 11, 2024

Do not user sudo for home-manager. sudo sets your current user (in fact, the effective uid) to the root user, but home-manager checks if the current user is the same as home.username (here).

Run without sudo and then retry. Since you use flake, I think there is no reason for you to run home-manager as the root user, namely, nothing needs root privilege.

@SpiderUnderUrBed
Copy link
Author

I need to use root privileges because it is located in /etc/nixos and I don't intend on giving other users who use my pc the ability to change their config, atleast not now.

Regardless, as a different user, can you build configurations for other users? How? What I did won't work if I was another user

@rennsax
Copy link
Contributor

rennsax commented Oct 11, 2024

I think you can chown these files and chmod to 600 so only you can read and write these files.

If you insist, I guess you can export SKIP_SANITY_CHECKS=1 and then retry. Remember to run in impure mode.

@SpiderUnderUrBed
Copy link
Author

[spiderunderurbed@daspidercave:~/home-manager]$ SKIP_SANITY_CHECKS=1 sudo home-manager switch --flake .#spiderunderurbed --impure
[sudo] password for spiderunderurbed: 
warning: Git tree '/home/spiderunderurbed/home-manager' is dirty
Starting Home Manager activation
Error: USER is set to "root" but we expect "spiderunderurbed"

@rennsax
Copy link
Contributor

rennsax commented Oct 15, 2024

How about sudo bash -c "USER=spiderunderurbed home-manager switch --impure --flake .#spiderunderurbed"?

@SpiderUnderUrBed
Copy link
Author

[spiderunderurbed@daspidercave:~/home-manager]$ sudo bash -c "USER=spiderunderurbed home-manager switch --impure --flake .#spiderunderurbed"
[sudo] password for spiderunderurbed: 
warning: Git tree '/home/spiderunderurbed/home-manager' is dirty
Starting Home Manager activation
Could not find suitable profile directory, tried /root/.local/state/nix/profiles and /nix/var/nix/profiles/per-user/spiderunderurbed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants