summaryrefslogtreecommitdiff
path: root/hosts/gnuslashprinter/klipper.nix
diff options
context:
space:
mode:
authorTim Keller <tjk@tjkeller.xyz>2026-06-03 13:54:18 -0500
committerTim Keller <tjk@tjkeller.xyz>2026-06-03 13:54:18 -0500
commit8264c4659dbdb8d98310414badf288f8200fe242 (patch)
treed4e967cd63990a464e36b7754676a58379e0f871 /hosts/gnuslashprinter/klipper.nix
parenta6d9a9de1defe2c39c9514c0de76d37dcf8a0576 (diff)
downloadnixos-8264c4659dbdb8d98310414badf288f8200fe242.tar.xz
nixos-8264c4659dbdb8d98310414badf288f8200fe242.zip
aliases for printer and new power control relay. moonraker power control for printer enabled and accessible via mainsail. power control python script for power control via http in moonraker
Diffstat (limited to 'hosts/gnuslashprinter/klipper.nix')
-rw-r--r--hosts/gnuslashprinter/klipper.nix66
1 files changed, 47 insertions, 19 deletions
diff --git a/hosts/gnuslashprinter/klipper.nix b/hosts/gnuslashprinter/klipper.nix
index a19261c..331a0c7 100644
--- a/hosts/gnuslashprinter/klipper.nix
+++ b/hosts/gnuslashprinter/klipper.nix
@@ -6,7 +6,7 @@
mcu = {
enable = true;
# Serial port connected to the microcontroller
- serial = "/dev/serial/by-id/usb-1a86_USB_Serial-if00-port0";
+ serial = "/dev/gsp-control";
# Klipper flash must be enabled in order to build mcu firmware
# The resulting `klipper-flash-mcu` command will show the location of the firmware bin in the nix store
enableKlipperFlash = true;
@@ -22,29 +22,31 @@
#configDir = "/var/lib/moonraker/config"; # Accessible by moonraker # TODO
# Moonraker web-api
+ security.polkit.enable = true; # required for services.moonraker.allowSystemControl
services.moonraker = {
user = "root";
enable = true;
address = "0.0.0.0";
+ allowSystemControl = true;
settings = {
- #authorization = {
- # force_logins = true;
- # cors_domains = [
- # "*.local"
- # "*.lan"
- # "*://app.fluidd.xyz"
- # "*://my.mainsail.xyz"
- # ];
- # trusted_clients = [
- # "10.0.0.0/8"
- # "127.0.0.0/8"
- # "169.254.0.0/16"
- # "172.16.0.0/12"
- # "192.168.0.0/16"
- # "FE80::/10"
- # "::1/128"
- # ];
- #};
+ authorization = {
+ force_logins = true;
+ cors_domains = [
+ "*.local"
+ "*.lan"
+ "*://app.fluidd.xyz"
+ "*://my.mainsail.xyz"
+ ];
+ trusted_clients = [
+ "10.0.0.0/8"
+ "127.0.0.0/8"
+ "169.254.0.0/16"
+ "172.16.0.0/12"
+ "192.168.0.0/16"
+ "FE80::/10"
+ "::1/128"
+ ];
+ };
#file_manager.check_klipper_config_path = false; # Disable warning when klipper config is not accessible by moonraker
# mainsail.cfg
#"update_manager mainsail-config" = {
@@ -54,6 +56,31 @@
# origin = "https://github.com/mainsail-crew/mainsail-config.git";
# managed_services = "klipper";
#};
+
+ "power printer" = let
+ relayApiHost = "http://localhost:5050";
+ in {
+ type = "http";
+ on_url = "${relayApiHost}/on";
+ off_url = "${relayApiHost}/off";
+ status_url = "${relayApiHost}/status";
+ response_template = ''
+
+ # The module will perform the "GET" request using the appropriate url.
+ # We use the `last_response` method to fetch the result and decode the
+ # json response.
+ {% set resp = http_request.last_response().json() %}
+ # The expression below will render "on" or "off".
+ {resp["state"].lower()}
+ '';
+ off_when_shutdown = true;
+ on_when_job_queued = true;
+ locked_while_printing = true;
+ restart_klipper_when_powered = true;
+ restart_delay = "1";
+ bound_services = "klipper";
+ initial_state = "off";
+ };
};
};
@@ -67,6 +94,7 @@
networking.firewall.allowedTCPPorts = [ 80 ]; # Port for mainsail via nginx
# Webcam support in mainsail
+ # TODO hook to restart ustreamer when webcam is connected
services.ustreamer.enable = true;
services.mainsail.nginx.locations."/webcam/".proxyPass = "http://localhost:8080/stream"; # Default location for ustreamer stream
}