mastodon: build nodejs modules with fetchYarnDeps

This commit is contained in:
Izorkin 2022-03-20 22:18:19 +03:00 committed by Kerstin
parent 9046ecff84
commit 04efb0c252
7 changed files with 33 additions and 12972 deletions

View file

@ -1,5 +1,6 @@
{ lib, stdenv, nodejs-slim, mkYarnPackage, fetchFromGitHub, fetchpatch, bundlerEnv, nixosTests
, yarn, callPackage, imagemagick, ffmpeg, file, ruby_3_0, writeShellScript
, fetchYarnDeps, fixup_yarn_lock
# Allow building a fork or custom version of Mastodon:
, pname ? "mastodon"
@ -23,6 +24,11 @@ stdenv.mkDerivation rec {
})
];
yarnOfflineCache = fetchYarnDeps {
yarnLock = "${src}/yarn.lock";
sha256 = "sha256-Z+nFMJcC2f+nDUxa2vPYnNezMLBGXfLdh+xMXPHqYyw=";
};
mastodon-gems = bundlerEnv {
name = "${pname}-gems-${version}";
inherit version;
@ -43,55 +49,43 @@ stdenv.mkDerivation rec {
'';
};
mastodon-js-modules = mkYarnPackage {
mastodon-modules = stdenv.mkDerivation {
pname = "${pname}-modules";
yarnNix = dependenciesDir + "/yarn.nix";
packageJSON = dependenciesDir + "/package.json";
inherit src version;
};
mastodon-assets = stdenv.mkDerivation {
pname = "${pname}-assets";
inherit src version;
buildInputs = [
mastodon-gems nodejs-slim yarn
];
nativeBuildInputs = [ fixup_yarn_lock mastodon-gems nodejs-slim yarn ];
# FIXME: "production" would require OTP_SECRET to be set, so we use
# development here.
RAILS_ENV = "development";
RAILS_ENV = "production";
NODE_ENV = "production";
buildPhase = ''
# Support Mastodon forks which don't call themselves 'mastodon' or which
# omit the organization name from package.json.
if [ "$(ls ${mastodon-js-modules}/libexec/* | grep node_modules)" ]; then
cp -r ${mastodon-js-modules}/libexec/*/node_modules node_modules
else
cp -r ${mastodon-js-modules}/libexec/*/*/node_modules node_modules
fi
chmod -R u+w node_modules
rake webpacker:compile
rails assets:precompile
export HOME=$PWD
fixup_yarn_lock ~/yarn.lock
yarn config --offline set yarn-offline-mirror ${yarnOfflineCache}
yarn install --offline --frozen-lockfile --ignore-engines --ignore-scripts --no-progress
patchShebangs ~/node_modules
OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder \
rails assets:precompile
yarn cache clean --offline
rm -rf ~/node_modules/.cache
'';
installPhase = ''
mkdir -p $out/public
cp -r node_modules $out/node_modules
cp -r public/assets $out/public
cp -r public/packs $out/public
'';
};
passthru.updateScript = callPackage ./update.nix {};
propagatedBuildInputs = [ imagemagick ffmpeg file mastodon-gems.wrappedRuby ];
buildInputs = [ mastodon-gems nodejs-slim ];
buildPhase = ''
if [ "$(ls ${mastodon-js-modules}/libexec/* | grep node_modules)" ]; then
ln -s ${mastodon-js-modules}/libexec/*/node_modules node_modules
else
ln -s ${mastodon-js-modules}/libexec/*/*/node_modules node_modules
fi
ln -s ${mastodon-assets}/public/assets public/assets
ln -s ${mastodon-assets}/public/packs public/packs
ln -s ${mastodon-modules}/node_modules node_modules
ln -s ${mastodon-modules}/public/assets public/assets
ln -s ${mastodon-modules}/public/packs public/packs
patchShebangs bin/
for b in $(ls ${mastodon-gems}/bin/)
@ -106,8 +100,6 @@ stdenv.mkDerivation rec {
ln -s /tmp tmp
'';
propagatedBuildInputs = [ imagemagick ffmpeg file mastodon-gems.wrappedRuby ];
installPhase = let
run-streaming = writeShellScript "run-streaming.sh" ''
# NixOS helper script to consistently use the same NodeJS version the package was built with.
@ -119,13 +111,16 @@ stdenv.mkDerivation rec {
ln -s ${run-streaming} $out/run-streaming.sh
'';
passthru.tests.mastodon = nixosTests.mastodon;
passthru = {
tests.mastodon = nixosTests.mastodon;
updateScript = callPackage ./update.nix {};
};
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; [ petabyteboy happy-river erictapen ];
maintainers = with maintainers; [ petabyteboy happy-river erictapen izorkin ];
};
}

View file

@ -1,197 +0,0 @@
{
"version": "3.4.6",
"name": "@mastodon/mastodon",
"license": "AGPL-3.0-or-later",
"engines": {
"node": ">=12"
},
"scripts": {
"postversion": "git push --tags",
"build:development": "cross-env RAILS_ENV=development NODE_ENV=development ./bin/webpack",
"build:production": "cross-env RAILS_ENV=production NODE_ENV=production ./bin/webpack",
"manage:translations": "node ./config/webpack/translationRunner.js",
"start": "node ./streaming/index.js",
"test": "${npm_execpath} run test:lint:js && ${npm_execpath} run test:jest",
"test:lint": "${npm_execpath} run test:lint:js && ${npm_execpath} run test:lint:sass",
"test:lint:js": "eslint --ext=js . --cache",
"test:lint:sass": "sass-lint -v",
"test:jest": "cross-env NODE_ENV=test jest --coverage"
},
"repository": {
"type": "git",
"url": "https://github.com/mastodon/mastodon.git"
},
"browserslist": [
"last 2 versions",
"not IE 11",
"iOS >= 9",
"not dead"
],
"jest": {
"projects": [
"<rootDir>/app/javascript/mastodon"
],
"testPathIgnorePatterns": [
"<rootDir>/node_modules/",
"<rootDir>/vendor/",
"<rootDir>/config/",
"<rootDir>/log/",
"<rootDir>/public/",
"<rootDir>/tmp/"
],
"setupFiles": [
"raf/polyfill"
],
"setupFilesAfterEnv": [
"<rootDir>/app/javascript/mastodon/test_setup.js"
],
"collectCoverageFrom": [
"app/javascript/mastodon/**/*.js",
"!app/javascript/mastodon/features/emoji/emoji_compressed.js",
"!app/javascript/mastodon/locales/locale-data/*.js",
"!app/javascript/mastodon/service_worker/entry.js",
"!app/javascript/mastodon/test_setup.js"
],
"coverageDirectory": "<rootDir>/coverage",
"moduleDirectories": [
"<rootDir>/node_modules",
"<rootDir>/app/javascript"
]
},
"private": true,
"dependencies": {
"@babel/core": "^7.14.3",
"@babel/plugin-proposal-decorators": "^7.14.2",
"@babel/plugin-transform-react-inline-elements": "^7.12.13",
"@babel/plugin-transform-runtime": "^7.14.3",
"@babel/preset-env": "^7.14.4",
"@babel/preset-react": "^7.13.13",
"@babel/runtime": "^7.14.0",
"@gamestdio/websocket": "^0.3.2",
"@github/webauthn-json": "^0.5.7",
"@rails/ujs": "^6.1.3",
"array-includes": "^3.1.3",
"arrow-key-navigation": "^1.2.0",
"autoprefixer": "^9.8.6",
"axios": "^0.21.1",
"babel-loader": "^8.2.2",
"babel-plugin-lodash": "^3.3.4",
"babel-plugin-preval": "^5.0.0",
"babel-plugin-react-intl": "^6.2.0",
"babel-plugin-transform-react-remove-prop-types": "^0.4.24",
"babel-runtime": "^6.26.0",
"blurhash": "^1.1.3",
"classnames": "^2.3.1",
"color-blend": "^3.0.1",
"compression-webpack-plugin": "^6.1.1",
"cross-env": "^7.0.3",
"css-loader": "^5.2.6",
"cssnano": "^4.1.11",
"detect-passive-events": "^2.0.3",
"dotenv": "^9.0.2",
"emoji-mart": "^3.0.1",
"es6-symbol": "^3.1.3",
"escape-html": "^1.0.3",
"exif-js": "^2.3.0",
"express": "^4.17.1",
"file-loader": "^6.2.0",
"font-awesome": "^4.7.0",
"glob": "^7.1.7",
"history": "^4.10.1",
"http-link-header": "^1.0.3",
"immutable": "^3.8.2",
"imports-loader": "^1.2.0",
"intersection-observer": "^0.12.0",
"intl": "^1.2.5",
"intl-messageformat": "^2.2.0",
"intl-relativeformat": "^6.4.3",
"is-nan": "^1.3.2",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"mark-loader": "^0.1.6",
"marky": "^1.2.2",
"mini-css-extract-plugin": "^1.6.0",
"mkdirp": "^1.0.4",
"npmlog": "^4.1.2",
"object-assign": "^4.1.1",
"object-fit-images": "^3.2.3",
"object.values": "^1.1.3",
"offline-plugin": "^5.0.7",
"path-complete-extname": "^1.0.0",
"pg": "^8.5.0",
"postcss-loader": "^3.0.0",
"postcss-object-fit-images": "^1.1.2",
"promise.prototype.finally": "^3.1.2",
"prop-types": "^15.5.10",
"punycode": "^2.1.0",
"react": "^16.14.0",
"react-dom": "^16.14.0",
"react-hotkeys": "^1.1.4",
"react-immutable-proptypes": "^2.2.0",
"react-immutable-pure-component": "^2.2.2",
"react-intl": "^2.9.0",
"react-masonry-infinite": "^1.2.2",
"react-motion": "^0.5.2",
"react-notification": "^6.8.5",
"react-overlays": "^0.9.3",
"react-redux": "^7.2.4",
"react-redux-loading-bar": "^4.0.8",
"react-router-dom": "^4.1.1",
"react-router-scroll-4": "^1.0.0-beta.1",
"react-select": "^4.3.1",
"react-sparklines": "^1.7.0",
"react-swipeable-views": "^0.14.0",
"react-textarea-autosize": "^8.3.2",
"react-toggle": "^4.1.2",
"redis": "^3.1.2",
"redux": "^4.1.0",
"redux-immutable": "^4.0.0",
"redux-thunk": "^2.2.0",
"regenerator-runtime": "^0.13.7",
"rellax": "^1.12.1",
"requestidlecallback": "^0.3.0",
"reselect": "^4.0.0",
"rimraf": "^3.0.2",
"sass": "^1.34.0",
"sass-loader": "^10.2.0",
"stacktrace-js": "^2.0.2",
"stringz": "^2.1.0",
"substring-trie": "^1.0.2",
"terser-webpack-plugin": "^4.2.3",
"tesseract.js": "^2.1.1",
"throng": "^4.0.0",
"tiny-queue": "^0.2.1",
"twitter-text": "3.1.0",
"uuid": "^8.3.1",
"webpack": "^4.46.0",
"webpack-assets-manifest": "^4.0.6",
"webpack-bundle-analyzer": "^4.4.2",
"webpack-cli": "^3.3.12",
"webpack-merge": "^5.7.3",
"wicg-inert": "^3.1.1",
"ws": "^7.4.6",
"kind-of": "^6.0.3"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.7",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.0.2",
"eslint": "^7.27.0",
"eslint-plugin-import": "~2.23.4",
"eslint-plugin-jsx-a11y": "~6.4.1",
"eslint-plugin-promise": "~5.1.0",
"eslint-plugin-react": "~7.24.0",
"jest": "^26.6.3",
"raf": "^3.4.1",
"react-intl-translations-manager": "^5.0.3",
"react-test-renderer": "^16.14.0",
"sass-lint": "^1.13.1",
"webpack-dev-server": "^3.11.2",
"yargs": "^17.0.1"
},
"optionalDependencies": {
"bufferutil": "^4.0.3",
"utf-8-validate": "^5.0.5"
}
}

View file

@ -1,68 +0,0 @@
diff --git a/package.json b/package.json
index f485b1370..ce8e42699 100644
--- a/package.json
+++ b/package.json
@@ -168,7 +168,8 @@
"webpack-cli": "^3.3.12",
"webpack-merge": "^5.7.3",
"wicg-inert": "^3.1.1",
- "ws": "^7.4.6"
+ "ws": "^7.4.6",
+ "kind-of": "^6.0.3"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.12.0",
@@ -188,9 +189,6 @@
"webpack-dev-server": "^3.11.2",
"yargs": "^17.0.1"
},
- "resolutions": {
- "kind-of": "^6.0.3"
- },
"optionalDependencies": {
"bufferutil": "^4.0.3",
"utf-8-validate": "^5.0.5"
diff --git a/yarn.lock b/yarn.lock
index b8ea0f369..32e929c0d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5939,6 +5939,11 @@ is-boolean-object@^1.1.0:
dependencies:
call-bind "^1.0.2"
+is-buffer@^1.1.5:
+ version "1.1.6"
+ resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
+ integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==
+
is-callable@^1.1.4, is-callable@^1.2.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/is-callable/-/is-callable-1.2.2.tgz#c7c6715cd22d4ddb48d3e19970223aceabb080d9"
@@ -6971,7 +6976,26 @@ killable@^1.0.1:
resolved "https://registry.yarnpkg.com/killable/-/killable-1.0.1.tgz#4c8ce441187a061c7474fb87ca08e2a638194892"
integrity sha512-LzqtLKlUwirEUyl/nicirVmNiPvYs7l5n8wOPP7fyJVpUPkvCnW/vuiXGpylGUlnPDnB7311rARzAt3Mhswpjg==
-kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0, kind-of@^4.0.0, kind-of@^5.0.0, kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3:
+kind-of@^3.0.2, kind-of@^3.0.3, kind-of@^3.2.0:
+ version "3.2.2"
+ resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64"
+ integrity sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=
+ dependencies:
+ is-buffer "^1.1.5"
+
+kind-of@^4.0.0:
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-4.0.0.tgz#20813df3d712928b207378691a45066fae72dd57"
+ integrity sha1-IIE989cSkosgc3hpGkUGb65y3Vc=
+ dependencies:
+ is-buffer "^1.1.5"
+
+kind-of@^5.0.0:
+ version "5.1.0"
+ resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-5.1.0.tgz#729c91e2d857b7a419a1f9aa65685c4c33f5845d"
+ integrity sha512-NGEErnH6F2vUuXDh+OlbcKW7/wOcfdRHaZ7VWtqCztfHri/++YKmP51OdWeGPuqCOba6kk2OTe5d02VmTB80Pw==
+
+kind-of@^6.0.0, kind-of@^6.0.2, kind-of@^6.0.3:
version "6.0.3"
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==

View file

@ -7,5 +7,5 @@
};
in applyPatches {
inherit src;
patches = [./resolutions.patch ./version.patch ];
patches = [ ];
}

View file

@ -50,7 +50,7 @@ if [[ -z "$REVISION" ]]; then
REVISION="$VERSION"
fi
rm -f gemset.nix yarn.nix version.nix version.patch source.nix package.json
rm -f gemset.nix version.nix source.nix
TARGET_DIR="$PWD"
@ -78,21 +78,6 @@ FETCHED_SOURCE_DIR=$(grep '^path is' $WORK_DIR/nix-prefetch-git.out | sed 's/^pa
echo "Creating version.nix"
echo \"$VERSION\" | sed 's/^"v/"/' > version.nix
echo "Creating source.nix"
# yarn2nix and mkYarnPackage want the version to be present in
# package.json. Mastodon itself does not include the version in
# package.json but at least one fork (Soapbox) does.
if [ $(jq .version $FETCHED_SOURCE_DIR/package.json) == "null" ]; then
mkdir $WORK_DIR/a $WORK_DIR/b
cp $FETCHED_SOURCE_DIR/package.json $WORK_DIR/a
cd $WORK_DIR
jq "{version:$(cat $TARGET_DIR/version.nix)} + ." a/package.json > b/package.json
diff -Naur --label a/package.json --label b/package.json a b > $TARGET_DIR/version.patch || true
rm -rf a b tmp
cd $TARGET_DIR
PATCHES="$PATCHES ./version.patch "
fi
cat > source.nix << EOF
# This file was generated by pkgs.mastodon.updateScript.
{ fetchgit, applyPatches }: let
@ -111,11 +96,3 @@ SOURCE_DIR="$(nix-build --no-out-link -E '(import <nixpkgs> {}).callPackage ./so
echo "Creating gemset.nix"
bundix --lockfile="$SOURCE_DIR/Gemfile.lock" --gemfile="$SOURCE_DIR/Gemfile"
echo "" >> $TARGET_DIR/gemset.nix # Create trailing newline to please EditorConfig checks
echo "Creating yarn.nix"
cp -r $SOURCE_DIR/* $WORK_DIR
chmod -R u+w $WORK_DIR
cd $WORK_DIR
yarn2nix > $TARGET_DIR/yarn.nix
sed "s/https___.*_//g" -i $TARGET_DIR/yarn.nix
cp $WORK_DIR/package.json $TARGET_DIR

View file

@ -1,9 +0,0 @@
diff -Naur --label a/package.json --label b/package.json a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -1,4 +1,5 @@
{
+ "version": "3.4.6",
"name": "@mastodon/mastodon",
"license": "AGPL-3.0-or-later",
"engines": {

File diff suppressed because it is too large Load diff