From 5b63b709581a068ca9ccca408b06f2b9787c89eb Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sun, 7 Mar 2021 17:47:33 +0000 Subject: [PATCH] modules: users: add to groups in single place --- machines/porthos/users.nix | 9 --------- modules/users.nix | 12 ++++++++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/machines/porthos/users.nix b/machines/porthos/users.nix index ea8de60..9ca91b2 100644 --- a/machines/porthos/users.nix +++ b/machines/porthos/users.nix @@ -2,11 +2,6 @@ { config, lib, ... }: let my = config.my; - groupIfExists = grp: - lib.lists.optional - (builtins.hasAttr grp config.users.groups) - grp; - groupsIfExist = grps: builtins.concatMap groupIfExists grps; in { users.users.blog = { @@ -17,8 +12,4 @@ in home = "/var/www/"; openssh.authorizedKeys.keys = [ my.secrets.drone.ssh.publicKey ]; }; - - users.users.ambroisie.extraGroups = groupsIfExist [ - "media" - ]; } diff --git a/modules/users.nix b/modules/users.nix index a67d725..291418d 100644 --- a/modules/users.nix +++ b/modules/users.nix @@ -1,7 +1,12 @@ # User setup -{ config, pkgs, ... }: +{ config, lib, pkgs, ... }: let my = config.my; + groupIfExists = grp: + lib.lists.optional + (builtins.hasAttr grp config.users.groups) + grp; + groupsIfExist = grps: builtins.concatMap groupIfExists grps; in { users.mutableUsers = false; # I want it to be declarative. @@ -13,7 +18,10 @@ in description = "Bruno BELANYI"; isNormalUser = true; 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 keyDir = ./ssh; contents = readDir keyDir;