summaryrefslogtreecommitdiff
path: root/modules/users/groups.nix
diff options
context:
space:
mode:
authorDaiderd Jordan <daiderd@gmail.com>2018-01-13 13:41:08 +0100
committerDaiderd Jordan <daiderd@gmail.com>2018-01-13 13:52:30 +0100
commit3db35e87f01175252cb5fb19b0eaa3d0ced1bb05 (patch)
treea61680ab9b6a8388b1c284c24b708317f7872510 /modules/users/groups.nix
parentb8713d540c3928a800ea676f38643012c89a97dc (diff)
users: move submodules to separate files
Diffstat (limited to 'modules/users/groups.nix')
-rw-r--r--modules/users/groups.nix95
1 files changed, 0 insertions, 95 deletions
diff --git a/modules/users/groups.nix b/modules/users/groups.nix
deleted file mode 100644
index 58c90da..0000000
--- a/modules/users/groups.nix
+++ /dev/null
@@ -1,95 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-with lib;
-
-let
- cfg = config.users;
-
- isCreatedGroup = name: elem name cfg.knownGroups;
- isDeletedGroup = name: ! elem name (mapAttrsToList (n: v: v.name) cfg.groups);
-
- createdGroups = mapAttrsToList (n: v: v) (filterAttrs (n: v: isCreatedGroup v.name) cfg.groups);
- deletedGroups = filter (n: isDeletedGroup n) cfg.knownGroups;
-
- group =
- { name, ... }:
- {
- options = {
- gid = mkOption {
- type = mkOptionType {
- name = "gid";
- check = t: isInt t && t > 501;
- };
- description = "The group's GID.";
- };
-
- name = mkOption {
- type = types.str;
- description = ''
- The group's name. If undefined, the name of the attribute set
- will be used.
- '';
- };
-
- description = mkOption {
- type = types.str;
- default = "";
- description = "The group's description.";
- };
- };
- config = {
- name = mkDefault name;
- };
- };
-in
-
-{
- options = {
- users.knownGroups = mkOption {
- type = types.listOf types.str;
- default = [];
- description = "List of groups that should be created and configured.";
- };
-
- users.groups = mkOption {
- type = types.loaOf (types.submodule group);
- default = {};
- description = "Configuration for groups.";
- };
- };
-
- config = {
-
- system.activationScripts.groups.text = mkIf (cfg.knownGroups != []) ''
- echo "setting up groups..." >&2
-
- ${concatMapStringsSep "\n" (v: ''
- g=$(dscl . -read '/Groups/${v.name}' PrimaryGroupID 2> /dev/null) || true
- g=''${g#PrimaryGroupID: }
- if [ -z "$g" ]; then
- echo "creating group ${v.name}..." >&2
- dscl . -create '/Groups/${v.name}' PrimaryGroupID ${toString v.gid}
- dscl . -create '/Groups/${v.name}' RealName '${v.description}'
- else
- if [ "$g" -ne ${toString v.gid} ]; then
- echo "warning: existing group '${v.name}' has unexpected gid $g, skipping..." >&2
- fi
- fi
- '') createdGroups}
-
- ${concatMapStringsSep "\n" (name: ''
- g=$(dscl . -read '/Groups/${name}' PrimaryGroupID 2> /dev/null) || true
- g=''${g#PrimaryGroupID: }
- if [ -n "$g" ]; then
- if [ "$g" -gt 501 ]; then
- echo "deleting group ${name}..." >&2
- dscl . -delete '/Groups/${name}' 2> /dev/null
- else
- echo "warning: existing group '${name}' has unexpected gid $g, skipping..." >&2
- fi
- fi
- '') deletedGroups}
- '';
-
- };
-}