@ -1,6 +1,7 @@
{ lib , stdenvNoCC , linkFarmFromDrvs , nuget-to-nix , writeScript , makeWrapper , fetchurl , xml2 , dotnetCorePackages , dotnetPackages , cacert }:
{ lib , stdenvNoCC , linkFarmFromDrvs , callPackage , nuget-to-nix , writeScript , makeWrapper , fetchurl , xml2 , dotnetCorePackages , dotnetPackages , cacert }:
{ name ? " ${ args . pname } - ${ args . version } "
, pname ? name
, enableParallelBuilding ? true
, doCheck ? false
# Flags to pass to `makeWrapper`. This is done to avoid double wrapping.
@ -19,6 +20,8 @@
# Flags to pass to dotnet in all phases.
, dotnetFlags ? [ ]
# The path to publish the project to. When unset, the directory "$out/lib/$pname" is used.
, installPath ? null
# The binaries that should get installed to `$out/bin`, relative to `$out/lib/$pname/`. These get wrapped accordingly.
# Unfortunately, dotnet has no method for doing this automatically.
# If unset, all executables in the projects root will get installed. This may cause bloat!
@ -67,6 +70,10 @@ assert projectFile == null -> throw "Defining the `projectFile` attribute is req
assert nugetDeps == null -> throw " D e f i n i n g t h e ` n u g e t D e p s ` a t t r i b u t e i s r e q u i r e d , a s t o l o c k t h e N u G e t d e p e n d e n c i e s . T h i s f i l e c a n b e g e n e r a t e d b y r u n n i n g t h e ` p a s s t h r u . f e t c h - d e p s ` s c r i p t . " ;
let
inherit ( callPackage ./hooks {
inherit dotnet-sdk dotnet-test-sdk disabledTests nuget-source dotnet-runtime runtimeDeps buildType ;
} ) dotnetConfigureHook dotnetBuildHook dotnetCheckHook dotnetInstallHook dotnetFixupHook ;
_nugetDeps = linkFarmFromDrvs " ${ name } - n u g e t - d e p s " ( import nugetDeps {
fetchNuGet = { pname , version , sha256 }: fetchurl {
name = " ${ pname } - ${ version } . n u p k g " ;
@ -77,8 +84,8 @@ let
_localDeps = linkFarmFromDrvs " ${ name } - l o c a l - n u g e t - d e p s " projectReferences ;
nuget-source = stdenvNoCC . mkDerivation rec {
name = " ${ args . pname } - n u g e t - s o u r c e " ;
meta . description = " A N u g e t s o u r c e w i t h t h e d e p e n d e n c i e s f o r ${ args . pname } " ;
name = " ${ pname } - n u g e t - s o u r c e " ;
meta . description = " A N u g e t s o u r c e w i t h t h e d e p e n d e n c i e s f o r ${ pname } " ;
nativeBuildInputs = [ dotnetPackages . Nuget xml2 ] ;
buildCommand = ''
@ -103,168 +110,62 @@ let
) ) ) ;
} ;
package = stdenvNoCC . mkDerivation ( args // {
inherit buildType ;
nativeBuildInputs = args . nativeBuildInputs or [ ] ++ [ dotnet-sdk cacert makeWrapper ] ;
# Stripping breaks the executable
dontStrip = true ;
# gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping
dontWrapGApps = true ;
DOTNET_NOLOGO = true ; # This disables the welcome message.
DOTNET_CLI_TELEMETRY_OPTOUT = true ;
passthru = {
fetch-deps = writeScript " f e t c h - ${ args . pname } - d e p s " ''
set - euo pipefail
cd " $ ( d i r n a m e " '' ${ BASH_SOURCE [ 0 ] } " ) "
export HOME = $ ( mktemp - d )
deps_file = " / t m p / ${ args . pname } - d e p s . n i x "
store_src = " ${ package . src } "
src = " $ ( m k t e m p - d / t m p / ${ args . pname } . X X X ) "
cp - rT " $ s t o r e _ s r c " " $ s r c "
chmod - R + w " $ s r c "
trap " r m - r f $ s r c $ H O M E " EXIT
pushd " $ s r c "
in stdenvNoCC . mkDerivation ( args // {
nativeBuildInputs = args . nativeBuildInputs or [ ] ++ [
dotnetConfigureHook
dotnetBuildHook
dotnetCheckHook
dotnetInstallHook
dotnetFixupHook
export DOTNET_NOLOGO = 1
export DOTNET_CLI_TELEMETRY_OPTOUT = 1
dotnet-sdk
cacert
makeWrapper
] ;
mkdir - p " $ H O M E / n u g e t _ p k g s "
# Stripping breaks the executable
dontStrip = args . dontStrip or true ;
for project in " ${ lib . concatStringsSep " \" \" " ( ( lib . toList projectFile ) ++ lib . optionals ( testProjectFile != " " ) ( lib . toList testProjectFile ) ) } " ; do
$ { dotnet-sdk } /bin/dotnet restore " $ p r o j e c t " \
$ { lib . optionalString ( ! enableParallelBuilding ) " - - d i s a b l e - p a r a l l e l " } \
- p:ContinuousIntegrationBuild=true \
- p:Deterministic=true \
- - packages " $ H O M E / n u g e t _ p k g s " \
" ' ' ${ dotnetRestoreFlags [ @ ] } " \
" ' ' ${ dotnetFlags [ @ ] } "
done
# gappsWrapperArgs gets included when wrapping for dotnet, as to avoid double wrapping
dontWrapGApps = args . dontWrapGApps or true ;
echo " W r i t i n g l o c k f i l e . . . "
$ { nuget-to-nix } /bin/nuget-to-nix " $ H O M E / n u g e t _ p k g s " > " $ d e p s _ f i l e "
echo " S u c c e s f u l l y w r o t e l o c k f i l e t o : $ d e p s _ f i l e "
'' ;
} // args . passthru or { } ;
DOTNET_NOLOGO = args . DOTNET_NOLOGO or true ; # This disables the welcome message.
DOTNET_CLI_TELEMETRY_OPTOUT = args . DOTNET_CLI_TELEMETRY_OPTOUT or true ;
configurePhase = args . configurePhase or ''
runHook preConfigure
passthru = {
fetch-deps = writeScript " f e t c h - ${ pname } - d e p s " ''
set - euo pipefail
cd " $ ( d i r n a m e " '' ${ BASH_SOURCE [ 0 ] } " ) "
export HOME = $ ( mktemp - d )
deps_file = " / t m p / ${ pname } - d e p s . n i x "
for project in '' ${ projectFile [ @ ] } ''$ { t e s t P r o j e c t F i l e [ @ ] } ; d o
dotnet restore " $ p r o j e c t " \
$ { lib . optionalString ( ! enableParallelBuilding ) " - - d i s a b l e - p a r a l l e l " } \
- p:ContinuousIntegrationBuild=true \
- p:Deterministic=true \
- - source " ${ nuget-source } / l i b " \
" ' ' ${ dotnetRestoreFlags [ @ ] } " \
" ' ' ${ dotnetFlags [ @ ] } "
done
store_src = " ${ args . src } "
src = " $ ( m k t e m p - d / t m p / ${ pname } . X X X ) "
cp - rT " $ s t o r e _ s r c " " $ s r c "
chmod - R + w " $ s r c "
runHook postConfigure
'' ;
trap " r m - r f $ s r c $ H O M E " EXIT
pushd " $ s r c "
buildPhase = args . buildPhase or ''
runHook preBuild
export DOTNET_NOLOGO = 1
export DOTNET_CLI_TELEMETRY_OPTOUT = 1
for project in '' ${ projectFile [ @ ] } ''$ { t e s t P r o j e c t F i l e [ @ ] } ; d o
dotnet build " $ p r o j e c t " \
- maxcpucount:$ { if enableParallelBuilding then " $ N I X _ B U I L D _ C O R E S " else " 1 " } \
- p:BuildInParallel=$ { if enableParallelBuilding then " t r u e " else " f a l s e " } \
- p:ContinuousIntegrationBuild=true \
- p:Deterministic=true \
- p:Version=$ { args . version } \
- - configuration " $ b u i l d T y p e " \
- - no-restore \
" ' ' ${ dotnetBuildFlags [ @ ] } " \
" ' ' ${ dotnetFlags [ @ ] } "
done
mkdir - p " $ H O M E / n u g e t _ p k g s "
runHook postBuild
'' ;
checkPhase = args . checkPhase or ''
runHook preCheck
for project in '' ${ testProjectFile [ @ ] } ; d o
$ { lib . getBin dotnet-test-sdk } /bin/dotnet test " $ p r o j e c t " \
- maxcpucount:$ { if enableParallelBuilding then " $ N I X _ B U I L D _ C O R E S " else " 1 " } \
for project in " ${ lib . concatStringsSep " \" \" " ( ( lib . toList projectFile ) ++ lib . optionals ( testProjectFile != " " ) ( lib . toList testProjectFile ) ) } " ; do
$ { dotnet-sdk } /bin/dotnet restore " $ p r o j e c t " \
$ { lib . optionalString ( ! enableParallelBuilding ) " - - d i s a b l e - p a r a l l e l " } \
- p:ContinuousIntegrationBuild=true \
- p:Deterministic=true \
- - configuration " $ b u i l d T y p e " \
- - no-build \
- - logger " c o n s o l e ; v e r b o s i t y = n o r m a l " \
$ { lib . optionalString ( disabledTests != [ ] ) " - - f i l t e r \" F u l l y Q u a l i f i e d N a m e ! = ${ lib . concatStringsSep " & F u l l y Q u a l i f i e d N a m e ! = " disabledTests } \" " } \
" ' ' ${ dotnetTestFlags [ @ ] } " \
" ' ' ${ dotnetFlags [ @ ] } "
- - packages " $ H O M E / n u g e t _ p k g s " \
$ { lib . optionalString ( dotnetRestoreFlags != [ ] ) ( builtins . toString dotnetRestoreFlags ) } \
$ { lib . optionalString ( dotnetFlags != [ ] ) ( builtins . toString dotnetFlags ) }
done
runHook postCheck
echo " W r i t i n g l o c k f i l e . . . "
$ { nuget-to-nix } /bin/nuget-to-nix " $ H O M E / n u g e t _ p k g s " > " $ d e p s _ f i l e "
echo " S u c c e s f u l l y w r o t e l o c k f i l e t o : $ d e p s _ f i l e "
'' ;
installPhase = args . installPhase or ''
runHook preInstall
for project in '' ${ projectFile [ @ ] } ; d o
dotnet publish " $ p r o j e c t " \
- p:ContinuousIntegrationBuild=true \
- p:Deterministic=true \
- - output $ out/lib / $ { args . pname } \
- - configuration " $ b u i l d T y p e " \
- - no-build \
- - no-self-contained \
" ' ' ${ dotnetInstallFlags [ @ ] } " \
" ' ' ${ dotnetFlags [ @ ] } "
done
'' + l i b . o p t i o n a l S t r i n g p a c k N u p k g ''
for project in '' ${ projectFile [ @ ] } ; d o
dotnet pack " $ p r o j e c t " \
- p:ContinuousIntegrationBuild=true \
- p:Deterministic=true \
- - output $ out/share \
- - configuration " $ b u i l d T y p e " \
- - no-build \
" ' ' ${ dotnetPackFlags [ @ ] } " \
" ' ' ${ dotnetFlags [ @ ] } "
done
'' + ''
runHook postInstall
'' ;
preFixup = ''
_wrapDotnetProgram ( ) {
makeWrapper " $ 1 " " $ o u t / b i n / $ ( b a s e n a m e " $ executable " ) " \
- - set DOTNET_ROOT " ${ dotnet-runtime } " \
- - suffix LD_LIBRARY_PATH : " ${ lib . makeLibraryPath runtimeDeps } " \
" ' ' ${ gappsWrapperArgs [ @ ] } " \
" ' ' ${ makeWrapperArgs [ @ ] } "
}
'' + ( i f e x e c u t a b l e s ! = n u l l t h e n ''
for executable in '' ${ executables [ @ ] } ; d o
execPath = " $ o u t / l i b / ${ args . pname } / $ e x e c u t a b l e "
if [ [ - f " $ e x e c P a t h " && - x " $ e x e c P a t h " ] ] ; then
_wrapDotnetProgram $ execPath
else
echo " S p e c i f i e d b i n a r y \" $ e x e c u t a b l e \" i s e i t h e r n o t a n e x e c u t a b l e , o r d o e s n o t e x i s t ! "
exit 1
fi
done
'' e l s e ''
for executable in $ out/lib / $ { args . pname } /* ; d o
if [ [ - f " $ e x e c u t a b l e " && - x " $ e x e c u t a b l e " && " $ e x e c u t a b l e " != * " d l l " * ] ] ; then
_wrapDotnetProgram $ executable
fi
done
'' ) ;
} ) ;
in
package
} // args . passthru or { } ;
} )