-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathcustom.nix
138 lines (129 loc) · 5.05 KB
/
custom.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
{ lib, config, pkgs, ... }: {
options = {
nixiosk.hostName = lib.mkOption {
type = lib.types.str;
};
nixiosk.hardware = lib.mkOption {
type = lib.types.str;
};
nixiosk.authorizedKeys = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
};
nixiosk.program.package = lib.mkOption {
type = lib.types.oneOf [ lib.types.package lib.types.str (lib.types.functionTo lib.types.package) ];
};
nixiosk.program.executable = lib.mkOption {
type = lib.types.str;
};
nixiosk.program.args = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
};
nixiosk.networks = lib.mkOption {
type = lib.types.attrsOf lib.types.str;
default = {};
};
# This should only be used when you’re in a closed NAT since
# anyone can mess with the kiosk user.
nixiosk.allowKioskLogin = lib.mkOption {
type = lib.types.bool;
default = false;
};
nixiosk.locale.lang = lib.mkOption {
type = lib.types.str;
default = "en_US.UTF-8";
};
nixiosk.locale.regDom = lib.mkOption {
type = lib.types.str;
default = "US";
};
nixiosk.locale.timeZone = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
nixiosk.localSystem.system = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
nixiosk.localSystem.sshUser = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
nixiosk.localSystem.hostName = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
nixiosk.raspberryPi.firmwareConfig = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
nixiosk.raspberryPi.enableExtraFirmware = lib.mkOption {
type = lib.types.bool;
default = builtins.elem config.nixiosk.hardware ["raspberryPi0" "raspberryPi1" "raspberryPi2"];
};
nixiosk.raspberryPi.cecSupport = lib.mkOption {
type = lib.types.bool;
default = true;
};
nixiosk.flake = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
};
};
config = let
package = if builtins.isAttrs config.nixiosk.program.package then config.nixiosk.program.package
else if builtins.isFunction config.nixiosk.program.package then config.nixiosk.program.package pkgs
else if builtins.isString config.nixiosk.program.package then pkgs.${config.nixiosk.program.package}
else throw "Invalid nixiosk.program.package value.";
in {
time = { timeZone = config.nixiosk.locale.timeZone; };
# localtime service doesn’t cross compile
# services.localtime.enable =
# config.nixiosk.locale.timeZone == null &&
# !(builtins.elem config.nixiosk.hardware ["ova" "qemu" "qemu-no-virtfs"]);
i18n.defaultLocale = config.nixiosk.locale.lang;
i18n.supportedLocales = [ "${config.nixiosk.locale.lang}/UTF-8" ];
boot.extraModprobeConfig = ''
options cfg80211 ieee80211_regdom="${config.nixiosk.locale.regDom}"
'';
nix.distributedBuilds = true;
nix.buildMachines = lib.optional ((config.nixiosk.localSystem.hostName != null) && (config.nixiosk.localSystem.sshUser != null) && (config.nixiosk.localSystem.system != null)) {
inherit (config.nixiosk.localSystem) system sshUser hostName;
# ??? is this okay to use for ssh keys?
sshKey = "/etc/ssh/ssh_host_rsa_key";
};
users.users.root.openssh.authorizedKeys.keys = config.nixiosk.authorizedKeys;
services.cage.program = "${lib.getBin package}${config.nixiosk.program.executable} ${toString (config.nixiosk.program.args)}";
environment.systemPackages = [ package ];
systemd.packages = [ package ];
services.dbus.packages = [ package ];
networking.hostName = config.nixiosk.hostName;
networking.wireless.networks = builtins.mapAttrs (_: value: { pskRaw = value; }) (config.nixiosk.networks or {});
users.users.kiosk.initialHashedPassword = if config.nixiosk.allowKioskLogin then "" else null;
# services.ddclient = {
# enable = config.nixiosk.custom.ddclient.enable;
# protocol = "${config.nixiosk.ddclient.protocol}";
# password = "${config.nixiosk.ddclient.password}";
# domains = ["${config.nixiosk.ddclient.domain}"];
# };
# systemd.services.port-map = {
# enable = config.nixiosk.upnp.enable;
# wantedBy = [ "multi-user.target" ];
# after = [ "network.target" ];
# serviceConfig = {
# Type = "oneshot";
# ExecStart = "${pkgs.miniupnpc}/bin/upnpc -r 22 ${toString cnofig.nixiosk.upnp.sshPort} tcp";
# };
# };
boot.postBootCommands = lib.optionalString (config.nixiosk.flake != null) ''
if ! [ -d /etc/nixos ] && ! [ "$(ls -A /etc/nixos)" ] ; then
mkdir -p /etc
cp -R ${config.nixiosk.flake} /etc/nixos
chmod -R u+w /etc/nixos
fi
'';
} // lib.optionalAttrs (builtins.pathExists ./nixiosk.json) {
nixiosk = builtins.fromJSON (builtins.readFile ./nixiosk.json);
};
}