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

Allow running nix without a /etc/passwd entry #8074

Open
viceice opened this issue Mar 20, 2023 · 8 comments
Open

Allow running nix without a /etc/passwd entry #8074

viceice opened this issue Mar 20, 2023 · 8 comments
Labels
feature Feature request or proposal

Comments

@viceice
Copy link

viceice commented Mar 20, 2023

Is your feature request related to a problem? Please describe.
We are using the nix flake update to update the nix lockfiles from renovatebot.
The executable is run inside docker containers which a custom user.
But sometimes the image needs to be run with an arbitrary userid, which is not inside the /etc/passwd of the prebuild image.
This happpens when running on openstack, then the userid is random and the primary group is root, so we've prepared our image for that usecase.
We also explicit set HOME to our prebuild user which is writable by root group.
This works fine for most tools but not for the nix cli, which fails with cannot determine user's home directory here

throw Error("cannot determine user's home directory");

Describe the solution you'd like
I like to skip that check somehow so the existing writable HOME can be used by nix cli.

Describe alternatives you've considered
No workaround possible.

Additional context
Not relevant

Priorities

Add 👍 to issues you find important.

@SuperSandro2000
Copy link
Member

But sometimes the image needs to be run with an arbitrary userid, which is not inside the /etc/passwd of the prebuild image.

Sidenote regardless of the feature request: This is usually a bad idea because it breaks all kinds of programs because this is expected to exist. I would recommend to use something similar to the systemd DynamicUser feature instead.

@viceice
Copy link
Author

viceice commented Mar 20, 2023

systemd isn't available inside docker container by default

@viceice
Copy link
Author

viceice commented Mar 20, 2023

and as described you can't influence the userid used by Openstack.

@thufschmitt
Copy link
Member

This might be a consequence of #6676 which will cause $HOME to be ignored if it doesn't belong to the calling user (mostly because Darwin's defaults for sudo was making this a bit of a pain otherwise).

Any chance you could run nix with a $HOME pointing to a folder owned by the current user?

@viceice
Copy link
Author

viceice commented Mar 21, 2023

sure, but the current user still has no entry inside /etc/passwd file, wouldn't it fail then anyways?

@thufschmitt
Copy link
Member

I don't think it would. /etc/passwd should only be looked at if Nix believes that $HOME isn't good-enough (unless it's used somewhere else in the code, but I don't think so)

@viceice
Copy link
Author

viceice commented Mar 21, 2023

ok, let me test if we can change the owner of the home dir on the fly, because it should be writable by current user anyways
🤞

@viceice
Copy link
Author

viceice commented Mar 22, 2023

ok, only root can change ownership. so i would need to create the home on the fly 😕

pnmadelaine added a commit to typhon-ci/typhon that referenced this issue Feb 23, 2024
- unset environment variables
- unmount `/etc`
- fix actions accordingly

see NixOS/nix#8074 about why `$HOME` is now
set before calling Nix from an action
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature request or proposal
Projects
None yet
Development

No branches or pull requests

3 participants