zaphyra's git: tgcNUR

fork of https://git.transgirl.cafe/zaphoid/tgc-nix-user-repository

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
64 
65 
66 
67 
68 
69 
70 
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 
81 
82 
83 
84 
85 
86 
87 
88 
89 
90 
91 
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
112 
113 
114 
115 
116 
117 
118 
119 
120 
121 
122 
123 
124 
125 
126 
127 
128 
129 
130 
131 
132 
133 
134 
135 
136 
137 
138 
139 
140 
141 
142 
143 
{
  tgcMaintainers,
  unstable,
  lib,
  fetchFromGitea,
  applyPatches,
  mkYarnPackage,
  makeWrapper,
  installShellFiles,
  nixosTests,
  ...
}:

unstable.buildGo125Module (finalAttrs: {
  pname = "gotosocial";
  version = "0.21.0-unstable-2025-10-21-${builtins.substring 0 6 finalAttrs.rev}";
  rev = "6cdb58fd376a10f68e5ec1c52373746d798a7734";
  srcHash = "sha256-MrP6xzx3Y0l40LdaZSHrKyNSjZqcEmiXBsP9EaP48EE=";

  src = applyPatches {
    src = fetchFromGitea {
      domain = "codeberg.org";
      owner = "superseriousbusiness";
      repo = "gotosocial";
      hash = finalAttrs.srcHash;
      inherit (finalAttrs) rev;
    };
    patches = [
      ./0001-disable-template-indentation.patch
    ];
  };

  frontend-assets = mkYarnPackage {
    name = "${finalAttrs.pname}-${finalAttrs.version}-frontendAssets";
    inherit (finalAttrs) src version;

    packageJSON = "${finalAttrs.src}/web/source/package.json";
    yarnLock = "${finalAttrs.src}/web/source/yarn.lock";

    configurePhase = ''
      runHook preConfigure

      cp -r $node_modules node_modules
      chmod +w -R node_modules

      runHook postConfigure
    '';

    buildPhase = ''
      runHook preBuild

      mkdir -p ./web/source ./web/assets

      cp -r $src/web/source/. ./web/source
      cp -r $src/web/assets/. ./web/assets

      export NODE_OPTIONS=--openssl-legacy-provider
      node ./node_modules/ts-patch/bin/ts-patch.js install
      yarn --offline --cwd ./web/source build

      runHook postBuild
    '';

    distPhase = "true";
    installPhase = "cp -r ./web/assets $out";

    meta.license = lib.licenses.agpl3Only;
  };

  ldflags = [
    "-s"
    "-w"
    "-X 'main.Commit=${finalAttrs.rev}'"
    "-X 'main.Version=${finalAttrs.version}'"
  ];
  tags = [
    "netgo"
    "osusergo"
    "static_build"
    "kvformat"
  ];

  env.CGO_ENABLED = 0;

  vendorHash = null;

  nativeBuildInputs = [ installShellFiles ];
  buildInputs = [ makeWrapper ];

  # tests are working only on x86_64-linux
  # doCheck = stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isx86_64;
  # checks are currently very unstable in our setup, so we should test manually for now
  doCheck = false;

  checkFlags =
    let
      # flaky / broken tests
      skippedTests = [
        # See: https://github.com/superseriousbusiness/gotosocial/issues/2651
        "TestPage/minID,_maxID_and_limit_set"
      ];
    in
    [ "-skip=^${builtins.concatStringsSep "$|^" skippedTests}$" ];

  installCheckPhase = ''
    runHook preCheck

    $out/bin/gotosocial --help

    runHook postCheck
  '';

  postInstall = ''
    mkdir -p $out/share/${finalAttrs.pname}/web/{templates,assets}

    cp -r  ./web/template/.                $out/share/${finalAttrs.pname}/web/template/
    cp -rf ${finalAttrs.frontend-assets}/. $out/share/${finalAttrs.pname}/web/assets/

    installShellCompletion --cmd gotosocial \
      --bash <($out/bin/gotosocial completion bash) \
      --fish <($out/bin/gotosocial completion fish) \
      --zsh <($out/bin/gotosocial completion zsh)
  '';

  passthru.tests.gotosocial = nixosTests.gotosocial;

  meta = with lib; {
    mainProgram = "gotosocial";
    maintainers = [ tgcMaintainers.zaphyra ];
    license = licenses.agpl3Only;
    homepage = "https://gotosocial.org";
    changelog = "https://codeberg.org/superseriousbusiness/gotosocial/releases";
    description = "Fast, fun, ActivityPub server, powered by Go";
    longDescription = ''
      ActivityPub social network server, written in Golang.
      You can keep in touch with your friends, post, read, and
      share images and articles. All without being tracked or
      advertised to! A light-weight alternative to Mastodon
      and Pleroma, with support for clients!
    '';
  };

})