nixos-configs/apps/nix/buildApp.nix

40 lines
902 B
Nix
Raw Normal View History

{
runtimeInputs,
npmDepsHash,
src,
lib,
buildNpmPackage,
makeWrapper,
nodejs_latest,
jq,
...
}: let
inherit (lib) concatMapStringsSep;
2024-11-23 19:35:01 -05:00
inherit (builtins) fromJSON readFile;
2024-11-23 19:35:01 -05:00
packageJSON = fromJSON (readFile "${src}/package.json");
in
buildNpmPackage rec {
2024-08-06 20:35:11 -04:00
pname = packageJSON.name;
inherit (packageJSON) version;
inherit src runtimeInputs npmDepsHash;
prePatch = ''
mv ./tsconfig.json ./project.json
2024-11-23 19:35:01 -05:00
sed 's/^ *\/\/.*//' ${../tsconfig.json} > ./base.json
${jq}/bin/jq -sr '.[0] * .[1] | del(.extends)' ./project.json ./base.json > ./tsconfig.json
rm base.json project.json
'';
nativeBuildInputs = [makeWrapper];
postInstall = ''
wrapProgram $out/bin/${pname} \
--prefix PATH : ${concatMapStringsSep ":" (p: p + "/bin") runtimeInputs}
'';
nodejs = nodejs_latest;
meta.mainProgram = pname;
}