Files
Dark Steveneq 646b892680
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s
push sheeet
2025-10-09 14:15:47 +02:00

66 lines
2.2 KiB
Nix

{
lib,
dotnet-sdk,
buildPackages, # buildDotnetModule, dotnet-runtime
testers,
runCommand,
removeReferencesTo,
}:
let
inherit (buildPackages) buildDotnetModule dotnet-runtime;
app = buildDotnetModule {
name = "use-dotnet-from-env-test-application";
src = ./src;
nugetDeps = ./nuget-deps.json;
useDotnetFromEnv = true;
env.TargetFramework = "net${lib.versions.majorMinor (lib.getVersion dotnet-sdk)}";
};
appWithoutFallback = app.overrideAttrs (oldAttrs: {
nativeBuildInputs = (oldAttrs.nativeBuildInputs or [ ]) ++ [
removeReferencesTo
];
postFixup = (oldAttrs.postFixup or "") + ''
remove-references-to -t ${dotnet-runtime} "$out/bin/Application"
'';
});
runtimeVersion = lib.head (lib.splitString "-" (lib.getVersion dotnet-runtime));
runtimeVersionFile = builtins.toFile "dotnet-version.txt" runtimeVersion;
in
{
fallback = testers.testEqualContents {
assertion = "buildDotnetModule sets fallback DOTNET_ROOT in wrapper";
expected = runtimeVersionFile;
actual = runCommand "use-dotnet-from-env-fallback-test" { } ''
${app}/bin/Application >"$out"
'';
};
# Check that appWithoutFallback does not use fallback .NET runtime.
without-fallback = testers.testBuildFailure (
runCommand "use-dotnet-from-env-without-fallback-test" { } ''
${appWithoutFallback}/bin/Application >"$out"
''
);
# NB assumes that without-fallback above to passes.
use-dotnet-root-env = testers.testEqualContents {
assertion = "buildDotnetModule uses DOTNET_ROOT from environment in wrapper";
expected = runtimeVersionFile;
actual =
runCommand "use-dotnet-from-env-root-test" { env.DOTNET_ROOT = "${dotnet-runtime}/share/dotnet"; }
''
${appWithoutFallback}/bin/Application >"$out"
'';
};
use-dotnet-path-env = testers.testEqualContents {
assertion = "buildDotnetModule uses DOTNET_ROOT from dotnet in PATH in wrapper";
expected = runtimeVersionFile;
actual = runCommand "use-dotnet-from-env-path-test" { dotnetRuntime = dotnet-runtime; } ''
PATH=$dotnetRuntime/bin''${PATH+:}$PATH ${appWithoutFallback}/bin/Application >"$out"
'';
};
}