lldap: build frontend from source

Co-authored-by: Emily Lange <git@indeednotjames.com>
This commit is contained in:
Herwig Hochleitner 2023-05-11 13:36:05 +02:00
parent 3cb5bc287d
commit a99852ad18

View file

@ -1,26 +1,46 @@
{ fetchFromGitHub
{ binaryen
, fetchFromGitHub
, fetchpatch
, fetchzip
, lib
, lldap
, nixosTests
, rustPlatform
, stdenv
, wasm-bindgen-cli
, wasm-pack
, which
}:
let
# We cannot build the wasm frontend from source, as the
# wasm32-unknown-unknown rustc target isn't available in nixpkgs yet.
# Tracking issue: https://github.com/NixOS/nixpkgs/issues/89426
frontend = fetchzip {
url = "https://github.com/lldap/lldap/releases/download/v${lldap.version}/amd64-lldap.tar.gz";
hash = "sha256-/Ml4L5Gxpnmt1pLSiLNuxtzQYjTCatsVe/hE+Btl8BI=";
name = "lldap-frontend-${lldap.version}";
postFetch = ''
mv $out $TMPDIR/extracted
mv $TMPDIR/extracted/app $out
'';
# version of wasm-opt, with https://github.com/rustwasm/wasm-pack/pull/1257 backported
wasm-pack-git = wasm-pack.overrideAttrs (oldAttrs: {
version = oldAttrs.version + "-git";
patches = [(fetchpatch {
url = "https://patch-diff.githubusercontent.com/raw/rustwasm/wasm-pack/pull/1257.patch";
sha256 = "sha256-npi9ewh0NaD67crTcje9AYxaLLOJOMzqjqEJXZF2LbQ=";
})];
});
# replace with upstream wasm rustc, after resolution of
# https://github.com/NixOS/nixpkgs/issues/89426
rustc-wasm = (rustPlatform.rust.rustc.override {
stdenv = stdenv.override {
targetPlatform = stdenv.targetPlatform // {
parsed = {
cpu.name = "wasm32";
vendor.name = "unknown";
kernel.name = "unknown";
abi.name = "unknown";
};
in
rustPlatform.buildRustPackage rec {
};
};
}).overrideAttrs (attrs: {
configureFlags = attrs.configureFlags ++ ["--set=build.docs=false"];
});
commonDerivationAttrs = rec {
pname = "lldap";
version = "0.4.3";
@ -31,6 +51,10 @@ rustPlatform.buildRustPackage rec {
hash = "sha256-FAUTykFh2eGVpx6LrCjV9xWbBPH8pCgAJv3vOXFMFZ4=";
};
postPatch = ''
ln -s --force ${./Cargo.lock} Cargo.lock
'';
# `Cargo.lock` has git dependencies, meaning can't use `cargoHash`
cargoLock = {
# 0.4.3 has been tagged before the actual Cargo.lock bump, resulting in an inconsitent lock file.
@ -43,26 +67,49 @@ rustPlatform.buildRustPackage rec {
"yew_form-0.1.8" = "sha256-1n9C7NiFfTjbmc9B5bDEnz7ZpYJo9ZT8/dioRXJ65hc=";
};
};
};
frontend = rustPlatform.buildRustPackage (commonDerivationAttrs // {
pname = commonDerivationAttrs.pname + "-frontend";
nativeBuildInputs = [
wasm-pack-git wasm-bindgen-cli binaryen which rustc-wasm rustc-wasm.llvmPackages.lld
];
buildPhase = ''
HOME=`pwd` RUSTFLAGS="-C linker=lld" ./app/build.sh
'';
installPhase = ''
mkdir -p $out
cp -R app/{index.html,pkg,static} $out/
'';
doCheck = false;
});
in rustPlatform.buildRustPackage (commonDerivationAttrs // {
patches = [
./static-frontend-path.patch
];
postPatch = ''
ln -s --force ${./Cargo.lock} Cargo.lock
postPatch = commonDerivationAttrs.postPatch + ''
substituteInPlace server/src/infra/tcp_server.rs --subst-var-by frontend '${frontend}'
'';
passthru.tests = {
passthru = {
inherit frontend;
tests = {
inherit (nixosTests) lldap;
};
};
meta = with lib; {
description = "A lightweight authentication server that provides an opinionated, simplified LDAP interface for authentication";
homepage = "https://github.com/lldap/lldap";
changelog = "https://github.com/lldap/lldap/blob/v${version}/CHANGELOG.md";
changelog = "https://github.com/lldap/lldap/blob/v${lldap.version}/CHANGELOG.md";
license = licenses.gpl3Only;
platforms = platforms.linux;
maintainers = with maintainers; [ indeednotjames ];
maintainers = with maintainers; [ indeednotjames bendlas ];
};
}
})