Unverified Commit d344ca55 authored by Daniel Nagy's avatar Daniel Nagy
Browse files

opengist: use finalAttrs pattern

parent de907f60
Loading
Loading
Loading
Loading
+19 −15
Original line number Diff line number Diff line
@@ -9,23 +9,26 @@
  git,
  writableTmpDirAsHomeHook,
}:
let
  # finalAttrs when 🥺 (buildGoModule does not support them)
  # https://github.com/NixOS/nixpkgs/issues/273815

buildGoModule (finalAttrs: {
  pname = "opengist";

  version = "1.9.1";

  src = fetchFromGitHub {
    owner = "thomiceli";
    repo = "opengist";
    tag = "v${version}";
    tag = "v${finalAttrs.version}";
    hash = "sha256-Zjn38OGnDtgD2OfIhgUxWo0Cx+ZmNv6UjJanASbjiYU=";
  };

  frontend = buildNpmPackage {
    pname = "opengist-frontend";
    inherit version src;
    inherit (finalAttrs) version src;

    # npm complains of "invalid package". shrug. we can give it a version.
    postPatch = ''
      ${lib.getExe jq} '.version = "${version}"' package.json | ${lib.getExe' moreutils "sponge"} package.json
      ${lib.getExe jq} '.version = "${finalAttrs.version}"' package.json | ${lib.getExe' moreutils "sponge"} package.json
    '';

    # copy pasta from the Makefile upstream, seems to be a workaround of sass
@@ -42,15 +45,14 @@ let

    npmDepsHash = "sha256-Uh+oXd//G/lPAMXRxijjEOpQNmeXK/XCIU7DJN3ujaY=";
  };
in
buildGoModule {
  pname = "opengist";
  inherit version src;

  vendorHash = "sha256-aqfr3yGyTXDtZDU8d1lbWWvFfY4fo6/PsSDwpiDtM90=";

  tags = [ "fs_embed" ];

  ldflags = [
    "-s"
    "-X github.com/thomiceli/opengist/internal/config.OpengistVersion=v${version}"
    "-X github.com/thomiceli/opengist/internal/config.OpengistVersion=v${finalAttrs.version}"
  ];

  nativeCheckInputs = [
@@ -62,16 +64,18 @@ buildGoModule {

  checkPhase = ''
    runHook preCheck

    make test

    runHook postCheck
  '';

  postPatch = ''
    cp -R ${frontend}/public/{manifest.json,assets} public/
    cp -R ${finalAttrs.frontend}/public/{manifest.json,assets} public/
  '';

  passthru = {
    inherit frontend;
    inherit (finalAttrs) frontend;
    updateScript = ./update.sh;
  };

@@ -79,9 +83,9 @@ buildGoModule {
    description = "Self-hosted pastebin powered by Git";
    homepage = "https://github.com/thomiceli/opengist";
    license = lib.licenses.agpl3Only;
    changelog = "https://github.com/thomiceli/opengist/blob/${src.tag}/CHANGELOG.md";
    changelog = "https://github.com/thomiceli/opengist/blob/v${finalAttrs.version}/CHANGELOG.md";
    platforms = lib.platforms.unix;
    maintainers = with lib.maintainers; [ phanirithvij ];
    mainProgram = "opengist";
  };
}
})