feat(octoprint): init on logistics

This commit is contained in:
arcnmx 2024-07-13 11:01:52 -07:00
parent aeb63b345b
commit 5508982563
8 changed files with 162 additions and 2 deletions

View file

@ -0,0 +1,36 @@
{
lib,
gensokyo-zone,
...
}: let
inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
inherit (lib.modules) mkIf;
in {
config.exports.services.octoprint = {config, ...}: {
displayName = mkAlmostOptionDefault "OctoPrint";
id = mkAlmostOptionDefault "print";
nixos = {
serviceAttr = "octoprint";
assertions = let
mkAssertion = f: nixosConfig: let
cfg = nixosConfig.services.octoprint;
in
f nixosConfig cfg;
in
mkIf config.enable [
(mkAssertion (nixosConfig: cfg: {
assertion = config.ports.default.port == cfg.port;
message = "port mismatch";
}))
];
};
defaults.port.listen = mkAlmostOptionDefault "lan";
ports = {
default = {
port = mkAlmostOptionDefault 5000;
protocol = "http";
status.enable = mkAlmostOptionDefault true;
};
};
};
}

View file

@ -3,9 +3,8 @@
gensokyo-zone, gensokyo-zone,
... ...
}: let }: let
inherit (gensokyo-zone.lib) mapAlmostOptionDefaults mkAlmostOptionDefault; inherit (gensokyo-zone.lib) mkAlmostOptionDefault;
inherit (lib.modules) mkIf; inherit (lib.modules) mkIf;
inherit (lib.attrsets) mapAttrs;
in { in {
config.exports.services.openwebrx = {config, ...}: { config.exports.services.openwebrx = {config, ...}: {
displayName = mkAlmostOptionDefault "OpenWebRX"; displayName = mkAlmostOptionDefault "OpenWebRX";

View file

@ -0,0 +1,58 @@
{
config,
lib,
...
}: let
inherit (lib.modules) mkIf mkDefault;
inherit (config.services) octoprint;
name.shortServer = mkDefault "print";
upstreamName = "octoprint'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);
accessService = {
name = "octoprint";
# XXX: logistics doesn't listen on v6
getAddressFor = "getAddress4For";
};
};
};
virtualHosts = let
copyFromVhost = mkDefault "octoprint";
locations = {
"/" = {
proxy.enable = true;
};
"/sockjs/" = {
proxy = {
enable = true;
websocket.enable = true;
};
};
};
in {
octoprint = {
inherit name locations;
proxy.upstream = mkDefault upstreamName;
vouch.enable = mkDefault true;
};
octoprint'local = {
inherit name locations;
ssl.cert = {
inherit copyFromVhost;
};
proxy = {
inherit copyFromVhost;
};
local.enable = mkDefault true;
};
};
};
}

53
nixos/octoprint.nix Normal file
View file

@ -0,0 +1,53 @@
{
config,
access,
lib,
...
}: let
inherit (lib.modules) mkIf mkMerge mkDefault;
inherit (config.services) motion;
cfg = config.services.octoprint;
behindVouch = false;
in {
services.octoprint = {
enable = mkDefault true;
# host = mkIf config.networking.enableIPv6 "::";
extraConfig = mkMerge [
# https://docs.octoprint.org/en/master/configuration/config_yaml.html
{
# TODO: api.key = sops?
server = {
# TODO: secretKey = sops?
reverseProxy = {
schemeHeader = "X-Forwarded-Proto";
trustedDownstream = access.cidrForNetwork.allLan.all;
};
};
webcam = mkIf motion.enable {
# TODO
};
plugins = {
_disabled = [
"softwareupdate"
];
};
}
(mkIf (!behindVouch) {
autologinLocal = true;
autologinAs = "guest";
localNetworks = access.cidrForNetwork.allLocal.all;
})
(mkIf behindVouch {
trustRemoteUser = true;
addRemoteUsers = true;
remoteUserHeader = "X-Vouch-User";
})
];
};
networking.firewall = mkIf cfg.enable {
interfaces.lan.allowedTCPPorts = [
cfg.port
];
};
}

View file

@ -42,6 +42,7 @@ in {
nixos.access.grafana nixos.access.grafana
nixos.access.loki nixos.access.loki
nixos.access.kitchencam nixos.access.kitchencam
nixos.access.octoprint
nixos.access.openwebrx nixos.access.openwebrx
nixos.access.deluge nixos.access.deluge
nixos.access.home-assistant nixos.access.home-assistant
@ -266,6 +267,14 @@ in {
virtualHosts.kitchencam'local.allServerNames virtualHosts.kitchencam'local.allServerNames
]; ];
}; };
print = {
inherit (nginx) group;
domain = virtualHosts.octoprint.serverName;
extraDomainNames = mkMerge [
virtualHosts.octoprint.otherServerNames
virtualHosts.octoprint'local.allServerNames
];
};
webrx = { webrx = {
inherit (nginx) group; inherit (nginx) group;
domain = virtualHosts.openwebrx.serverName; domain = virtualHosts.openwebrx.serverName;
@ -396,6 +405,7 @@ in {
}; };
}; };
kitchencam.ssl.cert.enable = true; kitchencam.ssl.cert.enable = true;
octoprint.ssl.cert.enable = true;
openwebrx.ssl.cert.enable = true; openwebrx.ssl.cert.enable = true;
deluge.ssl.cert.enable = true; deluge.ssl.cert.enable = true;
invidious = { invidious = {

View file

@ -11,6 +11,7 @@ _: {
enable = true; enable = true;
ports.stream.port = 41081; ports.stream.port = 41081;
}; };
octoprint.enable = true;
}; };
}; };
network.networks = { network.networks = {

View file

@ -14,6 +14,7 @@ in {
nixos.base nixos.base
nixos.barcodebuddy-scanner nixos.barcodebuddy-scanner
nixos.kitchencam nixos.kitchencam
nixos.octoprint
./hardware-configuration.nix ./hardware-configuration.nix
]; ];

View file

@ -28,6 +28,7 @@ module "hakurei_system_records" {
"smb", "smb",
"mqtt", "mqtt",
"kitchen", "kitchen",
"print",
"webrx", "webrx",
"deluge", "deluge",
"home", "home",
@ -46,6 +47,7 @@ module "hakurei_system_records" {
"smb", "smb",
"mqtt", "mqtt",
"kitchen", "kitchen",
"print",
"webrx", "webrx",
"syncplay", "syncplay",
"yt", "yt",