mirror of
https://codeberg.org/demostf/cleanup.git
synced 2026-06-03 10:04:10 +02:00
nix setup
This commit is contained in:
parent
7640ec5a79
commit
28ba46ec1a
8 changed files with 301 additions and 1 deletions
126
nix/module.nix
Normal file
126
nix/module.nix
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; let
|
||||
cfg = config.services.demostf-cleanup;
|
||||
format = pkgs.formats.toml {};
|
||||
configFile = format.generate "demostf-cleanup.toml" {
|
||||
api = {
|
||||
url = cfg.source;
|
||||
key_file = "$CREDENTIALS_DIRECTORY/api_key";
|
||||
};
|
||||
storage = {
|
||||
root = cfg.storageRoot;
|
||||
};
|
||||
cleanup = {
|
||||
from_backend = cfg.backend;
|
||||
age = cfg.age;
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.services.demostf-cleanup = {
|
||||
enable = mkEnableOption "demostf-cleanup";
|
||||
|
||||
source = mkOption {
|
||||
type = types.str;
|
||||
default = "https://api.demos.tf";
|
||||
description = "Api endpoint to cleanup demos for";
|
||||
};
|
||||
|
||||
storageRoot = mkOption {
|
||||
type = types.str;
|
||||
description = "path local demo files are stored at";
|
||||
};
|
||||
|
||||
backend = mkOption {
|
||||
type = types.str;
|
||||
description = "name of the local demos backend";
|
||||
};
|
||||
|
||||
age = mkOption {
|
||||
type = types.int;
|
||||
default = 157784629; # 5 years
|
||||
description = "age of demos to cleanup";
|
||||
};
|
||||
|
||||
keyFile = mkOption {
|
||||
type = types.str;
|
||||
description = "path containing the edit secret";
|
||||
};
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
description = "user that owns the local demos";
|
||||
};
|
||||
|
||||
log = mkOption {
|
||||
type = types.str;
|
||||
default = "info";
|
||||
description = "log level";
|
||||
};
|
||||
|
||||
interval = mkOption {
|
||||
type = types.str;
|
||||
default = "*:0/10";
|
||||
description = "how often to run";
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = types.package;
|
||||
defaultText = literalExpression "pkgs.demostf-cleanup";
|
||||
description = "package to use";
|
||||
};
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
systemd.services."demostf-cleanup" = {
|
||||
environment = {
|
||||
RUST_LOG = cfg.log;
|
||||
};
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${getExe cfg.package} ${configFile}";
|
||||
ReadWritePaths = [cfg.storageRoot];
|
||||
LoadCredential = [
|
||||
"api_key:${cfg.keyFile}"
|
||||
];
|
||||
Restart = "on-failure";
|
||||
User = cfg.user;
|
||||
PrivateTmp = true;
|
||||
ProtectSystem = "strict";
|
||||
ProtectHome = true;
|
||||
NoNewPrivileges = true;
|
||||
PrivateDevices = true;
|
||||
ProtectClock = true;
|
||||
CapabilityBoundingSet = true;
|
||||
ProtectKernelLogs = true;
|
||||
ProtectControlGroups = true;
|
||||
SystemCallArchitectures = "native";
|
||||
ProtectKernelModules = true;
|
||||
RestrictNamespaces = true;
|
||||
MemoryDenyWriteExecute = true;
|
||||
ProtectHostname = true;
|
||||
LockPersonality = true;
|
||||
ProtectKernelTunables = true;
|
||||
RestrictAddressFamilies = ["AF_INET" "AF_INET6"];
|
||||
RestrictRealtime = true;
|
||||
ProtectProc = "noaccess";
|
||||
SystemCallFilter = ["@system-service" "~@resources" "~@privileged"];
|
||||
IPAddressDeny = ["localhost" "link-local" "multicast"];
|
||||
ProcSubset = "pid";
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers."demostf-cleanup" = {
|
||||
enable = true;
|
||||
description = "Cleanup demos for demos.tf";
|
||||
wantedBy = ["multi-user.target"];
|
||||
timerConfig = {
|
||||
OnCalendar = cfg.interval;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
3
nix/overlay.nix
Normal file
3
nix/overlay.nix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
final: prev: {
|
||||
demostf-cleanup = final.callPackage ./package.nix {};
|
||||
}
|
||||
31
nix/package.nix
Normal file
31
nix/package.nix
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
{
|
||||
rustPlatform,
|
||||
lib,
|
||||
openssl,
|
||||
pkg-config,
|
||||
}: let
|
||||
inherit (lib.sources) sourceByRegex;
|
||||
inherit (builtins) fromTOML readFile;
|
||||
src = sourceByRegex ../. ["Cargo.*" "(src)(/.*)?"];
|
||||
cargoPackage = (fromTOML (readFile ../Cargo.toml)).package;
|
||||
in
|
||||
rustPlatform.buildRustPackage {
|
||||
pname = cargoPackage.name;
|
||||
inherit (cargoPackage) version;
|
||||
|
||||
inherit src;
|
||||
|
||||
buildInputs = [
|
||||
openssl
|
||||
];
|
||||
|
||||
nativeBuildInputs = [
|
||||
pkg-config
|
||||
];
|
||||
|
||||
cargoLock = {
|
||||
lockFile = ../Cargo.lock;
|
||||
};
|
||||
|
||||
meta.mainProgram = "cleanup";
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue