-
Notifications
You must be signed in to change notification settings - Fork 14
/
options.nix
108 lines (95 loc) · 3.16 KB
/
options.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
{ config
, options
, lib
, home-manager
, ...
}:
let inherit (builtins) elem pathExists toString;
inherit (lib)
findFirst
isList
mapAttrs
mapAttrsToList
mkAliasDefinitions
mkOption;
inherit (lib.strings) concatMapStringsSep concatStringsSep;
inherit (lib.types) attrs attrsOf either listOf oneOf path str;
inherit (lib.my) mkOpt mkOpt';
in
{
options = {
user = mkOpt attrs { };
snowflake = {
dir = mkOpt path (findFirst pathExists (toString ../.) [
"${config.user.home}/git/icy-thought/snowflake"
"/etc/snowflake"
]);
hostDir = mkOpt path "${config.snowflake.dir}/hosts/${config.networking.hostName}";
binDir = mkOpt path "${config.snowflake.dir}/bin";
configDir = mkOpt path "${config.snowflake.dir}/config";
modulesDir = mkOpt path "${config.snowflake.dir}/modules";
themesDir = mkOpt path "${config.snowflake.modulesDir}/themes";
};
home = {
file = mkOpt' attrs { } "Files to place directly in $HOME";
configFile = mkOpt' attrs { } "Files to place in $XDG_CONFIG_HOME";
dataFile = mkOpt' attrs { } "Files to place in $XDG_DATA_HOME";
pointerCursor = mkOpt' attrs { } "Cursor to be applied on running system";
activation = mkOpt' attrs { } "Script block to run after NixOS rebuild";
};
env = mkOption {
type = attrsOf (oneOf [ str path (listOf (either str path)) ]);
apply = mapAttrs (n: v:
if isList v
then concatMapStringsSep ":" (x: toString x) v
else (toString v));
default = { };
description = "Provides easy-access to `environment.extraInit`";
};
};
config = {
user =
let
user = builtins.getEnv "USER";
name =
if elem user [ "" "root" ]
then "icy-thought"
else user;
in
{
inherit name;
description = "Primary user account";
extraGroups = [ "wheel" "input" "audio" "video" "storage" ];
isNormalUser = true;
home = "/home/${name}";
group = "users";
uid = 1000;
};
# Necessary for nixos-rebuild build-vm to work.
home-manager.useUserPackages = true;
# Re-defining home-manager settings for modified option-names:
# home.configFile -> home-manager.users.icy-thought.home.xdg.configFile
# home.dataFile -> home-manager.users.icy-thought.home.xdg.dataFile
hm.home = {
activation = mkAliasDefinitions options.home.activation;
file = mkAliasDefinitions options.home.file;
pointerCursor = mkAliasDefinitions options.home.pointerCursor;
stateVersion = config.system.stateVersion;
};
hm.xdg = {
configFile = mkAliasDefinitions options.home.configFile;
dataFile = mkAliasDefinitions options.home.dataFile;
};
users.users.${config.user.name} = mkAliasDefinitions options.user;
nix.settings =
let users = [ "root" config.user.name ];
in {
trusted-users = users;
allowed-users = users;
};
env.PATH = [ "$SNOWFLAKE_BIN" "$XDG_BIN_HOME" "$PATH" ];
environment.extraInit =
concatStringsSep "\n"
(mapAttrsToList (n: v: ''export ${n}="${v}"'') config.env);
};
}