2024-09-07 19:36:21 -06:00
|
|
|
{
|
|
|
|
writeShellScript,
|
|
|
|
runtimeShell,
|
|
|
|
nix,
|
|
|
|
lib,
|
|
|
|
substituteAll,
|
|
|
|
nuget-to-nix,
|
|
|
|
cacert,
|
|
|
|
fetchNupkg,
|
|
|
|
callPackage,
|
|
|
|
}:
|
|
|
|
|
|
|
|
{
|
|
|
|
nugetDeps,
|
|
|
|
overrideFetchAttrs ? x: { },
|
|
|
|
}:
|
|
|
|
fnOrAttrs: finalAttrs:
|
|
|
|
let
|
|
|
|
attrs = if builtins.isFunction fnOrAttrs then fnOrAttrs finalAttrs else fnOrAttrs;
|
|
|
|
|
|
|
|
deps =
|
|
|
|
if (nugetDeps != null) then
|
|
|
|
if lib.isDerivation nugetDeps then
|
|
|
|
[ nugetDeps ]
|
|
|
|
else if lib.isList nugetDeps then
|
|
|
|
nugetDeps
|
|
|
|
else
|
|
|
|
assert (lib.isPath nugetDeps);
|
|
|
|
callPackage nugetDeps { fetchNuGet = fetchNupkg; }
|
|
|
|
else
|
|
|
|
[ ];
|
|
|
|
|
|
|
|
finalPackage = finalAttrs.finalPackage;
|
|
|
|
|
|
|
|
in
|
|
|
|
attrs
|
|
|
|
// {
|
|
|
|
buildInputs = attrs.buildInputs or [ ] ++ deps;
|
|
|
|
|
|
|
|
passthru =
|
|
|
|
attrs.passthru or { }
|
|
|
|
// {
|
|
|
|
nugetDeps = deps;
|
|
|
|
}
|
2024-09-08 22:50:49 -06:00
|
|
|
// lib.optionalAttrs (nugetDeps == null || lib.isPath nugetDeps) rec {
|
|
|
|
fetch-drv =
|
2024-09-07 19:36:21 -06:00
|
|
|
let
|
|
|
|
pkg' = finalPackage.overrideAttrs (old: {
|
|
|
|
buildInputs = attrs.buildInputs or [ ];
|
2024-09-08 19:08:44 -06:00
|
|
|
nativeBuildInputs = old.nativeBuildInputs or [ ] ++ [ cacert ];
|
2024-09-07 19:36:21 -06:00
|
|
|
keepNugetConfig = true;
|
|
|
|
dontBuild = true;
|
|
|
|
doCheck = false;
|
|
|
|
dontInstall = true;
|
|
|
|
doInstallCheck = false;
|
|
|
|
dontFixup = true;
|
|
|
|
doDist = false;
|
|
|
|
});
|
2024-09-08 22:50:49 -06:00
|
|
|
in
|
|
|
|
pkg'.overrideAttrs overrideFetchAttrs;
|
|
|
|
fetch-deps =
|
|
|
|
let
|
|
|
|
drv = builtins.unsafeDiscardOutputDependency fetch-drv.drvPath;
|
2024-09-07 19:36:21 -06:00
|
|
|
|
|
|
|
innerScript = substituteAll {
|
|
|
|
src = ./fetch-deps.sh;
|
|
|
|
isExecutable = true;
|
|
|
|
inherit cacert;
|
|
|
|
nugetToNix = nuget-to-nix;
|
|
|
|
};
|
|
|
|
|
2024-09-13 13:26:28 -06:00
|
|
|
defaultDepsFile =
|
|
|
|
# Wire in the depsFile such that running the script with no args
|
|
|
|
# runs it agains the correct deps file by default.
|
|
|
|
# Note that toString is necessary here as it results in the path at
|
|
|
|
# eval time (i.e. to the file in your local Nixpkgs checkout) rather
|
|
|
|
# than the Nix store path of the path after it's been imported.
|
|
|
|
if lib.isPath nugetDeps && !lib.isStorePath nugetDeps then
|
|
|
|
toString nugetDeps
|
|
|
|
else
|
|
|
|
''$(mktemp -t "${finalAttrs.pname or finalPackage.name}-deps-XXXXXX.nix")'';
|
|
|
|
|
2024-09-07 19:36:21 -06:00
|
|
|
in
|
|
|
|
writeShellScript "${finalPackage.name}-fetch-deps" ''
|
2024-09-08 18:34:04 -06:00
|
|
|
set -eu
|
2024-09-08 23:00:33 -06:00
|
|
|
|
2024-09-10 07:42:06 -06:00
|
|
|
echo 'fetching dependencies for' ${lib.escapeShellArg finalPackage.name} >&2
|
|
|
|
|
2024-09-13 13:26:28 -06:00
|
|
|
# this needs to be before TMPDIR is changed, so the output isn't deleted
|
|
|
|
# if it uses mktemp
|
|
|
|
depsFile=$(realpath "''${1:-${lib.escapeShellArg defaultDepsFile}}")
|
|
|
|
|
2024-09-08 18:34:04 -06:00
|
|
|
export TMPDIR
|
2024-09-13 13:26:28 -06:00
|
|
|
TMPDIR=$(mktemp -d -t fetch-deps-${lib.escapeShellArg finalPackage.name}.XXXXXX)
|
2024-09-08 18:34:04 -06:00
|
|
|
trap 'chmod -R +w "$TMPDIR" && rm -fr "$TMPDIR"' EXIT
|
2024-09-08 23:00:33 -06:00
|
|
|
|
2024-09-08 23:01:47 -06:00
|
|
|
export NUGET_HTTP_CACHE_PATH=''${NUGET_HTTP_CACHE_PATH-~/.local/share/NuGet/v3-cache}
|
|
|
|
|
2024-09-08 23:00:33 -06:00
|
|
|
HOME=$TMPDIR/home
|
|
|
|
mkdir "$HOME"
|
|
|
|
|
2024-09-08 18:34:04 -06:00
|
|
|
cd "$TMPDIR"
|
2024-09-08 23:01:47 -06:00
|
|
|
|
2024-09-13 13:26:28 -06:00
|
|
|
NIX_BUILD_SHELL=${lib.escapeShellArg runtimeShell} ${nix}/bin/nix-shell \
|
|
|
|
--pure --keep NUGET_HTTP_CACHE_PATH --run 'source '${lib.escapeShellArg innerScript}' '"''${depsFile@Q}" "${drv}"
|
2024-09-07 19:36:21 -06:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|