diff --git a/nixos/modules/services/matrix/appservice-irc.nix b/nixos/modules/services/matrix/appservice-irc.nix index 8883d604b2ea..d153ffc2ace8 100644 --- a/nixos/modules/services/matrix/appservice-irc.nix +++ b/nixos/modules/services/matrix/appservice-irc.nix @@ -12,16 +12,14 @@ let configFile = pkgs.runCommand "matrix-appservice-irc.yml" { # Because this program will be run at build time, we need `nativeBuildInputs` - nativeBuildInputs = [ (pkgs.python3.withPackages (ps: [ ps.pyyaml ps.jsonschema ])) ]; + nativeBuildInputs = [ (pkgs.python3.withPackages (ps: [ ps.jsonschema ])) pkgs.remarshal ]; preferLocalBuild = true; config = builtins.toJSON cfg.settings; passAsFile = [ "config" ]; } '' # The schema is given as yaml, we need to convert it to json - python -c 'import json; import yaml; import sys; json.dump(yaml.safe_load(sys.stdin), sys.stdout)' \ - < ${pkg}/lib/node_modules/matrix-appservice-irc/config.schema.yml \ - > config.schema.json + remarshal --if yaml --of json -i ${pkg}/config.schema.yml -o config.schema.json python -m jsonschema config.schema.json -i $configPath cp "$configPath" "$out" ''; diff --git a/pkgs/servers/matrix-synapse/matrix-appservice-irc/default.nix b/pkgs/servers/matrix-synapse/matrix-appservice-irc/default.nix index 69696cbf9195..a00104215453 100644 --- a/pkgs/servers/matrix-synapse/matrix-appservice-irc/default.nix +++ b/pkgs/servers/matrix-synapse/matrix-appservice-irc/default.nix @@ -1,32 +1,79 @@ { lib -, buildNpmPackage +, stdenv , fetchFromGitHub -, python3 +, fetchYarnDeps +, prefetch-yarn-deps +, nodejs +, nodejs-slim , matrix-sdk-crypto-nodejs , nixosTests , nix-update-script }: -buildNpmPackage rec { +let pname = "matrix-appservice-irc"; - version = "0.38.0"; + version = "1.0.1"; src = fetchFromGitHub { owner = "matrix-org"; - repo = "matrix-appservice-irc"; + repo = pname; rev = "refs/tags/${version}"; - hash = "sha256-rV4B9OQl1Ht26X4e7sqCe1PR5RpzIcjj4OvWG6udJWo="; + hash = "sha256-wUbWvCa9xvot73nXZjF3/RawM98ffBCW5YR2+ZKzmEo="; }; - npmDepsHash = "sha256-iZuPr3a1BPtRfkEoxOs4oRL/nCfy3PLx5T9dX49/B0s="; + yarnOfflineCache = fetchYarnDeps { + name = "${pname}-${version}-offline-cache"; + yarnLock = "${src}/yarn.lock"; + hash = "sha256-P9u5sK9rIHWRE8kFMj05fVjv26jwsawvHBZgSn7j5BE="; + }; + +in +stdenv.mkDerivation { + inherit pname version src yarnOfflineCache; nativeBuildInputs = [ - python3 + prefetch-yarn-deps + nodejs-slim + nodejs.pkgs.yarn + nodejs.pkgs.node-gyp-build ]; - postInstall = '' - rm -rv $out/lib/node_modules/matrix-appservice-irc/node_modules/@matrix-org/matrix-sdk-crypto-nodejs - ln -sv ${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/matrix-sdk-crypto-nodejs $out/lib/node_modules/matrix-appservice-irc/node_modules/@matrix-org/ + configurePhase = '' + runHook preConfigure + + export HOME=$(mktemp -d) + yarn config --offline set yarn-offline-mirror "$yarnOfflineCache" + fixup-yarn-lock yarn.lock + yarn install --frozen-lockfile --offline --no-progress --non-interactive --ignore-scripts + patchShebangs node_modules/ bin/ + + runHook postConfigure + ''; + + buildPhase = '' + runHook preBuild + + yarn --offline build + + runHook postBuild + ''; + + installPhase = '' + runHook preInstall + + mkdir $out + cp app.js config.schema.yml $out + cp -r bin lib public $out + + # prune dependencies to production only + yarn install --frozen-lockfile --offline --no-progress --non-interactive --ignore-scripts --production + cp -r node_modules $out + + # replace matrix-sdk-crypto-nodejs with nixos package + rm -rv $out/node_modules/@matrix-org/matrix-sdk-crypto-nodejs + ln -sv ${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/matrix-sdk-crypto-nodejs $out/node_modules/@matrix-org/ + + runHook postInstall ''; passthru.tests.matrix-appservice-irc = nixosTests.matrix-appservice-irc;