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 " ;
2024-10-11 05:15:48 +00:00
version = " 2 0 2 4 . 1 0 . 0 " ;
2024-09-19 14:19:46 +00:00
src = fetchFromGitHub {
owner = " m i s s k e y - d e v " ;
repo = finalAttrs . pname ;
rev = finalAttrs . version ;
2024-10-11 05:15:48 +00:00
hash = " s h a 2 5 6 - c Q 8 J Q n n a S 6 a X 2 w Z d n i m T z n H j 2 0 h J e 0 C J 4 N E S y b C k 9 C U = " ;
2024-09-19 14:19:46 +00:00
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 ;
2024-10-23 06:41:50 +00:00
hash = " s h a 2 5 6 - o H 4 r a w + z I Q K Y + m y d t e K k Y 0 L q W + 1 3 u 1 4 0 8 i b m 3 0 j 1 W s s = " ;
2024-09-19 14:19:46 +00: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 " 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 " ;
} ;
} )