about summary refs log tree commit diff stats
path: root/pkgs/by-name/sh/sharkey/unstable_package.nix
blob: a88b7df6767562413fb95943a9c0f52d1e67db73 (plain) (blame)
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Source: https://github.com/sodiboo/system/blob/b63c7b27f49043e8701b3ff5e1441cd27d5a2fff/sharkey/package.nix
{
  lib,
  stdenv,
  fetchFromGitLab,
  # Build time
  makeWrapper,
  copyDesktopItems,
  jq,
  moreutils,
  cacert,
  python3,
  pkg-config,
  # Run time
  bash,
  jemalloc,
  ffmpeg-headless,
  nodejs,
  pnpm_9,
  glib,
  vips,
  pixman,
  pango,
  cairo,
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "sharkey";
  version = "2025.2.3";

  src = fetchFromGitLab {
    owner = "TransFem-org";
    repo = "Sharkey";
    domain = "activitypub.software";
    rev = finalAttrs.version;
    hash = "sha256-VBfkJuoQzQ93sUmJNnr1JUjA2GQNgOIuX+j8nAz3bb4=";
    fetchSubmodules = true;
  };

  pnpmDeps = stdenv.mkDerivation {
    pname = "${finalAttrs.pname}-pnpm-deps";
    inherit (finalAttrs) src version;

    nativeBuildInputs = [
      jq
      moreutils
      pnpm_9
      cacert
    ];

    # https://github.com/NixOS/nixpkgs/blob/763e59ffedb5c25774387bf99bc725df5df82d10/pkgs/applications/misc/pot/default.nix#L56
    installPhase = ''
      export HOME=$(mktemp --directory)

      pnpm config set store-dir $out
      pnpm config set side-effects-cache false
      pnpm install --force --frozen-lockfile --ignore-scripts
    '';

    fixupPhase = ''
      rm --recursive --force $out/v3/tmp
      for f in $(find $out -name "*.json"); do
        sed --in-place --regexp-extended --expression='s/"checkedAt":[0-9]+,//g' "$f"
        jq --sort-keys . "$f" | sponge "$f"
      done
    '';

    dontBuild = true;
    outputHashMode = "recursive";
    outputHash = "sha256-ALstAaN8dr5qSnc/ly0hv+oaeKrYFQ3GhObYXOv4E6I=";
  };

  nativeBuildInputs = [
    copyDesktopItems
    pnpm_9
    nodejs
    makeWrapper
    python3
    pkg-config
  ];

  buildInputs = [
    glib
    vips

    pixman
    pango
    cairo
  ];

  configurePhase = ''
    runHook preConfigure

    export HOME=$(mktemp --directory)
    export STORE_PATH=$(mktemp --directory)

    export npm_config_nodedir=${nodejs}

    cp --no-target-directory --recursive "$pnpmDeps" "$STORE_PATH"
    chmod --recursive +w "$STORE_PATH"

    pnpm config set store-dir "$STORE_PATH"
    pnpm install --offline --frozen-lockfile --ignore-scripts

    (
      cd node_modules/.pnpm/node_modules/v-code-diff
      pnpm run postinstall
    )
    (
      cd node_modules/.pnpm/node_modules/re2
      pnpm run rebuild
    )
    (
      cd node_modules/.pnpm/node_modules/sharp
      pnpm run install
    )
    (
      cd node_modules/.pnpm/node_modules/canvas
      pnpm run install
    )

    runHook postConfigure
  '';

  buildPhase = ''
    runHook preBuild

    pnpm build

    runHook postBuild
  '';

  installPhase = let
    libPath = lib.makeLibraryPath [
      jemalloc
      ffmpeg-headless
      stdenv.cc.cc.lib
    ];

    binPath = lib.makeBinPath [
      bash
      pnpm_9
      nodejs
    ];
  in
    # bash
    ''
      runHook preInstall

      mkdir --parents $out/Sharkey

      ln --symbolic /var/lib/sharkey $out/Sharkey/files
      ln --symbolic /run/sharkey $out/Sharkey/.config
      cp --recursive * $out/Sharkey

      # We cannot `--set` the PATH, because sharkey runs shellscripts at start (and maybe
      # at other times), which need these things.
      makeWrapper ${lib.getExe pnpm_9} $out/bin/sharkey \
        --chdir $out/Sharkey \
        --prefix PATH : ${binPath} \
        --prefix LD_LIBRARY_PATH : ${libPath}

      runHook postInstall
    '';

  passthru = {
    inherit (finalAttrs) pnpmDeps;
  };

  meta = {
    description = "🌎 A Sharkish microblogging platform 🚀";
    homepage = "https://joinsharkey.org";
    license = lib.licenses.gpl3Only;
    platforms = ["x86_64-linux" "aarch64-linux"];
    mainProgram = "sharkey";
  };
})