summaryrefslogtreecommitdiff
path: root/users.nix
blob: 06d465a2e6fe95bfd19c5d9fe589394fbf17afd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ config, lib, ...}:

with lib;

let
  genUsersList = dirPath: concatLists (let contents = builtins.readDir dirPath; in map (name: (dirEntryToList."${contents."${name}"}" or (x: [])) "${dirPath}/${name}") (attrNames contents));
  dirEntryToList = {
    "regular" = path: [(import (builtins.toPath path))];
  };

  users = genUsersList ./users;
  host = config.networking.hostName;
in {
  users.mutableUsers = false;
  users.extraUsers = listToAttrs
    (map (user: nameValuePair (user.name) (removeAttrs user ["hosts" "allHosts"])) (filter (user: elem host (user.hosts or []) || (user.allHosts or false)) users));
}