Skip to content

Conversation

@S0AndS0
Copy link
Member

@S0AndS0 S0AndS0 commented Sep 14, 2025

Main intent is to provide Prettier plugins for PR #442463 to consume.

Prettier provides, at time of this commit, four official plugins. And there are about two dozen community plugins available too.

So it seems wise to leverage existing code, where possible, and follow examples provided by similar NPM projects that have been packaged with plugins.

Much of these changes are based on examples found from;

  • ./pkgs/by-name/le/lessc/plugins/
  • ./pkgs/development/node-packages/

... as well as documentation provided in;

  • ./doc/languages-frameworks/javascript.section.md

Most of the changes from above references are under;

  • ./pkgs/by-name/pr/prettier/plugins/aliases.nix, within the mapAliases call near end of file
  • ./pkgs/by-name/pr/prettier/plugins/node-packages.json, which lists NPM package names
  • ./pkgs/by-name/pr/prettier/package.nix, which updates doc-comment and adds passthru.plugins

... Other files were either copy/pasted, and slightly modified, or generated via the ./pkgs/by-name/pr/prettier/plugins/generate.sh script.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Tested basic functionality of all Prettier plugins
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.


Edit 2025-09-14 16:41 UTC

Not sure what should be done about the linter error;

  • pkgs/by-name/pr/prettier: File plugins/composition.nix at line 4 contains the nix search path expression "" which may point outside the directory of that package.

... because the plugins/composition.nix file's first line clearly states # This file has been generated by node2nix 1.11.1. Do not edit!, so manually fixing things are likely to be undone by next person (or myself) who updates plugins via the generate.sh script.

The plugins/default.nix is passing/forwarding the attrs in, so manually removing the ? ... stuff shouldn't break anything.

Main intent is to provide Prettier plugins for PR NixOS#442463 to consume.

Prettier provides, at time of this commit, four
[official](https://prettier.io/docs/plugins/#official-plugins)
plugins.  And there are about two dozen
[community](https://prettier.io/docs/plugins/#community-plugins) plugins
available too.

So it seems wise to leverage existing code, where possible, and follow
examples provided by similar NPM projects that have been packaged with
plugins.

Much of these changes are based on examples found from;

- `./pkgs/by-name/le/lessc/plugins/`
- `./pkgs/development/node-packages/`

...  as well as documentation provided in;

- `./doc/languages-frameworks/javascript.section.md`
This _should_ be the final, for now, officially supported plugin from
Prettier to be added via this patch-set.
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Sep 14, 2025
⚠️ this will be a source of future maintenance friction.
@nixpkgs-ci nixpkgs-ci bot added the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Sep 14, 2025
@oneingan oneingan requested a review from l0b0 October 31, 2025 10:30
@nixpkgs-ci nixpkgs-ci bot removed the 9.needs: reviewer This PR currently has no reviewers requested and needs attention. label Oct 31, 2025
inherit system;
},
system ? builtins.currentSystem,
nodejs ? pkgs."nodejs_22",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This shouldn't need quotes, because underscore is not a special character.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top of that file says;

# This file has been generated by node2nix 1.11.1. Do not edit!

... I'll remove the quotes, but expect 'em to resurrect next time node2nix gets ideas ;-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, missed that. I'd just leave it in that case.

@@ -0,0 +1,73 @@
#!/usr/bin/env nix-shell
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file supposed to be included?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly node2nix blessed us with it, and doing a bit of vimgrep /remove-attr/ pkgs/by-name/pr/prettier/plugins/* exposes a note;

pkgs/by-name/pr/prettier/plugins/aliases.nix

### Deprecated aliases - for backward compatibility
###
### !!! NOTE !!!
### Use `./remove-attr.py [attrname]` in this directory to remove your alias
### from the `nodePackages` set without regenerating the entire file.

... I'm not sure if it needs to be included at this point 🤷

@@ -0,0 +1,23 @@
# Do not use overrides in this file to add `meta.mainProgram` to packages. Use `./main-programs.nix`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a no-op right now? If so, can we exclude it until it's needed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is loaded by pkgs/by-name/pr/prettier/plugins/default.nix;

  extensions = composeManyExtensions [
    aliases
    mainProgramOverrides
    (import ./overrides.nix { inherit pkgs nodejs; })
  ];

... which I think was also generated by node2nix so, similar to removing other files it generates, it is likely to resurrect itself

Copy link
Contributor

@l0b0 l0b0 Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks like all the extra code is node2nix's, let's just keep it if other reviewers agree. I'm not sure what the norm is.

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Nov 1, 2025
@pyrox0
Copy link
Member

pyrox0 commented Nov 4, 2025

I would much rather this use the npm/yarn/pnpm tooling built into nixpkgs, as node2nix-generated files are generally more difficult to maintain. Can this PR use that instead?

@S0AndS0
Copy link
Member Author

S0AndS0 commented Nov 8, 2025

I would much rather this use the npm/yarn/pnpm tooling built into nixpkgs, as node2nix-generated files are generally more difficult to maintain. Can this PR use that instead?

... Perhaps?... if ya can point me to the instructions, and it ain't too much trouble, I may be able to convert and after it looks good squash the Git-commit-churn ;-)

@pyrox0
Copy link
Member

pyrox0 commented Nov 8, 2025

I would much rather this use the npm/yarn/pnpm tooling built into nixpkgs, as node2nix-generated files are generally more difficult to maintain. Can this PR use that instead?

... Perhaps?... if ya can point me to the instructions, and it ain't too much trouble, I may be able to convert and after it looks good squash the Git-commit-churn ;-)

https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#buildnpmpackage-javascript-buildnpmpackage has the instructions for packages that rely on npm, and if you scroll down you'll see instructions for pnpm- and yarn-based packages.

@S0AndS0
Copy link
Member Author

S0AndS0 commented Nov 9, 2025

... Perhaps?... if ya can point me to the instructions, and it ain't too much trouble, I may be able to convert and after it looks good squash the Git-commit-churn ;-)

https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#buildnpmpackage-javascript-buildnpmpackage has the instructions for packages that rely on npm, and if you scroll down you'll see instructions for pnpm- and yarn-based packages.

Thanks!!!

Seems the Prettier main package provides a yarn.lock so I may lean towards that though, as it has been a bit and I made some questionable coding choices to inject plugins, it may take me a bit to catch-up to whatever my past self was thinkin' x-)


Edit; I've got issues, skill issues x-)

SyntaxError: Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in lockfile

Tried copy/pastying the examples provided by javascript.section.md -> Yarn with something like;

let
  gitpkgs = import /home/s0ands0/git/hub/NixOS/nixpkgs/wt/prettier-plugins-official { };
in
{
  lib ? gitpkgs.lib,
  stdenv ? gitpkgs.stdenv,
  fetchFromGitHub ? gitpkgs.fetchFromGitHub,
  fetchYarnDeps ? gitpkgs.fetchYarnDeps,
  yarnConfigHook ? gitpkgs.yarnConfigHook,
  yarnBuildHook ? gitpkgs.yarnBuildHook,
  yarnInstallHook ? gitpkgs.yarnInstallHook,
  nodejs ? gitpkgs.nodejs,
  plugins ? [ ],
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "prettier";
  version = "3.6.2";

  src = fetchFromGitHub {
    owner = "prettier";
    repo = "prettier";
    tag = finalAttrs.version;
    hash = "sha256-uMLRFBZP7/42R6nReONcb9/kVGCn3yGHLcLFajMZLmQ=";
  };

  yarnOfflineCache = fetchYarnDeps {
    yarnLock = finalAttrs.src + "/yarn.lock";
    hash = "";
  };

  nativeBuildInputs = [
    yarnConfigHook
    yarnBuildHook
    yarnInstallHook
    nodejs
  ];

  meta = {
    changelog = "https://github.com/prettier/prettier/blob/${finalAttrs.version}/CHANGELOG.md";
    description = "Code formatter";
    homepage = "https://prettier.io/";
    license = lib.licenses.mit;
    mainProgram = "prettier";
    maintainers = with lib.maintainers; [
      l0b0
      S0AndS0
    ];
  };
})

... but, running nix-build pkgs/by-name/pr/prettier/package.nix was no joy :-|

And checking the "Full logs" didn't illuminate why fetchYarnDeps ain't happy, just a stack trace that doesn't point to the full yarn.lock path it thinks its reading;

Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
no configure script, doing nothing
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
SyntaxError: Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in lockfile
    at Parser.unexpected (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:5064:11)
    at Parser.parse (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:5193:14)
    at parse (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:5262:17)
    at module.exports.exports.default (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:4835:96)
    at prefetchYarnDeps (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/index.js:159:29)
    at main (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/index.js:204:11)

I like the idea of yarn, especially if it acktually reduces the grossness needed to inject plugins, but at this point I kinda prefer something that works; even if it lurches x-)

@pyrox0
Copy link
Member

pyrox0 commented Nov 9, 2025

... Perhaps?... if ya can point me to the instructions, and it ain't too much trouble, I may be able to convert and after it looks good squash the Git-commit-churn ;-)

master/doc/languages-frameworks/javascript.section.md#buildnpmpackage-javascript-buildnpmpackage has the instructions for packages that rely on npm, and if you scroll down you'll see instructions for pnpm- and yarn-based packages.

Thanks!!!

Seems the Prettier main package provides a yarn.lock so I may lean towards that though, as it has been a bit and I made some questionable coding choices to inject plugins, it may take me a bit to catch-up to whatever my past self was thinkin' x-)

Edit; I've got issues, skill issues x-)

SyntaxError: Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in lockfile

Tried copy/pastying the examples provided by javascript.section.md -> Yarn with something like;

let
  gitpkgs = import /home/s0ands0/git/hub/NixOS/nixpkgs/wt/prettier-plugins-official { };
in
{
  lib ? gitpkgs.lib,
  stdenv ? gitpkgs.stdenv,
  fetchFromGitHub ? gitpkgs.fetchFromGitHub,
  fetchYarnDeps ? gitpkgs.fetchYarnDeps,
  yarnConfigHook ? gitpkgs.yarnConfigHook,
  yarnBuildHook ? gitpkgs.yarnBuildHook,
  yarnInstallHook ? gitpkgs.yarnInstallHook,
  nodejs ? gitpkgs.nodejs,
  plugins ? [ ],
}:
stdenv.mkDerivation (finalAttrs: {
  pname = "prettier";
  version = "3.6.2";

  src = fetchFromGitHub {
    owner = "prettier";
    repo = "prettier";
    tag = finalAttrs.version;
    hash = "sha256-uMLRFBZP7/42R6nReONcb9/kVGCn3yGHLcLFajMZLmQ=";
  };

  yarnOfflineCache = fetchYarnDeps {
    yarnLock = finalAttrs.src + "/yarn.lock";
    hash = "";
  };

  nativeBuildInputs = [
    yarnConfigHook
    yarnBuildHook
    yarnInstallHook
    nodejs
  ];

  meta = {
    changelog = "https://github.com/prettier/prettier/blob/${finalAttrs.version}/CHANGELOG.md";
    description = "Code formatter";
    homepage = "https://prettier.io/";
    license = lib.licenses.mit;
    mainProgram = "prettier";
    maintainers = with lib.maintainers; [
      l0b0
      S0AndS0
    ];
  };
})

... but, running nix-build pkgs/by-name/pr/prettier/package.nix was no joy :-|

And checking the "Full logs" didn't illuminate why fetchYarnDeps ain't happy, just a stack trace that doesn't point to the full yarn.lock path it thinks its reading;

Running phase: patchPhase
@nix { "action": "setPhase", "phase": "patchPhase" }
Running phase: updateAutotoolsGnuConfigScriptsPhase
@nix { "action": "setPhase", "phase": "updateAutotoolsGnuConfigScriptsPhase" }
Running phase: configurePhase
@nix { "action": "setPhase", "phase": "configurePhase" }
no configure script, doing nothing
Running phase: buildPhase
@nix { "action": "setPhase", "phase": "buildPhase" }
SyntaxError: Unknown token: { line: 3, col: 2, type: 'INVALID', value: undefined } 3:2 in lockfile
    at Parser.unexpected (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:5064:11)
    at Parser.parse (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:5193:14)
    at parse (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:5262:17)
    at module.exports.exports.default (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/yarnpkg-lockfile.js:4835:96)
    at prefetchYarnDeps (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/index.js:159:29)
    at main (/nix/store/afvd0gfvjr417337rsya4ixqh3w9vj5l-prefetch-yarn-deps/libexec/index.js:204:11)

I like the idea of yarn, especially if it acktually reduces the grossness needed to inject plugins, but at this point I kinda prefer something that works; even if it lurches x-)

Prettier uses yarn berry, so you want to scroll down to the Yarn Berry section below that and use that instead. You'll have to provide your own buildPhase and installPhase but otherwise should be similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants