Unverified Commit 77d4f4fe authored by Maximilian Bosch's avatar Maximilian Bosch
Browse files

discourse.assets: work around `cannot execute: required file not found`

`yarn run patch-package` as `postinstall`-hook doesn't work because it
has a shebang using `/usr/bin/env` which isn't available in the sandbox.
Removing the postinstall hook and manually running this after
`patchShebangs` appears to solve the issue.

Relevant error log of the build error
(`NIXPKGS_ALLOW_INSECURE=1 nix-build -A discourse.assets`)

    error /build/source/app/assets/javascripts/node_modules/discourse: Command failed.
    Exit code: 127
    Command: patch-package
    Arguments:
    Directory: /build/source/app/assets/javascripts/node_modules/discourse
    Output:
    /bin/sh: line 1: /build/source/app/assets/javascripts/node_modules/.bin/patch-package: cannot execute: required file not found
    info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
parent dc5364a1
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@
, nodePackages
, nodejs_16
, dart-sass-embedded
, jq
, moreutils

, plugins ? []
}@args:
@@ -225,6 +227,8 @@ let
      nodePackages.patch-package
      yarn
      nodejs_16
      jq
      moreutils
    ];

    outputs = [ "out" "javascripts" ];
@@ -266,10 +270,19 @@ let

      export SSL_CERT_FILE=${cacert}/etc/ssl/certs/ca-bundle.crt

      find app/assets/javascripts -name package.json -print0 \
        | xargs -0 -I {} bash -c "jq 'del(.scripts.postinstall)' -r <{} | sponge {}"
      yarn install --offline --cwd app/assets/javascripts/discourse

      patchShebangs app/assets/javascripts/node_modules/

      # Run `patch-package` AFTER the corresponding shebang inside `.bin/patch-package`
      # got patched. Otherwise this will fail with
      #     /bin/sh: line 1: /build/source/app/assets/javascripts/node_modules/.bin/patch-package: cannot execute: required file not found
      pushd app/assets/javascripts &>/dev/null
        yarn run patch-package
      popd &>/dev/null

      redis-server >/dev/null &

      initdb -A trust $NIX_BUILD_TOP/postgres >/dev/null