r/o

TODO. 25bf0267 parent 39fdd76a

authored by ~talya

1
{
2
inputs = {
3
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
4
fenix = {
5
url = "github:nix-community/fenix";
6
inputs.nixpkgs.follows = "nixpkgs";
7
};
8
};
9
10
outputs =
11
{
12
self,
13
nixpkgs,
14
fenix,
15
}:
16
let
17
systems = [
18
"aarch64-darwin"
19
"aarch64-linux"
20
"x86_64-darwin"
21
"x86_64-linux"
22
];
23
eachSystem = nixpkgs.lib.genAttrs systems;
24
25
mkServerEnv =
26
pkgs:
27
pkgs.bundlerEnv {
28
name = "outfoxsync-server-bundler-env";
29
inherit (pkgs) ruby;
30
gemfile = ./server/Gemfile;
31
lockfile = ./server/Gemfile.lock;
32
gemset =
33
import ./server/gemset.nix
34
// (
35
if pkgs.stdenv.isDarwin then import ./server/gemset-darwin.nix else import ./server/gemset-linux.nix
36
);
37
};
38
in
39
{
40
formatter = eachSystem (system: nixpkgs.legacyPackages.${system}.nixfmt-rfc-style);
41
42
packages = eachSystem (
43
system:
44
let
45
toolchain = fenix.packages.${system}.stable.minimalToolchain;
46
pkgs = nixpkgs.legacyPackages.${system};
47
server-env = mkServerEnv pkgs;
48
in
49
rec {
50
client =
51
(pkgs.makeRustPlatform {
52
cargo = toolchain;
53
rustc = toolchain;
54
}).buildRustPackage
55
{
56
pname = "outfoxsync-client";
57
version = "0.1.0";
58
59
nativeBuildInputs = [ pkgs.pkg-config ];
60
buildInputs = [ pkgs.openssl ];
61
62
src = ./client;
63
64
postInstall = ''
65
mkdir $out/assets
66
cp ./assets/* $out/assets/
67
'';
68
69
cargoLock.lockFile = ./client/Cargo.lock;
70
};
71
72
server = pkgs.stdenv.mkDerivation {
73
pname = "outfoxsync-server";
74
version = "0.0.1";
75
76
src = ./server;
77
78
nativeBuildInputs = [ pkgs.makeWrapper ];
79
80
buildInputs = [ server-env ];
81
82
# I'm sure there's a better way to get the GEM_PATH out here.
83
# Right?
84
installPhase = ''
85
mkdir -p $out
86
cp -r * $out/
87
wrapProgram $out/bin/outfoxsync-server \
88
--prefix PATH : ${pkgs.lib.makeBinPath [ server-env ]} \
89
--prefix GEM_PATH : ${server-env}/lib/ruby/gems/3.1.0
90
'';
91
};
92
93
server-docker = pkgs.callPackage ./nix/docker.nix {
94
outfoxsync-server-rev = self.rev or "dev";
95
outfoxsync-server = server;
96
};
97
}
98
);
99
100
devShells = eachSystem (
101
system:
102
let
103
pkgs = nixpkgs.legacyPackages.${system};
104
server-env = mkServerEnv pkgs;
105
in
106
{
107
default = pkgs.mkShell {
108
name = "outfoxsync";
109
buildInputs = [
110
pkgs.ruby
111
server-env
112
(fenix.packages.${system}.stable.withComponents [
113
"cargo"
114
"rustc"
115
"rust-analyzer"
116
"clippy"
117
"rustfmt"
118
"rust-src"
119
])
120
pkgs.pkg-config
121
pkgs.openssl
122
];
123
};
124
}
125
);
126
127
nixosModules = eachSystem (system: {
128
default =
129
{
130
config,
131
lib,
132
...
133
}:
134
let
135
client-cfg = config.services.outfoxsync-client;
136
server-cfg = config.services.outfoxsync-server;
137
inherit (lib)
138
mkIf
139
mkMerge
140
mkEnableOption
141
mkOption
142
types
143
;
144
in
145
{
146
options.services.outfoxsync-client = {
147
enable = mkEnableOption "Enable the outfoxsync-client service";
148
149
package = mkOption {
150
type = types.package;
151
default = self.packages.${system}.client;
152
description = "Package to use for outfoxsync-client (defaults to this flake's).";
153
};
154
155
port = mkOption {
156
type = types.int;
157
default = 9298;
158
description = "Port to listen on.";
159
};
160
};
161
162
options.services.outfoxsync-server = {
163
enable = mkEnableOption "Enable the outfoxsync-server service";
164
165
package = mkOption {
166
type = types.package;
167
default = self.packages.${system}.server;
168
description = "Package to use for outfoxsync-server (defaults to this flake's).";
169
};
170
171
user = mkOption {
172
type = types.str;
173
description = "User account to run outfoxsync-server as (defaults to 'outfoxsync-server', which I'll create).";
174
default = "outfoxsync-server";
175
};
176
177
group = mkOption {
178
type = types.str;
179
description = "Group user to run nossa as (defaults to 'outfoxsync-server', which I'll create).";
180
default = "outfoxsync-server";
181
};
182
183
port = mkOption {
184
type = types.int;
185
default = 9299;
186
description = "Port to listen on.";
187
};
188
};
189
190
config = mkMerge [
191
(mkIf (client-cfg.enable) {
192
systemd.services.outfoxsync-client = {
193
description = "OutFox sync client";
194
wantedBy = [ "multi-user.target" ];
195
196
serviceConfig = {
197
DynamicUser = "yes";
198
ExecStart = "${client-cfg.package}/bin/outfoxsync-client";
199
Restart = "on-failure";
200
RestartSec = "5s";
201
};
202
environment.OUTFOXSYNC_CLIENT_PORT = builtins.toString client-cfg.port;
203
};
204
})
205
(mkIf (server-cfg.enable) {
206
users.groups.outfoxsync-server = mkIf (server-cfg.group == "outfoxsync-server") { };
207
users.users.outfoxsync-server = mkIf (server-cfg.user == "outfoxsync-server") {
208
description = "outfoxsync-server user";
209
group = server-cfg.group;
210
isSystemUser = true;
211
};
212
213
systemd.services.outfoxsync-server = {
214
description = "OutFox sync server";
215
wantedBy = [ "multi-user.target" ];
216
217
serviceConfig = {
218
User = server-cfg.user;
219
ProtectSystem = "strict";
220
PrivateTmp = true;
221
UMask = "0007";
222
ExecStart = "${server-cfg.package}/bin/outfoxsync-server";
223
Restart = "on-failure";
224
RestartSec = "5s";
225
StateDirectory = "outfoxsync-server";
226
StateDirectoryMode = "0750";
227
};
228
environment.OUTFOXSYNC_SERVER_PORT = builtins.toString server-cfg.port;
229
};
230
})
231
];
232
};
233
});
234
235
darwinModules = nixpkgs.lib.genAttrs [ "aarch64-darwin" "x86_64-darwin" ] (system: {
236
default =
237
{
238
config,
239
lib,
240
...
241
}:
242
let
243
cfg = config.services.outfoxsync-client;
244
inherit (lib)
245
mkIf
246
mkEnableOption
247
mkOption
248
types
249
;
250
in
251
{
252
options.services.outfoxsync-client = {
253
enable = mkEnableOption "Enable the outfoxsync-client service";
254
255
package = mkOption {
256
type = types.package;
257
default = self.packages.${system}.client;
258
description = "Package to use for outfoxsync-client (defaults to this flake's).";
259
};
260
261
logFile = mkOption {
262
type = types.nullOr types.path;
263
default = null;
264
description = "The logfile to use for the outfoxsync-client service.";
265
};
266
};
267
268
config = mkIf (cfg.enable) {
269
launchd.user.agents.outfoxsync-client = {
270
serviceConfig = {
271
ProgramArguments = [ "${cfg.package}/bin/outfoxsync-client" ];
272
KeepAlive = true;
273
RunAtLoad = true;
274
ProcessType = "Background";
275
StandardOutPath = cfg.logFile;
276
StandardErrorPath = cfg.logFile;
277
EnvironmentVariables = {
278
OUTFOXSYNC_CLIENT_ASSET_BASE = "${cfg.package}/assets";
279
};
280
};
281
};
282
};
283
};
284
});
285
};
286
}
287