lab132 / buildbot-gitea

Buildbot plugin for integration with gitea.
MIT License
62 stars 21 forks source link

nixos support #27

Closed xfnw closed 2 years ago

xfnw commented 2 years ago

could there be an installation procedure for nixos? or preferably be packaged in nixpkgs?

buildbot's normal "plugin discovery" is not really compatible with nixos

pampersrocker commented 2 years ago

I don't know anything about NixOS, but if the plugin directory is not working, you can use the classes directly in your master.cfg after installing the plugin from pip:

So instead of writing

from buildbot.plugins import *

you import them directly and use them:

from buildbot_gitea.step_source import Gitea
from buildbot_gitea.reporter import GiteaStatusPush
from buildbot_gitea.webhook import GiteaHandler

c['services'] = [
    # Report status back to gitea, verbose flag enables verbose output in logging for debugging
    GiteaStatusPush(
        'https://example.com', "SECRET", verbose=True)
]

buildFactory = util.BuildFactory()

factory.addStep(Gitea(
    repourl="ssh://git@example.com/example_user/example_project.git",
    mode='incremental',
    workdir="build",
    branch="master",
    codebase='example_codebase',
    progress=True,
    logEnviron=False,
))

c['www'] = {
    'change_hook_dialects': {
        'gitea': {
            'class': GiteaHandler,
            # ...
        }
    }
}
Thesola10 commented 1 year ago

Hey, (small-time) Nixpkgs maintainer here, this ticket should be filed as a packaging request for buildbot-gitea from PyPI on Nixpkgs. The Nixpkgs project has shortcut functions to package Python modules with ease.

In the mean time, here's a draft derivation you can include into your configuration to add this module to your Buildbot on NixOS:

let
  buildbot-gitea = with pkgs.python3Packages;
  buildPythonPackage rec
  { pname = "buildbot-gitea";
    version = 1.7.2;

    src = fetchPypi
    { inherit pname version;
      sha256 = "hash of retrieved file, see below";
    };
  };
in
{ services.buildbot-master.pythonPackages = [ buildbot-gitea ... ];
}

To obtain the sha256 in src, run something like:

nix run nixpkgs#nix-prefetch -- -E 'pkgs.python3Packages.fetchPypi { pname = "buildbot-gitea"; version = "1.7.2"; }'

Plugin discovery still very much works on NixOS, but for technical reasons, the PYTHONPATH is linked to the specific Python interpreter (see pkgs.python3.withPackages). The NixOS option for Buildbot gives you the ability to add Python modules to Buildbot's PYTHONPATH.


Well, if we want to be futuristic, and your NixOS configuration is based on Flakes, adding a flake.nix to this repository could be enough to allow NixOS users to import it into their own configs, without the whole buildPythonPackage mess above.

Thesola10 commented 1 year ago

@xfnw To sum things up, I might file a PR to Nixpkgs for this module, but I hope you'll beat me to it ;)

You'll learn a lot that way.