Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ npmConfigHook() {
export NIX_NODEJS_BUILDNPMPACKAGE=1
export prefetchNpmDeps="@prefetchNpmDeps@"

if [ -n "${npmRoot-}" ]; then
pushd "$npmRoot"
fi

echo "Configuring npm"

export HOME="$TMPDIR"
Expand Down Expand Up @@ -105,6 +109,10 @@ npmConfigHook() {
rm "$CACHE_MAP_PATH"
unset CACHE_MAP_PATH

if [ -n "${npmRoot-}" ]; then
popd
fi

echo "Finished npmConfigHook"
}

Expand Down
66 changes: 26 additions & 40 deletions pkgs/tools/audio/botamusique/default.nix
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
{ 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";
repo = "botamusique";
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
Expand All @@ -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
];

Expand All @@ -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
)

Expand All @@ -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 = {
Expand Down
Loading