-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdefault.nix
164 lines (151 loc) · 4.24 KB
/
default.nix
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
{
config,
lib,
util,
inputs,
files,
...
}: let
inherit (util.map) modules;
inherit (builtins) all attrNames attrValues mapAttrs pathExists;
inherit
(lib)
filterAttrs
findFirst
findSingle
getValues
mkIf
mkEnableOption
mkOption
mkOptionType
optionals
types
;
inherit (config.user) groups homeConfig settings;
# Merged Sets Type
mergedAttrs = mkOptionType {
name = "mergedAttrs";
merge = _: getValues;
};
in {
## USER Configuration ##
imports = modules.list ./. ++ [inputs.home-manager.nixosModules.home-manager];
options = {
# Global Home Manager Configuration
home-manager.users = mkOption {
type = types.attrsOf (types.submoduleWith {
modules =
if (all (value: value.minimal) (attrValues settings))
then [{home.stateVersion = config.system.stateVersion;}]
else homeConfig;
});
};
# Configuration Options
user = {
homeConfig = mkOption {
description = "Shared User Home Configuration";
type = mergedAttrs;
default = {};
};
groups = mkOption {
description = "Additional User Groups";
type = types.listOf types.str;
default = [];
};
settings = mkOption {
description = "User Settings";
default = {};
type = with types;
attrsOf (submodule ({
options,
config,
...
}: {
freeformType = attrsOf anything;
options = {
forwarded = mkOption {};
autologin = mkEnableOption "Enable Automatic User Login";
minimal = mkEnableOption "Enable Minimal User Configuration";
extraGroups = mkOption {
apply = group: group ++ optionals config.isNormalUser groups;
};
shells = mkOption {
description = "List of Additional Supported Shells";
type = listOf (enum (modules.name ../shell));
default = ["bash"];
};
homeConfig = mkOption {
description = "User Specific Home Configuration";
type = mergedAttrs;
default = {};
};
};
config = {
isNormalUser = true;
group = "users";
useDefaultShell = false;
homeConfig = let
path = ../../. + "/users/${config.name}";
in
if (pathExists (path + "/default.nix"))
then {
imports = [path];
}
else if (pathExists (path + ".nix"))
then {
imports = [(path + ".nix")];
}
else {};
forwarded =
filterAttrs
(name: _: !(options ? "${name}") || name == "extraGroups")
config;
};
}));
};
};
};
config = {
# Settings
users = {
mutableUsers = false;
users = mapAttrs (_: name: name.forwarded) settings;
extraUsers.root = {
isNormalUser = false;
extraGroups = ["wheel"];
};
};
# Login
services.displayManager.autoLogin = let
find =
findSingle (value: value.autologin || value.minimal) "0" "1"
(attrValues settings);
in rec {
enable =
if (find == "0")
then false
else if (config.services.displayManager.defaultSession == null)
then throw "Graphical Environment must be present for Automatic Log-In"
else if (find == "1")
then throw "Only one User can be Automatically Logged-In"
else true;
user =
mkIf enable
(findFirst (name: with settings."${name}"; autologin || minimal) "nixos"
(attrNames settings));
};
# Home Management
home-manager = {
useGlobalPkgs = true;
useUserPackages = true;
backupFileExtension = "bak";
users = mapAttrs (_: value: {imports = value.homeConfig;}) settings;
extraSpecialArgs = {
inherit util inputs files;
sys = config;
};
};
# Debug
specialisation.recovery.configuration.home-manager.verbose = true;
};
}