blob: c56c11ed288473afa41ad3305f09153ceecdb147 (
plain)
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
139
140
141
142
143
144
145
146
147
148
149
150
|
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.devpi-server;
package = cfg.package.override { inherit (cfg) extraPackages; };
secretsFileName = "devpi-secret-file";
stateDirName = "devpi";
runtimeDir = "/run/${stateDirName}";
serverDir = "/var/lib/${stateDirName}";
in
{
options.services.devpi-server = {
enable = lib.mkEnableOption "Devpi Server";
package = lib.mkPackageOption pkgs "devpi-server" { };
primaryUrl = lib.mkOption {
type = lib.types.str;
description = "Url for the primary node. Required option for replica nodes.";
};
replica = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Run node as a replica.
Requires the secretFile option and the primaryUrl to be enabled.
'';
};
secretFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
description = ''
Path to a shared secret file used for synchronization,
Required for all nodes in a replica/primary setup.
'';
};
host = lib.mkOption {
type = lib.types.str;
default = "localhost";
description = ''
domain/ip address to listen on
'';
};
port = lib.mkOption {
type = lib.types.port;
default = 3141;
description = "The port on which Devpi Server will listen.";
};
extraPackages = lib.mkOption {
default = (ps: [ ]);
defaultText = lib.literalExpression "ps: [ ]";
example = lib.literalExpression ''
ps: with ps; [ devpi-web devpi-ldap ]
'';
type =
with lib.types;
coercedTo (listOf lib.types.package) (v: (_: v)) (functionTo (listOf lib.types.package));
description = ''
Plugins and extra Python packages to be available to devpi-server.
'';
};
openFirewall = lib.mkEnableOption "opening the default ports in the firewall for Devpi Server";
};
config = lib.mkIf cfg.enable {
systemd.services.devpi-server = {
enable = true;
description = "devpi PyPI-compatible server";
documentation = [ "https://devpi.net/docs/devpi/devpi/stable/+d/index.html" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
after = [ "network-online.target" ];
# Since at least devpi-server 6.10.0, devpi requires the secrets file to
# have 0600 permissions.
preStart = ''
${lib.optionalString (
!isNull cfg.secretFile
) "install -Dm 0600 \${CREDENTIALS_DIRECTORY}/devpi-secret ${runtimeDir}/${secretsFileName}"}
if [ -f ${serverDir}/.nodeinfo ]; then
# already initialized the package index, exit gracefully
exit 0
fi
${package}/bin/devpi-init --serverdir ${serverDir} ''
+ lib.optionalString cfg.replica "--role=replica --master-url=${cfg.primaryUrl}";
serviceConfig = {
LoadCredential = lib.mkIf (!isNull cfg.secretFile) [
"devpi-secret:${cfg.secretFile}"
];
Restart = "always";
ExecStart =
let
args = [
"--request-timeout=5"
"--serverdir=${serverDir}"
"--host=${cfg.host}"
"--port=${toString cfg.port}"
]
++ lib.optionals (!isNull cfg.secretFile) [
"--secretfile=${runtimeDir}/${secretsFileName}"
]
++ (
if cfg.replica then
[
"--role=replica"
"--master-url=${cfg.primaryUrl}"
]
else
[ "--role=master" ]
);
in
"${package}/bin/devpi-server ${lib.concatStringsSep " " args}";
DynamicUser = true;
StateDirectory = stateDirName;
RuntimeDirectory = stateDirName;
PrivateDevices = true;
PrivateTmp = true;
ProtectHome = true;
ProtectSystem = "strict";
};
};
networking.firewall = lib.mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
};
meta.maintainers = with lib.maintainers; [
cafkafk
confus
];
}
|