Unverified Commit 7a6a45da authored by Aleksana's avatar Aleksana Committed by GitHub
Browse files

nezha: correct format of metadata; migrate to finalAttrs; refactor (#471400)

parents 9a8e50c2 4398f9b0
Loading
Loading
Loading
Loading
+47 −49
Original line number Diff line number Diff line
@@ -13,70 +13,68 @@
}:

let
  pname = "nezha";
  version = "1.14.10";

  frontendName = lib.removePrefix "nezha-theme-";

  frontend-templates =
    let
      mkTemplate = theme: {
      mkTemplate =
        theme: extra:
        {
          path = "${frontendName theme.pname}-dist";
          name = frontendName theme.pname;
        repository = theme.meta.homepage;
        author = theme.src.owner;
          repository = theme.meta.homepage or "";
          author = theme.src.owner or "";
          version = theme.version;
        isofficial = false;
        isadmin = false;
      };
    in
    (formats.yaml { }).generate "frontend-templates.yaml" (
      [
        (
          mkTemplate nezha-theme-admin
          // {
            name = "OfficialAdmin";
            isadmin = true;
            isofficial = true;
          is_official = false;
          is_admin = false;
        }
        )
        (
          mkTemplate nezha-theme-user
          // {
        // extra;

      officialThemes = [
        (mkTemplate nezha-theme-admin {
          name = "OfficialAdmin";
          is_admin = true;
          is_official = true;
        })
        (mkTemplate nezha-theme-user {
          name = "Official";
            isofficial = true;
          }
        )
      ]
      ++ map mkTemplate withThemes
    );
          is_official = true;
        })
      ];

      communityThemes = map (t: mkTemplate t { }) withThemes;
    in
    (formats.yaml { }).generate "frontend-templates.yaml" (officialThemes ++ communityThemes);
in
buildGoModule {
  inherit pname version;
buildGoModule (finalAttrs: {
  pname = "nezha";
  version = "1.14.10";

  src = fetchFromGitHub {
    owner = "nezhahq";
    repo = "nezha";
    tag = "v${version}";
    tag = "v${finalAttrs.version}";
    hash = "sha256-tgjLkNSNEQCJP1/Pcgfldl5DGQnzca6KMrqEjl45ex4=";
  };

  proxyVendor = true;

  prePatch = ''
    rm -rf cmd/dashboard/*-dist

    cp ${frontend-templates} service/singleton/frontend-templates.yaml
  ''
  + lib.concatStringsSep "\n" (
    map (theme: "cp -r ${theme} cmd/dashboard/${frontendName theme.pname}-dist") (
      [
  prePatch =
    let
      allThemes = [
        nezha-theme-admin
        nezha-theme-user
      ]
      ++ withThemes
    )
  );
      ++ withThemes;

      installThemeCmd = theme: "cp -r ${theme} cmd/dashboard/${frontendName theme.pname}-dist";
    in
    ''
      rm -rf cmd/dashboard/*-dist

      cp ${frontend-templates} service/singleton/frontend-templates.yaml
      ${lib.concatMapStringsSep "\n" installThemeCmd allThemes}
    '';

  patches = [
    # Nezha originally used ipinfo.mmdb to provide geoip query feature.
@@ -100,7 +98,7 @@ buildGoModule {

  ldflags = [
    "-s"
    "-X github.com/nezhahq/nezha/service/singleton.Version=${version}"
    "-X github.com/nezhahq/nezha/service/singleton.Version=${finalAttrs.version}"
  ];

  checkFlags = "-skip=^TestSplitDomainSOA$";
@@ -120,9 +118,9 @@ buildGoModule {
  meta = {
    description = "Self-hosted, lightweight server and website monitoring and O&M tool";
    homepage = "https://github.com/nezhahq/nezha";
    changelog = "https://github.com/nezhahq/nezha/releases/tag/v${version}";
    changelog = "https://github.com/nezhahq/nezha/releases/tag/v${finalAttrs.version}";
    license = lib.licenses.asl20;
    maintainers = with lib.maintainers; [ moraxyc ];
    mainProgram = "nezha";
  };
}
})