2024-12-05 12:31:58 +02:00
{
stdenv ,
lib ,
nixosTests ,
fetchFromGitHub ,
nodejs ,
pnpm ,
makeWrapper ,
python3 ,
bash ,
jemalloc ,
ffmpeg-headless ,
writeShellScript ,
xcbuild ,
. . .
} :
stdenv . mkDerivation ( finalAttrs : {
pname = " s h a r k e y " ;
version = " 2 0 2 4 . 1 0 . 0 " ;
src = fetchGit {
url = " h t t p s : / / a c t i v i t y p u b . s o f t w a r e / T r a n s F e m - o r g / S h a r k e y . g i t " ;
rev = " 1 5 0 d 9 4 9 a 3 e c 2 b 5 1 6 2 e 2 d f d a 1 0 c 2 c c 5 d d d e a 8 c 5 9 a " ;
submodules = true ;
} ;
nativeBuildInputs = [
nodejs
pnpm . configHook
makeWrapper
python3
] ++ lib . optionals stdenv . hostPlatform . isDarwin [ xcbuild . xcrun ] ;
# https://nixos.org/manual/nixpkgs/unstable/#javascript-pnpm
pnpmDeps = pnpm . fetchDeps {
inherit ( finalAttrs ) pname version src ;
2025-05-10 15:14:30 +03:00
hash = " s h a 2 5 6 - y m H P z o U 5 / 0 R L 1 Z 0 v 5 M V D u n F C s F U 1 c 6 u z K K 5 w u s a b Z + E = " ;
2024-12-05 12:31:58 +02:00
} ;
buildPhase = ''
runHook preBuild
# https://github.com/NixOS/nixpkgs/pull/296697/files#r1617546739
(
cd node_modules/.pnpm/node_modules/v-code-diff
pnpm run postinstall
)
# https://github.com/NixOS/nixpkgs/pull/296697/files#r1617595593
export npm_config_nodedir = $ { nodejs }
(
cd node_modules/.pnpm/node_modules/re2
pnpm run rebuild
)
(
cd node_modules/.pnpm/node_modules/sharp
pnpm run install
)
pnpm build
runHook postBuild
'' ;
installPhase =
let
checkEnvVarScript = writeShellScript " s h a r k e y - c h e c k - e n v - v a r " ''
if [ [ - z $ MISSKEY_CONFIG_YML ] ] ; then
echo " M I S S K E Y _ C O N F I G _ Y M L m u s t b e s e t t o t h e l o c a t i o n o f t h e M i s s k e y c o n f i g f i l e . "
exit 1
fi
'' ;
in
''
runHook preInstall
mkdir - p $ out/data
cp - r . $ out/data
# Set up symlink for use at runtime
# TODO: Find a better solution for this (potentially patch Misskey to make this configurable?)
# Line that would need to be patched: https://github.com/sharkey-dev/sharkey/blob/9849aab40283cbde2184e74d4795aec8ef8ccba3/packages/backend/src/core/InternalStorageService.ts#L18
# Otherwise, maybe somehow bindmount a writable directory into <package>/data/files.
ln - s /var/lib/sharkey $ out/data/files
makeWrapper $ { pnpm } /bin/pnpm $ out/bin/sharkey \
- - run " ${ checkEnvVarScript } | | e x i t " \
- - chdir $ out/data \
- - add-flags run \
- - set-default NODE_ENV production \
- - prefix PATH : $ {
lib . makeBinPath [
nodejs
pnpm
bash
]
} \
- - prefix LD_LIBRARY_PATH : $ {
lib . makeLibraryPath [
jemalloc
ffmpeg-headless
stdenv . cc . cc
]
}
runHook postInstall
'' ;
passthru = {
inherit ( finalAttrs ) pnpmDeps ;
tests . sharkey = nixosTests . sharkey ;
} ;
meta = {
description = " 🌎 A n i n t e r p l a n e t a r y m i c r o b l o g g i n g p l a t f o r m 🚀 " ;
homepage = " h t t p s : / / s h a r k e y - h u b . n e t / " ;
license = lib . licenses . agpl3Only ;
maintainers = [ lib . maintainers . feathecutie ] ;
platforms = lib . platforms . unix ;
mainProgram = " s h a r k e y " ;
} ;
} )