mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 04:19:19 -08:00
feat(klipper): deploy printer configs
This commit is contained in:
parent
e04d59016b
commit
8925b00445
10 changed files with 125 additions and 69 deletions
53
modules/nixos/klipper.nix
Normal file
53
modules/nixos/klipper.nix
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
pkgs,
|
||||
config,
|
||||
gensokyo-zone,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (gensokyo-zone.lib) mapListToAttrs;
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf mkMerge mkAfter mkOptionDefault;
|
||||
inherit (lib.attrsets) nameValuePair;
|
||||
inherit (lib.strings) concatMapStrings escapeShellArg;
|
||||
cfg = config.services.klipper;
|
||||
includeFileName = "00-includes.cfg";
|
||||
includeFile = pkgs.writeText "klipper-includes.cfg" (concatMapStrings (
|
||||
path: "[include ${path}]\n"
|
||||
)
|
||||
cfg.configFiles);
|
||||
mkIncludeSetting = path: nameValuePair "include ${path}" (mkOptionDefault {});
|
||||
includeSettings = mapListToAttrs mkIncludeSetting (
|
||||
if cfg.mutableConfig
|
||||
then [includeFileName]
|
||||
else cfg.configFiles
|
||||
);
|
||||
in {
|
||||
options.services.klipper = with lib.types; {
|
||||
quiet = mkEnableOption "more silent logs";
|
||||
configFiles = mkOption {
|
||||
type = listOf path;
|
||||
default = [];
|
||||
};
|
||||
};
|
||||
config.services.klipper = {
|
||||
settings = mkMerge [
|
||||
(mkIf (cfg.configFiles != []) includeSettings)
|
||||
{
|
||||
virtual_sdcard = mkIf cfg.mutableConfig {
|
||||
path = mkOptionDefault "${cfg.mutableConfigFolder}/gcodes";
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
config.systemd.services.klipper = mkIf cfg.enable {
|
||||
serviceConfig = mkIf cfg.quiet {
|
||||
LogFilterPatterns = [
|
||||
''~INFO:root:Stats''
|
||||
];
|
||||
};
|
||||
preStart = mkIf (cfg.configFiles != [] && cfg.mutableConfig) (mkAfter ''
|
||||
ln -sfT ${includeFile} ${escapeShellArg "${cfg.mutableConfigFolder}/${includeFileName}"}
|
||||
'');
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue