Discourseパッケージがnix-shellでビルドに失敗する

DiscourseのNixパッケージのダウンロードとビルドを試みましたが、pnpmの依存関係エラーのようですべて失敗しました。

 ERR_PNPM_INVALID_DEPENDENCY_NAME  Refusing to place a dependency under /build/source/frontend/discourse-types/node_modules with the invalid alias "@types/@glimmer__component"

ERROR: pnpm failed to install dependencies

If you see ERR_PNPM_NO_OFFLINE_TARBALL above this, follow these to fix the issue:
1. Set pnpmDeps.hash to "" (empty string)
2. Build the derivation and wait for it to fail with a hash mismatch
3. Copy the 'got: sha256-' value back into the pnpmDeps.hash field

If you see ERR_PNPM_LOCKFILE_CONFIG_MISMATCH above this, try changing the pnpm version
Found 'pnpm' with version '10.34.4'

error: Cannot build '/nix/store/k90f0nxqhlyb1bym9lg5xl6pfjz4vamf-discourse-assets-2026.1.4.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/biwwabb1xl58v4ywqmmc7d4vm0sl78q3-discourse-assets-2026.1.4-node_modules
         /nix/store/jsbd94c63h63yq5xvrp27m5l1sg6667c-discourse-assets-2026.1.4-generated
         /nix/store/n278iw1v8kzswvwm8f6n6g15gkw6wb0q-discourse-assets-2026.1.4-frontend
         /nix/store/qnxglj6z2n8fn46af9rp7161634brcgk-discourse-assets-2026.1.4
       Last 25 log lines:
       > Progress: resolved 1909, reused 1263, downloaded 0, added 0
       > Progress: resolved 1909, reused 1907, downloaded 0, added 65
       > Progress: resolved 1909, reused 1909, downloaded 0, added 435
       > Progress: resolved 1909, reused 1909, downloaded 0, added 530
       > Progress: resolved 1909, reused 1909, downloaded 0, added 672
       > Progress: resolved 1909, reused 1909, downloaded 0, added 838
       > Progress: resolved 1909, reused 1909, downloaded 0, added 1036
       > Progress: resolved 1909, reused 1909, downloaded 0, added 1175
       > Progress: resolved 1909, reused 1909, downloaded 0, added 1464
       > Progress: resolved 1909, reused 1909, downloaded 0, added 1767
       > Progress: resolved 1909, reused 1909, downloaded 0, added 1907
       > Progress: resolved 1909, reused 1909, downloaded 0, added 1908
       > Progress: resolved 1909, reused 1909, downloaded 0, added 1909, done
       >  ERR_PNPM_INVALID_DEPENDENCY_NAME  Refusing to place a dependency under /build/source/frontend/discourse-types/node_modules with the invalid alias "@types/@glimmer__component"
       >
       > ERROR: pnpm failed to install dependencies
       >
       > If you see ERR_PNPM_NO_OFFLINE_TARBALL above this, follow these to fix the issue:
       > 1. Set pnpmDeps.hash to "" (empty string)
       > 2. Build the derivation and wait for it to fail with a hash mismatch
       > 3. Copy the 'got: sha256-' value back into the pnpmDeps.hash field
       >
       > If you see ERR_PNPM_LOCKFILE_CONFIG_MISMATCH above this, try changing the pnpm version
       > Found 'pnpm' with version '10.34.4'
       >
       For full logs, run:
         nix log /nix/store/k90f0nxqhlyb1bym9lg5xl6pfjz4vamf-discourse-assets-2026.1.4.drv
error: Cannot build '/nix/store/9n8grwvci4gd2c64i9wm5ggw5v4r63xf-discourse-2026.1.4.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/l9xhbd5scihfln5jr9vh1c6l4xznaall-discourse-2026.1.4
error: Build failed due to failed dependency

この問題は他の場所では見当たらず、皆様にもご一報したく投稿しました。

問題は、Debian/Ubuntu しかサポートされておらず、Nix はサポートされていないということです。これは開発環境用ですか、それとも本番環境用ですか?

これは、Nix パッケージマネージャーを使用して nixpkgs から Discourse パッケージをダウンロードしているだけです。派生パッケージ(Derivations)は、本質的にソースからパッケージを複製してビルドすることで動作します。

私は単に、他の NixOS パッケージと同様に一時的にパッケージをインストールしただけです。特に開発や本番環境用というわけではなく、CLI で Discourse を使用できるかを確認したかったのです。私の TUI ブラウザでは UI の一部が表示されないため、Nix パッケージを試して、UX がより使いやすくなるかを確認しようとしました。

Nix を介した単純なダウンロード/ビルドを試みましたが、前述のエラーが発生しました。

興味深いですね。このパッケージは公式に Discourse によって提供されているものではないと見ています。メンテナーの一覧をざっと見ましたが、私が知る限り Discourse チームのメンバーは記載されていません。また、AFAIK(私の知る限り)では、これに関する#documentation もありません。

参考:このプラグイン だと思われます

ああ、そうです。それが nixpkg のメンテナーです。

実際のソースは let in ブロック内にあります。

55行目:

let
  version = "2026.1.4";

  src = fetchFromGitHub {
    owner = "discourse";
    repo = "discourse";
    rev = "v${version}";
    sha256 = "sha256-kQYDKZIMsWByuCZQfUlwhoIew5QykVylRMh6xvrHIBY=";
  };
in
# ...

つまり、ソースは discourse/discourse から取得されており、残りの派生定義は基本的にビルド手順、ファイルの配置場所、特定のビルドエラーへの対応方法などです。

この src パラメータは、派生定義の残りの部分に伝播される変数のようなものです。

つまり、これをテストするためにフルの nixOS にコミットする必要はありません。

nix パッケージマネージャーは、ほぼすべてのマシンで利用可能です。

`nix-shell -p discourse`

ここで、`nix-shell` はシェルを起動し、`-p` で指定したパッケージがシステム上で利用可能になります。シェルを閉じると、それらのパッケージはインストールされなくなります。

nix の概念を説明するために apt の類比を持ち合わせていませんが、水が容器の形に収まるように、nix は中身に合わせて自ら形を変える「容器」です。`nix` が解決しようとしている問題は「自分のマシンでは動く」ことであり、ソフトウェアがコンパイルして実行できるなら、nix を通じてもコンパイルして実行できるということです。

このスレッドがロックされているかどうかを確認するためにテストしています。最近の編集の一つが表示されないからです。

おそらく、編集が承認されて初めて投稿に表示されるのでしょう

スレッドはロックされておらず、私たちはこのトピックを楽しみ、学んでいます。ご協力いただきありがとうございます。Metaへようこそ :+1:

大丈夫だよ!説明ありがとう。

承認プロセスがあると思ったのは、私がこの編集をしたのに、自分の画面には反映されなかったからだ:

まだ左側にテキストだけが見えている

追記:さっき表示された

報告ありがとうございます。確認したところ、これは依存関係のハッシュの問題ではなく、Nixパッケージにおけるpnpmのバージョン不一致であるようです。

Discourse v2026.1.4pnpm@10.28.0 を宣言していますが、Nix式 には移動する pnpm_10 パッケージが使用されており、現在これは 10.34.4 に解決されています。この新しいpnpmバージョンは、このDiscourseリリースで使用されている一部の依存関係のエイリアスを拒否します。

Nixpkgsでの修正としては、derivationを互換性のある古いpnpmにピン留めすることが考えられます。既存の pnpm_10_29_2 パッケージ、または正確には 10.28.0 に固定し、必要に応じて pnpmDeps.hash を更新する方法です。

Nixパッケージはコミュニティによってメンテナンスされているため、その修正はNixpkgs側で行う必要がありますが、この情報がメンテナに適切な方向性を示すことを願っています。

解決済みとマークするのは早すぎたかもしれません。実際にはまだテストしていないので、すみません。

Nixpkgsでは、ローカルでパッケージのオーバーレイやオーバーライドを行うことができます。時間ができたら、自分でderivationに変更を実装して、結果を報告してみます。

ここまで進めました:

let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-26.05";
  pkgs = import nixpkgs {
    config = { };
    overlays = with pkgs; [
      (final: prev: {
        discourse = prev.discourse.override (oa: {
          pnpm_10 = oa.pnpm_10.overrideAttrs (_: {
            src = fetchFromGitHub {
              owner = "pnpm";
              repo = "pnpm";
              rev = "ea870c786fc74c99bf9de644c78453b4d25a7d59";
              hash = "sha256-g+TjAW1SGuEXh04RnGZOQTLkJTHs/3zyCp/P+MzBn4c=";
            };
          });
        });

      })
    ];
  };
in

pkgs.mkShellNoCC {
  packages = with pkgs; [
    # for debug
    discourse
  ];
}

エラー:

Running phase: unpackPhase
unpacking source archive /nix/store/ci631zzm890b2dzsrxxxrg15qpbac6jy-source
source root is source
rm: cannot remove 'package/dist/vendor': No such file or directory
error: Cannot build '/nix/store/lq23pl8ycyf8myl9mynwzx9a2f2miywv-pnpm-10.34.0.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/kf62vww5jdfpr32qgxhz4qv9dkfdb0pf-pnpm-10.34.0
       Last 5 log lines:
       > structuredAttrs is enabled
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/ci631zzm890b2dzsrxxxrg15qpbac6jy-source
       > source root is source
       > rm: cannot remove 'package/dist/vendor': No such file or directory
       For full logs, run:
         nix log /nix/store/lq23pl8ycyf8myl9mynwzx9a2f2miywv-pnpm-10.34.0.drv
error: Cannot build '/nix/store/1hi18g4r0gmmlnj059irx91grry7ymv7-discourse-assets-2026.1.4.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/bw2pzh74fbp0wkn9f4b2bf2p6lwcva3d-discourse-assets-2026.1.4
         /nix/store/kqnrdh18f4pn87rpzk2af0d18xcvbj7k-discourse-assets-2026.1.4-generated
         /nix/store/mcbvqw0y8r3as9zrjmrq7pc32n64bj2r-discourse-assets-2026.1.4-frontend
         /nix/store/my9x48zhzzqi2w8rriww6qm4v9iaxxhx-discourse-assets-2026.1.4-node_modules
error: Cannot build '/nix/store/05ffysx25hfzw34km225d2krpnifwj75-discourse-2026.1.4.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/2b1pvnvln95dx7rxr88kc5b9g24x45dr-discourse-2026.1.4

どうやらログは、私がオーバーライドしたかのように見せて、間違ったビルドを表示するだけで、非常に助かります。package/dist/vendor というファイルが作成されていないことを指摘しています。

まあ、これはおそらくメンテナに任せるべき問題ですね。

nixpkgsに含まれていたDiscourseのバージョンが1月のものというかなり古いものだったので、アップデートするPRを開きました。nixpkgsへの貢献は初めてなので、どうなるかは分かりません。

@fuguesoft 更新されたDiscourseのnixpkgがマージされたようです。試してみたい場合はどうぞ。