-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
80 lines (76 loc) · 2.15 KB
/
module.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
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.services.print-interface;
appEnv = pkgs.python311.withPackages (p: with p; [ gunicorn (pkgs.python311Packages.callPackage ./default.nix { }) ]);
in
{
options.services.print-interface = {
enable = mkEnableOption "";
listenPort = mkOption {
type = types.port;
default = 8090;
description = mdDoc ''
Port the app will run on.
'';
};
user = mkOption {
type = types.str;
default = "print-interface";
description = "The user under which the server runs.";
};
group = mkOption {
type = types.str;
default = "print-interface";
description = "The group under which the server runs.";
};
dataDir = mkOption {
type = types.path;
default = "/var/cache/print-interface";
description = mdDoc ''
The service's working directory
'';
};
smtp = {
username = mkOption {
type = types.str;
description = mdDoc ''
SMTP username.
'';
};
passwordFile = mkOption {
type = types.path;
default = null;
description = mdDoc ''
File containing the SMTP password.
'';
};
};
};
config = mkIf (cfg.enable) {
systemd.tmpfiles.rules = [
"d '${cfg.dataDir}' 0700 ${cfg.user} ${cfg.group} - -"
];
users.users.print-interface = lib.mkIf (cfg.user == "print-interface") {
group = cfg.group;
isSystemUser = true;
};
users.groups.print-interface = lib.mkIf (cfg.group == "print-interface") { };
systemd.services.print-interface = {
enable = true;
path = [ pkgs.cups ];
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
environment = {
PRINT_INTERFACE_USERNAME = cfg.smtp.username;
};
serviceConfig = {
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.dataDir;
LoadCredential = "print_interface_password:${cfg.smtp.passwordFile}";
ExecStart = "${appEnv}/bin/gunicorn print_interface:app -b 0.0.0.0:${toString cfg.listenPort} --error-logfile -";
};
};
};
}