summaryrefslogtreecommitdiff
path: root/hosts/gnuslashprinter/klipper.nix
diff options
context:
space:
mode:
Diffstat (limited to 'hosts/gnuslashprinter/klipper.nix')
-rw-r--r--hosts/gnuslashprinter/klipper.nix100
1 files changed, 100 insertions, 0 deletions
diff --git a/hosts/gnuslashprinter/klipper.nix b/hosts/gnuslashprinter/klipper.nix
new file mode 100644
index 0000000..331a0c7
--- /dev/null
+++ b/hosts/gnuslashprinter/klipper.nix
@@ -0,0 +1,100 @@
+{
+ # Klipper firmware
+ services.klipper = {
+ enable = true;
+ firmwares = {
+ mcu = {
+ enable = true;
+ # Serial port connected to the microcontroller
+ 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;
+ # Run klipper-genconf to generate this
+ configFile = ./resources/klipper/mcu/config;
+ };
+ };
+ configFile = ./resources/klipper/printer.cfg;
+ logFile = "/var/lib/klipper/klipper.log";
+ };
+ # Mutable config
+ services.klipper.mutableConfig = true;
+ #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"
+ ];
+ };
+ #file_manager.check_klipper_config_path = false; # Disable warning when klipper config is not accessible by moonraker
+ # mainsail.cfg
+ #"update_manager mainsail-config" = {
+ # type = "git_repo";
+ # primary_branch = "master";
+ # path = "~/mainsail-config";
+ # 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";
+ };
+ };
+ };
+
+ # Mainsail web-interface
+ services.mainsail = {
+ enable = true;
+ hostName = "0.0.0.0";
+ nginx.listenAddresses = [ "0.0.0.0" ];
+ };
+ services.nginx.clientMaxBodySize = "1000m"; # Allow large gcodes, etc.
+ 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
+}