2023-11-16 02:10:40 +00:00
|
|
|
selfprivacy-graphql-api: { config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.selfprivacy-api;
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options.services.selfprivacy-api = {
|
2023-12-12 10:13:32 +00:00
|
|
|
enable = lib.mkOption {
|
2023-11-16 02:10:40 +00:00
|
|
|
default = true;
|
2023-12-12 10:13:32 +00:00
|
|
|
type = lib.types.bool;
|
2023-11-16 02:10:40 +00:00
|
|
|
description = ''
|
|
|
|
Enable SelfPrivacy API service
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
2023-12-16 05:36:31 +00:00
|
|
|
users.users."selfprivacy-api" = {
|
|
|
|
isNormalUser = false;
|
|
|
|
isSystemUser = true;
|
|
|
|
extraGroups = [ "opendkim" ];
|
|
|
|
group = "selfprivacy-api";
|
|
|
|
};
|
|
|
|
users.groups."selfprivacy-api".members = [ "selfprivacy-api" ];
|
2023-11-16 02:10:40 +00:00
|
|
|
|
|
|
|
systemd.services.selfprivacy-api = {
|
|
|
|
description = "API Server used to control system from the mobile application";
|
|
|
|
environment = config.nix.envVars // {
|
|
|
|
HOME = "/root";
|
|
|
|
PYTHONUNBUFFERED = "1";
|
|
|
|
} // 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";
|
|
|
|
ExecStart = "${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 // {
|
|
|
|
HOME = "/root";
|
|
|
|
PYTHONUNBUFFERED = "1";
|
2023-11-22 22:47:02 +00:00
|
|
|
PYTHONPATH =
|
|
|
|
pkgs.python310Packages.makePythonPath [ selfprivacy-graphql-api ];
|
2023-11-16 02:10:40 +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";
|
|
|
|
ExecStart = "${pkgs.python310Packages.huey}/bin/huey_consumer.py selfprivacy_api.task_registry.huey";
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "5";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
# One shot systemd service to rebuild NixOS using nixos-rebuild
|
|
|
|
systemd.services.sp-nixos-rebuild = {
|
2023-11-18 02:37:14 +00:00
|
|
|
description = "nixos-rebuild switch";
|
2023-11-16 02:10:40 +00:00
|
|
|
environment = config.nix.envVars // {
|
|
|
|
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 ];
|
2023-12-12 10:13:32 +00:00
|
|
|
# TODO set proper timeout for reboot instead of service restart
|
2023-11-16 02:10:40 +00:00
|
|
|
serviceConfig = {
|
|
|
|
User = "root";
|
|
|
|
KillMode = "none";
|
|
|
|
SendSIGKILL = "no";
|
|
|
|
};
|
2023-11-23 07:36:02 +00:00
|
|
|
script = ''
|
2023-12-12 10:13:32 +00:00
|
|
|
# relock sp-modules to absolute path (in terms of Nix) due to Nix bugs:
|
|
|
|
# https://github.com/NixOS/nix/issues/9339
|
|
|
|
${config.nix.package}/bin/nix flake lock /etc/nixos --override-input sp-modules /etc/nixos/sp-modules
|
|
|
|
|
2023-11-23 07:36:02 +00:00
|
|
|
${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --flake /etc/nixos#sp-nixos
|
|
|
|
'';
|
2023-11-16 02:10:40 +00:00
|
|
|
};
|
|
|
|
# One shot systemd service to upgrade NixOS using nixos-rebuild
|
|
|
|
systemd.services.sp-nixos-upgrade = {
|
2023-12-18 19:38:29 +00:00
|
|
|
# protection against simultaneous runs
|
|
|
|
after = [ "sp-nixos-rebuild.service" ];
|
2023-12-12 10:13:32 +00:00
|
|
|
description = "Upgrade NixOS and SP modules to latest versions";
|
2023-11-16 02:10:40 +00:00
|
|
|
environment = config.nix.envVars // {
|
|
|
|
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";
|
|
|
|
KillMode = "none";
|
|
|
|
SendSIGKILL = "no";
|
|
|
|
};
|
2023-11-18 02:37:14 +00:00
|
|
|
script = ''
|
2023-12-12 10:13:32 +00:00
|
|
|
# FIXME get URL from systemd parameter
|
2023-12-18 18:24:57 +00:00
|
|
|
${config.nix.package}/bin/nix flake update /etc/nixos/sp-modules/
|
2023-12-12 10:13:32 +00:00
|
|
|
${config.nix.package}/bin/nix flake update /etc/nixos --override-input selfprivacy-nixos-config git+https://git.selfprivacy.org/SelfPrivacy/selfprivacy-nixos-config.git?ref=flakes
|
2023-11-21 03:10:41 +00:00
|
|
|
${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --flake /etc/nixos#sp-nixos
|
2023-11-18 02:37:14 +00:00
|
|
|
'';
|
2023-11-16 02:10:40 +00:00
|
|
|
};
|
|
|
|
# One shot systemd service to rollback NixOS using nixos-rebuild
|
|
|
|
systemd.services.sp-nixos-rollback = {
|
2023-12-18 19:38:29 +00:00
|
|
|
# protection against simultaneous runs
|
|
|
|
after = [ "sp-nixos-rebuild.service" "sp-nixos-upgrade.service" ];
|
2023-11-16 02:10:40 +00:00
|
|
|
description = "Rollback NixOS using nixos-rebuild";
|
|
|
|
environment = config.nix.envVars // {
|
|
|
|
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";
|
2023-11-21 03:10:41 +00:00
|
|
|
ExecStart = "${pkgs.nixos-rebuild}/bin/nixos-rebuild switch --rollback --flake /etc/nixos#sp-nixos";
|
2023-11-16 02:10:40 +00:00
|
|
|
KillMode = "none";
|
|
|
|
SendSIGKILL = "no";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|