2021-11-15 10:02:05 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.selfprivacy-api;
|
|
|
|
directionArg =
|
|
|
|
if cfg.direction == ""
|
|
|
|
then ""
|
|
|
|
else "--direction=${cfg.direction}";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.selfprivacy-api = {
|
|
|
|
enable = mkOption {
|
2022-07-19 12:18:46 +00:00
|
|
|
default = true;
|
2021-11-15 10:02:05 +00:00
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Enable SelfPrivacy API service
|
|
|
|
'';
|
|
|
|
};
|
2021-11-16 14:08:58 +00:00
|
|
|
enableSwagger = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Enable Swagger UI
|
|
|
|
'';
|
|
|
|
};
|
2021-12-02 15:16:16 +00:00
|
|
|
b2Bucket = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = ''
|
|
|
|
B2 bucket
|
|
|
|
'';
|
|
|
|
};
|
2021-11-15 10:02:05 +00:00
|
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
|
|
|
|
systemd.services.selfprivacy-api = {
|
|
|
|
description = "API Server used to control system from the mobile application";
|
|
|
|
environment = config.nix.envVars // {
|
|
|
|
inherit (config.environment.sessionVariables) NIX_PATH;
|
|
|
|
HOME = "/root";
|
|
|
|
PYTHONUNBUFFERED = "1";
|
2021-11-16 14:08:58 +00:00
|
|
|
ENABLE_SWAGGER = (if cfg.enableSwagger then "1" else "0");
|
2021-12-02 15:16:16 +00:00
|
|
|
B2_BUCKET = cfg.b2Bucket;
|
2021-11-15 10:02:05 +00:00
|
|
|
} // config.networking.proxy.envVars;
|
2022-07-27 13:14:38 +00:00
|
|
|
path = [
|
|
|
|
"/var/"
|
|
|
|
"/var/dkim/"
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.gnutar
|
|
|
|
pkgs.xz.bin
|
|
|
|
pkgs.gzip
|
|
|
|
pkgs.gitMinimal
|
|
|
|
config.nix.package.out
|
|
|
|
pkgs.nixos-rebuild
|
|
|
|
pkgs.restic
|
|
|
|
pkgs.mkpasswd
|
|
|
|
pkgs.util-linux
|
|
|
|
pkgs.e2fsprogs
|
2022-08-26 10:21:05 +00:00
|
|
|
pkgs.iproute2
|
2022-07-27 13:14:38 +00:00
|
|
|
];
|
2021-11-15 10:02:05 +00:00
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wantedBy = [ "network-online.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
2022-08-26 10:21:05 +00:00
|
|
|
ExecStart = "${pkgs.selfprivacy-graphql-api}/bin/app.py";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "5";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.selfprivacy-api-worker = {
|
|
|
|
description = "Task worker for SelfPrivacy API";
|
|
|
|
environment = config.nix.envVars // {
|
|
|
|
inherit (config.environment.sessionVariables) NIX_PATH;
|
|
|
|
HOME = "/root";
|
|
|
|
PYTHONUNBUFFERED = "1";
|
|
|
|
ENABLE_SWAGGER = (if cfg.enableSwagger then "1" else "0");
|
|
|
|
B2_BUCKET = cfg.b2Bucket;
|
2023-03-17 12:09:13 +00:00
|
|
|
PYTHONPATH = pkgs.selfprivacy-graphql-api.pythonPath + ":${pkgs.selfprivacy-graphql-api}/lib/python3.10/site-packages/";
|
2022-08-26 10:21:05 +00:00
|
|
|
} // config.networking.proxy.envVars;
|
|
|
|
path = [
|
|
|
|
"/var/"
|
|
|
|
"/var/dkim/"
|
|
|
|
pkgs.coreutils
|
|
|
|
pkgs.gnutar
|
|
|
|
pkgs.xz.bin
|
|
|
|
pkgs.gzip
|
|
|
|
pkgs.gitMinimal
|
|
|
|
config.nix.package.out
|
|
|
|
pkgs.nixos-rebuild
|
|
|
|
pkgs.restic
|
|
|
|
pkgs.mkpasswd
|
|
|
|
pkgs.util-linux
|
|
|
|
pkgs.e2fsprogs
|
|
|
|
pkgs.iproute2
|
|
|
|
];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
wantedBy = [ "network-online.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
2023-03-17 11:54:14 +00:00
|
|
|
ExecStart = "${pkgs.python310Packages.huey}/bin/huey_consumer.py selfprivacy_api.task_registry.huey";
|
2021-11-15 10:02:05 +00:00
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "5";
|
|
|
|
};
|
|
|
|
};
|
2021-11-17 10:34:55 +00:00
|
|
|
# One shot systemd service to rebuild NixOS using nixos-rebuild
|
|
|
|
systemd.services.sp-nixos-rebuild = {
|
|
|
|
description = "Upgrade NixOS using nixos-rebuild";
|
|
|
|
environment = config.nix.envVars // {
|
|
|
|
inherit (config.environment.sessionVariables) NIX_PATH;
|
|
|
|
HOME = "/root";
|
|
|
|
} // config.networking.proxy.envVars;
|
|
|
|
path = [ pkgs.coreutils pkgs.gnutar pkgs.xz.bin pkgs.gzip pkgs.gitMinimal config.nix.package.out pkgs.nixos-rebuild ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
|
|
|
ExecStart = "${pkgs.nixos-rebuild}/bin/nixos-rebuild switch";
|
2022-04-29 12:19:38 +00:00
|
|
|
KillMode = "none";
|
2022-04-29 12:48:08 +00:00
|
|
|
SendSIGKILL = "no";
|
2021-11-17 10:34:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
# One shot systemd service to upgrade NixOS using nixos-rebuild
|
|
|
|
systemd.services.sp-nixos-upgrade = {
|
|
|
|
description = "Upgrade NixOS using nixos-rebuild";
|
|
|
|
environment = config.nix.envVars // {
|
|
|
|
inherit (config.environment.sessionVariables) NIX_PATH;
|
|
|
|
HOME = "/root";
|
|
|
|
} // config.networking.proxy.envVars;
|
|
|
|
path = [ pkgs.coreutils pkgs.gnutar pkgs.xz.bin pkgs.gzip pkgs.gitMinimal config.nix.package.out pkgs.nixos-rebuild ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
|
|
|
ExecStart = "${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --upgrade";
|
2022-04-29 12:19:38 +00:00
|
|
|
KillMode = "none";
|
2022-04-29 12:48:08 +00:00
|
|
|
SendSIGKILL = "no";
|
2021-11-17 10:34:55 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
# One shot systemd service to rollback NixOS using nixos-rebuild
|
|
|
|
systemd.services.sp-nixos-rollback = {
|
|
|
|
description = "Rollback NixOS using nixos-rebuild";
|
|
|
|
environment = config.nix.envVars // {
|
|
|
|
inherit (config.environment.sessionVariables) NIX_PATH;
|
|
|
|
HOME = "/root";
|
|
|
|
} // config.networking.proxy.envVars;
|
|
|
|
path = [ pkgs.coreutils pkgs.gnutar pkgs.xz.bin pkgs.gzip pkgs.gitMinimal config.nix.package.out pkgs.nixos-rebuild ];
|
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
|
|
|
ExecStart = "${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --rollback";
|
2022-04-29 12:19:38 +00:00
|
|
|
KillMode = "none";
|
2022-04-29 12:48:08 +00:00
|
|
|
SendSIGKILL = "no";
|
2021-11-17 10:34:55 +00:00
|
|
|
};
|
|
|
|
};
|
2021-11-15 10:02:05 +00:00
|
|
|
};
|
|
|
|
}
|