botamusique: move to fetchNpmDeps

This commit is contained in:
ajs124 2023-05-05 12:47:55 +02:00 committed by Lily Foster
parent 9117f01272
commit a8c39f772b
No known key found for this signature in database
GPG key ID: 49340081E484C893
3 changed files with 28 additions and 5278 deletions

View file

@ -1,31 +1,23 @@
{ pkgs
, lib
{ lib
, stdenv
, fetchFromGitHub
, python3Packages
, ffmpeg
, makeWrapper
, nixosTests
, nodejs
, npmHooks
, fetchNpmDeps
# For the update script
, coreutils
, curl
, nix-prefetch-git
, prefetch-npm-deps
, jq
, nodePackages
, writeShellScript
}:
let
nodejs = pkgs.nodejs_14;
nodeEnv = import ../../../development/node-packages/node-env.nix {
inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript;
inherit pkgs nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
botamusiqueNodePackages = import ./node-packages.nix {
inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
inherit nodeEnv;
};
srcJson = lib.importJSON ./src.json;
src = fetchFromGitHub {
owner = "azlux";
@ -33,19 +25,23 @@ let
inherit (srcJson) rev sha256;
};
nodeDependencies = (botamusiqueNodePackages.shell.override (old: {
src = src + "/web";
})).nodeDependencies;
# Python needed to instantiate the html templates
buildPython = python3Packages.python.withPackages (ps: [ ps.jinja2 ]);
in
stdenv.mkDerivation rec {
pname = "botamusique";
version = srcJson.version;
inherit src;
npmDeps = fetchNpmDeps {
src = "${src}/web";
hash = srcJson.npmDepsHash;
};
npmRoot = "web";
patches = [
# botamusique by default resolves relative state paths by first checking
# whether it exists in the working directory, then falls back to using the
@ -67,9 +63,12 @@ stdenv.mkDerivation rec {
--replace "configuration.default.ini" "$out/share/botamusique/configuration.default.ini"
'';
NODE_OPTIONS = "--openssl-legacy-provider";
nativeBuildInputs = [
makeWrapper
nodejs
npmHooks.npmConfigHook
python3Packages.wrapPython
];
@ -91,9 +90,6 @@ stdenv.mkDerivation rec {
# Generates artifacts in ./static
(
cd web
ln -s ${nodeDependencies}/lib/node_modules ./node_modules
export PATH="${nodeDependencies}/bin:$PATH"
npm run build
)
@ -118,36 +114,26 @@ stdenv.mkDerivation rec {
runHook postInstall
'';
passthru.updateScript = pkgs.writeShellScript "botamusique-updater" ''
export PATH=${lib.makeBinPath [ coreutils curl nix-prefetch-git jq nodePackages.node2nix ]}
passthru.updateScript = writeShellScript "botamusique-updater" ''
export PATH=${lib.makeBinPath [ coreutils curl nix-prefetch-git jq prefetch-npm-deps ]}
set -ex
OWNER=azlux
REPO=botamusique
VERSION=$(curl https://api.github.com/repos/$OWNER/$REPO/releases/latest | jq -r '.tag_name')
VERSION="$(curl https://api.github.com/repos/$OWNER/$REPO/releases/latest | jq -r '.tag_name')"
nix-prefetch-git --rev "$VERSION" --url https://github.com/$OWNER/$REPO | \
jq > ${toString ./src.json } \
jq > "${toString ./src.json}" \
--arg version "$VERSION" \
'.version |= $version'
path=$(jq '.path' -r < ${toString ./src.json})
path="$(jq '.path' -r < "${toString ./src.json}")"
tmp=$(mktemp -d)
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' exit
# botamusique doesn't have a version in its package.json
# But that's needed for node2nix
jq < "$path"/web/package.json > "$tmp/package.json" \
--arg version "$VERSION" \
'.version |= $version'
node2nix \
--input "$tmp"/package.json \
--lock "$path"/web/package-lock.json \
--no-copy-node-env \
--development \
--composition /dev/null \
--output ${toString ./node-packages.nix}
npmHash="$(prefetch-npm-deps $path/web/package-lock.json)"
jq '. + { npmDepsHash: "'"$npmHash"'" }' < "${toString ./src.json}" > "$tmp/src.json"
mv "$tmp/src.json" "${toString ./src.json}"
'';
passthru.tests = {

File diff suppressed because it is too large Load diff

View file

@ -8,5 +8,6 @@
"fetchSubmodules": false,
"deepClone": false,
"leaveDotGit": false,
"version": "7.2.2"
"version": "7.2.2",
"npmDepsHash": "sha256-IzEO7TFqIZUkhNGf0pnHbK/WFexF27RPD9lkYvmFmDw="
}