From c9d4a5a9a47bad06cad0dc9c9ba379d0505554ac Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 23 Dec 2025 12:58:48 +0100 Subject: [PATCH] feat(nix): expose matomo-bootstrap as flake package and app - add flake packages and apps for matomo-bootstrap - provide nix run support for CLI execution - add Playwright browser installer app - simplify devShell (remove pytest, keep ruff only) - align pyproject license with MIT LICENSE - register stable CLI entry point via project.scripts --- flake.nix | 93 ++++++++++++++++++++++++++++++++++++++++++++++---- pyproject.toml | 11 ++++-- 2 files changed, 96 insertions(+), 8 deletions(-) diff --git a/flake.nix b/flake.nix index d5b28f4..2485d27 100644 --- a/flake.nix +++ b/flake.nix @@ -1,11 +1,92 @@ { description = "matomo-bootstrap"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + outputs = { self, nixpkgs }: - let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - in { - devShells.${system}.default = pkgs.mkShell { - packages = with pkgs; [ python312 python312Packages.pytest python312Packages.ruff ]; - }; + let + systems = [ "x86_64-linux" "aarch64-linux" ]; + forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system); + in + { + packages = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + python = pkgs.python312; + in + rec { + matomo-bootstrap = python.pkgs.buildPythonApplication { + pname = "matomo-bootstrap"; + version = "0.1.0"; # keep in sync with pyproject.toml + pyproject = true; + src = self; + + # Runtime deps (Python) + propagatedBuildInputs = with python.pkgs; [ + playwright + ]; + + # Optional: keep tests off in nix build by default + doCheck = false; + + meta = with pkgs.lib; { + description = "Headless bootstrap tooling for Matomo (installation + API token provisioning)"; + homepage = "https://github.com/kevinveenbirkenbach/matomo-bootstrap"; + license = licenses.mit; + mainProgram = "matomo-bootstrap"; + }; + }; + + default = matomo-bootstrap; + } + ); + + apps = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + matomo = self.packages.${system}.matomo-bootstrap; + + playwright-install = pkgs.writeShellApplication { + name = "matomo-bootstrap-playwright-install"; + runtimeInputs = [ matomo ]; + text = '' + # Installs the Playwright Chromium browser into the user cache. + # This is needed when the Matomo instance is not installed yet and + # the web installer must be driven via Playwright. + exec ${matomo}/bin/python -m playwright install chromium + ''; + }; + in + { + matomo-bootstrap = { + type = "app"; + program = "${matomo}/bin/matomo-bootstrap"; + }; + + matomo-bootstrap-playwright-install = { + type = "app"; + program = "${playwright-install}/bin/matomo-bootstrap-playwright-install"; + }; + + default = self.apps.${system}.matomo-bootstrap; + } + ); + + devShells = forAllSystems (system: + let + pkgs = import nixpkgs { inherit system; }; + python = pkgs.python312; + in + { + default = pkgs.mkShell { + packages = with pkgs; [ + python + python.pkgs.ruff + ]; + }; + } + ); }; } diff --git a/pyproject.toml b/pyproject.toml index faa6e9b..10ec643 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,17 +9,24 @@ description = "Headless bootstrap tooling for Matomo (installation + API token p readme = "README.md" requires-python = ">=3.10" authors = [{ name = "Kevin Veen-Birkenbach", email = "kevin@veen.world" }] -license = { text = "All rights reserved by Kevin Veen-Birkenbach" } +license = { text = "MIT" } urls = { Homepage = "https://github.com/kevinveenbirkenbach/matomo-bootstrap" } -# Playwright is needed at runtime to run the web installer when Matomo is not yet installed. dependencies = [ "playwright>=1.40.0", ] +# Provides a stable CLI name for Nix + pip installs: +[project.scripts] +matomo-bootstrap = "matomo_bootstrap.__main__:main" + [project.optional-dependencies] e2e = [] +dev = [ + "ruff", +] + [tool.setuptools] package-dir = { "" = "src" }