summaryrefslogtreecommitdiffstats
path: root/flake/pkgs/by-name/prettier-plugin-astro/package.nix
blob: 17602717d1d8574156d3adea722c70f6d3a5f991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{
  pins,
  stdenv,
  fetchFromGitHub,
  nodejs,
  pnpm_11,
  pnpmConfigHook,
  zstd,
  fetchPnpmDeps,
  writableTmpDirAsHomeHook,
}: let
  pin = pins.prettier-plugin-astro;
  pnpm = pnpm_11;
in
  stdenv.mkDerivation (finalAttrs: {
    pname = "prettier-plugin-astro";
    version = pin.version or pin.revision;

    src = fetchFromGitHub {
      inherit (pin.repository) owner repo;
      rev = finalAttrs.version;
      sha256 = pin.hash;
    };

    # Upstream still ships a lockfileVersion 6.0 pnpm-lock.yaml, which pnpm 11
    # refuses to use under --frozen-lockfile. Replace it with a pre-migrated
    # lockfile (generated via `pnpm install --lockfile-only` on pnpm 11) so
    # both the dependency fetch and the build itself see the same lockfile.
    # FIXME: this sucks
    postPatch = ''
      cp ${./pnpm-lock.yaml} pnpm-lock.yaml
    '';

    pnpmDeps = fetchPnpmDeps {
      inherit pnpm;
      inherit (finalAttrs) pname version src postPatch;
      hash = "sha256-ODVuEvZbFDXDWUl2Bfp4inG37frUbbRM7bCQxRa2bpM=";
      fetcherVersion = 4; # https://nixos.org/manual/nixpkgs/stable/#javascript-pnpm-fetcherVersion
    };

    nativeBuildInputs = [
      nodejs
      writableTmpDirAsHomeHook
      (pnpmConfigHook.override {
        inherit pnpm;
      })
      pnpm
      zstd
    ];

    buildPhase = ''
      runHook preBuild

      pnpm run build

      runHook postBuild
    '';

    preInstall = ''
      cp -r dist/ $out
      cp -r node_modules $out
    '';
  })