selfprivacy-nixos-config/api/api-module.nix

103 lines
3.5 KiB
Nix
Raw Normal View History

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-14 17:42:42 +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;
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 ];
after = [ "network-online.target" ];
wantedBy = [ "network-online.target" ];
serviceConfig = {
User = "root";
2021-11-17 13:35:00 +00:00
ExecStart = "${pkgs.selfprivacy-api}/bin/app.py";
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";
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";
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";
SendSIGKILL = "no";
2021-11-17 10:34:55 +00:00
};
};
2021-11-15 10:02:05 +00:00
};
}