feat(fluidd): take over print

This commit is contained in:
Kat Inskip 2024-08-07 15:21:58 -07:00
parent 6c3727a246
commit 1c8a8f7a9e
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
6 changed files with 82 additions and 21 deletions

View file

@ -0,0 +1,40 @@
{
lib,
gensokyo-zone,
...
}: let
inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
inherit (lib.modules) mkIf;
in {
config.exports.services.fluidd = {config, ...}: {
displayName = mkAlmostOptionDefault "Fluidd";
id = mkAlmostOptionDefault "print";
nixos = {
serviceAttr = "fluidd";
assertions = let
mkAssertion = f: nixosConfig: let
cfg = nixosConfig.services.nginx;
in
f nixosConfig cfg;
in
mkIf config.enable [
(mkAssertion (nixosConfig: cfg: {
assertion = config.ports.default.port == 80;
message = "port mismatch";
}))
];
};
defaults.port.listen = mkAlmostOptionDefault "lan";
ports = {
default = {
port = mkAlmostOptionDefault 80;
protocol = "http";
status = {
enable = mkAlmostOptionDefault true;
gatus.client.network = mkAlmostOptionDefault "ip4";
};
prometheus.exporter.enable = mkAlmostOptionDefault true;
};
};
};
}

View file

@ -4,33 +4,27 @@
...
}: let
inherit (lib.modules) mkIf mkDefault;
inherit (config.services) octoprint;
inherit (config.services) nginx fluidd;
name.shortServer = mkDefault "print";
upstreamName = "octoprint'access";
upstreamName = "fluidd'access";
in {
config.services.nginx = {
upstreams'.${upstreamName}.servers = {
local = {
enable = mkDefault octoprint.enable;
addr = mkDefault "localhost";
port = mkIf octoprint.enable (mkDefault octoprint.port);
};
service = {upstream, ...}: {
enable = mkIf upstream.servers.local.enable (mkDefault false);
enable = true;
accessService = {
name = "octoprint";
name = "nginx";
system = "logistics";
port = "http";
# XXX: logistics doesn't listen on v6
getAddressFor = "getAddress4For";
};
};
};
virtualHosts = let
copyFromVhost = mkDefault "octoprint";
copyFromVhost = mkDefault "fluidd";
locations = {
"/" = {
proxy.enable = true;
};
"/sockjs/" = {
proxy = {
enable = true;
websocket.enable = true;
@ -38,12 +32,15 @@ in {
};
};
in {
octoprint = {
fluidd = {
inherit name locations;
proxy.upstream = mkDefault upstreamName;
proxy = {
upstream = mkDefault upstreamName;
host = nginx.virtualHosts.fluidd'local.serverName;
};
vouch.enable = mkDefault true;
};
octoprint'local = {
fluidd'local = {
inherit name locations;
ssl.cert = {
inherit copyFromVhost;

View file

@ -5,10 +5,13 @@ in {
services = {
fluidd = {
enable = true;
hostName = "print.local.gensokyo.zone";
nginx.locations."/webcam".proxyPass = let
inherit (motion.cameras) printercam;
inherit (printercam.settings) camera_id;
in "https://kitchen.local.${domain}/${toString camera_id}/stream";
};
};
networking.firewall.interfaces.lan.allowedTCPPorts = [80];
}

View file

@ -1,4 +1,7 @@
_: {
{ config, gensokyo-zone, ... }: let
inherit (config.services) motion;
inherit (gensokyo-zone.lib) domain;
in {
services = {
moonraker = {
enable = true;
@ -8,6 +11,23 @@ _: {
settings = {
octoprint_compat = { };
history = { };
"webcam printer" = {
location = "printer";
enabled = true;
service = "mjpegstreamer";
icon = "mdiPrinter3d";
target_fps = 5;
target_fps_idle = 1;
stream_url = let
inherit (motion.cameras) printercam;
inherit (printercam.settings) camera_id;
in "https://kitchen.local.${domain}/${toString camera_id}/stream";
snapshot_url = let
inherit (motion.cameras) printercam;
inherit (printercam.settings) camera_id;
in "https://kitchen.local.${domain}/${toString camera_id}/current";
aspect_ratio = "16:9";
};
authorization = {
force_logins = true;
cors_domains = [

View file

@ -269,10 +269,10 @@ in {
};
print = {
inherit (nginx) group;
domain = virtualHosts.octoprint.serverName;
domain = virtualHosts.fluidd.serverName;
extraDomainNames = mkMerge [
virtualHosts.octoprint.otherServerNames
virtualHosts.octoprint'local.allServerNames
virtualHosts.fluidd.otherServerNames
virtualHosts.fluidd'local.allServerNames
];
};
webrx = {
@ -405,7 +405,7 @@ in {
};
};
kitchencam.ssl.cert.enable = true;
octoprint.ssl.cert.enable = true;
fluidd.ssl.cert.enable = true;
openwebrx.ssl.cert.enable = true;
deluge.ssl.cert.enable = true;
invidious = {

View file

@ -14,6 +14,7 @@ _: {
octoprint.enable = true;
nginx.enable = true;
moonraker.enable = true;
fluidd.enable = true;
};
};
network.networks = {