diff --git a/machines/regin/configuration.nix b/machines/regin/configuration.nix index d79e3ed..c1a89c3 100644 --- a/machines/regin/configuration.nix +++ b/machines/regin/configuration.nix @@ -1,35 +1,49 @@ -{ nixpkgs, nixos-hardware, ... }: -{ config, pkgs, ... }: +{ nixpkgs, ... }: +{ pkgs, ... }: { imports = [ "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" - nixos-hardware.nixosModules.raspberry-pi-4 - ../../users/root ../../users/erwin ]; eboskma = { - users.erwin.enable = true; - base.kernel = pkgs.linuxPackages_rpi4; + users.erwin = { + enable = true; + server = true; + }; + base.kernel = pkgs.linuxPackages_rpi3; + klipper.enable = true; networking.enable = true; nix-common.enable = true; systemd.enable = true; }; + users.users.erwin.initialHashedPassword = "$6$Tm4P3XjXJ/QrNaYW$7VqMt.AdQEtHXKjTWCJ3NVq1BiD.mx57skA3ZZrO7LgYnTM/jJLcD0CjWuED57IeGnKdBqYB1tFI5.J.UIVhR."; + hardware = { - enableRedistributableFirmware = true; - raspberry-pi."4" = { - fkms-3d.enable = true; - audio.enable = true; - }; + enableAllFirmware = true; # This also sets hardware.enableRedistributableFirmware }; + boot = { + initrd.availableKernelModules = [ + "usbhid" + "usb_storage" + "vc4" + ]; + kernelModules = [ "bcm2835-v4l2" ]; + }; + + zramSwap.enable = true; + + sdImage.compressImage = false; + networking = { hostName = "regin"; - useDHCP = false; + useDHCP = true; useNetworkd = true; + wireless.enable = true; }; systemd.network = { @@ -44,177 +58,11 @@ services.openssh.enable = true; - ### 3D printer config - # TODO: split to modules - - ### Klipper - services.klipper = { - enable = true; - firmwares = { - mcu = { - enable = true; - configFile = ./firmware-config; - serial = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A600KWST-if00-port0"; - }; - }; - - settings = { - stepper_x = { - step_pin = "PA3"; - dir_pin = "!PA1"; - enabe_pin = "!PA5"; - rotation_distance = 40; - microsteps = 16; - endstop_pin = "^PA0"; - position_min = -10; - position_endstop = -10; - position_max = 195; - homing_speed = 50; - homing_retract_dist = 5; - }; - stepper_y = { - step_pin = "PC6"; - dir_pin = "!PC4"; - enabe_pin = "!PA7"; - rotation_distance = 40; - microsteps = 16; - endstop_pin = "^PA4"; - position_min = 0; - position_endstop = 0; - position_max = 200; - homing_speed = 50; - homing_retract_dist = 5; - }; - stepper_z = { - step_pin = "PC0"; - dir_pin = "PG2"; - enabe_pin = "!PC2"; - rotation_distance = 2; - microsteps = 16; - endstop_pin = "^PC7"; - position_min = 0; - position_endstop = 0; - position_max = 180; - homing_speed = 5; - homing_retract_dist = 5; - }; - - extruder = { - step_pin = "PL6"; - dir_pin = "!PL4"; - enable_pin = "!PG0"; - rotation_distance = 34.043; - microsteps = 16; - nozzle_diameter = 0.400; - filament_diameter = 1.75; - max_extrude_only_distance = 150; - heater_pin = "PE4"; - sensor_type = "EPCOS 100K B57560G104F"; - sensor_pin = "PK0"; - control = "pid"; - pid_Kp = 12.33; - pid_Ki = 0.51; - pid_Kd = 74.50; - min_temp = 0; - max_temp = 250; - max_extrude_cross_section = 5; - }; - - heater_bed = { - heater_pin = "PG5"; - sensor_type = "ATC Semitec 104GT-2"; - sensor_pin = "PK2"; - control = "pid"; - pid_Kp = 234.88; - pid_Ki = 42.79; - pid_Kd = 322.28; - min_temp = 0; - max_temp = 120; - }; - - bed_screws = { - screw1 = "20,7"; - screw2 = "190,7"; - screw3 = "190,180"; - screw4 = "20,180"; - }; - - fan.pin = "PH4"; - - mcu.serial = config.services.klipper.firmwares.mcu.serial; - - printer = { - kinematics = "cartesian"; - max_velocity = 400; - max_accel = 5000; - max_z_velocity = 5; - max_z_accel = 75; - }; - - display = { - lcd_type = "hd44780"; - rs_pin = "PD1"; - e_pin = "PH0"; - d4_pin = "PH1"; - d5_pin = "PD0"; - d6_pin = "PE3"; - d7_pin = "PH3"; - encoder_pins = "PL7,PG1"; - click_pin = "^!PD2"; - }; - - # These are necessary for Fluidd - virtual_sdcard = { - path = "/var/lib/klipper/gcode_files"; - }; - - display_status = { }; - - pause_resume = { }; - } // (import ./klipper-macros.nix); - }; - - services.moonraker = { - enable = true; - allowSystemControl = true; - settings = { - authorization = { - cors_domains = [ - "*.local" - "*://app.fluidd.xyz" - ]; - - trusted_clients = [ - "10.0.0.0/24" - "10.1.0.0/24" - "127.0.0.0/8" - "fe80::/10" - "::1/128" - ]; - }; - - history = { }; - - octoprint_compat = { - enable_ufp = false; - }; - - zeroconf = { }; - }; - }; - - services.fluidd = { - enable = true; - hostName = config.networking.hostName; - }; - - ### END 3D printer config - security = { polkit.enable = true; }; environment.systemPackages = with pkgs; [ - raspberrypi-eeprom + libraspberrypi ]; system.stateVersion = "23.05"; diff --git a/modules/klipper/default.nix b/modules/klipper/default.nix new file mode 100644 index 0000000..76ce9e0 --- /dev/null +++ b/modules/klipper/default.nix @@ -0,0 +1,171 @@ +{ config, lib, ... }: +with lib; +let + cfg = config.eboskma.klipper; +in +{ + options.eboskma.klipper = { enable = mkEnableOption "klipper"; }; + + config = mkIf cfg.enable { + services.klipper = { + enable = true; + firmwares = { + mcu = { + enable = true; + configFile = ./firmware-config; + serial = "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A600KWST-if00-port0"; + }; + }; + + settings = { + stepper_x = { + step_pin = "PA3"; + dir_pin = "!PA1"; + enabe_pin = "!PA5"; + rotation_distance = 40; + microsteps = 16; + endstop_pin = "^PA0"; + position_min = -10; + position_endstop = -10; + position_max = 195; + homing_speed = 50; + homing_retract_dist = 5; + }; + stepper_y = { + step_pin = "PC6"; + dir_pin = "!PC4"; + enabe_pin = "!PA7"; + rotation_distance = 40; + microsteps = 16; + endstop_pin = "^PA4"; + position_min = 0; + position_endstop = 0; + position_max = 200; + homing_speed = 50; + homing_retract_dist = 5; + }; + stepper_z = { + step_pin = "PC0"; + dir_pin = "PG2"; + enabe_pin = "!PC2"; + rotation_distance = 2; + microsteps = 16; + endstop_pin = "^PC7"; + position_min = 0; + position_endstop = 0; + position_max = 180; + homing_speed = 5; + homing_retract_dist = 5; + }; + + extruder = { + step_pin = "PL6"; + dir_pin = "!PL4"; + enable_pin = "!PG0"; + rotation_distance = 34.043; + microsteps = 16; + nozzle_diameter = 0.400; + filament_diameter = 1.75; + max_extrude_only_distance = 150; + heater_pin = "PE4"; + sensor_type = "EPCOS 100K B57560G104F"; + sensor_pin = "PK0"; + control = "pid"; + pid_Kp = 12.33; + pid_Ki = 0.51; + pid_Kd = 74.50; + min_temp = 0; + max_temp = 250; + max_extrude_cross_section = 5; + }; + + heater_bed = { + heater_pin = "PG5"; + sensor_type = "ATC Semitec 104GT-2"; + sensor_pin = "PK2"; + control = "pid"; + pid_Kp = 234.88; + pid_Ki = 42.79; + pid_Kd = 322.28; + min_temp = 0; + max_temp = 120; + }; + + bed_screws = { + screw1 = "20,7"; + screw2 = "190,7"; + screw3 = "190,180"; + screw4 = "20,180"; + }; + + fan.pin = "PH4"; + + mcu.serial = config.services.klipper.firmwares.mcu.serial; + + printer = { + kinematics = "cartesian"; + max_velocity = 400; + max_accel = 5000; + max_z_velocity = 5; + max_z_accel = 75; + }; + + display = { + lcd_type = "hd44780"; + rs_pin = "PD1"; + e_pin = "PH0"; + d4_pin = "PH1"; + d5_pin = "PD0"; + d6_pin = "PE3"; + d7_pin = "PH3"; + encoder_pins = "PL7,PG1"; + click_pin = "^!PD2"; + }; + + # These are necessary for Fluidd + virtual_sdcard = { + path = "/var/lib/klipper/gcode_files"; + }; + + display_status = { }; + + pause_resume = { }; + } // (import ./klipper-macros.nix); + }; + + services.moonraker = { + enable = true; + allowSystemControl = true; + settings = { + authorization = { + cors_domains = [ + "*.local" + "*://app.fluidd.xyz" + ]; + + trusted_clients = [ + "10.0.0.0/24" + "10.1.0.0/24" + "127.0.0.0/8" + "fe80::/10" + "::1/128" + ]; + }; + + history = { }; + + octoprint_compat = { + enable_ufp = false; + }; + + zeroconf = { }; + }; + }; + + services.fluidd = { + enable = true; + hostName = config.networking.hostName; + }; + + }; +} diff --git a/machines/regin/firmware-config b/modules/klipper/firmware-config similarity index 100% rename from machines/regin/firmware-config rename to modules/klipper/firmware-config diff --git a/machines/regin/klipper-macros.nix b/modules/klipper/klipper-macros.nix similarity index 100% rename from machines/regin/klipper-macros.nix rename to modules/klipper/klipper-macros.nix