1
{
2
description = "a1d Argon ONE V3 fan/power daemon";
3
4
inputs = {
5
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
6
fenix = {
7
url = "github:nix-community/fenix";
8
inputs.nixpkgs.follows = "nixpkgs";
9
};
10
};
11
12
outputs =
13
{
14
self,
15
nixpkgs,
16
fenix,
17
}:
18
let
19
systems = [
20
"aarch64-darwin"
21
"aarch64-linux"
22
"x86_64-darwin"
23
"x86_64-linux"
24
];
25
eachSystem = nixpkgs.lib.genAttrs systems;
26
in
27
rec {
28
formatter = eachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
29
30
packages = eachSystem (
31
system:
32
let
33
toolchain = fenix.packages.${system}.stable.minimalToolchain;
34
pkgs = nixpkgs.legacyPackages.${system};
35
in
36
rec {
37
default = a1d;
38
39
a1d =
40
(pkgs.makeRustPlatform {
41
cargo = toolchain;
42
rustc = toolchain;
43
}).buildRustPackage
44
{
45
pname = "a1d";
46
version = "0.1.0";
47
48
src = ./.;
49
50
cargoLock.lockFile = ./Cargo.lock;
51
};
52
}
53
);
54
55
devShells = eachSystem (
56
system:
57
let
58
pkgs = nixpkgs.legacyPackages.${system};
59
in
60
{
61
default = pkgs.mkShell {
62
name = "a1d";
63
64
packages = [
65
(fenix.packages.${system}.stable.withComponents [
66
"cargo"
67
"rustc"
68
"rust-analyzer"
69
"clippy"
70
"rustfmt"
71
"rust-src"
72
])
73
];
74
};
75
}
76
);
77
78
nixosModules = eachSystem (system: rec {
79
default = a1d;
80
81
a1d =
82
{ config, lib, ... }:
83
let
84
cfg = config.services.a1d;
85
inherit (lib)
86
mkIf
87
mkEnableOption
88
mkOption
89
types
90
;
91
in
92
{
93
options.services.a1d = {
94
enable = mkEnableOption "Enable the a1d Argon ONE V3 fan/power daemon";
95
package = mkOption {
96
type = types.package;
97
default = packages.${system}.a1d;
98
description = "Package to use for a1d (defaults to this flake's).";
99
};
100
};
101
102
config = mkIf (cfg.enable) {
103
users.groups.a1d = { };
104
105
users.users.a1d = {
106
description = "a1d Argon ONE V3 fan/power daemon";
107
group = "a1d";
108
extraGroups = [
109
"i2c"
110
"gpio"
111
];
112
isSystemUser = true;
113
};
114
115
systemd.services.a1d = {
116
description = "a1d Argon ONE V3 fan/power daemon";
117
wantedBy = [ "multi-user.target" ];
118
path = [ config.systemd.package ];
119
120
serviceConfig = {
121
ExecStart = "${cfg.package}/bin/a1d";
122
User = "a1d";
123
ProtectSystem = "strict";
124
PrivateTmp = true;
125
Restart = "on-failure";
126
RestartSec = "10s";
127
};
128
};
129
130
systemd.shutdown.a1d = "${cfg.package}/bin/a1d";
131
132
security.polkit.enable = true;
133
134
# XXX: subject.system_unit is null. Why?
135
security.polkit.extraConfig = ''
136
polkit.addRule(function(action, subject) {
137
if (subject.user !== "a1d")
138
return;
139
140
if (action.id === "org.freedesktop.login1.power-off" ||
141
action.id === "org.freedesktop.login1.power-off-multiple-sessions" ||
142
action.id === "org.freedesktop.login1.power-off-ignore-inhibit" ||
143
action.id === "org.freedesktop.login1.reboot" ||
144
action.id === "org.freedesktop.login1.reboot-multiple-sessions" ||
145
action.id === "org.freedesktop.login1.reboot-ignore-inhibit") {
146
return polkit.Result.YES;
147
}
148
});
149
'';
150
};
151
};
152
});
153
};
154
}
155