From 27424c4c882164e68ecdc66d6a80740b7738b61f Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Mon, 5 Aug 2024 18:31:34 +0300 Subject: [PATCH 1/5] pnpm_{8,9}.fetchDeps: put all pnpm install arguments in separate lines --- pkgs/development/tools/pnpm/fetch-deps/default.nix | 5 ++++- pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/pnpm/fetch-deps/default.nix b/pkgs/development/tools/pnpm/fetch-deps/default.nix index eb8b847960c5..17252c6cc043 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/default.nix +++ b/pkgs/development/tools/pnpm/fetch-deps/default.nix @@ -60,7 +60,10 @@ pnpm config set update-notifier false # pnpm is going to warn us about using --force # --force allows us to fetch all dependencies including ones that aren't meant for our host platform - pnpm install --frozen-lockfile --ignore-script --force + pnpm install \ + --force \ + --ignore-script \ + --frozen-lockfile runHook postInstall ''; diff --git a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh index fc0c47dbb70b..ba7b1b4094e8 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh +++ b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh @@ -24,7 +24,11 @@ pnpmConfigHook() { echo "Installing dependencies" - pnpm install --offline --frozen-lockfile --ignore-script + pnpm install \ + --offline \ + --ignore-script \ + --frozen-lockfile + echo "Patching scripts" From 7eaa7e82529cb727f67453feb26e8e460b8385aa Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Mon, 5 Aug 2024 18:32:27 +0300 Subject: [PATCH 2/5] pnpm_{8,9}.fetchDeps: fix --ignore-scripts argument Co-authored-by: Niklas Korz --- pkgs/development/tools/pnpm/fetch-deps/default.nix | 2 +- pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/development/tools/pnpm/fetch-deps/default.nix b/pkgs/development/tools/pnpm/fetch-deps/default.nix index 17252c6cc043..65dc7c9cf527 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/default.nix +++ b/pkgs/development/tools/pnpm/fetch-deps/default.nix @@ -62,7 +62,7 @@ # --force allows us to fetch all dependencies including ones that aren't meant for our host platform pnpm install \ --force \ - --ignore-script \ + --ignore-scripts \ --frozen-lockfile runHook postInstall diff --git a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh index ba7b1b4094e8..00172f840aef 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh +++ b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh @@ -26,7 +26,7 @@ pnpmConfigHook() { pnpm install \ --offline \ - --ignore-script \ + --ignore-scripts \ --frozen-lockfile From 875c9f044f4d9183933d72003987812e18ce3bc8 Mon Sep 17 00:00:00 2001 From: Pyrox Date: Sat, 29 Jun 2024 19:04:05 -0400 Subject: [PATCH 3/5] pnpm.fetchDeps: Add workspaces support and support for custom pnpm configuration commands Solves #316908 --- .../javascript.section.md | 55 ++++++++++++++++++- .../tools/pnpm/fetch-deps/default.nix | 6 ++ .../tools/pnpm/fetch-deps/pnpm-config-hook.sh | 6 ++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/doc/languages-frameworks/javascript.section.md b/doc/languages-frameworks/javascript.section.md index dbb0a78b2874..8eb3d1ff39a4 100644 --- a/doc/languages-frameworks/javascript.section.md +++ b/doc/languages-frameworks/javascript.section.md @@ -346,11 +346,11 @@ NOTE: It is highly recommended to use a pinned version of pnpm (i.e. `pnpm_8` or In case you are patching `package.json` or `pnpm-lock.yaml`, make sure to pass `finalAttrs.patches` to the function as well (i.e. `inherit (finalAttrs) patches`. +`pnpm.configHook` supports adding additional `pnpm install` flags via `pnpmInstallFlags` which can be set to a Nix string array. + #### Dealing with `sourceRoot` {#javascript-pnpm-sourceRoot} -NOTE: Nixpkgs pnpm tooling doesn't support building projects with a `pnpm-workspace.yaml`, or building monorepos. It maybe possible to use `pnpm.fetchDeps` for these projects, but it may be hard or impossible to produce a binary from such projects ([an example attempt](https://github.com/NixOS/nixpkgs/pull/290715#issuecomment-2144543728)). - -If the pnpm project is in a subdirectory, you can just define `sourceRoot` or `setSourceRoot` for `fetchDeps`. Note, that projects using `pnpm-workspace.yaml` are currently not supported, and will probably not work using this approach. +If the pnpm project is in a subdirectory, you can just define `sourceRoot` or `setSourceRoot` for `fetchDeps`. If `sourceRoot` is different between the parent derivation and `fetchDeps`, you will have to set `pnpmRoot` to effectively be the same location as it is in `fetchDeps`. Assuming the following directory structure, we can define `sourceRoot` and `pnpmRoot` as follows: @@ -375,6 +375,55 @@ Assuming the following directory structure, we can define `sourceRoot` and `pnpm pnpmRoot = "frontend"; ``` +#### PNPM Workspaces {#javascript-pnpm-workspaces} + +If you need to use a PNPM workspace for your project, then set `pnpmWorkspace = ""` in your `pnpm.fetchDeps` call, +which will make PNPM only install dependencies for that workspace package. + +For example: + +```nix +... +pnpmWorkspace = "@astrojs/language-server"; +pnpmDeps = pnpm.fetchDeps { + inherit (finalAttrs) pnpmWorkspace; + ... +} +``` + +The above would make `pnpm.fetchDeps` call only install dependencies for the `@astrojs/language-server` workspace package. +Note that you do not need to set `sourceRoot` to make this work. + +Usually in such cases, you'd want to use `pnpm --filter=$pnpmWorkspace build` to build your project, as `npmHooks.npmBuildHook` probably won't work. A `buildPhase` based on the following example will probably fit most workspace projects: + +```nix +buildPhase = '' + runHook preBuild + + pnpm --filter=@astrojs/language-server build + + runHook postBuild +''; +``` + +#### Additional PNPM Commands and settings {#javascript-pnpm-extraCommands} + +If you require setting an additional PNPM configuration setting (such as `dedupe-peer-dependents` or similar), +set `prePnpmInstall` to the right commands to run. For example: + +```nix +prePnpmInstall = '' + pnpm config set dedupe-peer-dependants false +''; +pnpmDeps = pnpm.fetchDeps { + inherit (finalAttrs) prePnpmInstall; + ... +}; +``` + +In this example, `prePnpmInstall` will be run by both `pnpm.configHook` and by the `pnpm.fetchDeps` builder. + + ### Yarn {#javascript-yarn} Yarn based projects use a `yarn.lock` file instead of a `package-lock.json` to pin dependencies. Nixpkgs provides the Nix function `fetchYarnDeps` which fetches an offline cache suitable for running `yarn install` before building the project. In addition, Nixpkgs provides the hooks: diff --git a/pkgs/development/tools/pnpm/fetch-deps/default.nix b/pkgs/development/tools/pnpm/fetch-deps/default.nix index 65dc7c9cf527..e5032da10590 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/default.nix +++ b/pkgs/development/tools/pnpm/fetch-deps/default.nix @@ -14,6 +14,8 @@ { hash ? "", pname, + pnpmWorkspace ? "", + prePnpmInstall ? "", ... }@args: let @@ -29,6 +31,7 @@ outputHash = ""; outputHashAlgo = "sha256"; }; + installFlags = lib.optionalString (pnpmWorkspace != "") "--filter=${pnpmWorkspace}"; in stdenvNoCC.mkDerivation (finalAttrs: ( args' @@ -58,11 +61,14 @@ pnpm config set side-effects-cache false # As we pin pnpm versions, we don't really care about updates pnpm config set update-notifier false + # Run any additional pnpm configuration commands that users provide. + ${prePnpmInstall} # pnpm is going to warn us about using --force # --force allows us to fetch all dependencies including ones that aren't meant for our host platform pnpm install \ --force \ --ignore-scripts \ + ${installFlags} \ --frozen-lockfile runHook postInstall diff --git a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh index 00172f840aef..e82a62f9101c 100644 --- a/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh +++ b/pkgs/development/tools/pnpm/fetch-deps/pnpm-config-hook.sh @@ -24,9 +24,15 @@ pnpmConfigHook() { echo "Installing dependencies" + if [[ -n "$pnpmWorkspace" ]]; then + pnpmInstallFlags+=("--filter=$pnpmWorkspace") + fi + runHook prePnpmInstall + pnpm install \ --offline \ --ignore-scripts \ + "${pnpmInstallFlags[@]}" \ --frozen-lockfile From a48987f2a3fbf604422334c6d1ea0c0b35c9061c Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Wed, 3 Jul 2024 20:47:15 +0300 Subject: [PATCH 4/5] bash-language-server: use pnpmWorkspace --- .../ba/bash-language-server/package.nix | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/pkgs/by-name/ba/bash-language-server/package.nix b/pkgs/by-name/ba/bash-language-server/package.nix index eb47dfdd9f6b..46fd2fe26608 100644 --- a/pkgs/by-name/ba/bash-language-server/package.nix +++ b/pkgs/by-name/ba/bash-language-server/package.nix @@ -3,7 +3,6 @@ , fetchFromGitHub , pnpm_8 , nodejs -, npmHooks , makeBinaryWrapper , shellcheck }: @@ -19,26 +18,23 @@ stdenv.mkDerivation (finalAttrs: { hash = "sha256-yJ81oGd9aNsWQMLvDSgMVVH1//Mw/SVFYFIPsJTQYzE="; }; + pnpmWorkspace = "bash-language-server"; pnpmDeps = pnpm_8.fetchDeps { - inherit (finalAttrs) pname version src; + inherit (finalAttrs) pname version src pnpmWorkspace; hash = "sha256-W25xehcxncBs9QgQBt17F5YHK0b+GDEmt27XzTkyYWg="; }; nativeBuildInputs = [ nodejs pnpm_8.configHook - npmHooks.npmBuildHook makeBinaryWrapper ]; - npmBuildScript = "compile"; - # We are only interested in the bash-language-server executable, which is - # part of the `./server` directory. From some reason, the `./vscode-client` - # directory is not included in upstream's `pnpm-workspace.yaml`, so perhaps - # that's why our ${pnpmDeps} don't include the dependencies required for it. - preBuild = '' - rm -r vscode-client - substituteInPlace tsconfig.json \ - --replace-fail '{ "path": "./vscode-client" },' "" + buildPhase = '' + runHook preBuild + + pnpm --filter=bash-language-server build + + runHook postBuild ''; installPhase = '' From d128948f8c908057d56078380c797df14b6c4237 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Wed, 3 Jul 2024 20:50:31 +0300 Subject: [PATCH 5/5] astro-language-server: init at 2.10.0 Close #309100 . Co-authored-by: Pyrox --- .../as/astro-language-server/package.nix | 69 +++++++++++++++++++ pkgs/development/node-packages/aliases.nix | 1 + .../node-packages/main-programs.nix | 1 - .../node-packages/node-packages.json | 1 - 4 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 pkgs/by-name/as/astro-language-server/package.nix diff --git a/pkgs/by-name/as/astro-language-server/package.nix b/pkgs/by-name/as/astro-language-server/package.nix new file mode 100644 index 000000000000..9859765bf897 --- /dev/null +++ b/pkgs/by-name/as/astro-language-server/package.nix @@ -0,0 +1,69 @@ +{ + lib, + stdenv, + fetchFromGitHub, + pnpm_8, + nodejs_22, +}: + +stdenv.mkDerivation (finalAttrs: { + pname = "astro-language-server"; + version = "2.10.0"; + + src = fetchFromGitHub { + owner = "withastro"; + repo = "language-tools"; + rev = "@astrojs/language-server@${finalAttrs.version}"; + hash = "sha256-WdeQQaC9AVHT+/pXLzaC6MZ6ddHsFSpxoDPHqWvqmiQ="; + }; + + pnpmDeps = pnpm_8.fetchDeps { + inherit (finalAttrs) + pname + version + src + pnpmWorkspace + prePnpmInstall + ; + hash = "sha256-n7HTd/rKxJdQKnty5TeOcyvBU9j/EClQ9IHqbBaEwQE="; + }; + + nativeBuildInputs = [ + nodejs_22 + pnpm_8.configHook + ]; + + buildInputs = [ nodejs_22 ]; + + pnpmWorkspace = "@astrojs/language-server"; + prePnpmInstall = '' + pnpm config set dedupe-peer-dependents false + ''; + + buildPhase = '' + runHook preBuild + + pnpm --filter=@astrojs/language-server build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir -p $out/{bin,lib/astro-language-server} + cp -r {packages,node_modules} $out/lib/astro-language-server + ln -s $out/lib/astro-language-server/packages/language-server/bin/nodeServer.js $out/bin/astro-ls + + runHook postInstall + ''; + + meta = { + description = "The Astro language server"; + homepage = "https://github.com/withastro/language-tools"; + license = lib.licenses.mit; + maintainers = with lib.maintainers; [ pyrox0 ]; + mainProgram = "astro-ls"; + platforms = lib.platforms.unix; + }; +}) diff --git a/pkgs/development/node-packages/aliases.nix b/pkgs/development/node-packages/aliases.nix index 5bbe69039d84..2c59d8a07d76 100644 --- a/pkgs/development/node-packages/aliases.nix +++ b/pkgs/development/node-packages/aliases.nix @@ -37,6 +37,7 @@ in mapAliases { "@antora/cli" = pkgs.antora; # Added 2023-05-06 + "@astrojs/language-server" = pkgs.astro-language-server; # Added 2024-02-12 "@bitwarden/cli" = pkgs.bitwarden-cli; # added 2023-07-25 "@emacs-eask/cli" = pkgs.eask; # added 2023-08-17 "@forge/cli" = throw "@forge/cli was removed because it was broken"; # added 2023-09-20 diff --git a/pkgs/development/node-packages/main-programs.nix b/pkgs/development/node-packages/main-programs.nix index 92b2d2271c70..b2425ac52962 100644 --- a/pkgs/development/node-packages/main-programs.nix +++ b/pkgs/development/node-packages/main-programs.nix @@ -8,7 +8,6 @@ # Packages that provide a single executable. "@angular/cli" = "ng"; - "@astrojs/language-server" = "astro-ls"; "@babel/cli" = "babel"; "@commitlint/cli" = "commitlint"; "@gitbeaker/cli" = "gitbeaker"; diff --git a/pkgs/development/node-packages/node-packages.json b/pkgs/development/node-packages/node-packages.json index 4a23f5a83649..654694325bd6 100644 --- a/pkgs/development/node-packages/node-packages.json +++ b/pkgs/development/node-packages/node-packages.json @@ -1,7 +1,6 @@ [ "@angular/cli" , "@antfu/ni" -, "@astrojs/language-server" , "@babel/cli" , "@commitlint/cli" , "@commitlint/config-conventional"