modules: users: add to groups in single place

This commit is contained in:
Bruno BELANYI 2021-03-07 17:47:33 +00:00
parent 960f65f62c
commit 5b63b70958
2 changed files with 10 additions and 11 deletions

View file

@ -2,11 +2,6 @@
{ config, lib, ... }: { config, lib, ... }:
let let
my = config.my; my = config.my;
groupIfExists = grp:
lib.lists.optional
(builtins.hasAttr grp config.users.groups)
grp;
groupsIfExist = grps: builtins.concatMap groupIfExists grps;
in in
{ {
users.users.blog = { users.users.blog = {
@ -17,8 +12,4 @@ in
home = "/var/www/"; home = "/var/www/";
openssh.authorizedKeys.keys = [ my.secrets.drone.ssh.publicKey ]; openssh.authorizedKeys.keys = [ my.secrets.drone.ssh.publicKey ];
}; };
users.users.ambroisie.extraGroups = groupsIfExist [
"media"
];
} }

View file

@ -1,7 +1,12 @@
# User setup # User setup
{ config, pkgs, ... }: { config, lib, pkgs, ... }:
let let
my = config.my; my = config.my;
groupIfExists = grp:
lib.lists.optional
(builtins.hasAttr grp config.users.groups)
grp;
groupsIfExist = grps: builtins.concatMap groupIfExists grps;
in in
{ {
users.mutableUsers = false; # I want it to be declarative. users.mutableUsers = false; # I want it to be declarative.
@ -13,7 +18,10 @@ in
description = "Bruno BELANYI"; description = "Bruno BELANYI";
isNormalUser = true; isNormalUser = true;
shell = pkgs.zsh; shell = pkgs.zsh;
extraGroups = [ "wheel" ]; # Enable sudo for the user. extraGroups = groupsIfExist [
"media" # access to media files
"wheel" # `sudo` for the user.
];
openssh.authorizedKeys.keys = with builtins; let openssh.authorizedKeys.keys = with builtins; let
keyDir = ./ssh; keyDir = ./ssh;
contents = readDir keyDir; contents = readDir keyDir;