Move klipper config to module, convert regin for Pi3

This commit is contained in:
Erwin Boskma 2023-04-10 23:25:25 +02:00
parent c2ee52267d
commit 5253dae5be
Signed by: erwin
SSH key fingerprint: SHA256:9LmFDe1C6jSrEyqxxvX8NtJBmcbB105XoqyUZF092bg
4 changed files with 198 additions and 179 deletions

View file

@ -1,35 +1,49 @@
{ nixpkgs, nixos-hardware, ... }: { nixpkgs, ... }:
{ config, pkgs, ... }: { pkgs, ... }:
{ {
imports = [ imports = [
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
nixos-hardware.nixosModules.raspberry-pi-4
../../users/root ../../users/root
../../users/erwin ../../users/erwin
]; ];
eboskma = { eboskma = {
users.erwin.enable = true; users.erwin = {
base.kernel = pkgs.linuxPackages_rpi4; enable = true;
server = true;
};
base.kernel = pkgs.linuxPackages_rpi3;
klipper.enable = true;
networking.enable = true; networking.enable = true;
nix-common.enable = true; nix-common.enable = true;
systemd.enable = true; systemd.enable = true;
}; };
users.users.erwin.initialHashedPassword = "$6$Tm4P3XjXJ/QrNaYW$7VqMt.AdQEtHXKjTWCJ3NVq1BiD.mx57skA3ZZrO7LgYnTM/jJLcD0CjWuED57IeGnKdBqYB1tFI5.J.UIVhR.";
hardware = { hardware = {
enableRedistributableFirmware = true; enableAllFirmware = true; # This also sets hardware.enableRedistributableFirmware
raspberry-pi."4" = {
fkms-3d.enable = true;
audio.enable = true;
}; };
boot = {
initrd.availableKernelModules = [
"usbhid"
"usb_storage"
"vc4"
];
kernelModules = [ "bcm2835-v4l2" ];
}; };
zramSwap.enable = true;
sdImage.compressImage = false;
networking = { networking = {
hostName = "regin"; hostName = "regin";
useDHCP = false; useDHCP = true;
useNetworkd = true; useNetworkd = true;
wireless.enable = true;
}; };
systemd.network = { systemd.network = {
@ -44,177 +58,11 @@
services.openssh.enable = true; 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 = { security = {
polkit.enable = true; polkit.enable = true;
}; };
environment.systemPackages = with pkgs; [ environment.systemPackages = with pkgs; [
raspberrypi-eeprom libraspberrypi
]; ];
system.stateVersion = "23.05"; system.stateVersion = "23.05";

171
modules/klipper/default.nix Normal file
View file

@ -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;
};
};
}