zaphyra's git: nixfiles

zaphyra's nixfiles

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 
{
  unstable,
  lib,
  fetchFromGitea,
  applyPatches,
  fetchYarnDeps,
  nodejs,
  yarn,
  yarnConfigHook,
  makeWrapper,
  installShellFiles,
  nixosTests,
  ...
}:

unstable.buildGoModule (finalAttrs: {
  pname = "gotosocial";
  version = "0.22.0-unstable-2026-06-18-${builtins.substring 0 6 finalAttrs.rev}";
  rev = "c53f27bc1ceb246ade3494190cd7b3e253d6375d";
  srcHash = "sha256-sSL0VKTn6uDjrkS/fKbTXvaDWxlzh7D74HV469ZD3sI=";

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

  buildInputs = [ makeWrapper ];
  nativeBuildInputs = [
    nodejs
    yarn
    yarnConfigHook
    installShellFiles
  ];

  yarnOfflineCache = fetchYarnDeps {
    yarnLock = "${finalAttrs.src}/web/source/yarn.lock";
    hash = "sha256-rfZxslIEoOTufENIvk8Eq5wzdD3rUpUP3wrMjmLH44k=";
  };

  # manually calling yarnConfigHook in sub-directory
  dontYarnInstallDeps = true;

  postConfigure = ''
    pushd ./web/source
    runHook yarnConfigHook
    popd
  '';

  # preparing assets
  # https://codeberg.org/superseriousbusiness/gotosocial/src/branch/main/.goreleaser.yml#L12
  preBuild = ''
    go run ./vendor/github.com/go-swagger/go-swagger/cmd/swagger generate spec --scan-models --exclude-deps -o web/assets/swagger.yaml
    substituteInPlace web/assets/swagger.yaml --replace-fail "REPLACE_ME" "${finalAttrs.version}"
    yarn --offline --cwd ./web/source ts-patch install
    yarn --offline --cwd ./web/source build
    ./scripts/bundle_licenses.sh
  '';

  postInstall = ''
    mkdir -p $out/share/gotosocial/web
    mv web/{assets,template} $out/share/gotosocial/web

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

  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;

  # 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
  '';

  passthru.tests.gotosocial = nixosTests.gotosocial;

  meta = with lib; {
    mainProgram = "gotosocial";
    maintainers = with lib.maintainers; [ 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!
    '';
  };

})