depot/third_party/nixpkgs/pkgs/by-name/ma/matrix-authentication-service/package.nix

100 lines
2.7 KiB
Nix
Raw Normal View History

{ lib
, rustPlatform
, fetchFromGitHub
, fetchNpmDeps
, npmHooks
, nodejs
, python3
, pkg-config
, sqlite
, zstd
, stdenv
, darwin
, open-policy-agent
}:
rustPlatform.buildRustPackage rec {
pname = "matrix-authentication-service";
version = "0.12.0";
src = fetchFromGitHub {
owner = "element-hq";
repo = "matrix-authentication-service";
rev = "refs/tags/v${version}";
hash = "sha256-QLtyYxV2yXHJtwWgGcyi7gRcKypYoy9Z8bkEuTopVXc=";
};
cargoLock = {
lockFile = ./Cargo.lock;
outputHashes = {
"sea-query-0.32.0-rc.1" = "sha256-Q/NFiIBu8L5rQj4jwcIo8ACmAhLBy4HSTcJv06UdK8E=";
};
};
npmDeps = fetchNpmDeps {
name = "${pname}-${version}-npm-deps";
src = "${src}/${npmRoot}";
hash = "sha256-EfDxbdjzF0yLQlueIYKmdpU4v9dx7g8bltU63mIWfo0=";
};
npmRoot = "frontend";
nativeBuildInputs = [
pkg-config
open-policy-agent
npmHooks.npmConfigHook
nodejs
(python3.withPackages (ps: [ ps.setuptools ])) # Used by gyp
];
buildInputs = [
sqlite
zstd
] ++ lib.optionals stdenv.hostPlatform.isDarwin [
darwin.apple_sdk_11_0.frameworks.CoreFoundation
darwin.apple_sdk_11_0.frameworks.Security
darwin.apple_sdk_11_0.frameworks.SystemConfiguration
];
env = {
ZSTD_SYS_USE_PKG_CONFIG = true;
};
buildNoDefaultFeatures = true;
buildFeatures = [ "dist" ];
postPatch = ''
substituteInPlace crates/config/src/sections/http.rs \
--replace ./frontend/dist/ "$out/share/$pname/assets/"
substituteInPlace crates/config/src/sections/templates.rs \
--replace ./share/templates/ "$out/share/$pname/templates/" \
--replace ./share/translations/ "$out/share/$pname/translations/" \
--replace ./share/manifest.json "$out/share/$pname/assets/manifest.json"
substituteInPlace crates/config/src/sections/policy.rs \
--replace ./share/policy.wasm "$out/share/$pname/policy.wasm"
'';
preBuild = ''
make -C policies
(cd "$npmRoot" && npm run build)
'';
# Adopted from https://github.com/element-hq/matrix-authentication-service/blob/main/Dockerfile
postInstall = ''
install -Dm444 -t "$out/share/$pname" "policies/policy.wasm"
install -Dm444 -t "$out/share/$pname/assets" "$npmRoot/dist/"*
cp -r templates "$out/share/$pname/templates"
cp -r translations "$out/share/$pname/translations"
'';
meta = {
description = "OAuth2.0 + OpenID Provider for Matrix Homeservers";
homepage = "https://github.com/element-hq/matrix-authentication-service";
changelog = "https://github.com/element-hq/matrix-authentication-service/releases/tag/v${version}";
license = lib.licenses.agpl3Only;
maintainers = with lib.maintainers; [ teutat3s ];
mainProgram = "mas-cli";
};
}