2024-09-19 14:19:46 +00:00
{
stdenv ,
lib ,
nixosTests ,
fetchFromGitHub ,
nodejs ,
pnpm ,
makeWrapper ,
python3 ,
bash ,
jemalloc ,
ffmpeg-headless ,
writeShellScript ,
2024-10-04 16:56:33 +00:00
xcbuild ,
2024-09-19 14:19:46 +00:00
. . .
} :
stdenv . mkDerivation ( finalAttrs : {
pname = " m i s s k e y " ;
version = " 2 0 2 4 . 5 . 0 " ;
src = fetchFromGitHub {
owner = " m i s s k e y - d e v " ;
repo = finalAttrs . pname ;
rev = finalAttrs . version ;
hash = " s h a 2 5 6 - n K f + S f u F 6 M Q t N O 5 3 E 6 v N 9 C M D v Q z K M v 3 P r D 6 g s 9 Q a 8 6 w = " ;
fetchSubmodules = true ;
} ;
nativeBuildInputs = [
nodejs
pnpm . configHook
makeWrapper
python3
2024-10-04 16:56:33 +00:00
] ++ lib . optionals stdenv . isDarwin [ xcbuild . xcrun ] ;
2024-09-19 14:19:46 +00:00
# https://nixos.org/manual/nixpkgs/unstable/#javascript-pnpm
pnpmDeps = pnpm . fetchDeps {
inherit ( finalAttrs ) pname version src ;
hash = " s h a 2 5 6 - A 1 J B L a 6 l I w 5 t X F u D 2 L 3 v v k H 6 p H S 5 r l w t 8 v U 2 + U U Q Y d g = " ;
} ;
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 " m i s s 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/misskey-dev/misskey/blob/9849aab40283cbde2184e74d4795aec8ef8ccba3/packages/backend/src/core/InternalStorageService.ts#L18
# Otherwise, maybe somehow bindmount a writable directory into <package>/data/files.
ln - s /var/lib/misskey $ out/data/files
makeWrapper $ { pnpm } /bin/pnpm $ out/bin/misskey \
- - 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 . lib
]
}
runHook postInstall
'' ;
passthru = {
inherit ( finalAttrs ) pnpmDeps ;
tests . misskey = nixosTests . misskey ;
} ;
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 : / / m i s s k e y - h u b . n e t / " ;
license = lib . licenses . agpl3Only ;
maintainers = [ lib . maintainers . feathecutie ] ;
platforms = lib . platforms . unix ;
mainProgram = " m i s s k e y " ;
} ;
} )