This repository has been archived on 2024-10-13. You can view files and clone it, but cannot push or open issues or pull requests.
nix-packages/akkoma/akkoma-fe/default.nix

79 lines
2.4 KiB
Nix
Raw Normal View History

2022-09-25 13:06:44 +00:00
{
lib,
mkYarnPackage,
fetchFromGitea,
fetchYarnDeps,
fixup_yarn_lock,
yarn,
nodejs,
jpegoptim,
oxipng,
nodePackages,
writeScript,
applyPatches,
callPackage,
2022-09-25 13:06:44 +00:00
}: let
source = builtins.fromJSON (builtins.readFile ./source.json);
src = applyPatches {
src = fetchFromGitea {
domain = "akkoma.dev";
owner = "AkkomaGang";
2023-08-05 15:25:06 +00:00
repo = "akkoma-fe";
2022-09-25 13:06:44 +00:00
inherit (source) rev sha256;
};
2023-08-05 15:25:06 +00:00
patches = [./akkoma-fe.patch ./jxl-polyfill.patch];
2022-09-25 13:06:44 +00:00
};
nodeOptions = callPackage ../../lib/opensslLegacyProvider.nix {};
2022-09-25 13:06:44 +00:00
in
mkYarnPackage rec {
2023-08-05 15:25:06 +00:00
pname = "akkoma-fe";
2022-09-25 13:06:44 +00:00
version = source.date;
inherit src;
2022-10-27 06:19:29 +00:00
packageJSON = ./package.json;
2022-10-09 15:33:31 +00:00
yarnLock = ./yarn.lock;
2022-09-25 13:06:44 +00:00
yarnNix = ./yarn.nix;
nativeBuildInputs = [
jpegoptim
oxipng
nodePackages.svgo
];
# Build scripts assume to be used within a Git repository checkout
patchPhase = ''
sed -E -i \
-e '/^let commitHash =/,/;$/clet commitHash = "${builtins.substring 0 7 source.rev}";' \
build/webpack.prod.conf.js
'';
2022-12-01 15:37:57 +00:00
configurePhase = ''
cp -r $node_modules node_modules
for f in $(find node_modules/jxl.js -type f); do chmod -v +w $f; done
for f in $(find node_modules/jxl.js -type l);do cp -rv --remove-destination $(readlink $f) $f;done;
'';
2022-09-25 13:06:44 +00:00
buildPhase = ''
export NODE_OPTIONS="${nodeOptions}"
2022-09-25 13:06:44 +00:00
yarn build --offline
'';
installPhase = "cp -rv dist $out";
distPhase = ''
# (Losslessly) optimise compression of image artifacts
find $out -type f -name '*.jpg' -execdir ${jpegoptim}/bin/jpegoptim -w$NIX_BUILD_CORES {} \;
find $out -type f -name '*.png' -execdir ${oxipng}/bin/oxipng -o max -t $NIX_BUILD_CORES {} \;
find $out -type f -name '*.svg' -execdir ${nodePackages.svgo}/bin/svgo {} \;
'';
passthru = {
2023-08-05 15:25:06 +00:00
updateScript = writeScript "update-akkoma-fe" ''
${../../scripts/update-git.sh} https://akkoma.dev/AkkomaGang/akkoma-fe.git akkoma/akkoma-fe/source.json
if [ "$(git diff -- akkoma/akkoma-fe/source.json)" ]; then
SRC_PATH=$(nix-build -E '(import ./. {}).${pname}.src')
2023-08-05 15:25:06 +00:00
${../../scripts/update-yarn.sh} $SRC_PATH akkoma/akkoma-fe
fi
2022-09-25 13:06:44 +00:00
'';
};
meta = with lib; {
2023-08-05 15:25:06 +00:00
description = "Frontend for Akkoma and akkoma";
homepage = "https://akkoma.dev/AkkomaGang/akkoma-fe/";
2022-09-25 13:06:44 +00:00
license = licenses.agpl3;
};
}