buildDartApplication: Use package source builders and setup hooks instead of package overrides

This commit is contained in:
hacker1024 2023-10-29 01:16:08 +11:00 committed by FlafyDev
parent cf55bc7300
commit 2bd3e5d779
14 changed files with 153 additions and 113 deletions

View file

@ -44,7 +44,6 @@
, runtimeDependencies ? [ ]
, extraWrapProgramArgs ? ""
, customPackageOverrides ? { }
, autoDepsList ? false
, depsListFile ? null
, pubspecLock
@ -143,25 +142,7 @@ let
meta = (args.meta or { }) // { platforms = args.meta.platforms or dart.meta.platforms; };
});
packageOverrideRepository = (callPackage ../../../development/compilers/dart/package-overrides { }) // customPackageOverrides;
productPackages = if depsList == null then [ ] else depsList;
in
assert !(builtins.isString dartOutputType && dartOutputType != "") ->
throw "dartOutputType must be a non-empty string";
builtins.foldl'
(prev: package:
if packageOverrideRepository ? ${package.name}
then
prev.overrideAttrs
(packageOverrideRepository.${package.name} {
inherit (package)
name
version
kind
source
dependencies;
})
else prev)
baseDerivation
productPackages
baseDerivation

View file

@ -1,4 +1,5 @@
{ lib
, callPackage
, fetchurl
, fetchgit
, runCommand
@ -22,6 +23,14 @@
# Functions to generate SDK package sources.
# The function names should match the SDK names, and the package name is given as an argument.
, sdkSourceBuilders ? { }
# Functions that create custom package source derivations.
#
# The function names should match the package names, and the package version,
# source, and source files are given in an attribute set argument.
#
# The passthru of the source derivation should be propagated.
, customSourceBuilders ? { }
}:
let
@ -77,20 +86,22 @@ let
addDependencySourceUtils = dependencySource: details: dependencySource.overrideAttrs ({ passthru, ... }: {
passthru = passthru // {
inherit (details) version;
packagePath = dependencySource + "/${dependencySource.packageRoot}";
};
});
sourceBuilders = callPackage ../../../development/compilers/dart/package-source-builders { } // customSourceBuilders;
dependencySources = lib.filterAttrs (name: src: src != null) (builtins.mapAttrs
(name: details:
addDependencySourceUtils
(({
(sourceBuilders.${name} or ({ src, ... }: src)) {
inherit (details) version source;
src = ((addDependencySourceUtils (({
"hosted" = mkHostedDependencySource;
"git" = mkGitDependencySource;
"path" = mkPathDependencySource;
"sdk" = mkSdkDependencySource;
}.${details.source} name) details)
details)
}.${details.source} name) details)) details);
})
pubspecLock.packages);
in
{

View file

@ -1,14 +0,0 @@
{ lib
, llvmPackages
}:
{ ... }:
{ FFIGEN_COMPILER_OPTS ? ""
, ...
}:
{
FFIGEN_LIBCLANG = lib.getLib llvmPackages.libclang;
FFIGEN_COMPILER_OPTS = "-I${FFIGEN_COMPILER_OPTS} ${llvmPackages.clang}/resource-root/include -I${lib.makeSearchPathOutput "dev" "include" [ llvmPackages.clang.libc_dev ]}";
}

View file

@ -1,17 +0,0 @@
{ lib
, pkg-config
, libsecret
, jsoncpp
}:
{ ... }:
{ nativeBuildInputs ? [ ]
, buildInputs ? [ ]
, ...
}:
{
nativeBuildInputs = [ pkg-config ] ++ nativeBuildInputs;
buildInputs = [ libsecret jsoncpp ] ++ buildInputs;
}

View file

@ -1,14 +0,0 @@
{ lib
, cairo
, fribidi
}:
{ ... }:
{ CFLAGS ? ""
, ...
}:
{
CFLAGS = "${CFLAGS} -isystem ${lib.getOutput "dev" fribidi}/include/fribidi -isystem ${lib.getOutput "dev" cairo}/include";
}

View file

@ -1,12 +0,0 @@
{ openssl
}:
{ ... }:
{ runtimeDependencies ? [ ]
, ...
}:
{
runtimeDependencies = runtimeDependencies ++ [ openssl ];
}

View file

@ -1,12 +0,0 @@
{ olm
}:
{ ... }:
{ runtimeDependencies ? [ ]
, ...
}:
{
runtimeDependencies = runtimeDependencies ++ [ olm ];
}

View file

@ -1,18 +0,0 @@
{ libayatana-appindicator
}:
{ ... }:
{ preBuild ? ""
, ...
}:
{
preBuild = preBuild + ''
# $PUB_CACHE/hosted is a symlink to a store path.
mv $PUB_CACHE/hosted $PUB_CACHE/hosted_copy
cp -HR $PUB_CACHE/hosted_copy $PUB_CACHE/hosted
substituteInPlace $PUB_CACHE/hosted/pub.dev/system_tray-*/linux/tray.cc \
--replace "libappindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1"
'';
}

View file

@ -1,7 +1,6 @@
{ callPackage }:
{
ffigen = callPackage ./ffigen { };
flutter_secure_storage_linux = callPackage ./flutter-secure-storage-linux { };
handy_window = callPackage ./handy-window { };
matrix = callPackage ./matrix { };

View file

@ -0,0 +1,23 @@
{ stdenv
, libsecret
, jsoncpp
}:
{ version, src, ... }:
stdenv.mkDerivation {
pname = "flutter-secure-storage-linux";
inherit version src;
inherit (src) passthru;
propagatedBuildInputs = [ libsecret jsoncpp ];
installPhase = ''
runHook preInstall
mkdir -p "$out"
ln -s '${src}'/* "$out"
runHook postInstall
'';
}

View file

@ -0,0 +1,31 @@
{ stdenv
, lib
, writeScript
, cairo
, fribidi
}:
{ version, src, ... }:
stdenv.mkDerivation rec {
pname = "handy-window";
inherit version src;
inherit (src) passthru;
setupHook = writeScript "${pname}-setup-hook" ''
handyWindowConfigureHook() {
export CFLAGS="$CFLAGS -isystem ${lib.getDev fribidi}/include/fribidi -isystem ${lib.getDev cairo}/include"
}
postConfigureHooks+=(handyWindowConfigureHook)
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
ln -s '${src}'/* "$out"
runHook postInstall
'';
}

View file

@ -0,0 +1,30 @@
{ stdenv
, lib
, writeScript
, openssl
}:
{ version, src, ... }:
stdenv.mkDerivation rec {
pname = "matrix";
inherit version src;
inherit (src) passthru;
setupHook = writeScript "${pname}-setup-hook" ''
matrixFixupHook() {
runtimeDependencies+=('${lib.getLib openssl}')
}
preFixupHooks+=(matrixFixupHook)
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
ln -s '${src}'/* "$out"
runHook postInstall
'';
}

View file

@ -0,0 +1,30 @@
{ stdenv
, lib
, writeScript
, olm
}:
{ version, src, ... }:
stdenv.mkDerivation rec {
pname = "olm";
inherit version src;
inherit (src) passthru;
setupHook = writeScript "${pname}-setup-hook" ''
olmFixupHook() {
runtimeDependencies+=('${lib.getLib olm}')
}
preFixupHooks+=(olmFixupHook)
'';
installPhase = ''
runHook preInstall
mkdir -p "$out"
ln -s '${src}'/* "$out"
runHook postInstall
'';
}

View file

@ -0,0 +1,22 @@
{ stdenv
, libayatana-appindicator
}:
{ version, src, ... }:
stdenv.mkDerivation rec {
pname = "system-tray";
inherit version src;
inherit (src) passthru;
installPhase = ''
runHook preInstall
mkdir -p "$out"
cp -r '${src}'/* "$out"
substituteInPlace "$out/linux/tray.cc" \
--replace "libappindicator3.so.1" "${libayatana-appindicator}/lib/libayatana-appindicator3.so.1"
runHook postInstall
'';
}