2024-05-13 21:24:10 +00:00
|
|
|
{ lib, stdenv, fetchurl, linkFarm, dub, ldc, removeReferencesTo, }:
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
# See https://nixos.org/manual/nixpkgs/unstable#dlang for more detailed usage information
|
|
|
|
|
|
|
|
{
|
2024-05-13 21:24:10 +00:00
|
|
|
# A lockfile generated by `dub-to-nix` from the source of the package.
|
|
|
|
# Can be either a path to the file, or an attrset already parsed with `lib.importJSON`.
|
|
|
|
dubLock,
|
|
|
|
# The build type to pass to `dub build` as a value for the `--build=` flag.
|
|
|
|
dubBuildType ? "release",
|
|
|
|
# The flags to pass to `dub build` and `dub test`.
|
|
|
|
dubFlags ? [ ],
|
|
|
|
# The flags to pass to `dub build`.
|
|
|
|
dubBuildFlags ? [ ],
|
|
|
|
# The flags to pass to `dub test`.
|
|
|
|
dubTestFlags ? [ ],
|
|
|
|
# The D compiler to be used by `dub`.
|
|
|
|
compiler ? ldc, ... }@args:
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
let
|
2024-05-13 21:24:10 +00:00
|
|
|
makeDubDep = { pname, version, sha256, }: {
|
|
|
|
inherit pname version;
|
|
|
|
src = fetchurl {
|
|
|
|
name = "dub-${pname}-${version}.zip";
|
|
|
|
url = "mirror://dub/${pname}/${version}.zip";
|
|
|
|
inherit sha256;
|
2024-05-02 00:46:19 +00:00
|
|
|
};
|
2024-05-13 21:24:10 +00:00
|
|
|
};
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
lockJson = if lib.isPath dubLock then lib.importJSON dubLock else dubLock;
|
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
lockedDeps = lib.mapAttrsToList
|
|
|
|
(pname: { version, sha256 }: makeDubDep { inherit pname version sha256; })
|
|
|
|
lockJson.dependencies;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
|
|
|
# a directory with multiple single element registries
|
|
|
|
# one big directory with all .zip files leads to version parsing errors
|
|
|
|
# when the name of a package is a prefix of the name of another package
|
2024-05-13 21:24:10 +00:00
|
|
|
dubRegistryBase = linkFarm "dub-registry-base" (map (dep: {
|
|
|
|
name = "${dep.pname}/${dep.pname}-${dep.version}.zip";
|
|
|
|
path = dep.src;
|
|
|
|
}) lockedDeps);
|
|
|
|
|
|
|
|
combinedFlags = "--skip-registry=all --compiler=${lib.getExe compiler} ${
|
|
|
|
toString dubFlags
|
|
|
|
}";
|
|
|
|
combinedBuildFlags =
|
|
|
|
"${combinedFlags} --build=${dubBuildType} ${toString dubBuildFlags}";
|
2024-05-02 00:46:19 +00:00
|
|
|
combinedTestFlags = "${combinedFlags} ${toString dubTestFlags}";
|
2024-05-13 21:24:10 +00:00
|
|
|
in stdenv.mkDerivation (builtins.removeAttrs args [ "dubLock" ] // {
|
|
|
|
strictDeps = args.strictDeps or true;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
nativeBuildInputs = args.nativeBuildInputs or [ ]
|
|
|
|
++ [ dub compiler removeReferencesTo ];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
configurePhase = args.configurePhase or ''
|
|
|
|
runHook preConfigure
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
export DUB_HOME="$NIX_BUILD_TOP/.dub"
|
|
|
|
mkdir -p $DUB_HOME
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
# register dependencies
|
|
|
|
${lib.concatMapStringsSep "\n" (dep: ''
|
|
|
|
dub fetch ${dep.pname}@${dep.version} --cache=user --skip-registry=standard --registry=file://${dubRegistryBase}/${dep.pname}
|
|
|
|
'') lockedDeps}
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
runHook postConfigure
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
buildPhase = args.buildPhase or ''
|
|
|
|
runHook preBuild
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
dub build ${combinedBuildFlags}
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
runHook postBuild
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
doCheck = args.doCheck or false;
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
checkPhase = args.checkPhase or ''
|
|
|
|
runHook preCheck
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
dub test ${combinedTestFlags}
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
runHook postCheck
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
preFixup = ''
|
|
|
|
${args.preFixup or ""}
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
find "$out" -type f -exec remove-references-to -t ${compiler} '{}' +
|
|
|
|
'';
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
disallowedReferences = [ compiler ];
|
2024-05-02 00:46:19 +00:00
|
|
|
|
2024-05-13 21:24:10 +00:00
|
|
|
meta = { platforms = dub.meta.platforms; } // args.meta or { };
|
|
|
|
})
|