nixos-config/modules/services/seafile.nix

87 lines
2.2 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.custom.services.seafile;
in {
options.custom.services.seafile = {
enable = mkEnableOption "enable custom.services.seafile";
hostname = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; string;
2019-10-24 02:20:38 +02:00
description = ''
hostname of the seafile server
'';
};
port = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; int;
2019-10-24 02:20:38 +02:00
description = ''
port on where ther server runs on
'';
};
home = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; path;
2019-10-24 02:20:38 +02:00
description = ''
folder in where the seafile stuff gets stored
'';
};
serviceName = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; string;
2019-10-24 02:20:38 +02:00
default = "seafile-docker";
description = ''
name of the systemd service
'';
};
};
config = mkIf cfg.enable {
virtualisation.docker.enable = true;
systemd.services."${cfg.serviceName}" = {
enable = true;
description = "seafile service running as docker";
after = [ "network.target" "docker.service" ];
requires = [ "docker.service" ];
wantedBy = [ "multi-user.target" ];
2019-12-20 05:54:26 +01:00
script = # sh
''
# delete old instance to ensure update
${pkgs.docker}/bin/docker stop seafile || true && ${pkgs.docker}/bin/docker rm -f seafile || true
# start instance
${pkgs.docker}/bin/docker run \
--name seafile \
--env SEAFILE_SERVER_HOSTNAME=${cfg.hostname} \
--env SEAFILE_ADMIN_EMAIL="root@${cfg.hostname}" \
--env SEAFILE_ADMIN_PASSWORD="${
lib.fileContents <secrets/seafile/root>
}" \
--volume ${cfg.home}:/shared \
--publish ${toString cfg.port}:80 \
seafileltd/seafile:latest
'';
2019-10-24 02:20:38 +02:00
};
};
}
# ! todo
# requires = [ "${config.module.backup.services.encfs."seafile".serviceName}.service" ];
# krops.keys."seafile".path = toString <keys/seafile/encfs>;
#
# module.backup.services.encfs = {
# "seafile" = {
# enable = true;
# encryptedFolder = "/home/seafile.ct";
# decryptedFolder = "/home/seafile";
# keyFile = config.krops.keys."seafile".path;
# requires = [ ''${config.krops.keys."seafile".serviceName}.service'' ];
# };
# };