diff --git a/nixos/doc/manual/release-notes/rl-2505.section.md b/nixos/doc/manual/release-notes/rl-2505.section.md index c9e5123743be5..ab77e510ac845 100644 --- a/nixos/doc/manual/release-notes/rl-2505.section.md +++ b/nixos/doc/manual/release-notes/rl-2505.section.md @@ -164,6 +164,8 @@ - `python3Packages.jaeger-client` was removed because it was deprecated upstream. [OpenTelemetry](https://opentelemetry.io) is the recommended replacement. +- Immutable `klipper` config is deprecated. Klipper macros that use SAVE_CONFIG (eg. bed mesh calibration, PID tuning, ...) don't work with an immutable config. Set `services.klipper.mutableConfig = true;`, or carefully update your `system.stateVersion` to `"25.05"`. + - `nodePackages.meshcommander` has been removed, as the package was deprecated by Intel. - `kanata` was updated to v1.7.0, which introduces several breaking changes. diff --git a/nixos/modules/services/misc/klipper.nix b/nixos/modules/services/misc/klipper.nix index b2345cbf7f337..2f940b100a703 100644 --- a/nixos/modules/services/misc/klipper.nix +++ b/nixos/modules/services/misc/klipper.nix @@ -49,11 +49,11 @@ in mutableConfig = lib.mkOption { type = lib.types.bool; - default = false; - example = true; + default = lib.versionAtLeast config.system.stateVersion "25.05"; + example = !(lib.versionAtLeast config.system.stateVersion "25.05"); description = '' Whether to copy the config to a mutable directory instead of using the one directly from the nix store. - This will only copy the config if the file at `services.klipper.mutableConfigPath` doesn't exist. + This will keep a backup if `services.klipper.mutableConfigPath` already exists and differs. ''; }; @@ -136,7 +136,12 @@ in }; ##### implementation + config = lib.mkIf cfg.enable { + warnings = + lib.optional (!cfg.mutableConfig) + "Immutable klipper config is deprecated. Klipper macros that use SAVE_CONFIG (eg. bed mesh calibration, PID tuning, ...) don't work with an immutable config. Set services.klipper.mutableConfig = true, or carefully update your system.stateVersion to 25.05."; + assertions = [ { assertion = cfg.octoprintIntegration -> config.services.octoprint.enable; @@ -189,13 +194,17 @@ in after = [ "network.target" ]; preStart = '' mkdir -p ${cfg.mutableConfigFolder} + pushd ${cfg.mutableConfigFolder} ${lib.optionalString (cfg.mutableConfig) '' - [ -e ${printerConfigPath} ] || { - cp ${printerConfigFile} ${printerConfigPath} - chmod +w ${printerConfigPath} - } + # Backup existing config using the same date format klipper uses for SAVE_CONFIG + old_config="printer-$(date +"%Y%m%d_%H%M%S").cfg" + [ -e printer.cfg ] && mv printer.cfg "$old_config" + # Preserve SAVE_CONFIG section from the existing config + [ -e "$old_config" ] cat ${printerConfigFile} <(printf "\n") <(sed -n '/#*# <---------------------- SAVE_CONFIG ---------------------->/,$p' "$old_config") > printer.cfg + ${pkgs.diffutils}/bin/cmp printer.cfg "$old_config" && rm "$old_config" ''} - mkdir -p ${cfg.mutableConfigFolder}/gcodes + mkdir -p gcodes + popd ''; serviceConfig =