home-manager icon indicating copy to clipboard operation
home-manager copied to clipboard

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

Open SpiderUnderUrBed opened this issue 1 year ago • 8 comments

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

SpiderUnderUrBed avatar Sep 22 '24 01:09 SpiderUnderUrBed

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>

loicreynier avatar Sep 22 '24 08:09 loicreynier

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"

SpiderUnderUrBed avatar Oct 11 '24 03:10 SpiderUnderUrBed

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.

rennsax avatar Oct 11 '24 13:10 rennsax

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

SpiderUnderUrBed avatar Oct 11 '24 13:10 SpiderUnderUrBed

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.

rennsax avatar Oct 11 '24 13:10 rennsax

[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"

SpiderUnderUrBed avatar Oct 12 '24 22:10 SpiderUnderUrBed

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

rennsax avatar Oct 15 '24 07:10 rennsax

[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

SpiderUnderUrBed avatar Oct 15 '24 11:10 SpiderUnderUrBed

Thank you for your contribution! I marked this issue as stale due to inactivity. Please be considerate of people watching this issue and receiving notifications before commenting 'I have this issue too'. We welcome additional information that will help resolve this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.
Memorandum on closing issues

Don't be afraid to manually close an issue, even if it holds valuable information. Closed issues stay in the system for people to search, read, cross-reference, or even reopen – nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

stale[bot] avatar Jan 18 '25 07:01 stale[bot]