Something went wrong. Try again.
lol
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247{ lib, pkgs, config, ...}:
let inherit (lib) getExe maintainers mapAttrs' mkEnableOption mkIf mkOption mkPackageOption nameValuePair optionalAttrs types ;
cfg = config.services.tinyauth;
format = pkgs.formats.keyValue { }; settingsFile = format.generate "tinyauth-env-vars" ( mapAttrs' (name: value: nameValuePair "TINYAUTH_${name}" value) cfg.settings );in{ options.services.tinyauth = { enable = mkEnableOption "Tinyauth server";
package = mkPackageOption pkgs "tinyauth" { };
environmentFile = mkOption { type = types.path; description = '' Path to an environment file loaded for Tinyauth.
This can be used to securely store tokens and secrets outside of the world-readable Nix store.
Example contents of the file: ``` TINYAUTH_AUTH_USERS=user-hash TINYAUTH_OAUTH_PROVIDERS_GOOGLE_CLIENTSECRET=client-secret ``` ''; default = "/dev/null"; example = "/var/lib/secrets/tinyauth"; };
settings = mkOption { type = types.submodule { freeformType = format.type;
options = { SERVER_ADDRESS = mkOption { type = types.str; description = '' Address to bind the server to. ''; default = "0.0.0.0"; };
SERVER_PORT = mkOption { type = types.port; description = '' The port to run the server on. ''; default = 3000; };
APPURL = mkOption { type = types.str; description = '' URL of the app. ''; example = "https://auth.example.com"; };
ANALYTICS_ENABLED = mkOption { type = types.bool; description = '' Whether to enable anonymous version collection. ''; default = false; };
RESOURCES_ENABLED = mkOption { type = types.bool; description = '' Whether to enable the resources server. ''; default = true; };
AUTH_LOGINMAXRETRIES = mkOption { type = types.ints.unsigned; description = '' Maximum login attempts before timeout (0 to disable). ''; default = 3; };
AUTH_LOGINTIMEOUT = mkOption { type = types.ints.unsigned; description = '' Login timeout in seconds after max retries reached (0 to disable). ''; default = 300; };
AUTH_TRUSTEDPROXIES = mkOption { type = types.str; description = '' Comma-separated list of trusted proxy addresses. ''; default = ""; }; }; };
default = { };
description = '' Environment variables that will be passed to Tinyauth. The "TINYAUTH_" prefix will be prepended to the setting names. See [configuration options](https://tinyauth.app/docs/reference/configuration) for supported values. ''; };
dataDir = mkOption { type = types.path; default = "/var/lib/tinyauth"; description = '' The directory where Tinyauth will store its data. ''; };
user = mkOption { type = types.str; default = "tinyauth"; description = "User account under which Tinyauth runs."; };
group = mkOption { type = types.str; default = "tinyauth"; description = "Group account under which Tinyauth runs."; }; };
config = mkIf cfg.enable { systemd.tmpfiles.settings.tinyauth = { "${cfg.dataDir}".d = { mode = "0750"; user = cfg.user; group = cfg.group; }; };
systemd.services.tinyauth = { description = "Tinyauth"; after = [ "network.target" ]; wantedBy = [ "multi-user.target" ]; restartTriggers = [ cfg.package cfg.environmentFile settingsFile ];
environment = { GIN_MODE = "release"; TINYAUTH_DATABASE_PATH = "${cfg.dataDir}/tinyauth.db"; TINYAUTH_RESOURCES_PATH = "${cfg.dataDir}/resources"; };
serviceConfig = { Type = "simple"; User = cfg.user; Group = cfg.group; WorkingDirectory = cfg.dataDir; ExecStart = getExe cfg.package; Restart = "always";
EnvironmentFile = [ cfg.environmentFile settingsFile ];
# Hardening AmbientCapabilities = ""; CapabilityBoundingSet = ""; LockPersonality = true; MemoryDenyWriteExecute = true; NoNewPrivileges = true; PrivateDevices = true; PrivateTmp = "disconnected"; PrivateUsers = true; ProcSubset = "pid"; ProtectClock = true; ProtectControlGroups = true; ProtectHome = true; ProtectHostname = true; ProtectKernelLogs = true; ProtectKernelModules = true; ProtectKernelTunables = true; ProtectProc = "invisible"; ProtectSystem = "strict"; ReadWritePaths = [ cfg.dataDir ]; RemoveIPC = true; RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ]; RestrictNamespaces = true; RestrictRealtime = true; RestrictSUIDSGID = true; SystemCallArchitectures = "native"; SystemCallFilter = [ "@system-service" "~@privileged" "~@resources" ]; UMask = "0077"; }; };
users.users = optionalAttrs (cfg.user == "tinyauth") { tinyauth = { isSystemUser = true; group = cfg.group; description = "Tinyauth user"; home = cfg.dataDir; }; };
users.groups = optionalAttrs (cfg.group == "tinyauth") { tinyauth = { }; }; };
meta.maintainers = with maintainers; [ shaunren ];}