about summary refs log tree commit diff
path: root/pkgs/servers/monitoring/karma/default.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/servers/monitoring/karma/default.nix')
-rw-r--r--pkgs/servers/monitoring/karma/default.nix56
1 files changed, 19 insertions, 37 deletions
diff --git a/pkgs/servers/monitoring/karma/default.nix b/pkgs/servers/monitoring/karma/default.nix
index 416e388d8f493..e176a692780dd 100644
--- a/pkgs/servers/monitoring/karma/default.nix
+++ b/pkgs/servers/monitoring/karma/default.nix
@@ -1,22 +1,13 @@
-{ pkgs
-, lib
+{ lib
 , stdenv
 , buildGoModule
-, callPackage
 , fetchFromGitHub
+, fetchNpmDeps
 , nixosTests
-, nodejs_18
+, nodejs
+, npmHooks
 }:
 
-let
-  uiNodeDependencies = (import ./node-composition.nix {
-    inherit pkgs;
-    inherit (stdenv.hostPlatform) system;
-    # pin nodejs version
-    nodejs = nodejs_18;
-   }).nodeDependencies;
-in
-
 buildGoModule rec {
   pname = "karma";
   version = "0.114";
@@ -30,10 +21,22 @@ buildGoModule rec {
 
   vendorHash = "sha256-ZsXPA4KyKbc/bwkidyHNDg62mE8KlE+yIssOBZLmHVg=";
 
+  npmDeps = fetchNpmDeps {
+    src = "${src}/ui";
+    hash = "sha256-gxsq+wwD+fUACkC07DWeVkvVtipZkEcPIR5RcPsPato=";
+  };
+
+  npmRoot = "ui";
+
   nativeBuildInputs = [
-    nodejs_18
+    nodejs
+    npmHooks.npmConfigHook
   ];
 
+  overrideModAttrs = oldAttrs: {
+    nativeBuildInputs = lib.filter (drv: drv != npmHooks.npmConfigHook) oldAttrs.nativeBuildInputs;
+  };
+
   postPatch = ''
     # Since we're using node2nix packages, the NODE_INSTALL hook isn't needed in the makefile
     sed -i \
@@ -43,32 +46,11 @@ buildGoModule rec {
   '';
 
   buildPhase = ''
-    # node will fail without this
-    export HOME=$(mktemp -d)
-
-    # build requires a writable .cache directory, so we'll create a
-    # temporary writable node_modules dir and link every package to it
-
-    # simply linking the node_modules directory would increase the closure size for uiNodeDependencies to >700MB
-    cp -r ${uiNodeDependencies}/lib/node_modules ./ui/
-    chmod -R +w ./ui/node_modules
-    mkdir -p ./ui/node_modules/.bin
-
-    pushd ./ui/node_modules/.bin
-
-    for x in ${uiNodeDependencies}/lib/node_modules/.bin/*; do
-      ln -sfv ./$(readlink "$x") ./$(basename "$x")
-    done
-
-    popd
-
-    mkdir -p ./ui/node_modules/.cache
+    runHook preBuild
 
-    # build package
     VERSION="v${version}" make -j$NIX_BUILD_CORES
 
-    # clean up
-    rm -rf ./ui/node_modules
+    runHook postBuild
   '';
 
   installPhase = ''