about summary refs log tree commit diff
path: root/nixpkgs/pkgs/tools/audio/botamusique/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/tools/audio/botamusique/default.nix')
-rw-r--r--nixpkgs/pkgs/tools/audio/botamusique/default.nix75
1 files changed, 34 insertions, 41 deletions
diff --git a/nixpkgs/pkgs/tools/audio/botamusique/default.nix b/nixpkgs/pkgs/tools/audio/botamusique/default.nix
index 249e9629a6f1..5eaaa9c873e3 100644
--- a/nixpkgs/pkgs/tools/audio/botamusique/default.nix
+++ b/nixpkgs/pkgs/tools/audio/botamusique/default.nix
@@ -1,31 +1,24 @@
-{ pkgs
-, lib
+{ lib
 , stdenv
 , fetchFromGitHub
+, fetchpatch
 , 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_x;
-  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 +26,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
@@ -57,6 +54,11 @@ stdenv.mkDerivation rec {
     # We can't update the package at runtime with NixOS, so this patch makes
     # the !update command mention that
     ./no-runtime-update.patch
+
+    # Fix passing of invalid "git" version into version.parse, which results
+    # in an InvalidVersion exception. The upstream fix is insufficient, so
+    # we carry the correct patch downstream for now.
+    ./catch-invalid-versions.patch
   ];
 
   postPatch = ''
@@ -64,12 +66,16 @@ stdenv.mkDerivation rec {
     # configuration.default.ini, which is in the installation directory
     # after all. So we need to counter-patch it here so it can find it absolutely
     substituteInPlace mumbleBot.py \
-      --replace "configuration.default.ini" "$out/share/botamusique/configuration.default.ini"
+      --replace "configuration.default.ini" "$out/share/botamusique/configuration.default.ini" \
+      --replace "version = 'git'" "version = '${version}'"
   '';
 
+  NODE_OPTIONS = "--openssl-legacy-provider";
+
   nativeBuildInputs = [
     makeWrapper
     nodejs
+    npmHooks.npmConfigHook
     python3Packages.wrapPython
   ];
 
@@ -91,9 +97,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 +121,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 = {