···
description = lib.mdDoc "Path of the API socket to create.";
38
+
mutableConfig = mkOption {
42
+
description = lib.mdDoc ''
43
+
Whether to copy the config to a mutable directory instead of using the one directly from the nix store.
44
+
This will only copy the config if the file at `services.klipper.mutableConfigPath` doesn't exist.
48
+
mutableConfigFolder = mkOption {
50
+
default = "/var/lib/klipper";
51
+
description = lib.mdDoc "Path to mutable Klipper config file.";
54
+
configFile = mkOption {
55
+
type = types.nullOr types.path;
57
+
description = lib.mdDoc ''
58
+
Path to default Klipper config.
octoprintIntegration = mkOption {
···
89
+
type = types.nullOr format.type;
description = lib.mdDoc ''
Configuration for Klipper. See the [documentation](https://www.klipper3d.org/Overview.html#configuration-and-tuning-guides)
···
building of firmware and addition of klipper-flash tools for manual flashing.
This will add `klipper-flash-$mcu` scripts to your environment which can be called to flash the firmware.
107
+
serial = mkOption {
108
+
type = types.nullOr path;
109
+
description = lib.mdDoc "Path to serial port this printer is connected to. Leave `null` to derive it from `service.klipper.settings`.";
description = lib.mdDoc "Path to firmware config which is generated using `klipper-genconf`";
···
assertion = cfg.octoprintIntegration -> config.services.octoprint.enable;
98
-
message = "Option klipper.octoprintIntegration requires Octoprint to be enabled on this system. Please enable services.octoprint to use it.";
126
+
message = "Option services.klipper.octoprintIntegration requires Octoprint to be enabled on this system. Please enable services.octoprint to use it.";
assertion = cfg.user != null -> cfg.group != null;
102
-
message = "Option klipper.group is not set when a user is specified.";
130
+
message = "Option services.klipper.group is not set when services.klipper.user is specified.";
105
-
assertion = foldl (a: b: a && b) true (mapAttrsToList (mcu: _: mcu != null -> (hasAttrByPath [ "${mcu}" "serial" ] cfg.settings)) cfg.firmwares);
106
-
message = "Option klipper.settings.$mcu.serial must be set when klipper.firmware.$mcu is specified";
133
+
assertion = cfg.settings != null -> foldl (a: b: a && b) true (mapAttrsToList (mcu: _: mcu != null -> (hasAttrByPath [ "${mcu}" "serial" ] cfg.settings)) cfg.firmwares);
134
+
message = "Option services.klipper.settings.$mcu.serial must be set when settings.klipper.firmware.$mcu is specified";
137
+
assertion = (cfg.configFile != null) != (cfg.settings != null);
138
+
message = "You need to either specify services.klipper.settings or services.klipper.defaultConfig.";
110
-
environment.etc."klipper.cfg".source = format.generate "klipper.cfg" cfg.settings;
142
+
environment.etc = mkIf (!cfg.mutableConfig) {
143
+
"klipper.cfg".source = if cfg.settings != null then format.generate "klipper.cfg" cfg.settings else cfg.configFile;
services.klipper = mkIf cfg.octoprintIntegration {
user = config.services.octoprint.user;
···
klippyArgs = "--input-tty=${cfg.inputTTY}"
+ optionalString (cfg.apiSocket != null) " --api-server=${cfg.apiSocket}";
155
+
printerConfigPath =
156
+
if cfg.mutableConfig
157
+
then cfg.mutableConfigFolder + "/printer.cfg"
158
+
else "/etc/klipper.cfg";
159
+
printerConfigFile =
160
+
if cfg.settings != null
161
+
then format.generate "klipper.cfg" cfg.settings
162
+
else cfg.configFile;
description = "Klipper 3D Printer Firmware";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
169
+
mkdir -p ${cfg.mutableConfigFolder}
170
+
${lib.optionalString (cfg.mutableConfig) ''
171
+
[ -e ${printerConfigPath} ] || {
172
+
cp ${printerConfigFile} ${printerConfigPath}
173
+
chmod +w ${printerConfigPath}
176
+
mkdir -p ${cfg.mutableConfigFolder}/gcodes
128
-
ExecStart = "${cfg.package}/lib/klipper/klippy.py ${klippyArgs} /etc/klipper.cfg";
180
+
ExecStart = "${cfg.package}/lib/klipper/klippy.py ${klippyArgs} ${printerConfigPath}";
RuntimeDirectory = "klipper";
182
+
StateDirectory = "klipper";
SupplementaryGroups = [ "dialout" ];
WorkingDirectory = "${cfg.package}/lib";
···
CPUSchedulingPriority = 99;
IOSchedulingClass = "realtime";
IOSchedulingPriority = 0;
} // (if cfg.user != null then {
···
environment.systemPackages =
203
+
default = a: b: if a != null then a else b;
firmwares = filterAttrs (n: v: v!= null) (mapAttrs
150
-
(mcu: { enable, configFile }: if enable then pkgs.klipper-firmware.override {
205
+
(mcu: { enable, configFile, serial }: if enable then pkgs.klipper-firmware.override {
mcu = lib.strings.sanitizeDerivationName mcu;
firmwareConfig = configFile;
···
(mcu: firmware: pkgs.klipper-flash.override {
mcu = lib.strings.sanitizeDerivationName mcu;
klipper-firmware = firmware;
159
-
flashDevice = cfg.settings."${mcu}".serial;
214
+
flashDevice = default cfg.firmwares."${mcu}".serial cfg.settings."${mcu}".serial;
firmwareConfig = cfg.firmwares."${mcu}".configFile;
[ klipper-genconf ] ++ firmwareFlasher ++ attrValues firmwares;
221
+
meta.maintainers = [