Unverified Commit 1107c1a4 authored by Sandro Jäckel's avatar Sandro Jäckel Committed by GitHub
Browse files

anubis: refactor, add updateScript, adopt (#415932)

parents 21f1277f 588af0fe
Loading
Loading
Loading
Loading
+0 −35
Original line number Diff line number Diff line
{ buildNpmPackage, anubis }:

buildNpmPackage {
  pname = "${anubis.pname}-xess";
  inherit (anubis) version src;

  npmDepsHash = "sha256-wI8XCUGq3aI20B++RAT3lc/nBrDMEmE9+810lewzXa0=";

  buildPhase = ''
    runHook preBuild

    npx postcss ./xess/xess.css -o xess.min.css

    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    install -Dm644 xess.min.css $out/xess.min.css

    runHook postInstall
  '';

  meta = anubis.meta // {
    description = "Xess files for Anubis";
    longDescription = ''
      This package is consumed by the main `anubis` package to render the final
      styling for the bot check page.

      **It is not supposed to be used as a standalone package**, and it exists to
      ensure Anubis' styling is override-able by downstreams.
    '';
  };
}
+30 −15
Original line number Diff line number Diff line
@@ -4,8 +4,7 @@
  fetchFromGitHub,
  nixosTests,
  stdenv,

  anubis-xess,
  buildNpmPackage,

  esbuild,
  brotli,
@@ -31,26 +30,39 @@ buildGoModule (finalAttrs: {
    zstd
  ];

  subPackages = [
    "cmd/anubis"
  ];
  xess = buildNpmPackage {
    pname = "anubis-xess";
    inherit (finalAttrs) version src;

    npmDepsHash = "sha256-wI8XCUGq3aI20B++RAT3lc/nBrDMEmE9+810lewzXa0=";

    buildPhase = ''
      runHook preBuild
      npx postcss ./xess/xess.css -o xess.min.css
      runHook postBuild
    '';

  ldflags =
    [
    installPhase = ''
      runHook preInstall
      install -Dm644 xess.min.css $out/xess.min.css
      runHook postInstall
    '';
  };

  subPackages = [ "cmd/anubis" ];

  ldflags = [
    "-s"
    "-w"
    "-X=github.com/TecharoHQ/anubis.Version=v${finalAttrs.version}"
    ]
    ++ lib.optionals stdenv.hostPlatform.isLinux [
      "-extldflags=-static"
    ];
  ] ++ lib.optionals stdenv.hostPlatform.isLinux [ "-extldflags=-static" ];

  postPatch = ''
    patchShebangs ./web/build.sh
  '';

  preBuild = ''
    go generate ./... && ./web/build.sh && cp -r ${anubis-xess}/xess.min.css ./xess
    go generate ./... && ./web/build.sh && cp -r ${finalAttrs.xess}/xess.min.css ./xess
  '';

  preCheck = ''
@@ -58,10 +70,12 @@ buildGoModule (finalAttrs: {
  '';

  passthru.tests = { inherit (nixosTests) anubis; };
  passthru.updateScript = ./update.sh;

  meta = {
    description = "Weighs the soul of incoming HTTP requests using proof-of-work to stop AI crawlers";
    homepage = "https://anubis.techaro.lol/";
    downloadPage = "https://github.com/TecharoHQ/anubis";
    changelog = "https://github.com/TecharoHQ/anubis/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [
@@ -69,6 +83,7 @@ buildGoModule (finalAttrs: {
      soopyc
      ryand56
      sigmasquadron
      defelo
    ];
    mainProgram = "anubis";
  };
+8 −0
Original line number Diff line number Diff line
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p nix-update

set -euo pipefail

nix-update anubis --src-only
nix-update anubis.xess --version=skip
nix-update anubis --version=skip