1 { config, lib, pkgs, ... }:
4 cfg = config.services.xtreemfs;
6 xtreemfs = pkgs.xtreemfs;
10 startupScript = class: configPath: pkgs.writeScript "xtreemfs-osd.sh" ''
11 #! ${pkgs.runtimeShell}
12 JAVA_HOME="${pkgs.jdk}"
13 JAVADIR="${xtreemfs}/share/java"
14 JAVA_CALL="$JAVA_HOME/bin/java -ea -cp $JAVADIR/XtreemFS.jar:$JAVADIR/BabuDB.jar:$JAVADIR/Flease.jar:$JAVADIR/protobuf-java-2.5.0.jar:$JAVADIR/Foundation.jar:$JAVADIR/jdmkrt.jar:$JAVADIR/jdmktk.jar:$JAVADIR/commons-codec-1.3.jar"
15 $JAVA_CALL ${class} ${configPath}
18 dirReplicationConfig = pkgs.writeText "xtreemfs-dir-replication-plugin.properties" ''
19 babudb.repl.backupDir = ${home}/server-repl-dir
20 plugin.jar = ${xtreemfs}/share/java/BabuDB_replication_plugin.jar
21 babudb.repl.dependency.0 = ${xtreemfs}/share/java/Flease.jar
23 ${cfg.dir.replication.extraConfig}
26 dirConfig = pkgs.writeText "xtreemfs-dir-config.properties" ''
27 uuid = ${cfg.dir.uuid}
28 listen.port = ${toString cfg.dir.port}
29 ${lib.optionalString (cfg.dir.address != "") "listen.address = ${cfg.dir.address}"}
30 http_port = ${toString cfg.dir.httpPort}
31 babudb.baseDir = ${home}/dir/database
32 babudb.logDir = ${home}/dir/db-log
33 babudb.sync = ${if cfg.dir.replication.enable then "FDATASYNC" else cfg.dir.syncMode}
35 ${lib.optionalString cfg.dir.replication.enable "babudb.plugin.0 = ${dirReplicationConfig}"}
37 ${cfg.dir.extraConfig}
40 mrcReplicationConfig = pkgs.writeText "xtreemfs-mrc-replication-plugin.properties" ''
41 babudb.repl.backupDir = ${home}/server-repl-mrc
42 plugin.jar = ${xtreemfs}/share/java/BabuDB_replication_plugin.jar
43 babudb.repl.dependency.0 = ${xtreemfs}/share/java/Flease.jar
45 ${cfg.mrc.replication.extraConfig}
48 mrcConfig = pkgs.writeText "xtreemfs-mrc-config.properties" ''
49 uuid = ${cfg.mrc.uuid}
50 listen.port = ${toString cfg.mrc.port}
51 ${lib.optionalString (cfg.mrc.address != "") "listen.address = ${cfg.mrc.address}"}
52 http_port = ${toString cfg.mrc.httpPort}
53 babudb.baseDir = ${home}/mrc/database
54 babudb.logDir = ${home}/mrc/db-log
55 babudb.sync = ${if cfg.mrc.replication.enable then "FDATASYNC" else cfg.mrc.syncMode}
57 ${lib.optionalString cfg.mrc.replication.enable "babudb.plugin.0 = ${mrcReplicationConfig}"}
59 ${cfg.mrc.extraConfig}
62 osdConfig = pkgs.writeText "xtreemfs-osd-config.properties" ''
63 uuid = ${cfg.osd.uuid}
64 listen.port = ${toString cfg.osd.port}
65 ${lib.optionalString (cfg.osd.address != "") "listen.address = ${cfg.osd.address}"}
66 http_port = ${toString cfg.osd.httpPort}
67 object_dir = ${home}/osd/
69 ${cfg.osd.extraConfig}
72 optionalDir = lib.optionals cfg.dir.enable ["xtreemfs-dir.service"];
74 systemdOptionalDependencies = {
75 after = [ "network.target" ] ++ optionalDir;
76 wantedBy = [ "multi-user.target" ] ++ optionalDir;
89 enable = lib.mkEnableOption "XtreemFS";
91 homeDir = lib.mkOption {
92 type = lib.types.path;
93 default = "/var/lib/xtreemfs";
95 XtreemFS home dir for the xtreemfs user.
100 enable = lib.mkOption {
101 type = lib.types.bool;
104 Whether to enable XtreemFS DIR service.
108 uuid = lib.mkOption {
109 example = "eacb6bab-f444-4ebf-a06a-3f72d7465e40";
110 type = lib.types.str;
112 Must be set to a unique identifier, preferably a UUID according to
113 RFC 4122. UUIDs can be generated with `uuidgen` command, found in
114 the `util-linux` package.
117 port = lib.mkOption {
119 type = lib.types.port;
121 The port to listen on for incoming connections (TCP).
124 address = lib.mkOption {
125 type = lib.types.str;
126 example = "127.0.0.1";
129 If specified, it defines the interface to listen on. If not
130 specified, the service will listen on all interfaces (any).
133 httpPort = lib.mkOption {
135 type = lib.types.port;
137 Specifies the listen port for the HTTP service that returns the
141 syncMode = lib.mkOption {
142 type = lib.types.enum [ "ASYNC" "SYNC_WRITE_METADATA" "SYNC_WRITE" "FDATASYNC" "FSYNC" ];
144 example = "FDATASYNC";
146 The sync mode influences how operations are committed to the disk
147 log before the operation is acknowledged to the caller.
149 -ASYNC mode the writes to the disk log are buffered in memory by the operating system. This is the fastest mode but will lead to data loss in case of a crash, kernel panic or power failure.
150 -SYNC_WRITE_METADATA opens the file with O_SYNC, the system will not buffer any writes. The operation will be acknowledged when data has been safely written to disk. This mode is slow but offers maximum data safety. However, BabuDB cannot influence the disk drive caches, this depends on the OS and hard disk model.
151 -SYNC_WRITE similar to SYNC_WRITE_METADATA but opens file with O_DSYNC which means that only the data is commit to disk. This can lead to some data loss depending on the implementation of the underlying file system. Linux does not implement this mode.
152 -FDATASYNC is similar to SYNC_WRITE but opens the file in asynchronous mode and calls fdatasync() after writing the data to disk.
153 -FSYNC is similar to SYNC_WRITE_METADATA but opens the file in asynchronous mode and calls fsync() after writing the data to disk.
155 For best throughput use ASYNC, for maximum data safety use FSYNC.
157 (If xtreemfs.dir.replication.enable is true then FDATASYNC is forced)
160 extraConfig = lib.mkOption {
161 type = lib.types.lines;
164 # specify whether SSL is required
166 ssl.service_creds.pw = passphrase
167 ssl.service_creds.container = pkcs12
168 ssl.service_creds = /etc/xos/xtreemfs/truststore/certs/dir.p12
169 ssl.trusted_certs = /etc/xos/xtreemfs/truststore/certs/trusted.jks
170 ssl.trusted_certs.pw = jks_passphrase
171 ssl.trusted_certs.container = jks
174 Configuration of XtreemFS DIR service.
175 WARNING: configuration is saved as plaintext inside nix store.
176 For more options: https://www.xtreemfs.org/xtfs-guide-1.5.1/index.html
180 enable = lib.mkEnableOption "XtreemFS DIR replication plugin";
181 extraConfig = lib.mkOption {
182 type = lib.types.lines;
184 # participants of the replication including this replica
185 babudb.repl.participant.0 = 192.168.0.10
186 babudb.repl.participant.0.port = 35676
187 babudb.repl.participant.1 = 192.168.0.11
188 babudb.repl.participant.1.port = 35676
189 babudb.repl.participant.2 = 192.168.0.12
190 babudb.repl.participant.2.port = 35676
192 # number of servers that at least have to be up to date
193 # To have a fault-tolerant system, this value has to be set to the
194 # majority of nodes i.e., if you have three replicas, set this to 2
195 # Please note that a setup with two nodes provides no fault-tolerance.
196 babudb.repl.sync.n = 2
198 # specify whether SSL is required
199 babudb.ssl.enabled = true
201 babudb.ssl.protocol = tlsv12
203 # server credentials for SSL handshakes
204 babudb.ssl.service_creds = /etc/xos/xtreemfs/truststore/certs/osd.p12
205 babudb.ssl.service_creds.pw = passphrase
206 babudb.ssl.service_creds.container = pkcs12
208 # trusted certificates for SSL handshakes
209 babudb.ssl.trusted_certs = /etc/xos/xtreemfs/truststore/certs/trusted.jks
210 babudb.ssl.trusted_certs.pw = jks_passphrase
211 babudb.ssl.trusted_certs.container = jks
213 babudb.ssl.authenticationWithoutEncryption = false
216 Configuration of XtreemFS DIR replication plugin.
217 WARNING: configuration is saved as plaintext inside nix store.
218 For more options: https://www.xtreemfs.org/xtfs-guide-1.5.1/index.html
225 enable = lib.mkOption {
226 type = lib.types.bool;
229 Whether to enable XtreemFS MRC service.
233 uuid = lib.mkOption {
234 example = "eacb6bab-f444-4ebf-a06a-3f72d7465e41";
235 type = lib.types.str;
237 Must be set to a unique identifier, preferably a UUID according to
238 RFC 4122. UUIDs can be generated with `uuidgen` command, found in
239 the `util-linux` package.
242 port = lib.mkOption {
244 type = lib.types.port;
246 The port to listen on for incoming connections (TCP).
249 address = lib.mkOption {
250 example = "127.0.0.1";
251 type = lib.types.str;
254 If specified, it defines the interface to listen on. If not
255 specified, the service will listen on all interfaces (any).
258 httpPort = lib.mkOption {
260 type = lib.types.port;
262 Specifies the listen port for the HTTP service that returns the
266 syncMode = lib.mkOption {
268 type = lib.types.enum [ "ASYNC" "SYNC_WRITE_METADATA" "SYNC_WRITE" "FDATASYNC" "FSYNC" ];
269 example = "FDATASYNC";
271 The sync mode influences how operations are committed to the disk
272 log before the operation is acknowledged to the caller.
274 -ASYNC mode the writes to the disk log are buffered in memory by the operating system. This is the fastest mode but will lead to data loss in case of a crash, kernel panic or power failure.
275 -SYNC_WRITE_METADATA opens the file with O_SYNC, the system will not buffer any writes. The operation will be acknowledged when data has been safely written to disk. This mode is slow but offers maximum data safety. However, BabuDB cannot influence the disk drive caches, this depends on the OS and hard disk model.
276 -SYNC_WRITE similar to SYNC_WRITE_METADATA but opens file with O_DSYNC which means that only the data is commit to disk. This can lead to some data loss depending on the implementation of the underlying file system. Linux does not implement this mode.
277 -FDATASYNC is similar to SYNC_WRITE but opens the file in asynchronous mode and calls fdatasync() after writing the data to disk.
278 -FSYNC is similar to SYNC_WRITE_METADATA but opens the file in asynchronous mode and calls fsync() after writing the data to disk.
280 For best throughput use ASYNC, for maximum data safety use FSYNC.
282 (If xtreemfs.mrc.replication.enable is true then FDATASYNC is forced)
285 extraConfig = lib.mkOption {
286 type = lib.types.lines;
288 osd_check_interval = 300
290 local_clock_renewal = 0
291 remote_time_sync = 30000
292 authentication_provider = org.xtreemfs.common.auth.NullAuthProvider
294 # shared secret between the MRC and all OSDs
295 capability_secret = iNG8UuQJrJ6XVDTe
297 dir_service.host = 192.168.0.10
298 dir_service.port = 32638
300 # if replication is enabled
301 dir_service.1.host = 192.168.0.11
302 dir_service.1.port = 32638
303 dir_service.2.host = 192.168.0.12
304 dir_service.2.port = 32638
306 # specify whether SSL is required
308 ssl.protocol = tlsv12
309 ssl.service_creds.pw = passphrase
310 ssl.service_creds.container = pkcs12
311 ssl.service_creds = /etc/xos/xtreemfs/truststore/certs/mrc.p12
312 ssl.trusted_certs = /etc/xos/xtreemfs/truststore/certs/trusted.jks
313 ssl.trusted_certs.pw = jks_passphrase
314 ssl.trusted_certs.container = jks
317 Configuration of XtreemFS MRC service.
318 WARNING: configuration is saved as plaintext inside nix store.
319 For more options: https://www.xtreemfs.org/xtfs-guide-1.5.1/index.html
323 enable = lib.mkEnableOption "XtreemFS MRC replication plugin";
324 extraConfig = lib.mkOption {
325 type = lib.types.lines;
327 # participants of the replication including this replica
328 babudb.repl.participant.0 = 192.168.0.10
329 babudb.repl.participant.0.port = 35678
330 babudb.repl.participant.1 = 192.168.0.11
331 babudb.repl.participant.1.port = 35678
332 babudb.repl.participant.2 = 192.168.0.12
333 babudb.repl.participant.2.port = 35678
335 # number of servers that at least have to be up to date
336 # To have a fault-tolerant system, this value has to be set to the
337 # majority of nodes i.e., if you have three replicas, set this to 2
338 # Please note that a setup with two nodes provides no fault-tolerance.
339 babudb.repl.sync.n = 2
341 # specify whether SSL is required
342 babudb.ssl.enabled = true
344 babudb.ssl.protocol = tlsv12
346 # server credentials for SSL handshakes
347 babudb.ssl.service_creds = /etc/xos/xtreemfs/truststore/certs/osd.p12
348 babudb.ssl.service_creds.pw = passphrase
349 babudb.ssl.service_creds.container = pkcs12
351 # trusted certificates for SSL handshakes
352 babudb.ssl.trusted_certs = /etc/xos/xtreemfs/truststore/certs/trusted.jks
353 babudb.ssl.trusted_certs.pw = jks_passphrase
354 babudb.ssl.trusted_certs.container = jks
356 babudb.ssl.authenticationWithoutEncryption = false
359 Configuration of XtreemFS MRC replication plugin.
360 WARNING: configuration is saved as plaintext inside nix store.
361 For more options: https://www.xtreemfs.org/xtfs-guide-1.5.1/index.html
368 enable = lib.mkOption {
369 type = lib.types.bool;
372 Whether to enable XtreemFS OSD service.
376 uuid = lib.mkOption {
377 example = "eacb6bab-f444-4ebf-a06a-3f72d7465e42";
378 type = lib.types.str;
380 Must be set to a unique identifier, preferably a UUID according to
381 RFC 4122. UUIDs can be generated with `uuidgen` command, found in
382 the `util-linux` package.
385 port = lib.mkOption {
387 type = lib.types.port;
389 The port to listen on for incoming connections (TCP and UDP).
392 address = lib.mkOption {
393 example = "127.0.0.1";
394 type = lib.types.str;
397 If specified, it defines the interface to listen on. If not
398 specified, the service will listen on all interfaces (any).
401 httpPort = lib.mkOption {
403 type = lib.types.port;
405 Specifies the listen port for the HTTP service that returns the
409 extraConfig = lib.mkOption {
410 type = lib.types.lines;
412 local_clock_renewal = 0
413 remote_time_sync = 30000
414 report_free_space = true
415 capability_secret = iNG8UuQJrJ6XVDTe
417 dir_service.host = 192.168.0.10
418 dir_service.port = 32638
420 # if replication is used
421 dir_service.1.host = 192.168.0.11
422 dir_service.1.port = 32638
423 dir_service.2.host = 192.168.0.12
424 dir_service.2.port = 32638
426 # specify whether SSL is required
428 ssl.service_creds.pw = passphrase
429 ssl.service_creds.container = pkcs12
430 ssl.service_creds = /etc/xos/xtreemfs/truststore/certs/osd.p12
431 ssl.trusted_certs = /etc/xos/xtreemfs/truststore/certs/trusted.jks
432 ssl.trusted_certs.pw = jks_passphrase
433 ssl.trusted_certs.container = jks
436 Configuration of XtreemFS OSD service.
437 WARNING: configuration is saved as plaintext inside nix store.
438 For more options: https://www.xtreemfs.org/xtfs-guide-1.5.1/index.html
447 ###### implementation
449 config = lib.mkIf cfg.enable {
451 environment.systemPackages = [ xtreemfs ];
453 users.users.xtreemfs =
454 { uid = config.ids.uids.xtreemfs;
455 description = "XtreemFS user";
460 users.groups.xtreemfs =
461 { gid = config.ids.gids.xtreemfs;
464 systemd.services.xtreemfs-dir = lib.mkIf cfg.dir.enable {
465 description = "XtreemFS-DIR Server";
466 after = [ "network.target" ];
467 wantedBy = [ "multi-user.target" ];
470 ExecStart = "${startupScript "org.xtreemfs.dir.DIR" dirConfig}";
474 systemd.services.xtreemfs-mrc = lib.mkIf cfg.mrc.enable ({
475 description = "XtreemFS-MRC Server";
478 ExecStart = "${startupScript "org.xtreemfs.mrc.MRC" mrcConfig}";
480 } // systemdOptionalDependencies);
482 systemd.services.xtreemfs-osd = lib.mkIf cfg.osd.enable ({
483 description = "XtreemFS-OSD Server";
486 ExecStart = "${startupScript "org.xtreemfs.osd.OSD" osdConfig}";
488 } // systemdOptionalDependencies);