Skip to content

Commit

Permalink
nixos/klipper: always update mutable config & deprecate immutable config
Browse files Browse the repository at this point in the history
Klipper macros that use SAVE_CONFIG (eg. bed mesh calibration, PID
tuning, ...) don't work with an immutable config.

The mutableConfig option was added in #188273 to support SAVE_CONFIG,
but it only seeds the config if it doesn't already exist.

This refactors `mutableConfig` to always replace the
config (preserving the SAVE_CONFIG section) and deprecates immutable
configs.
  • Loading branch information
kira-bruneau committed Jan 3, 2025
1 parent 8193466 commit 88ebe25
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions nixos/doc/manual/release-notes/rl-2505.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 21 additions & 8 deletions nixos/modules/services/misc/klipper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'';
};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -189,13 +194,21 @@ 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"
if [ -e printer.cfg ]; then
mv printer.cfg "$old_config"
# Preserve SAVE_CONFIG section from the existing 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"
else
cat ${printerConfigFile} > printer.cfg
fi
''}
mkdir -p ${cfg.mutableConfigFolder}/gcodes
mkdir -p gcodes
popd
'';

serviceConfig =
Expand Down

0 comments on commit 88ebe25

Please sign in to comment.