{ lib, namespace, nodejs, stdenv, }: let inherit (lib.trivial) importJSON; inherit (lib.${namespace}) mkAllSources selectVariant; versionSpec = importJSON ./version.json; selected = selectVariant versionSpec null null; sources = mkAllSources selected; inherit (selected.variables) version; in stdenv.mkDerivation { pname = "cockpit-machines"; inherit version; src = sources.src; # Pre-vendored node_modules from cockpit-project/node-cache, pinned via the # node_modules submodule reference in the source tree. inherit (sources) nodeModules; # pkg/lib checked out from the main cockpit repo at the commit pinned in # the Makefile (COCKPIT_REPO_COMMIT). inherit (sources) cockpitLib; nativeBuildInputs = [ nodejs ]; # passthru.cockpitPath is used by the NixOS cockpit module to add runtime # dependencies to the cockpit service's PATH. passthru.cockpitPath = [ ]; configurePhase = '' runHook preConfigure # Replace the empty git submodule placeholder with the real vendored modules. # Use dotglob so hidden entries (.bin, .package-lock.json, etc.) are included. rm -rf node_modules mkdir node_modules (shopt -s dotglob; cp -r $nodeModules/* node_modules/) chmod -R u+w node_modules # Node needs package-lock.json at the project root to resolve modules. cp node_modules/.package-lock.json package-lock.json # Wire up pkg/lib from the pinned cockpit repo. mkdir -p pkg cp -r $cockpitLib/pkg/lib pkg/lib chmod -R u+w pkg runHook postConfigure ''; buildPhase = '' runHook preBuild NODE_ENV=production node build.js runHook postBuild ''; installPhase = '' runHook preInstall mkdir -p $out/share/cockpit/machines cp -r dist/* $out/share/cockpit/machines/ runHook postInstall ''; meta = { description = "Cockpit UI for virtual machines (libvirt/KVM)"; homepage = "https://github.com/cockpit-project/cockpit-machines"; changelog = "https://github.com/cockpit-project/cockpit-machines/releases/tag/${version}"; license = lib.licenses.lgpl21Plus; platforms = lib.platforms.linux; maintainers = [ ]; }; }