-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnixos-module.nix
More file actions
107 lines (99 loc) · 2.92 KB
/
nixos-module.nix
File metadata and controls
107 lines (99 loc) · 2.92 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
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
{
config,
lib,
pkgs,
...
}: let
inherit (lib) types mkOption mkIf mkMerge;
inherit (pkgs) writeShellScript writeShellScriptBin;
poweroffdScript = writeShellScript "poweroffd.sh" "${builtins.readFile ./src/poweroffd.sh}";
SCpowerOffScript = writeShellScriptBin "SC_poweroff.sh" "${builtins.readFile ./src/SC_poweroff.sh}";
SCpowerOffPopupScript = writeShellScriptBin "SC_poweroff_popup.sh" "${builtins.readFile ./src/SC_poweroff_popup.sh}";
cfg = config.services.poweroffd;
in {
options = {
services.poweroffd = {
enable = lib.mkEnableOption "poweroffd";
mqttHost = mkOption {
type = types.str;
default = "127.0.0.1";
description = "Hostname address of the MQTT server to connect to.";
};
mqttPort = mkOption {
type = types.int;
default = 1883;
description = "Port of the MQTT server to connect to.";
};
mqttUsername = mkOption {
type = types.str;
default = "";
description = "Username for the MQTT server connection.";
};
mqttPassword = mkOption {
type = types.str;
default = "";
description = "Password for the MQTT server connection.";
};
mqttTopic = mkOption {
type = types.str;
default = "";
description = "Topic for the MQTT connection.";
};
};
};
config = mkIf cfg.enable (mkMerge [
{
# FIXME: Consider not running as root
systemd.services.poweroffd = {
description = "Poweroffd Space Control";
wantedBy = ["multi-user.target"];
after = [
"network-online.target"
];
wants = ["network-online.target"];
serviceConfig = {
ExecStart = "${poweroffdScript}";
};
environment = {
MQTT_HOST = cfg.mqttHost;
MQTT_PORT = builtins.toString cfg.mqttPort;
MQTT_USERNAME = cfg.mqttUsername;
MQTT_PASSWORD = cfg.mqttPassword;
MQTT_TOPIC = cfg.mqttTopic;
};
path = with pkgs; [
mosquitto
sudo
xorg.xhost
xorg.xset
# Zenity with gtk3 for extra speed?
(zenity.overrideAttrs (oldAttrs: rec {
version = "3.44.0";
src = fetchurl {
url = "mirror://gnome/sources/zenity/${lib.versions.majorMinor version}/${oldAttrs.pname}-${version}.tar.xz";
sha256 = "wVWCMB7ZC51CzlIdvM+ZqYnyLxIEG91SecZjbamev2U=";
};
nativeBuildInputs = [
meson
ninja
pkg-config
gettext
itstool
libxml2
wrapGAppsHook
];
buildInputs = [
gtk3
xorg.libX11
];
patches = [
./zenity-fix-icon-install.patch
];
}))
SCpowerOffPopupScript
SCpowerOffScript
];
};
}
]);
}