A Nix module that builds reproducible .NET SDK derivations from global.json or explicit SDK versions.
1. Create global.json:
{
"sdk": {
"version": "10.0.100",
"rollForward": "disable",
"workloadVersion": "10.0.100.1"
}
}2. Use in your flake:
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nix-dotnet.url = "github:adampoit/nix-dotnet";
};
outputs = { self, nixpkgs, nix-dotnet }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in {
devShells.${system}.default = pkgs.mkShell {
buildInputs = [
(nix-dotnet.lib.${system}.mkDotnet {
globalJsonPath = ./global.json;
workloads = [ "android" "maui" ];
outputHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
})
];
};
};
}nix-dotnet.lib.${system}.mkDotnet {
globalJsonPath = ./global.json; # Use this for global.json-driven versioning
# sdkVersion = "10.0.103"; # Alternative to globalJsonPath
# workloadVersion = "10.0.100.1"; # Optional with sdkVersion
additionalSdks = [
{
sdkVersion = "9.0.304";
}
];
outputHash = "sha256-..."; # Required for fixed-output
}Parameters:
globalJsonPath- Path to global.json (optional; mutually exclusive withsdkVersion)sdkVersion- SDK version string like10.0.103(optional; mutually exclusive withglobalJsonPath)workloadVersion- Workload manifest version when using explicitsdkVersion(optional)workloads- List of workload names (optional, versions fromglobal.jsonorworkloadVersion)additionalSdks- Extra SDK configs to merge into the samedotnetinstallation (optional, no per-SDK hash)outputHash- Fixed-output derivation hash (required)
additionalSdks lets one dotnet command expose multiple SDK versions, so dotnet --list-sdks can show entries like .NET 10 and .NET 9 together.
Use one top-level outputHash for the whole combined installation.
Use checks.<system>.integration-tests to run all integration checks that are configured for that system.
Note: additionalSdks entries do not support installing workloads.
- Use a placeholder hash
- Build:
nix build(fails with "hash mismatch") - Copy the "got:" hash from the error
- Update your flake with the correct hash
Note: Workload installation requires executing dotnet during build, so you cannot cross-compile workload-enabled SDKs (e.g., building Linux workloads on macOS).
examples/basic/- SDK without workloadsexamples/with-workloads/- SDK with MAUI workloadsexamples/multi-sdk/- singledotnetwith both .NET 10 and .NET 9 SDKs
x86_64-linuxaarch64-linuxx86_64-darwinaarch64-darwin
# Unit tests (fast)
nix run github:nix-community/nix-unit -- --flake '.#tests'
# Integration tests (slow, builds SDK)
nix build .#checks.<system>.integration-tests --no-link
# All checks
nix flake check
# Build examples
nix build .#basic-example --no-link
nix build .#workload-example --no-linkMIT