Commit Graph

57 Commits

Author SHA1 Message Date
piegames
68927918d0 treewide: Fix indentation in strings
The indentation stripping semantics of strings are fairly bad and have a
few gotchas where the resulting string has not the intended indentation.
This commit fixes most if not all such instances in Nixpkgs.

I tried to strive a balance between keeping the diff small and
reformatting/refactoring the code to look better. In general,
reformatting should be left to Nixfmt.

Note that this causes a lot of rebuilds by design. All changes need to
be thoroughly vetted and reviewed for correctness. There is no automatic
way to prove correctness.

List of files to fix generated by running
https://gerrit.lix.systems/c/lix/+/2092 on Nixpkgs and looking at the
warnings.
2024-10-22 21:36:42 +02:00
Jörg Thalheim
a808f823bb
Merge branch 'master' into docs/improve-go-builder 2024-10-12 13:16:51 +02:00
Gabriel Nützi
9a6d7cc9f7
module.nix aktualisieren
Co-authored-by: Wael Nasreddine <wael.nasreddine@gmail.com>
2024-10-11 12:00:13 +02:00
Yueh-Shun Li
e31ace5cd4 buildGoModule: use lib.toExtension
Use toExtension from Nixpkgs library instead of the one defined locally.
2024-09-14 21:47:59 +08:00
Gabriel Nützi
ba2b91866b
chore: typos and comment fixups in Go build-support function 2024-09-13 13:26:51 +02:00
K900
23b4832da0 Merge remote-tracking branch 'origin/master' into staging-next 2024-09-04 08:53:48 +03:00
Sandro Jäckel
bc12ef1bf0
buildGoModule: be nicer when overrideAttrs clears passthru
Before an overlay in the form of:

package.overrideAttrs (old: {
  passthru = {};
})

would fail evaluation like:

       error: attribute 'overrideModAttrs' missing
       at /nix/store/afwc3m1sm49qq57xjv2hmd7iy4x0j33h-source/pkgs/build-support/go/module.nix:179:20:
          178|     outputHashAlgo = if finalAttrs.vendorHash == "" then "sha256" else null;
          179|   }).overrideAttrs finalAttrs.passthru.overrideModAttrs;
             |                    ^
          180|

Now instead we take the fallback default.
2024-09-02 17:53:36 +02:00
Tim Cuthbertson
911aa1440f treewide: support NIX_SSL_CERT_FILE as an impureEnvVar
This envvar is also added to lib.proxyImpureEnvVars since it's
typically required for https proxies.

This change also updates fetchgit and go module fetching to use this
envvar. NIX_GIT_SSL_CAINFO is still supported for backwards
compatibility in fetchgit.
2024-08-23 21:34:22 +10:00
Yueh-Shun Li
eed069a5bc buildGoModule: fix overrideAttrs overriding
Fix overriding of vendorHash and various attributes via the fixed point
attribute support of stdenv.mkDerivation.

Pass as derivation attributes
goModules, modRoot, vendorHash, deleteVendor, and proxyVendor.

Move goModules and vendorHash out of passthru.

Co-authored-by: Doron Behar <doron.behar@gmail.com>
2024-08-11 13:38:11 +08:00
Yueh-Shun Li
010277de84 buildGoModule: respect user-specified passthru
Prioritize user-specified passthru arguments over those added by
buildGoModule.
2024-07-29 06:47:12 +08:00
Paul Meyer
b6c7f1bfd6 buildGoPackage: deprecate
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
2024-07-21 12:50:54 +02:00
Wael Nasreddine
0505253a30
Merge pull request #303217 from deshaw/buildGoModule-setSourceRoot
buildGoModule: propagate setSourceRoot
2024-07-09 15:10:02 -07:00
Yueh-Shun Li
26baea8388 buildGoModule: don't pass buildFlagsArray as file
Store buildFlagsArray as Bash global array variable instead of
creating/sourcing a file containing its declaration.

buildFlagsArray is short enough, and it is not assigned in a sub-shell.
There's no reason to pass it as a file. Storing it as a variable makes
the build more efficient.
2024-06-01 23:29:41 +00:00
Weijia Wang
b4617eb071 Merge branch 'staging-next' into staging 2024-05-03 19:03:51 +02:00
Weijia Wang
a6742256e2
Merge pull request #279391 from katexochen/buildGoModule/deprecate-buildflags
buildGoModule: announce removal of `buildFlags` and `buildFlagsArray`
2024-05-02 12:58:35 +02:00
Elliot Cameron
e6adf1505c buildGoModule: propagate setSourceRoot to goModules
The underlying goModules derivation must have the same source root as
the overall package. sourceRoot is being propagated already, but
setSourceRoot was not. This was surely an oversight.

This is implemented in such a way that it cannot break existing
vendorHashes unless the package is using setSourceRoot already. If
that's the case, then the package is either broken or found a workaround
to do deal with this very issue (e.g. by using `cd path` in an early
phase).

A simple search (`rg setSourceRoot $(rg -l buildGoModule)`) reveals that
no such packages obviously exist in Nixpkgs.
2024-04-29 14:12:26 -04:00
Yueh-Shun Li
8d861e6118 buildGoModule: place GOFLAGS-related warnings around GOFLAGS specification
Avoid "global" warnings that complicates fixed-point arguments support.
2024-04-18 15:14:43 +00:00
Yueh-Shun Li
6500de413a buildGoModule: warn about flags only when using provided buildPhase
Warn about buildFlags and ldflags only when using buildPhase provided by
buildGoModule.

This allows developers to use buildFlags in custom buildPhase.
2024-04-18 15:05:37 +00:00
Yongun Seong
3e28bdc678
buildGoModule: inherit env from main package to goModule derivation 2024-04-14 14:27:44 +09:00
Paul Meyer
dd540970e2 buildGoModule: announce removal of buildFlags
and `buildFlagsArray`
2024-04-12 10:40:35 +02:00
Weijia Wang
cb00e17a14
Merge pull request #299169 from ShamrockLee/go-module-vendorsha256
buildGoModule: Deprecate vendorSha256 with throw
2024-03-28 10:58:18 +01:00
Paul Meyer
63a052eb57 buildGoModule: warn if -trimpath or -mod= is used
in GOFLAGS
2024-03-28 07:57:19 +01:00
Yueh-Shun Li
c9da94beff buildGoModule: Deprecate vendorSha256 with throw
Ignore vendorSha256 when vendorHash is specified.

Throw when vendorHash isn't specified:
- "buildGoModule: Expect vendorHash instead of vendorSha256" when
  vendorSha256 is specified.
- "buildGoModule: vendorHash is missing" otherwise.

`goModules.outputHashAlgo` is specified as null when vendorHash is not
empty, "sha256" otherwise.

Co-authored-by: zowoq <59103226+zowoq@users.noreply.github.com>
2024-03-27 11:19:40 +08:00
Jörg Thalheim
a292058564
Merge pull request #276685 from katexochen/buildGoModule/buildid
buildGoModule: always set `-buildid=` as ldflag
2024-01-14 14:13:16 +01:00
Sergei Trofimovich
a1422a7f8f build-support/go: fix eval of vendorSha256 accesses
Before the change there was no way to poll for presence of
`vendorSha256` attribute:

    $ nix-instantiate --strict --eval --expr 'with import ./. {}; _3mux.vendorSha256 or "no hash"'
       error: attribute 'vendorSha256' missing
          292|     passthru = passthru // { inherit go goModules vendorHash; } // { inherit (args') vendorSha256; };
             |                                                                     ^

After the change the poll happens as expected:

    $ nix-instantiate --strict --eval --expr 'with import ./. {}; _3mux.vendorSha256 or "no hash"'
    "no hash"
2023-12-30 12:03:28 +10:00
Paul Meyer
891a634876 buildGoModule: always set -buildid= as ldflag
Signed-off-by: Paul Meyer <49727155+katexochen@users.noreply.github.com>
2023-12-28 09:59:34 +01:00
Aaron Jheng
c3104c4cad buildGoModule: deprecate vendorSha256 attribute 2023-11-14 09:37:22 +01:00
zowoq
9b562802e0 Revert "buildGoModule: set GOPROXY to go default"
This reverts commit 3392d56b72.

Fixed in cbc976a97c
2023-08-22 09:20:22 +10:00
zowoq
3392d56b72 buildGoModule: set GOPROXY to go default 2023-08-02 01:08:27 +10:00
zowoq
86cd7e0948 buildGo{Module,Package}: set GOTOOLCHAIN to local
prevent go from downloading another toolchain
2023-08-02 01:08:27 +10:00
zowoq
41ccfa322e buildGoModule: refactor GO111MODULE 2023-08-02 01:08:27 +10:00
Artturin
7da39a7a9e
treewide .goModules: revert renaming the derivation
This is a workaround to avoid exposing non-reproducible .goModules
At least for now.
https://github.com/NixOS/nixpkgs/pull/242905#issuecomment-1646820126
2023-07-24 08:15:48 +02:00
Artturin
1c29673fcc treewide: go-modules -> goModules
In 787af0f79f
I had to change ${go-modules} to $goModules to allow overrideAttrs to work;
However, env vars cannot contain -, so  i had to change go-modules too.
This in turn broke nix-update because it uses the go-modules attr.

Instead of making nix-update more complicated, make go-modules naming match cargoDeps.

`fd --type f | xargs sd '\bgo-modules\b' 'goModules'`
and revert change to pkgs/applications/misc/dstask/default.nix
and pkgs/servers/http/dave/default.nix
and pkgs/os-specific/darwin/plistwatch/default.nix

release note added
2023-07-14 00:18:06 +03:00
Yueh-Shun Li
aea73adfdd buildGo{Module,Package}: remove input argument "tags"
Unify how ldflags and tags are passed
2023-05-31 07:14:18 +10:00
zowoq
a91f6eba1e buildGoPackage: remove ldflags and with builtins
as done for buildGoModule in abd5dfa013 and 3be02ada9e
2023-05-31 07:14:18 +10:00
zowoq
304940d98e buildGoModule: format
Co-authored-by: Yueh-Shun Li <shamrocklee@posteo.net>
2023-05-30 19:30:06 +10:00
Yueh-Shun Li
1a89cfae1f buildGoModule: simplify go-module attribute structure without rebuild 2023-05-28 07:50:02 +10:00
zowoq
0ba51a51f8 buildGoModule: alias vendorSha256 to vendorHash 2023-05-27 09:19:47 +10:00
figsoda
3be02ada9e buildGoModule: remove unused lambda parameters 2023-05-24 11:58:12 -04:00
figsoda
abd5dfa013 buildGoModule: remove unused with builtins; 2023-05-24 11:56:21 -04:00
Doron Behar
a82c8611ce
buildGoModule: don't inherit build hooks when building go-modules (#225349)
* buildGoModule: don't inherit postBuild hook when building go-modules

This is a slight revert of 5ce647b8bf
(#212800).

Inheriting these hooks in the `.go-modules` derivation can be confusing:
One doesn't expect them to run when generating the fixed output modules
derivation, but only on the main derivation. A `postBuild` hook that
adds some files to $out will cause a very hard to debug issue[1].

This commit adds support for a dedicated `modPostBuild` hook that will
be used only by the derivation building `.go-modules`. Additionally,
`go.section.md` now explains these attributes behavior better.

[1]:
https://discourse.nixos.org/t/cant-update-a-go-package-getting-go-inconsistent-vendoring/27063/6

Co-authored-by: Sandro <sandro.jaeckel@gmail.com>
2023-04-22 11:08:54 +10:00
github-actions[bot]
fc0616b73d
Merge master into staging-next 2023-04-09 06:01:16 +00:00
zowoq
dc73bd6430 buildGo{Module,Package}: minor cleanup 2023-04-09 12:23:16 +10:00
Ivan Trubach
dcc576176c buildGo{Module,Package}: fix precedence for or operator 2023-03-24 15:45:25 +10:00
github-actions[bot]
d3648def80
Merge staging-next into staging 2023-02-07 00:02:46 +00:00
zowoq
3feeedb5e2 buildGoModule: make the vendor fetcher error if it is empty 2023-02-07 06:23:39 +10:00
zowoq
421acf1022 buildGo{Module,Package}: respect nix hardening flags when setting buildmode 2023-02-07 06:20:57 +10:00
Sandro Jäckel
5ce647b8bf
buildGoModule: forward prePatch, postPatch and postBuild to vendoring
to be more prediactable
2023-01-26 17:08:55 +01:00
Jörg Thalheim
4a94d77712 buildGo{module,package}: do not build with verbose flags
This creates a lot of noise that can hide actual compile errors.
2022-12-04 16:42:53 +01:00
Sandro
5b76f42372
buildGo{Module,Package}: don't run vet linter 2022-08-20 07:37:14 +10:00