From 70ae16e6bff005ab5ab40090a0dae4b92fad6a57 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Sat, 15 Mar 2025 16:11:45 +0530 Subject: [PATCH 1/3] buildNpmPackage: restructure with lib.extendMkDerivation This allows using finalAttrs pattern. --- .../node/build-npm-package/default.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkgs/build-support/node/build-npm-package/default.nix b/pkgs/build-support/node/build-npm-package/default.nix index cef4de9f98f7c..6e31d2536e15c 100644 --- a/pkgs/build-support/node/build-npm-package/default.nix +++ b/pkgs/build-support/node/build-npm-package/default.nix @@ -7,6 +7,11 @@ cctools, }@topLevelArgs: +lib.extendMkDerivation { + constructDrv = stdenv.mkDerivation; + + extendDrvArgs = + finalAttrs: { name ? "${args.pname}-${args.version}", src ? null, @@ -77,9 +82,7 @@ let inherit nodejs; }; in -stdenv.mkDerivation ( - args - // { +{ inherit npmDeps npmBuildScript; nativeBuildInputs = @@ -103,5 +106,5 @@ stdenv.mkDerivation ( meta = (args.meta or { }) // { platforms = args.meta.platforms or nodejs.meta.platforms; }; - } -) + }; +} From e6ca2b65cae19e23191213efc04b6341d61947f6 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Sat, 15 Mar 2025 16:12:31 +0530 Subject: [PATCH 2/3] buildNpmPackage: nixfmt --- .../node/build-npm-package/default.nix | 178 +++++++++--------- 1 file changed, 89 insertions(+), 89 deletions(-) diff --git a/pkgs/build-support/node/build-npm-package/default.nix b/pkgs/build-support/node/build-npm-package/default.nix index 6e31d2536e15c..747043e3d12a9 100644 --- a/pkgs/build-support/node/build-npm-package/default.nix +++ b/pkgs/build-support/node/build-npm-package/default.nix @@ -12,99 +12,99 @@ lib.extendMkDerivation { extendDrvArgs = finalAttrs: -{ - name ? "${args.pname}-${args.version}", - src ? null, - srcs ? null, - sourceRoot ? null, - prePatch ? "", - patches ? [ ], - postPatch ? "", - patchFlags ? [ ], - nativeBuildInputs ? [ ], - buildInputs ? [ ], - # The output hash of the dependencies for this project. - # Can be calculated in advance with prefetch-npm-deps. - npmDepsHash ? "", - # Whether to force the usage of Git dependencies that have install scripts, but not a lockfile. - # Use with care. - forceGitDeps ? false, - # Whether to force allow an empty dependency cache. - # This can be enabled if there are truly no remote dependencies, but generally an empty cache indicates something is wrong. - forceEmptyCache ? false, - # Whether to make the cache writable prior to installing dependencies. - # Don't set this unless npm tries to write to the cache directory, as it can slow down the build. - makeCacheWritable ? false, - # The script to run to build the project. - npmBuildScript ? "build", - # Flags to pass to all npm commands. - npmFlags ? [ ], - # Flags to pass to `npm ci`. - npmInstallFlags ? [ ], - # Flags to pass to `npm rebuild`. - npmRebuildFlags ? [ ], - # Flags to pass to `npm run ${npmBuildScript}`. - npmBuildFlags ? [ ], - # Flags to pass to `npm pack`. - npmPackFlags ? [ ], - # Flags to pass to `npm prune`. - npmPruneFlags ? npmInstallFlags, - # Value for npm `--workspace` flag and directory in which the files to be installed are found. - npmWorkspace ? null, - nodejs ? topLevelArgs.nodejs, - npmDeps ? fetchNpmDeps { - inherit - forceGitDeps - forceEmptyCache - src - srcs - sourceRoot - prePatch - patches - postPatch - patchFlags - ; - name = "${name}-npm-deps"; - hash = npmDepsHash; - }, - # Custom npmConfigHook - npmConfigHook ? null, - # Custom npmBuildHook - npmBuildHook ? null, - # Custom npmInstallHook - npmInstallHook ? null, - ... -}@args: + { + name ? "${args.pname}-${args.version}", + src ? null, + srcs ? null, + sourceRoot ? null, + prePatch ? "", + patches ? [ ], + postPatch ? "", + patchFlags ? [ ], + nativeBuildInputs ? [ ], + buildInputs ? [ ], + # The output hash of the dependencies for this project. + # Can be calculated in advance with prefetch-npm-deps. + npmDepsHash ? "", + # Whether to force the usage of Git dependencies that have install scripts, but not a lockfile. + # Use with care. + forceGitDeps ? false, + # Whether to force allow an empty dependency cache. + # This can be enabled if there are truly no remote dependencies, but generally an empty cache indicates something is wrong. + forceEmptyCache ? false, + # Whether to make the cache writable prior to installing dependencies. + # Don't set this unless npm tries to write to the cache directory, as it can slow down the build. + makeCacheWritable ? false, + # The script to run to build the project. + npmBuildScript ? "build", + # Flags to pass to all npm commands. + npmFlags ? [ ], + # Flags to pass to `npm ci`. + npmInstallFlags ? [ ], + # Flags to pass to `npm rebuild`. + npmRebuildFlags ? [ ], + # Flags to pass to `npm run ${npmBuildScript}`. + npmBuildFlags ? [ ], + # Flags to pass to `npm pack`. + npmPackFlags ? [ ], + # Flags to pass to `npm prune`. + npmPruneFlags ? npmInstallFlags, + # Value for npm `--workspace` flag and directory in which the files to be installed are found. + npmWorkspace ? null, + nodejs ? topLevelArgs.nodejs, + npmDeps ? fetchNpmDeps { + inherit + forceGitDeps + forceEmptyCache + src + srcs + sourceRoot + prePatch + patches + postPatch + patchFlags + ; + name = "${name}-npm-deps"; + hash = npmDepsHash; + }, + # Custom npmConfigHook + npmConfigHook ? null, + # Custom npmBuildHook + npmBuildHook ? null, + # Custom npmInstallHook + npmInstallHook ? null, + ... + }@args: -let - # .override {} negates splicing, so we need to use buildPackages explicitly - npmHooks = buildPackages.npmHooks.override { - inherit nodejs; - }; -in -{ - inherit npmDeps npmBuildScript; + let + # .override {} negates splicing, so we need to use buildPackages explicitly + npmHooks = buildPackages.npmHooks.override { + inherit nodejs; + }; + in + { + inherit npmDeps npmBuildScript; - nativeBuildInputs = - nativeBuildInputs - ++ [ - nodejs - # Prefer passed hooks - (if npmConfigHook != null then npmConfigHook else npmHooks.npmConfigHook) - (if npmBuildHook != null then npmBuildHook else npmHooks.npmBuildHook) - (if npmInstallHook != null then npmInstallHook else npmHooks.npmInstallHook) - nodejs.python - ] - ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; - buildInputs = buildInputs ++ [ nodejs ]; + nativeBuildInputs = + nativeBuildInputs + ++ [ + nodejs + # Prefer passed hooks + (if npmConfigHook != null then npmConfigHook else npmHooks.npmConfigHook) + (if npmBuildHook != null then npmBuildHook else npmHooks.npmBuildHook) + (if npmInstallHook != null then npmInstallHook else npmHooks.npmInstallHook) + nodejs.python + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ cctools ]; + buildInputs = buildInputs ++ [ nodejs ]; - strictDeps = true; + strictDeps = true; - # Stripping takes way too long with the amount of files required by a typical Node.js project. - dontStrip = args.dontStrip or true; + # Stripping takes way too long with the amount of files required by a typical Node.js project. + dontStrip = args.dontStrip or true; - meta = (args.meta or { }) // { - platforms = args.meta.platforms or nodejs.meta.platforms; + meta = (args.meta or { }) // { + platforms = args.meta.platforms or nodejs.meta.platforms; + }; }; - }; } From 43bf9e325cd1599d88740e4f52f476cf7afad366 Mon Sep 17 00:00:00 2001 From: John Titor <50095635+JohnRTitor@users.noreply.github.com> Date: Sat, 15 Mar 2025 16:12:08 +0530 Subject: [PATCH 3/3] ags_1: move to finalAttrs --- pkgs/by-name/ag/ags_1/package.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/ag/ags_1/package.nix b/pkgs/by-name/ag/ags_1/package.nix index 09efa681b42ab..21d9ccf648946 100644 --- a/pkgs/by-name/ag/ags_1/package.nix +++ b/pkgs/by-name/ag/ags_1/package.nix @@ -20,14 +20,14 @@ nix-update-script, }: -buildNpmPackage rec { +buildNpmPackage (finalAttrs: { pname = "ags"; version = "1.8.2"; src = fetchFromGitHub { owner = "Aylur"; repo = "ags"; - rev = "v${version}"; + rev = "v${finalAttrs.version}"; hash = "sha256-ebnkUaee/pnfmw1KmOZj+MP1g5wA+8BT/TPKmn4Dkwc="; fetchSubmodules = true; }; @@ -68,7 +68,7 @@ buildNpmPackage rec { meta = { homepage = "https://github.com/Aylur/ags"; description = "EWW-inspired widget system as a GJS library"; - changelog = "https://github.com/Aylur/ags/releases/tag/v${version}"; + changelog = "https://github.com/Aylur/ags/releases/tag/v${finalAttrs.version}"; license = lib.licenses.gpl3Plus; maintainers = with lib.maintainers; [ foo-dogsquared @@ -77,4 +77,4 @@ buildNpmPackage rec { mainProgram = "ags"; platforms = lib.platforms.linux; }; -} +})