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

Making the user available in profiles #230

Closed
diogox opened this issue Apr 5, 2021 · 6 comments
Closed

Making the user available in profiles #230

diogox opened this issue Apr 5, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@diogox
Copy link
Contributor

diogox commented Apr 5, 2021

I'm using a somewhat outdated version of this template, so this may already be possible and I may not know about it.
I'm planning on updating my config but want to wait until it's a bit more stable :)

So, my question is: Is it possible (or is there a way) to provide the user(s) to the profiles?

The use case I'm trying to solve is adding the docker group to the user in a docker user profile. That way I don't have the group in the user file and the docker config in a profile.

I apologize in advance if this had already been discussed. I couldn't find any references to it 😄


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@diogox diogox added the enhancement New feature or request label Apr 5, 2021
@Pacman99
Copy link
Member

I've read this over a couple times and I'm still not sure I understand what your asking.

When you say add a group to a user, I think of something like this:

users.users.docker.group = "docker";

And when I read "making the user available in profiles", I would just think you could create a docker profile that creates the docker user - I usually just use the users folder for my personal users not system ones.

But all those things are standard nixos things and also are possible in pretty much any version of devos.

So I think I don't think I understand this issue and what your goal is. If you could clarify that would be helpful.

@diogox
Copy link
Contributor Author

diogox commented Apr 26, 2021

Ah, I see what the confusion is.
I didn't mean I wanted to add the docker group to a user named docker.
What I meant was: I want to add the docker user group to my main user (diogox) in a user profile. The docker user group here is just an example. I can see this being useful for other user groups.
To do this, I'd need the user for which I set the profile to be available inside the profile itself, I'd imagine.
The reason I'd like this to be possible is so that I don't directly reference a username inside a profile. Because if I do, that profile is not generic. I'll need to refractor it if I want to use a different username.

Does this look possible to you?

@Pacman99
Copy link
Member

Got it, I see the issue. I think anything done by profiles should be made available through standard module system semantics and profiles only edit config.

Can you use config to get the information you need?

  • you could put something like this in your own user profile users.users.diogox.extraGroups = mkIf (config.virtualisation.docker.enable) [ "docker" ];
  • or in the docker profile you can look for users that have isNormalUser set and add them all to the docker group.

In terms of changes for devos, maybe we could pass more information about profiles somehow, I'm not sure how that would look since profiles are just standard module system modules.

@diogox
Copy link
Contributor Author

diogox commented Apr 27, 2021

I wish I could give you some ideas, but I'm not that well versed in Nix, unfortunately.

From the two options, I prefer the second one. Could you give an example of how to do that? I think that would be pretty useful as a library util function, at least. If that's even possible.

@Pacman99
Copy link
Member

For the second option I think it would look something like this:

{ config, lib,  ... }:
{
  users.groups.docker.members = builtins.attrNames (lib.filterAttrs (n: v: v.isNormalUser) config.users.users);
}

and then make sure to enable isNormalUser for your user - which is a good idea either way.

This is definitely a good idea for a lib function lib.getMyUsers and I think it would be good if we started to add more useful functions like this in general. Because right now devos lib is mostly things needed to get devos to work. But it could use some functions that are more helpful.

@diogox
Copy link
Contributor Author

diogox commented Apr 27, 2021

Yeah, that would be great. But in the meantime, I appreciate the code snippet 😁

I'll go ahead and close this issue now, but feel free to open it back up if you need it.

Thanks once again!

@diogox diogox closed this as completed Apr 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants