build-support/go: support `finalAttrs` through `lib.extendMkDerivation` (#390220)

authored by Pol Dellaiera and committed by GitHub 06a152f9 a73a7a65

+341 -288
+335 -282
pkgs/build-support/go/module.nix
··· 1 - { go, cacert, git, lib, stdenv }: 2 3 - { name ? "${args'.pname}-${args'.version}" 4 - # The source used to build the derivation. 5 - , src 6 - # Native build inputs used for the derivation. 7 - , nativeBuildInputs ? [ ] 8 - , passthru ? { } 9 - , patches ? [ ] 10 11 - # A function to override the `goModules` derivation. 12 - , overrideModAttrs ? (finalAttrs: previousAttrs: { }) 13 14 - # Directory to the `go.mod` and `go.sum` relative to the `src`. 15 - , modRoot ? "./" 16 17 - # The SRI hash of the vendored dependencies. 18 - # If `vendorHash` is `null`, no dependencies are fetched and 19 - # the build relies on the vendor folder within the source. 20 - , vendorHash ? throw ( 21 - if args'?vendorSha256 then 22 - "buildGoModule: Expect vendorHash instead of vendorSha256" 23 - else 24 - "buildGoModule: vendorHash is missing" 25 - ) 26 27 - # Whether to delete the vendor folder supplied with the source. 28 - , deleteVendor ? false 29 30 - # Whether to fetch (go mod download) and proxy the vendor directory. 31 - # This is useful if your code depends on c code and go mod tidy does not 32 - # include the needed sources to build or if any dependency has case-insensitive 33 - # conflicts which will produce platform dependant `vendorHash` checksums. 34 - , proxyVendor ? false 35 36 - # We want parallel builds by default. 37 - , enableParallelBuilding ? true 38 39 - # Do not enable this without good reason 40 - # IE: programs coupled with the compiler. 41 - , allowGoReference ? false 42 43 - # Meta data for the final derivation. 44 - , meta ? { } 45 46 - # Go linker flags. 47 - , ldflags ? [ ] 48 - # Go build flags. 49 - , GOFLAGS ? [ ] 50 51 - , ... 52 - }@args': 53 54 - let 55 - args = removeAttrs args' [ 56 - "overrideModAttrs" 57 - # Compatibility layer to the directly-specified CGO_ENABLED. 58 - # TODO(@ShamrockLee): Remove after Nixpkgs 25.05 branch-off 59 - "CGO_ENABLED" 60 - ]; 61 - in 62 - (stdenv.mkDerivation (finalAttrs: 63 - args 64 - // { 65 66 - inherit modRoot vendorHash deleteVendor proxyVendor; 67 - goModules = if (finalAttrs.vendorHash == null) then "" else 68 - (stdenv.mkDerivation { 69 - name = "${finalAttrs.name or "${finalAttrs.pname}-${finalAttrs.version}"}-go-modules"; 70 71 - nativeBuildInputs = (finalAttrs.nativeBuildInputs or [ ]) ++ [ go git cacert ]; 72 73 - inherit (finalAttrs) src modRoot; 74 75 - # The following inheritance behavior is not trivial to expect, and some may 76 - # argue it's not ideal. Changing it may break vendor hashes in Nixpkgs and 77 - # out in the wild. In anycase, it's documented in: 78 - # doc/languages-frameworks/go.section.md. 79 - prePatch = finalAttrs.prePatch or ""; 80 - patches = finalAttrs.patches or [ ]; 81 - patchFlags = finalAttrs.patchFlags or [ ]; 82 - postPatch = finalAttrs.postPatch or ""; 83 - preBuild = finalAttrs.preBuild or ""; 84 - postBuild = finalAttrs.modPostBuild or ""; 85 - sourceRoot = finalAttrs.sourceRoot or ""; 86 - setSourceRoot = finalAttrs.setSourceRoot or ""; 87 - env = finalAttrs.env or { }; 88 89 - impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ 90 - "GIT_PROXY_COMMAND" 91 - "SOCKS_SERVER" 92 - "GOPROXY" 93 - ]; 94 95 - configurePhase = args.modConfigurePhase or '' 96 - runHook preConfigure 97 - export GOCACHE=$TMPDIR/go-cache 98 - export GOPATH="$TMPDIR/go" 99 - cd "$modRoot" 100 - runHook postConfigure 101 - ''; 102 103 - buildPhase = args.modBuildPhase or ('' 104 - runHook preBuild 105 - '' + lib.optionalString finalAttrs.deleteVendor '' 106 - if [ ! -d vendor ]; then 107 - echo "vendor folder does not exist, 'deleteVendor' is not needed" 108 - exit 10 109 - else 110 - rm -rf vendor 111 - fi 112 - '' + '' 113 - if [ -d vendor ]; then 114 - echo "vendor folder exists, please set 'vendorHash = null;' in your expression" 115 - exit 10 116 - fi 117 118 - export GIT_SSL_CAINFO=$NIX_SSL_CERT_FILE 119 - ${if finalAttrs.proxyVendor then '' 120 - mkdir -p "$GOPATH/pkg/mod/cache/download" 121 - go mod download 122 - '' else '' 123 - if (( "''${NIX_DEBUG:-0}" >= 1 )); then 124 - goModVendorFlags+=(-v) 125 - fi 126 - go mod vendor "''${goModVendorFlags[@]}" 127 - ''} 128 129 - mkdir -p vendor 130 131 - runHook postBuild 132 - ''); 133 134 - installPhase = args.modInstallPhase or '' 135 - runHook preInstall 136 137 - ${if finalAttrs.proxyVendor then '' 138 - rm -rf "$GOPATH/pkg/mod/cache/download/sumdb" 139 - cp -r --reflink=auto "$GOPATH/pkg/mod/cache/download" $out 140 - '' else '' 141 - cp -r --reflink=auto vendor $out 142 - ''} 143 144 - if ! [ "$(ls -A $out)" ]; then 145 - echo "vendor folder is empty, please set 'vendorHash = null;' in your expression" 146 - exit 10 147 - fi 148 149 - runHook postInstall 150 - ''; 151 152 - dontFixup = true; 153 154 - outputHashMode = "recursive"; 155 - outputHash = finalAttrs.vendorHash; 156 - # Handle empty `vendorHash`; avoid error: 157 - # empty hash requires explicit hash algorithm. 158 - outputHashAlgo = if finalAttrs.vendorHash == "" then "sha256" else null; 159 - # in case an overlay clears passthru by accident, don't fail evaluation 160 - }).overrideAttrs (finalAttrs.passthru.overrideModAttrs or overrideModAttrs); 161 162 - nativeBuildInputs = [ go ] ++ nativeBuildInputs; 163 164 - env = args.env or { } // { 165 - inherit (go) GOOS GOARCH; 166 167 - GO111MODULE = "on"; 168 - GOTOOLCHAIN = "local"; 169 170 - CGO_ENABLED = args.env.CGO_ENABLED or ( 171 - if args'?CGO_ENABLED then 172 - # Compatibility layer to the CGO_ENABLED attribute not specified as env.CGO_ENABLED 173 - # TODO(@ShamrockLee): Remove and convert to 174 - # CGO_ENABLED = args.env.CGO_ENABLED or go.CGO_ENABLED 175 - # after the Nixpkgs 25.05 branch-off. 176 - lib.warn 177 - "${finalAttrs.finalPackage.meta.position}: buildGoModule: specify CGO_ENABLED with env.CGO_ENABLED instead." 178 - args'.CGO_ENABLED 179 - else 180 - go.CGO_ENABLED 181 - ); 182 - }; 183 184 - GOFLAGS = GOFLAGS 185 - ++ lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" 186 - (lib.optional (!finalAttrs.proxyVendor) "-mod=vendor") 187 - ++ lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" 188 - (lib.optional (!allowGoReference) "-trimpath"); 189 190 - inherit enableParallelBuilding; 191 192 - # If not set to an explicit value, set the buildid empty for reproducibility. 193 - ldflags = ldflags ++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags) "-buildid="; 194 - 195 - configurePhase = args.configurePhase or ('' 196 - runHook preConfigure 197 - 198 - export GOCACHE=$TMPDIR/go-cache 199 - export GOPATH="$TMPDIR/go" 200 - export GOPROXY=off 201 - export GOSUMDB=off 202 - cd "$modRoot" 203 - '' + lib.optionalString (finalAttrs.vendorHash != null) '' 204 - ${if finalAttrs.proxyVendor then '' 205 - export GOPROXY="file://$goModules" 206 - '' else '' 207 - rm -rf vendor 208 - cp -r --reflink=auto "$goModules" vendor 209 - ''} 210 - '' + '' 211 212 - # currently pie is only enabled by default in pkgsMusl 213 - # this will respect the `hardening{Disable,Enable}` flags if set 214 - if [[ $NIX_HARDENING_ENABLE =~ "pie" ]]; then 215 - export GOFLAGS="-buildmode=pie $GOFLAGS" 216 - fi 217 218 - runHook postConfigure 219 - ''); 220 221 - buildPhase = args.buildPhase or ( 222 - lib.warnIf (builtins.elem "-buildid=" ldflags) 223 - "`-buildid=` is set by default as ldflag by buildGoModule" 224 - '' 225 - runHook preBuild 226 227 - exclude='\(/_\|examples\|Godeps\|testdata' 228 - if [[ -n "$excludedPackages" ]]; then 229 - IFS=' ' read -r -a excludedArr <<<$excludedPackages 230 - printf -v excludedAlternates '%s\\|' "''${excludedArr[@]}" 231 - excludedAlternates=''${excludedAlternates%\\|} # drop final \| added by printf 232 - exclude+='\|'"$excludedAlternates" 233 - fi 234 - exclude+='\)' 235 236 - buildGoDir() { 237 - local cmd="$1" dir="$2" 238 239 - declare -a flags 240 - flags+=(''${tags:+-tags=$(concatStringsSep "," tags)}) 241 - flags+=(''${ldflags:+-ldflags="''${ldflags[*]}"}) 242 - flags+=("-p" "$NIX_BUILD_CORES") 243 - if (( "''${NIX_DEBUG:-0}" >= 1 )); then 244 - flags+=(-x) 245 - fi 246 247 - if [ "$cmd" = "test" ]; then 248 - flags+=(-vet=off) 249 - flags+=($checkFlags) 250 - fi 251 252 - local OUT 253 - if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then 254 - if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then 255 - echo "$OUT" >&2 256 - return 1 257 - fi 258 - fi 259 - if [ -n "$OUT" ]; then 260 - echo "$OUT" >&2 261 - fi 262 - return 0 263 - } 264 265 - getGoDirs() { 266 - local type; 267 - type="$1" 268 - if [ -n "$subPackages" ]; then 269 - echo "$subPackages" | sed "s,\(^\| \),\1./,g" 270 - else 271 - find . -type f -name \*$type.go -exec dirname {} \; | grep -v "/vendor/" | sort --unique | grep -v "$exclude" 272 - fi 273 - } 274 275 - if [ -z "$enableParallelBuilding" ]; then 276 - export NIX_BUILD_CORES=1 277 - fi 278 - for pkg in $(getGoDirs ""); do 279 - echo "Building subPackage $pkg" 280 - buildGoDir install "$pkg" 281 - done 282 - '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' 283 - # normalize cross-compiled builds w.r.t. native builds 284 - ( 285 - dir=$GOPATH/bin/''${GOOS}_''${GOARCH} 286 - if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]]; then 287 - mv $dir/* $dir/.. 288 - fi 289 - if [[ -d $dir ]]; then 290 - rmdir $dir 291 - fi 292 - ) 293 - '' + '' 294 - runHook postBuild 295 - ''); 296 297 - doCheck = args.doCheck or true; 298 - checkPhase = args.checkPhase or '' 299 - runHook preCheck 300 - # We do not set trimpath for tests, in case they reference test assets 301 - export GOFLAGS=''${GOFLAGS//-trimpath/} 302 303 - for pkg in $(getGoDirs test); do 304 - buildGoDir test "$pkg" 305 - done 306 307 - runHook postCheck 308 - ''; 309 310 - installPhase = args.installPhase or '' 311 - runHook preInstall 312 313 - mkdir -p $out 314 - dir="$GOPATH/bin" 315 - [ -e "$dir" ] && cp -r $dir $out 316 317 - runHook postInstall 318 - ''; 319 320 - strictDeps = true; 321 322 - disallowedReferences = lib.optional (!allowGoReference) go; 323 324 - passthru = { 325 - inherit go; 326 - # Canonicallize `overrideModAttrs` as an attribute overlay. 327 - # `passthru.overrideModAttrs` will be overridden 328 - # when users want to override `goModules`. 329 - overrideModAttrs = lib.toExtension overrideModAttrs; 330 - } // passthru; 331 332 - meta = { 333 - # Add default meta information. 334 - platforms = go.meta.platforms or lib.platforms.all; 335 - } // meta; 336 - } 337 - ))
··· 1 + { 2 + go, 3 + cacert, 4 + gitMinimal, 5 + lib, 6 + stdenv, 7 + }: 8 9 + lib.extendMkDerivation { 10 + constructDrv = stdenv.mkDerivation; 11 + excludeDrvArgNames = [ 12 + "overrideModAttrs" 13 + # Compatibility layer to the directly-specified CGO_ENABLED. 14 + # TODO(@ShamrockLee): Remove after Nixpkgs 25.05 branch-off 15 + "CGO_ENABLED" 16 + ]; 17 + extendDrvArgs = 18 + finalAttrs: 19 + { 20 + nativeBuildInputs ? [ ], # Native build inputs used for the derivation. 21 + passthru ? { }, 22 + patches ? [ ], 23 24 + # A function to override the `goModules` derivation. 25 + overrideModAttrs ? (finalAttrs: previousAttrs: { }), 26 27 + # Directory to the `go.mod` and `go.sum` relative to the `src`. 28 + modRoot ? "./", 29 30 + # The SRI hash of the vendored dependencies. 31 + # If `vendorHash` is `null`, no dependencies are fetched and 32 + # the build relies on the vendor folder within the source. 33 + vendorHash ? throw ( 34 + if args ? vendorSha256 then 35 + "buildGoModule: Expect vendorHash instead of vendorSha256" 36 + else 37 + "buildGoModule: vendorHash is missing" 38 + ), 39 40 + # Whether to delete the vendor folder supplied with the source. 41 + deleteVendor ? false, 42 43 + # Whether to fetch (go mod download) and proxy the vendor directory. 44 + # This is useful if your code depends on c code and go mod tidy does not 45 + # include the needed sources to build or if any dependency has case-insensitive 46 + # conflicts which will produce platform dependant `vendorHash` checksums. 47 + proxyVendor ? false, 48 49 + # We want parallel builds by default. 50 + enableParallelBuilding ? true, 51 52 + # Do not enable this without good reason 53 + # IE: programs coupled with the compiler. 54 + allowGoReference ? false, 55 56 + # Meta data for the final derivation. 57 + meta ? { }, 58 59 + # Go linker flags. 60 + ldflags ? [ ], 61 + # Go build flags. 62 + GOFLAGS ? [ ], 63 64 + ... 65 + }@args: 66 + { 67 + inherit 68 + modRoot 69 + vendorHash 70 + deleteVendor 71 + proxyVendor 72 + ; 73 + goModules = 74 + if (finalAttrs.vendorHash == null) then 75 + "" 76 + else 77 + (stdenv.mkDerivation { 78 + name = "${finalAttrs.name or "${finalAttrs.pname}-${finalAttrs.version}"}-go-modules"; 79 80 + nativeBuildInputs = (finalAttrs.nativeBuildInputs or [ ]) ++ [ 81 + go 82 + gitMinimal 83 + cacert 84 + ]; 85 86 + inherit (finalAttrs) src modRoot; 87 88 + # The following inheritance behavior is not trivial to expect, and some may 89 + # argue it's not ideal. Changing it may break vendor hashes in Nixpkgs and 90 + # out in the wild. In anycase, it's documented in: 91 + # doc/languages-frameworks/go.section.md. 92 + prePatch = finalAttrs.prePatch or ""; 93 + patches = finalAttrs.patches or [ ]; 94 + patchFlags = finalAttrs.patchFlags or [ ]; 95 + postPatch = finalAttrs.postPatch or ""; 96 + preBuild = finalAttrs.preBuild or ""; 97 + postBuild = finalAttrs.modPostBuild or ""; 98 + sourceRoot = finalAttrs.sourceRoot or ""; 99 + setSourceRoot = finalAttrs.setSourceRoot or ""; 100 + env = finalAttrs.env or { }; 101 102 + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ 103 + "GIT_PROXY_COMMAND" 104 + "SOCKS_SERVER" 105 + "GOPROXY" 106 + ]; 107 108 + configurePhase = 109 + args.modConfigurePhase or '' 110 + runHook preConfigure 111 + export GOCACHE=$TMPDIR/go-cache 112 + export GOPATH="$TMPDIR/go" 113 + cd "$modRoot" 114 + runHook postConfigure 115 + ''; 116 117 + buildPhase = 118 + args.modBuildPhase or ( 119 + '' 120 + runHook preBuild 121 + '' 122 + + lib.optionalString finalAttrs.deleteVendor '' 123 + if [ ! -d vendor ]; then 124 + echo "vendor folder does not exist, 'deleteVendor' is not needed" 125 + exit 10 126 + else 127 + rm -rf vendor 128 + fi 129 + '' 130 + + '' 131 + if [ -d vendor ]; then 132 + echo "vendor folder exists, please set 'vendorHash = null;' in your expression" 133 + exit 10 134 + fi 135 136 + export GIT_SSL_CAINFO=$NIX_SSL_CERT_FILE 137 + ${ 138 + if finalAttrs.proxyVendor then 139 + '' 140 + mkdir -p "$GOPATH/pkg/mod/cache/download" 141 + go mod download 142 + '' 143 + else 144 + '' 145 + if (( "''${NIX_DEBUG:-0}" >= 1 )); then 146 + goModVendorFlags+=(-v) 147 + fi 148 + go mod vendor "''${goModVendorFlags[@]}" 149 + '' 150 + } 151 152 + mkdir -p vendor 153 154 + runHook postBuild 155 + '' 156 + ); 157 158 + installPhase = 159 + args.modInstallPhase or '' 160 + runHook preInstall 161 162 + ${ 163 + if finalAttrs.proxyVendor then 164 + '' 165 + rm -rf "$GOPATH/pkg/mod/cache/download/sumdb" 166 + cp -r --reflink=auto "$GOPATH/pkg/mod/cache/download" $out 167 + '' 168 + else 169 + '' 170 + cp -r --reflink=auto vendor $out 171 + '' 172 + } 173 174 + if ! [ "$(ls -A $out)" ]; then 175 + echo "vendor folder is empty, please set 'vendorHash = null;' in your expression" 176 + exit 10 177 + fi 178 179 + runHook postInstall 180 + ''; 181 182 + dontFixup = true; 183 184 + outputHashMode = "recursive"; 185 + outputHash = finalAttrs.vendorHash; 186 + # Handle empty `vendorHash`; avoid error: 187 + # empty hash requires explicit hash algorithm. 188 + outputHashAlgo = if finalAttrs.vendorHash == "" then "sha256" else null; 189 + # in case an overlay clears passthru by accident, don't fail evaluation 190 + }).overrideAttrs 191 + (finalAttrs.passthru.overrideModAttrs or overrideModAttrs); 192 193 + nativeBuildInputs = [ go ] ++ nativeBuildInputs; 194 195 + env = args.env or { } // { 196 + inherit (go) GOOS GOARCH; 197 198 + GO111MODULE = "on"; 199 + GOTOOLCHAIN = "local"; 200 201 + CGO_ENABLED = 202 + args.env.CGO_ENABLED or ( 203 + if args ? CGO_ENABLED then 204 + # Compatibility layer to the CGO_ENABLED attribute not specified as env.CGO_ENABLED 205 + # TODO(@ShamrockLee): Remove and convert to 206 + # CGO_ENABLED = args.env.CGO_ENABLED or go.CGO_ENABLED 207 + # after the Nixpkgs 25.05 branch-off. 208 + lib.warn 209 + "${finalAttrs.finalPackage.meta.position}: buildGoModule: specify CGO_ENABLED with env.CGO_ENABLED instead." 210 + args.CGO_ENABLED 211 + else 212 + go.CGO_ENABLED 213 + ); 214 + }; 215 216 + GOFLAGS = 217 + GOFLAGS 218 + ++ 219 + lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) 220 + "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" 221 + (lib.optional (!finalAttrs.proxyVendor) "-mod=vendor") 222 + ++ 223 + lib.warnIf (builtins.elem "-trimpath" GOFLAGS) 224 + "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" 225 + (lib.optional (!allowGoReference) "-trimpath"); 226 227 + inherit enableParallelBuilding; 228 229 + # If not set to an explicit value, set the buildid empty for reproducibility. 230 + ldflags = ldflags ++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags) "-buildid="; 231 232 + configurePhase = 233 + args.configurePhase or ( 234 + '' 235 + runHook preConfigure 236 237 + export GOCACHE=$TMPDIR/go-cache 238 + export GOPATH="$TMPDIR/go" 239 + export GOPROXY=off 240 + export GOSUMDB=off 241 + cd "$modRoot" 242 + '' 243 + + lib.optionalString (finalAttrs.vendorHash != null) '' 244 + ${ 245 + if finalAttrs.proxyVendor then 246 + '' 247 + export GOPROXY="file://$goModules" 248 + '' 249 + else 250 + '' 251 + rm -rf vendor 252 + cp -r --reflink=auto "$goModules" vendor 253 + '' 254 + } 255 + '' 256 + + '' 257 258 + # currently pie is only enabled by default in pkgsMusl 259 + # this will respect the `hardening{Disable,Enable}` flags if set 260 + if [[ $NIX_HARDENING_ENABLE =~ "pie" ]]; then 261 + export GOFLAGS="-buildmode=pie $GOFLAGS" 262 + fi 263 264 + runHook postConfigure 265 + '' 266 + ); 267 268 + buildPhase = 269 + args.buildPhase or ( 270 + lib.warnIf (builtins.elem "-buildid=" ldflags) 271 + "`-buildid=` is set by default as ldflag by buildGoModule" 272 + '' 273 + runHook preBuild 274 275 + exclude='\(/_\|examples\|Godeps\|testdata' 276 + if [[ -n "$excludedPackages" ]]; then 277 + IFS=' ' read -r -a excludedArr <<<$excludedPackages 278 + printf -v excludedAlternates '%s\\|' "''${excludedArr[@]}" 279 + excludedAlternates=''${excludedAlternates%\\|} # drop final \| added by printf 280 + exclude+='\|'"$excludedAlternates" 281 + fi 282 + exclude+='\)' 283 284 + buildGoDir() { 285 + local cmd="$1" dir="$2" 286 287 + declare -a flags 288 + flags+=(''${tags:+-tags=$(concatStringsSep "," tags)}) 289 + flags+=(''${ldflags:+-ldflags="''${ldflags[*]}"}) 290 + flags+=("-p" "$NIX_BUILD_CORES") 291 + if (( "''${NIX_DEBUG:-0}" >= 1 )); then 292 + flags+=(-x) 293 + fi 294 295 + if [ "$cmd" = "test" ]; then 296 + flags+=(-vet=off) 297 + flags+=($checkFlags) 298 + fi 299 300 + local OUT 301 + if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then 302 + if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then 303 + echo "$OUT" >&2 304 + return 1 305 + fi 306 + fi 307 + if [ -n "$OUT" ]; then 308 + echo "$OUT" >&2 309 + fi 310 + return 0 311 + } 312 313 + getGoDirs() { 314 + local type; 315 + type="$1" 316 + if [ -n "$subPackages" ]; then 317 + echo "$subPackages" | sed "s,\(^\| \),\1./,g" 318 + else 319 + find . -type f -name \*$type.go -exec dirname {} \; | grep -v "/vendor/" | sort --unique | grep -v "$exclude" 320 + fi 321 + } 322 323 + if [ -z "$enableParallelBuilding" ]; then 324 + export NIX_BUILD_CORES=1 325 + fi 326 + for pkg in $(getGoDirs ""); do 327 + echo "Building subPackage $pkg" 328 + buildGoDir install "$pkg" 329 + done 330 + '' 331 + + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' 332 + # normalize cross-compiled builds w.r.t. native builds 333 + ( 334 + dir=$GOPATH/bin/''${GOOS}_''${GOARCH} 335 + if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]]; then 336 + mv $dir/* $dir/.. 337 + fi 338 + if [[ -d $dir ]]; then 339 + rmdir $dir 340 + fi 341 + ) 342 + '' 343 + + '' 344 + runHook postBuild 345 + '' 346 + ); 347 348 + doCheck = args.doCheck or true; 349 + checkPhase = 350 + args.checkPhase or '' 351 + runHook preCheck 352 + # We do not set trimpath for tests, in case they reference test assets 353 + export GOFLAGS=''${GOFLAGS//-trimpath/} 354 355 + for pkg in $(getGoDirs test); do 356 + buildGoDir test "$pkg" 357 + done 358 359 + runHook postCheck 360 + ''; 361 362 + installPhase = 363 + args.installPhase or '' 364 + runHook preInstall 365 366 + mkdir -p $out 367 + dir="$GOPATH/bin" 368 + [ -e "$dir" ] && cp -r $dir $out 369 370 + runHook postInstall 371 + ''; 372 373 + strictDeps = true; 374 375 + disallowedReferences = lib.optional (!allowGoReference) go; 376 377 + passthru = { 378 + inherit go; 379 + # Canonicallize `overrideModAttrs` as an attribute overlay. 380 + # `passthru.overrideModAttrs` will be overridden 381 + # when users want to override `goModules`. 382 + overrideModAttrs = lib.toExtension overrideModAttrs; 383 + } // passthru; 384 385 + meta = { 386 + # Add default meta information. 387 + platforms = go.meta.platforms or lib.platforms.all; 388 + } // meta; 389 + }; 390 + }
+6 -6
pkgs/by-name/sy/symfony-cli/package.nix
··· 9 makeBinaryWrapper, 10 }: 11 12 - buildGoModule rec { 13 pname = "symfony-cli"; 14 version = "5.11.0"; 15 vendorHash = "sha256-6DNirMtVuuWJziDy6HeJxHQnV2f7jmie7kcXvUDfN94="; ··· 17 src = fetchFromGitHub { 18 owner = "symfony-cli"; 19 repo = "symfony-cli"; 20 - rev = "v${version}"; 21 hash = "sha256-r8B9lFcTG0TWb3U8eRzg9SkwUY90805wdFlmPbtMywk="; 22 leaveDotGit = true; 23 postFetch = '' ··· 29 ldflags = [ 30 "-s" 31 "-w" 32 - "-X main.version=${version}" 33 "-X main.channel=stable" 34 ]; 35 ··· 53 passthru = { 54 updateScript = nix-update-script { }; 55 tests.version = testers.testVersion { 56 - inherit version; 57 package = symfony-cli; 58 command = "symfony version --no-ansi"; 59 }; 60 }; 61 62 meta = { 63 - changelog = "https://github.com/symfony-cli/symfony-cli/releases/tag/v${version}"; 64 description = "Symfony CLI"; 65 homepage = "https://github.com/symfony-cli/symfony-cli"; 66 license = lib.licenses.agpl3Plus; 67 mainProgram = "symfony"; 68 maintainers = with lib.maintainers; [ drupol ]; 69 }; 70 - }
··· 9 makeBinaryWrapper, 10 }: 11 12 + buildGoModule (finalAttrs: { 13 pname = "symfony-cli"; 14 version = "5.11.0"; 15 vendorHash = "sha256-6DNirMtVuuWJziDy6HeJxHQnV2f7jmie7kcXvUDfN94="; ··· 17 src = fetchFromGitHub { 18 owner = "symfony-cli"; 19 repo = "symfony-cli"; 20 + rev = "v${finalAttrs.version}"; 21 hash = "sha256-r8B9lFcTG0TWb3U8eRzg9SkwUY90805wdFlmPbtMywk="; 22 leaveDotGit = true; 23 postFetch = '' ··· 29 ldflags = [ 30 "-s" 31 "-w" 32 + "-X main.version=${finalAttrs.version}" 33 "-X main.channel=stable" 34 ]; 35 ··· 53 passthru = { 54 updateScript = nix-update-script { }; 55 tests.version = testers.testVersion { 56 + inherit (finalAttrs) version; 57 package = symfony-cli; 58 command = "symfony version --no-ansi"; 59 }; 60 }; 61 62 meta = { 63 + changelog = "https://github.com/symfony-cli/symfony-cli/releases/tag/v${finalAttrs.version}"; 64 description = "Symfony CLI"; 65 homepage = "https://github.com/symfony-cli/symfony-cli"; 66 license = lib.licenses.agpl3Plus; 67 mainProgram = "symfony"; 68 maintainers = with lib.maintainers; [ drupol ]; 69 }; 70 + })