nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 236 lines 9.3 kB view raw
1{ 2 lib, 3 runtimeShell, 4 stdenvNoCC, 5 callPackage, 6 writeShellScript, 7 makeWrapper, 8 dotnetCorePackages, 9 cacert, 10 addNuGetDeps, 11 dotnet-sdk, 12}: 13let 14 default-sdk = dotnet-sdk; 15 transformArgs = 16 finalAttrs: 17 { 18 enableParallelBuilding ? true, 19 # Flags to pass to `makeWrapper`. This is done to avoid double wrapping. 20 makeWrapperArgs ? [ ], 21 22 # Flags to pass to `dotnet restore`. 23 dotnetRestoreFlags ? [ ], 24 # Flags to pass to `dotnet build`. 25 dotnetBuildFlags ? [ ], 26 # Flags to pass to `dotnet test`, if running tests is enabled. 27 dotnetTestFlags ? [ ], 28 # Flags to pass to `dotnet install`. 29 dotnetInstallFlags ? [ ], 30 # Flags to pass to `dotnet pack`. 31 dotnetPackFlags ? [ ], 32 # Flags to pass to dotnet in all phases. 33 dotnetFlags ? [ ], 34 35 # The path to publish the project to. When unset, the directory "$out/lib/$pname" is used. 36 installPath ? null, 37 # The binaries that should get installed to `$out/bin`, relative to `$installPath/`. These get wrapped accordingly. 38 # Unfortunately, dotnet has no method for doing this automatically. 39 # If unset, all executables in the projects root will get installed. This may cause bloat! 40 executables ? null, 41 dontPublish ? false, 42 # Packs a project as a `nupkg`, and installs it to `$out/share`. If set to `true`, the derivation can be used as a dependency for another dotnet project by adding it to `projectReferences`. 43 packNupkg ? false, 44 # The packages project file, which contains instructions on how to compile it. This can be an array of multiple project files as well. 45 projectFile ? null, 46 # The NuGet dependency file. This locks all NuGet dependency versions, as otherwise they cannot be deterministically fetched. 47 # This can be generated by running the `passthru.fetch-deps` script. 48 nugetDeps ? null, 49 # A list of derivations containing nupkg packages for local project references. 50 # Referenced derivations can be built with `buildDotnetModule` with `packNupkg=true` flag. 51 # Since we are sharing them as nugets they must be added to csproj/fsproj files as `PackageReference` as well. 52 # For example, your project has a local dependency: 53 # <ProjectReference Include="../foo/bar.fsproj" /> 54 # To enable discovery through `projectReferences` you would need to add a line: 55 # <ProjectReference Include="../foo/bar.fsproj" /> 56 # <PackageReference Include="bar" Version="*" Condition=" '$(ContinuousIntegrationBuild)'=='true' "/> 57 projectReferences ? [ ], 58 # Libraries that need to be available at runtime should be passed through this. 59 # These get wrapped into `LD_LIBRARY_PATH`. 60 runtimeDeps ? [ ], 61 # The dotnet runtime ID. If null, fetch-deps will gather dependencies for all 62 # platforms in meta.platforms which are supported by the sdk. 63 runtimeId ? null, 64 65 # Test filters. This gets passed to `dotnet test --filter`, concatenated using `&`. 66 # You may also use `disabledTests` to filter tests based on their name. 67 # See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details. 68 testFilters ? [ ], 69 # Tests to disable. This gets passed to `dotnet test --filter "FullyQualifiedName!={}"`, to ensure compatibility with all frameworks. 70 # You may also use `testFilters` to pass more generic filters to `dotnet test --filter`. 71 # See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-test#filter-option-details for more details. 72 disabledTests ? [ ], 73 # The project file to run unit tests against. This is usually referenced in the regular project file, but sometimes it needs to be manually set. 74 # It gets restored and build, but not installed. You may need to regenerate your nuget lockfile after setting this. 75 testProjectFile ? null, 76 77 # The type of build to perform. This is passed to `dotnet` with the `--configuration` flag. Possible values are `Release`, `Debug`, etc. 78 buildType ? "Release", 79 # If set to true, builds the application as a self-contained - removing the runtime dependency on dotnet 80 selfContainedBuild ? false, 81 # Whether to use an alternative wrapper, that executes the application DLL using the dotnet runtime from the user environment. `dotnet-runtime` is provided as a default in case no .NET is installed 82 # This is useful for .NET tools and applications that may need to run under different .NET runtimes 83 useDotnetFromEnv ? false, 84 # Whether to explicitly enable UseAppHost when building. This is redundant if useDotnetFromEnv is enabled 85 useAppHost ? true, 86 # The dotnet SDK to use. 87 dotnet-sdk ? default-sdk, 88 # The dotnet runtime to use. 89 dotnet-runtime ? dotnet-sdk.runtime, 90 ... 91 }@args: 92 let 93 projectFiles = lib.optionals (projectFile != null) (lib.toList projectFile); 94 testProjectFiles = lib.optionals (testProjectFile != null) (lib.toList testProjectFile); 95 96 platforms = 97 if args ? meta.platforms then 98 lib.intersectLists args.meta.platforms dotnet-sdk.meta.platforms 99 else 100 dotnet-sdk.meta.platforms; 101 102 hook = callPackage ./hook { inherit dotnet-runtime; }; 103 104 inherit (dotnetCorePackages) systemToDotnetRid; 105 in 106 args 107 // { 108 dotnetInstallPath = installPath; 109 dotnetExecutables = executables; 110 dotnetBuildType = buildType; 111 dotnetProjectFiles = projectFiles; 112 dotnetTestProjectFiles = testProjectFiles; 113 dotnetTestFilters = testFilters; 114 dotnetDisabledTests = disabledTests; 115 dotnetRuntimeIds = lib.singleton ( 116 if runtimeId != null then runtimeId else systemToDotnetRid stdenvNoCC.hostPlatform.system 117 ); 118 dotnetRuntimeDeps = map lib.getLib runtimeDeps; 119 dotnetSelfContainedBuild = selfContainedBuild; 120 dotnetUseAppHost = useAppHost; 121 122 inherit 123 enableParallelBuilding 124 dotnetRestoreFlags 125 dotnetBuildFlags 126 dotnetTestFlags 127 dotnetInstallFlags 128 dotnetPackFlags 129 dotnetFlags 130 packNupkg 131 useDotnetFromEnv 132 nugetDeps 133 runtimeId 134 dotnet-sdk 135 ; 136 137 nativeBuildInputs = args.nativeBuildInputs or [ ] ++ [ 138 hook 139 140 cacert 141 makeWrapper 142 dotnet-sdk 143 ]; 144 145 buildInputs = args.buildInputs or [ ] ++ dotnet-sdk.packages ++ projectReferences; 146 147 # Parse the version attr into a format acceptable for the Version msbuild property 148 # The actual version attr is saved in InformationalVersion, which accepts an arbitrary string 149 versionForDotnet = 150 if !(lib.hasAttr "version" args) || args.version == null then 151 null 152 else 153 let 154 components = lib.pipe args.version [ 155 lib.splitVersion 156 (lib.filter (x: (lib.strings.match "[0-9]+" x) != null)) 157 (lib.filter (x: (lib.toIntBase10 x) < 65535)) # one version component in dotnet has to fit in 16 bits 158 ]; 159 in 160 if (lib.length components) == 0 then 161 null 162 else 163 lib.concatStringsSep "." ( 164 (lib.take 4 components) 165 ++ (if (lib.length components) < 4 then lib.replicate (4 - (lib.length components)) "0" else [ ]) 166 ); 167 168 makeWrapperArgs = args.makeWrapperArgs or [ ] ++ [ 169 "--prefix" 170 "LD_LIBRARY_PATH" 171 ":" 172 "${dotnet-sdk.icu}/lib" 173 ]; 174 175 # Stripping breaks the executable 176 dontStrip = args.dontStrip or true; 177 178 # gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping 179 dontWrapGApps = args.dontWrapGApps or true; 180 181 # propagate the runtime sandbox profile since the contents apply to published 182 # executables 183 propagatedSandboxProfile = lib.optionalString (dotnet-runtime != null) ( 184 toString dotnet-runtime.__propagatedSandboxProfile 185 ); 186 187 meta = (args.meta or { }) // { 188 inherit platforms; 189 }; 190 }; 191 192in 193fnOrAttrs: 194stdenvNoCC.mkDerivation ( 195 finalAttrs: 196 let 197 args = if lib.isFunction fnOrAttrs then fnOrAttrs (args' // finalAttrs) else fnOrAttrs; 198 args' = transformArgs finalAttrs args; 199 inherit (args') 200 nugetDeps 201 runtimeId 202 meta 203 dotnet-sdk 204 ; 205 args'' = removeAttrs args' [ 206 "nugetDeps" 207 "runtimeId" 208 "installPath" 209 "executables" 210 "projectFile" 211 "projectReferences" 212 "runtimeDeps" 213 "disabledTests" 214 "testProjectFile" 215 "buildType" 216 "selfContainedBuild" 217 "useDotnet" 218 "useAppHost" 219 "dotnet-sdk" 220 ]; 221 in 222 if nugetDeps != null then 223 addNuGetDeps { 224 inherit nugetDeps; 225 overrideFetchAttrs = 226 old: 227 lib.optionalAttrs ((args'.runtimeId or null) == null) rec { 228 dotnetRuntimeIds = map (system: dotnetCorePackages.systemToDotnetRid system) meta.platforms; 229 buildInputs = 230 old.buildInputs 231 ++ lib.concatLists (lib.attrValues (lib.getAttrs dotnetRuntimeIds dotnet-sdk.targetPackages)); 232 }; 233 } args'' finalAttrs 234 else 235 args'' 236)