How to add extra octoprint plugins to the existing plugins attribute set?

Hi folks!

I started using NixOS a few weeks ago and I’m still in the process of connecting the dots with using the Nix language.

I need help with customizing the octoprint package with its plugins by adding the PrettyGCode plugin to it via my /etc/nixos/configuration.nix file.

If this approach is not possible, what other approaches can I use?

This comment suggests you should use pkgs.octoprint.override { packageOverrides = self: super: { pluginName = ...; }; }.

Unfortunately, I’m still lost and not able to get it working after much experimentation and looking around for other solutions related to what you shared. I got burnt out afterwards.

Here is what I’m using in my environment.systemPackages. I don’t know what I’m doing wrong:

    (octoprint.override {
      packageOverrides = self: super: {
        prettygcode = python3.buildPythonPackage rec {
          pname = "PrettyGCode";
          version = "1.2.4";

          src = fetchFromGitHub {
            owner = "Kragrathea";
            repo = "OctoPrint-PrettyGCode";
            rev = "v${version}";
            sha256 = "958259072a8645b5279ed782e4dd020e92ab862384e966fe97a5eedfe583708c";
          };
          doCheck = false;
        };
      };
    })

Hi folks,

I decided to take the path of least resistance by setting up a local cloned nixpkgs repository in my user home directory. I had to edit the plugins.nix file by adding and adjusting my plugin nix expression there.

While it would be a “nice to have” with it customized in the configuration.nix file, I’m fine with using git and pulling from the nixos-unstable branch whenever I need to upgrade.

So, I’ll go ahead and contribute my steps here so it might help someone reading this in the future:

NOTE:
$: command as user
#: command as root

$ git clone https://github.com/NixOS/nixpkgs.git
$ cd nixpkgs
$ git checkout nixos-unstable
$ $EDITOR ~/nixpkgs/pkgs/applications/misc/octoprint/plugins.nix

Add the following under the inherit buildPlugin line:

  prettygcode = buildPlugin rec {
    pname = "PrettyGCode";
    version = "1.2.4";

    src = fetchFromGitHub {
      owner = "Kragrathea";
      repo = "OctoPrint-PrettyGCode";
      rev = "v${version}";
      sha256 = "sha256-q/B2oEy+D6L66HqmMkvKfboN+z3jhTQZqt86WVhC2vQ=";
    };

    meta = with lib; {
      description = "Adds a 3D GCode visualizer tab. It displays colored lines to show what the printer is doing and animates progress during printing.";
      homepage = "https://github.com/Kragrathea/OctoPrint-PrettyGCode";
      license = licenses.agpl3Only;
      maintainers = with maintainers; [ ];
    };
  };
# $EDITOR /etc/nixos/configuration.nix

Add the plugin if not already:

  services.octoprint.plugins = plugins: with plugins; [ prettygcode ];

Finally, wrap it up with a rebuild! Make sure to persistently use the -I nixpkgs=/path/to/cloned/nixpkgs argument for each rebuild from then on.

# nixos-rebuild switch -I nixpkgs=/path/to/cloned/nixpkgs

Ah, I was missing a piece of the puzzle. The nixos module provides the list of plugins. So you need to use an overlay to override it, since the module doesn’t expose a .package option. (It probably should)

  nixpkgs.overlays = [(self: super: {
    octoprint = super.octoprint.override {
      packageOverrides = pyself: pysuper: {
        octoprint-prettygcode = pyself.buildPythonPackage rec {
          pname = "PrettyGCode";
          version = "1.2.4";
          src = self.fetchFromGitHub {
            owner = "Kragrathea";
            repo = "OctoPrint-PrettyGCode";
            rev = "v${version}";
            sha256 = "sha256-q/B2oEy+D6L66HqmMkvKfboN+z3jhTQZqt86WVhC2vQ=";
          };
          propagatedBuildInputs = [ pysuper.octoprint ];
          doCheck = false;
        };
      };
    };
  })];
  services.octoprint.enable = true;
  services.octoprint.plugins = plugins: with plugins; [ octoprint-prettygcode ];

in your configuration.nix should do the trick I think. It builds, at least.

1 Like

Ah, gotcha!

And thank you, that really did the trick! That propagatedBuildInputs was the missing piece for sure.

The PrettyGCode plugin shows up in my OctoPrint’s web UI instance even after I stopped using my workaround solution.

:v:

I copied that from here, in case you’re interested:

1 Like