diff --git a/pkgs/servers/mastodon/default.nix b/pkgs/servers/mastodon/default.nix index d75e148bf1e3..31a092359cfc 100644 --- a/pkgs/servers/mastodon/default.nix +++ b/pkgs/servers/mastodon/default.nix @@ -1,29 +1,27 @@ -{ lib, stdenv, nodejs-slim, mkYarnPackage, fetchFromGitHub, bundlerEnv, nixosTests +{ lib, stdenv, nodejs-slim, bundlerEnv, nixosTests , yarn, callPackage, imagemagick, ffmpeg, file, ruby_3_0, writeShellScript , fetchYarnDeps, fixup_yarn_lock , brotli # Allow building a fork or custom version of Mastodon: , pname ? "mastodon" -, version ? import ./version.nix -, srcOverride ? null -, dependenciesDir ? ./. # Expected to contain gemset.nix -, yarnHash ? import ./yarn-hash.nix +, version ? srcOverride.version + # src is a package +, srcOverride ? callPackage ./source.nix {} +, gemset ? ./. + "/gemset.nix" +, yarnHash ? srcOverride.yarnHash }: stdenv.mkDerivation rec { inherit pname version; - # Using overrideAttrs on src does not build the gems and modules with the overridden src. - # Putting the callPackage up in the arguments list also does not work. - src = if srcOverride != null then srcOverride else callPackage ./source.nix {}; + src = srcOverride; mastodonGems = bundlerEnv { name = "${pname}-gems-${version}"; - inherit version; + inherit version gemset; ruby = ruby_3_0; gemdir = src; - gemset = dependenciesDir + "/gemset.nix"; # 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 `': uninitialized constant Bundler::Settings (NameError) diff --git a/pkgs/servers/mastodon/source.nix b/pkgs/servers/mastodon/source.nix index db090f192740..995b58476d78 100644 --- a/pkgs/servers/mastodon/source.nix +++ b/pkgs/servers/mastodon/source.nix @@ -1,12 +1,16 @@ # This file was generated by pkgs.mastodon.updateScript. -{ fetchFromGitHub, applyPatches }: let +{ fetchFromGitHub, applyPatches }: +let + version = "4.1.9"; +in +applyPatches { + inherit version; src = fetchFromGitHub { owner = "mastodon"; repo = "mastodon"; - rev = "v4.1.9"; + rev = "${version}"; hash = "sha256-xpE/mg2AeioW6NThUjLS+SBxGavG4w1xtp3BOMADfYo="; }; -in applyPatches { - inherit src; patches = []; + yarnHash = "sha256-e3rl/WuKXaUdeDEYvo1sSubuIwtBjkbguCYdAijwXOA="; } diff --git a/pkgs/servers/mastodon/update.sh b/pkgs/servers/mastodon/update.sh index 78a67e95cad9..6955f9e61805 100755 --- a/pkgs/servers/mastodon/update.sh +++ b/pkgs/servers/mastodon/update.sh @@ -56,7 +56,7 @@ if [[ -z "$REVISION" ]]; then VERSION="$(echo "$REVISION" | cut -c2-)" fi -rm -f gemset.nix version.nix source.nix +rm -f gemset.nix source.nix cd "$(dirname "${BASH_SOURCE[0]}")" || exit 1 WORK_DIR=$(mktemp -d) @@ -77,23 +77,24 @@ trap cleanup EXIT echo "Fetching source code $REVISION" JSON=$(nix-prefetch-github "$OWNER" "$REPO" --rev "$REVISION" 2> $WORK_DIR/nix-prefetch-git.out) -HASH="$(echo "$JSON" | jq -r .hash)" - -echo "Creating version.nix" -echo "\"$VERSION\"" | sed 's/^"v/"/' > version.nix +HASH=$(echo "$JSON" | jq -r .hash) cat > source.nix << EOF # This file was generated by pkgs.mastodon.updateScript. -{ fetchFromGitHub, applyPatches }: let +{ fetchFromGitHub, applyPatches }: +let + version = "$VERSION"; +in +applyPatches { + inherit version; src = fetchFromGitHub { owner = "$OWNER"; repo = "$REPO"; - rev = "$REVISION"; + rev = "\${version}"; hash = "$HASH"; }; -in applyPatches { - inherit src; patches = [$PATCHES]; + yarnHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="; } EOF SOURCE_DIR="$(nix-build --no-out-link -E '(import {}).callPackage ./source.nix {}')" @@ -105,4 +106,4 @@ echo "" >> gemset.nix # Create trailing newline to please EditorConfig checks echo "Creating yarn-hash.nix" YARN_HASH="$(prefetch-yarn-deps "$SOURCE_DIR/yarn.lock")" YARN_HASH="$(nix hash to-sri --type sha256 "$YARN_HASH")" -printf '"%s"\n' "$YARN_HASH" > yarn-hash.nix +sed -i "s/sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/$YARN_HASH/g" source.nix diff --git a/pkgs/servers/mastodon/version.nix b/pkgs/servers/mastodon/version.nix deleted file mode 100644 index 2647b9c70ad8..000000000000 --- a/pkgs/servers/mastodon/version.nix +++ /dev/null @@ -1 +0,0 @@ -"4.1.9" diff --git a/pkgs/servers/mastodon/yarn-hash.nix b/pkgs/servers/mastodon/yarn-hash.nix deleted file mode 100644 index f0e3e8a27af7..000000000000 --- a/pkgs/servers/mastodon/yarn-hash.nix +++ /dev/null @@ -1 +0,0 @@ -"sha256-e3rl/WuKXaUdeDEYvo1sSubuIwtBjkbguCYdAijwXOA="