update glitch

This commit is contained in:
Vivian 2024-06-01 21:01:24 +02:00
parent 87ffa71fe4
commit 045c0ed739
8 changed files with 704 additions and 540 deletions

View file

@ -1,63 +1,81 @@
/*
Copied from nixpkgs upstream:
https://github.com/NixOS/nixpkgs/blob/nixos-23.11/pkgs/servers/mastodon/default.nix
Modifications for new yarn lockfiles stolen (with permission) from:
https://git.catgirl.cloud/999eagle/dotfiles-nix/-/blob/main/overlay/mastodon/glitch/yarn.nix
*/
{ lib, stdenv, nodejs-slim, bundlerEnv, nixosTests
{ lib, stdenv, stdenvNoCC, nodejs-slim, bundlerEnv
, yarn-berry, callPackage, imagemagick, ffmpeg, file, ruby, writeShellScript
, brotli
# Allow building a fork or custom version of Mastodon:
, pname ? "mastodon"
, version ? srcOverride.version
, patches ? []
# src is a package
, srcOverride ? callPackage ./source.nix { inherit patches; }
, gemset ? ./. + "/gemset.nix"
, yarnHash ? srcOverride.yarnHash
, brotli, cacert
}:
stdenv.mkDerivation rec {
inherit pname version;
let
src = srcOverride;
# optimally, updates only need to touch `version_data.nix`, and nothing else should be in there
versionData = import ./version_data.nix;
# use the first 7 characters of the glitch-soc commit hash as version string
version = builtins.substring 0 7 versionData.rev;
# the patched glitch-soc source
src = callPackage ./source.nix { };
# ruby gems, built from `gemset.nix`, which is generated by bundix in `update.sh` from the source Gemfile
mastodonGems = bundlerEnv {
name = "${pname}-gems-${version}";
inherit version gemset ruby;
name = "glitch-soc-gems-${version}"; # bundlerEnv breaks when pname is set instead
inherit version ruby;
gemset = ./gemset.nix;
gemdir = src;
# This fix (copied from https://github.com/NixOS/nixpkgs/pull/76765) replaces the gem
# symlinks with directories, resolving this error when running rake:
# /nix/store/451rhxkggw53h7253izpbq55nrhs7iv0-mastodon-gems-3.0.1/lib/ruby/gems/2.6.0/gems/bundler-1.17.3/lib/bundler/settings.rb:6:in `<module:Bundler>': uninitialized constant Bundler::Settings (NameError)
postBuild = ''
for gem in "$out"/lib/ruby/gems/*/gems/*; do
cp -a "$gem/" "$gem.new"
rm "$gem"
# needed on macOS, otherwise the mv yields permission denied
chmod +w "$gem.new"
mv "$gem.new" "$gem"
done
'';
};
# fetches JS dependencies via yarn based on the lockfile in the source
mastodonYarnDeps = stdenvNoCC.mkDerivation {
pname = "glitch-soc-yarn-deps";
inherit version src;
nativeBuildInputs = [ yarn-berry cacert ];
dontInstall = true;
NODE_EXTRA_CA_CERTS = "${cacert}/etc/ssl/certs/ca-bundle.crt";
buildPhase = ''
mkdir -p $out
export HOME=$(mktemp -d)
echo $HOME
export YARN_ENABLE_TELEMETRY=0
export YARN_COMPRESSION_LEVEL=0
cache="$(yarn config get cacheFolder)"
yarn install --immutable --mode skip-build
cp -r $cache/* $out/
'';
outputHashAlgo = "sha256";
outputHash = versionData.yarnHash;
outputHashMode = "recursive";
};
# builds the node modules for mastodon using the previously fetched yarn deps
mastodonModules = stdenv.mkDerivation {
pname = "${pname}-modules";
inherit src version;
pname = "glitch-soc-modules";
inherit version src;
# use the fixed yarn berry offline cache thingy
yarnOfflineCache = callPackage ./yarn.nix {
inherit src;
hash = yarnHash;
};
yarnOfflineCache = mastodonYarnDeps;
nativeBuildInputs = [ nodejs-slim yarn-berry mastodonGems mastodonGems.wrappedRuby brotli ];
nativeBuildInputs = [ nodejs-slim yarn-berry brotli mastodonGems mastodonGems.wrappedRuby ];
RAILS_ENV = "production";
NODE_ENV = "production";
/*
So it seems that somehow a change in Linux 6.9 changed something that broke libuv, an IO lib
used by Node. This undocumented env var disables the broken IO feature in libuv and it works
again.
- https://lore.kernel.org/lkml/d7003b6e-b8e3-41c4-9e6e-2b9abd0c5572@gmail.com/t/
- https://github.com/nodejs/node/issues/53051#issuecomment-2124940205
- https://github.com/nodejs/docker-node/issues/1912#issuecomment-1594233686
*/
UV_USE_IO_URING = "0";
buildPhase = ''
runHook preBuild
@ -70,7 +88,8 @@ stdenv.mkDerivation rec {
mkdir -p ~/.yarn/berry
ln -sf $yarnOfflineCache ~/.yarn/berry/cache
yarn install --immutable --immutable-cache
# --inline-builds prints build logs inline so they can be inspected with nix log
yarn install --immutable --immutable-cache --inline-builds
patchShebangs ~/bin
patchShebangs ~/node_modules
@ -78,8 +97,13 @@ stdenv.mkDerivation rec {
# skip running yarn install
rm -rf ~/bin/yarn
OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder \
OTP_SECRET=precompile_placeholder \
SECRET_KEY_BASE=precompile_placeholder \
ACTIVE_RECORD_ENCRYPTION_DETERMINISTIC_KEY=precompile_placeholder \
ACTIVE_RECORD_ENCRYPTION_KEY_DERIVATION_SALT=precompile_placeholder \
ACTIVE_RECORD_ENCRYPTION_PRIMARY_KEY=precompile_placeholder \
rails assets:precompile
yarn cache clean
rm -rf ~/node_modules/.cache
@ -107,7 +131,15 @@ stdenv.mkDerivation rec {
'';
};
propagatedBuildInputs = [ imagemagick ffmpeg file mastodonGems.wrappedRuby ];
# the actual main glitch-soc package
in stdenv.mkDerivation {
pname = "glitch-soc";
inherit version src mastodonGems mastodonModules;
propagatedBuildInputs = [ mastodonGems.wrappedRuby ];
nativeBuildInputs = [ brotli ];
buildInputs = [ mastodonGems nodejs-slim ];
buildPhase = ''
@ -164,17 +196,4 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
passthru = {
tests.mastodon = nixosTests.mastodon;
# run with: nix-shell ./maintainers/scripts/update.nix --argstr package mastodon
updateScript = ./update.sh;
};
meta = with lib; {
description = "Self-hosted, globally interconnected microblogging software based on ActivityPub";
homepage = "https://joinmastodon.org";
license = licenses.agpl3Plus;
platforms = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
maintainers = with maintainers; [ happy-river erictapen izorkin ghuntley ];
};
}