packages.default is the app with its gems (bundlerEnv from Gemfile.lock and gemset.nix, generated by bundix): bin/asxpio is Puma serving config.ru, bin/asxpio-monitor the reachability worker. Photos are resized with ImageMagick 7's magick. nixosModules.default (services.asxpio) runs both as hardened systemd services with a dynamic user, the web one with readiness from Puma (Type=notify); settings and secrets come from one environment file. CI checks that gemset.nix matches Gemfile.lock (bin/check-gemset) and builds the package. Checked locally: migrations on an empty database, /healthz and /, an invoice PDF with the Noto fonts, a photo resized to WebP and cropped. The container deploy stays until the NixOS service has taken over. Assisted-by: Claude:opus-5-5
94 lines
2.7 KiB
Nix
94 lines
2.7 KiB
Nix
# services.asxpio: the site, invoices and admin (Puma on a port, for a
|
|
# proxy, Traefik on asxpio-ops, to route asxp.io and admin.asxp.io to), and
|
|
# the reachability worker for datacenterbingo's status page.
|
|
self:
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.asxpio;
|
|
inherit (lib) mkOption types;
|
|
hardening = {
|
|
DynamicUser = true;
|
|
Restart = "always";
|
|
RestartSec = 5;
|
|
# The database may be down for a while; keep trying
|
|
ProtectSystem = "strict";
|
|
ProtectHome = true;
|
|
PrivateTmp = true;
|
|
PrivateDevices = true;
|
|
NoNewPrivileges = true;
|
|
CapabilityBoundingSet = "";
|
|
RestrictAddressFamilies = [
|
|
"AF_INET"
|
|
"AF_INET6"
|
|
"AF_UNIX"
|
|
];
|
|
SystemCallFilter = [ "@system-service" ];
|
|
LockPersonality = true;
|
|
EnvironmentFile = cfg.environmentFile;
|
|
};
|
|
in
|
|
{
|
|
options.services.asxpio = {
|
|
enable = lib.mkEnableOption "asxp.io";
|
|
package = mkOption {
|
|
type = types.package;
|
|
default = self.packages.${pkgs.stdenv.hostPlatform.system}.default;
|
|
defaultText = lib.literalExpression "the asxpio flake's package";
|
|
};
|
|
port = mkOption {
|
|
type = types.port;
|
|
default = 3001;
|
|
};
|
|
threads = mkOption {
|
|
type = types.str;
|
|
default = "4:16";
|
|
description = "Puma's -t min:max.";
|
|
};
|
|
environmentFile = mkOption {
|
|
type = types.str;
|
|
description = "The app's settings and secrets (see .env.example).";
|
|
};
|
|
monitor.enable = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
description = "The reachability worker (bin/monitor). Run one only: two record every sample twice.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
systemd.services.asxpio = {
|
|
description = "asxp.io";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [ "network-online.target" ];
|
|
wants = [ "network-online.target" ];
|
|
startLimitIntervalSec = 0;
|
|
# Puma tells systemd when it listens; migrations run before that
|
|
serviceConfig = hardening // {
|
|
Type = "notify";
|
|
ExecStart = "${lib.getExe cfg.package} -b tcp://0.0.0.0:${toString cfg.port} -t ${cfg.threads}";
|
|
TimeoutStartSec = 120;
|
|
MemoryMax = "512M";
|
|
};
|
|
};
|
|
systemd.services.asxpio-monitor = lib.mkIf cfg.monitor.enable {
|
|
description = "asxpio reachability worker";
|
|
wantedBy = [ "multi-user.target" ];
|
|
after = [
|
|
"network-online.target"
|
|
"asxpio.service"
|
|
];
|
|
wants = [ "network-online.target" ];
|
|
startLimitIntervalSec = 0;
|
|
environment.MONITOR_HEARTBEAT = "/tmp/monitor.heartbeat";
|
|
serviceConfig = hardening // {
|
|
ExecStart = "${cfg.package}/bin/asxpio-monitor";
|
|
MemoryMax = "256M";
|
|
};
|
|
};
|
|
};
|
|
}
|