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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
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";
|
|
|
|
} // 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
|
2023-07-20 16:52:24 +00:00
|
|
|
pkgs.rclone
|
2022-07-27 13:14:38 +00:00
|
|
|
pkgs.restic
|
|
|
|
pkgs.mkpasswd
|
|
|
|
pkgs.util-linux
|
|
|
|
pkgs.e2fsprogs
|
2022-08-26 10:21:05 +00:00
|
|
|
pkgs.iproute2
|
2023-07-20 16:52:24 +00:00
|
|
|
pkgs.fuse-overlayfs
|
|
|
|
pkgs.fuse
|
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";
|
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
|
2023-07-20 16:52:24 +00:00
|
|
|
pkgs.rclone
|
2022-08-26 10:21:05 +00:00
|
|
|
pkgs.restic
|
|
|
|
pkgs.mkpasswd
|
|
|
|
pkgs.util-linux
|
|
|
|
pkgs.e2fsprogs
|
|
|
|
pkgs.iproute2
|
2023-07-20 16:52:24 +00:00
|
|
|
pkgs.fuse-overlayfs
|
|
|
|
pkgs.fuse
|
2022-08-26 10:21:05 +00:00
|
|
|
];
|
|
|
|
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
|
|
|
};
|
|
|
|
}
|