forked from lebzm/homini
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdarwin.nix
More file actions
62 lines (59 loc) · 1.75 KB
/
darwin.nix
File metadata and controls
62 lines (59 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{ config, lib, pkgs, ... }:
let
hominiConfigModule = import ./module.nix;
hominiConfigType = lib.types.submoduleWith {
modules = [ hominiConfigModule ];
specialArgs = { inherit pkgs; };
shorthandOnlyDefinesConfig = true;
};
hominiUserType = lib.types.submoduleWith {
modules = [
{
options.homini = lib.mkOption {
type = lib.types.nullOr hominiConfigType;
default = null;
description = ''
Homini configuration for this user.
'';
};
}
];
shorthandOnlyDefinesConfig = true;
};
enabledUsers = lib.filterAttrs (_: userCfg: userCfg.homini != null) config.users.users;
in
{
options.users.users = lib.mkOption {
type = lib.types.attrsOf hominiUserType;
};
config = {
assertions = lib.mapAttrsToList (
name: userCfg:
{
assertion = userCfg.homini == null || userCfg.home != null;
message = ''
users.users."${name}".home must be set when users.users."${name}".homini is configured.
'';
}
) config.users.users;
system.activationScripts.postActivation.text = lib.mkAfter (
lib.concatStringsSep "\n" (
lib.mapAttrsToList (
name: userCfg:
let
home = toString userCfg.home;
xdgConfigHome = "${home}/.config";
xdgStateHome = "${home}/.local/state";
in
''
/usr/bin/sudo -u ${lib.escapeShellArg name} /usr/bin/env \
HOME=${lib.escapeShellArg home} \
XDG_CONFIG_HOME=${lib.escapeShellArg xdgConfigHome} \
XDG_STATE_HOME=${lib.escapeShellArg xdgStateHome} \
"${userCfg.homini.activationPackage}/bin/homini"
''
) enabledUsers
)
);
};
}