aboutsummaryrefslogtreecommitdiff
path: root/hm-module.nix
diff options
context:
space:
mode:
Diffstat (limited to 'hm-module.nix')
-rw-r--r--hm-module.nix86
1 files changed, 86 insertions, 0 deletions
diff --git a/hm-module.nix b/hm-module.nix
new file mode 100644
index 0000000..d3fa652
--- /dev/null
+++ b/hm-module.nix
@@ -0,0 +1,86 @@
+self:
+{
+ config,
+ lib,
+ pkgs,
+ ...
+}:
+
+with lib;
+
+let
+ cfg = config.programs.openBambooNetworking;
+
+ mkClientPlugin =
+ clientType: obnVersion: pkgs.callPackage (self + "/package.nix") { inherit clientType obnVersion; };
+
+ # home.file targets are relative to $HOME; configDir is given as an
+ # absolute path (so it composes naturally whether it comes from
+ # config.xdg.configHome, a Flatpak path, or something else entirely).
+ relToHome =
+ path:
+ if lib.hasPrefix (config.home.homeDirectory + "/") path then
+ lib.removePrefix (config.home.homeDirectory + "/") path
+ else
+ throw "programs.openBambooNetworking: configDir (${path}) must be under $HOME (${config.home.homeDirectory})";
+
+ orcaPlugin = mkClientPlugin "orca_slicer" cfg.orcaSlicer.obnVersion;
+in
+{
+ options.programs.openBambooNetworking = {
+ enable = mkEnableOption ''
+ open-bamboo-networking (https://github.com/ClusterM/open-bamboo-networking),
+ an open-source replacement for Bambu Lab slicers' proprietary network
+ plugin, built from source
+ '';
+
+ # Each supported client gets its own nested option group. Only
+ # orcaSlicer is wired up today; add siblings here (e.g. bambuStudio)
+ # as upstream support for them matures.
+ orcaSlicer = {
+ enable = mkOption {
+ type = types.bool;
+ default = true;
+ description = "Build and link the plugin for OrcaSlicer (or a compatible fork).";
+ };
+
+ obnVersion = mkOption {
+ type = types.str;
+ default = "02.03.00.99";
+ description = ''
+ Plugin ABI version baked into the built filename. Must match what
+ the slicer expects: check with
+ jq -r '.app.network_plugin_version // "not set"' <configDir>/OrcaSlicer.conf
+ First three components should match what the app reports; the
+ last component should stay .99 (see README).
+ '';
+ };
+
+ configDir = mkOption {
+ type = types.str;
+ default = "${config.xdg.configHome}/OrcaSlicer";
+ defaultText = literalExpression ''"''${config.xdg.configHome}/OrcaSlicer"'';
+ description = ''
+ Directory containing OrcaSlicer.conf and its plugins/ subfolder.
+ Override this if you're on a fork with a different config
+ directory (e.g. ~/.config/BambuStudio, ~/.config/OrcaSlicer-Nightly),
+ or a Flatpak install (e.g. ~/.var/app/io.github.softfever.OrcaSlicer/config/OrcaSlicer).
+ Must be a path under $HOME.
+ '';
+ };
+ };
+ };
+
+ config = mkIf cfg.enable (mkMerge [
+ (mkIf cfg.orcaSlicer.enable {
+ home.packages = [ orcaPlugin ];
+
+ home.file = {
+ "${relToHome cfg.orcaSlicer.configDir}/plugins/libbambu_networking_${cfg.orcaSlicer.obnVersion}.so".source =
+ "${orcaPlugin}/plugins/libbambu_networking_${cfg.orcaSlicer.obnVersion}.so";
+ "${relToHome cfg.orcaSlicer.configDir}/plugins/libBambuSource.so".source =
+ "${orcaPlugin}/plugins/libBambuSource.so";
+ };
+ })
+ ]);
+}