Commit graph

50 commits

Author SHA1 Message Date
adisbladis
5149c67e6e Enable Cgo by default
To be in line with the behaviour of buildGoModule since https://github.com/NixOS/nixpkgs/pull/177594.
2022-08-24 11:57:43 +08:00
adisbladis
ac99f239a5 don't run vet linter
This is a port of 5b76f42372.
2022-08-24 11:34:30 +08:00
adisbladis
4141b461c4 builder/symlink.go: Remove commented code 2022-08-24 09:51:55 +08:00
adisbladis
f3314213be Add ldflags to buildGoApplication function signature
This is not strictly required but is good for discoverability.
2022-08-24 09:51:55 +08:00
adisbladis
564d1edc26 Set SSL_CERT_FILE by setup hook rather than explicit 2022-08-24 09:51:55 +08:00
adisbladis
b40e660f51 don't set trimpath for tests
This is a port of 64e6cc1a1d.
2022-08-24 09:41:59 +08:00
adisbladis
ab5ec79935 Run unit tests under subdirs
Bug:
Due to the way `buildGoDir` function was repurposed to also run `go
test`, if `checkFlags` was defined, `go test` was ran only at the top
level directory. Only the first element of `checkFlags` array would get
passed to the `go test` command as arguments.

Fix:
Now the first parameter to `buildGoDir` is handled as the command.  If
the command is "test" `checkFlags` get passed as arguments along with
other build flags like ldflags, tags, etc.

Readability:
- Iteratively build a flag array in `buildGoDir` instead of single long
  variable expansion command line.
- Bash style: Single line local assignment of positional parameters.

This is a port of 89864413b2.
2022-08-24 09:00:33 +08:00
adisbladis
4d9ea46f79 Copy vendor directory instead of symlinking to it
As pointed out in
https://github.com/NixOS/nixpkgs/pull/188035#discussion_r953044264
this can be a source of errors when builders do things they shouldn't.

I'm not really happy about this change as it causes quite a bit more
IO for larger dependency graphs.
2022-08-24 08:05:37 +08:00
adisbladis
bca2a1231e Fix Go compiler missing from mkGoEnv created environments
Closes #68
2022-08-23 21:11:28 +08:00
adisbladis
b8c2216317 builder/install.go: Make build failures more apparent by attaching stdout/stderr 2022-08-17 15:36:21 +08:00
HuangYi
71fd703317
Invalid regex on macOS
- fix the regex
2022-07-29 19:38:34 +08:00
adisbladis
0ea20c514a refactor: inherit lib/builtins in top level scope in builder 2022-06-15 06:14:59 +08:00
adisbladis
85eaf382e6 refactor: Move replace commands computation to mkVendorEnv
It should be shared between shell envs and packages.
2022-06-15 06:14:59 +08:00
adisbladis
74a2950c64 buildGoApplication: Remove package from let binding
It's the thing we return so no point in binding it to a temporary variable.
2022-06-14 19:27:24 +08:00
adisbladis
5a8afd711e builder: Reformat with nixpkgs-fmt
After porting builder changes from nixpkgs the structure has changed somewhat.
2022-06-14 19:14:19 +08:00
adisbladis
2028c2f3ff go: Apply package exclusion equally
The exclusion logic was moved out of getGoDirs but only buildPhase was updated
causing checkPhase to possibly fail. This happened in golint as it has go
files in testdata that are meant as testdata files and not go packages to
test which caused the checkPhase to fail.

This is a port of ddcc7c67d2
2022-06-14 19:14:19 +08:00
adisbladis
df791b8057 go: Drop unnecessary backslash-escape
There's no backslash interpretation going on within single-quote strings
which means there's no need to escape the backslash. Since this was going
on within single-quote strings the $exclude variable ended up having 2
backslashes (`\\`) instead of the intended single backslash. This meant
that the regex that was built up was incorrect. For example prometheus'
exclude contents before and after this change are:

✕: \(/_\|examples\|Godeps\|testdata\\|documentation/prometheus-mixin\)
✓: \(/_\|examples\|Godeps\|testdata\|documentation/prometheus-mixin\)

This is a port of 60543c4f9e
2022-06-14 19:14:19 +08:00
adisbladis
31102e0753 go: Bunch of fixes when using excludedPackages and other bits
Few things going on in this commit:

Do not print "Building subPakage $pkg" message if actually going to skip the
package. This was confusing to me when I was trying to figure out how to set
excludedPackages and seeing the "Building subpackage $pkg" messages for
packages I wanted to skip. Turns out this messages was being printed before
checking if we actually wanted to build the package and not necessarily that my
excludedPackages was wrong.

This commit also does some setup outside the buildGoDir function so that we
avoid checking `excludedPackages` for every package and cut down the number
of grep calls by half since we always want at least one grep for the default
excludedPackages, might as well just add to the patterns being checked.

Finally, adds documentation for usage of excludedPackages and subPackages. I
had to read the implementation to figure out how to correctly use these
function arguments since there was no documentation and different uses in the
code base. So this commit documents usage of the arguments.

This is a port of 8b5a7940b0
2022-06-14 19:14:19 +08:00
adisbladis
359449a284 buildGoApplication: warn if buildFlagsArray is used
This is a port of 3360a376cb
2022-06-14 19:14:19 +08:00
adisbladis
8aa44afb7e buildGoApplication: warn if buildFlags is used
This is a port of cb7d80dcaf
2022-06-14 19:14:19 +08:00
adisbladis
f42a0cddb4 buildGoApplication: add tags argument
Simpler method of setting tags rather than using some combination of buildFlags, buildFlagsArray, preBuild, etc

Using `lib.concatStringsSep ","` as space separated tags are deprecated in go.

This is a port of b60dde0c1e
2022-06-14 19:14:19 +08:00
adisbladis
5913cf95d5 buildGoApplication: add support for checkFlags
This is a port of dc973241a9
2022-06-14 19:14:19 +08:00
adisbladis
24c5e41124 buildGoApplication: Introduce ldflags argument
Previously it was not possible to define multiple ldflags, since only
the last definition applies, and there's some quoting issues with
`buildFlagsArray`. With the new `ldflags` argument it's possible to do
this, e.g.

    ldflags = drv.ldflags or [] ++ [
      "-X main.Version=1.0"
    ]

can now properly append a flag without clearing all previous ldflags.

This is a port of 155ae682a5
2022-06-14 19:14:19 +08:00
adisbladis
366c0e5a17 mkGoEnv: Pass attrs on to mkDerivation 2022-06-14 18:26:50 +08:00
adisbladis
509b97c288 Build non-development packages in the same way as development packages
The difference in behaviour was unfortunate.

The only downside I can see is that this doesn't allow for mixed
origins in the same package, which probably shouldn't be done anyway.
2022-06-14 08:19:42 +08:00
adisbladis
d404767bec builder: Build internal packages for host plattform 2022-06-14 05:27:43 +08:00
adisbladis
1ffea526a0 Add package generation for non development packages
This makes it possible to generate packages that you do not have a
local checkout for, e.g. running:
`gomod2nix generate --outdir example/ golang.org/x/tools/cmd/stringer`

This will be useful for packaging dependencies that you are not
developing, but just simply packaging.
2022-06-14 05:15:43 +08:00
adisbladis
aae59a6851 Don't set CGO_ENABLED by default
Instead let the compiler decide.
This will result in less cryptic errors.
2022-06-13 20:53:45 +08:00
adisbladis
ade4c20234 Factor out Go version selection from mkGoEnv and add it to buildGoApplication too 2022-06-13 20:53:45 +08:00
adisbladis
908ab2bb87 Precompile internal packages instead of using go run
It shaves off a second or so of wait time per environment.
2022-06-13 20:37:42 +08:00
adisbladis
973b050adf fetcher: Make sure sources are writable before filtering .ds_store 2022-06-13 20:37:42 +08:00
adisbladis
1eb70073c4 Bump dependencies 2022-06-13 20:37:42 +08:00
adisbladis
a4bed25a86 Add mkGoEnv function
This creates an `mkGoEnv` function which takes care of adding the
correct Go package to your development environment and installs
development dependencies from tools.go in a Nix derivation.

The "normal" workflow around Go with tools.go just sticks development
dependencies in $GOBIN which isn't ideal since you have no separation
between projects.
2022-06-13 20:37:42 +08:00
adisbladis
d7830bd5b2 Filter MacOS .DS_Store directories
Now that we're hashing files directly from the Go sources on the host
system we need to avoid these files.

Closes #49.
2022-06-01 01:46:29 +08:00
HuangYi
36bc9ef864
support impure env GOPROXY
which is by go mod download
2022-05-30 11:13:30 +08:00
adisbladis
79d737ec6e Fix passing of Go to buildGoApplication 2022-05-29 16:24:58 +08:00
adisbladis
d831b947fc Fix go.mod parser for repeated replace directives
Constructs such as
```
replace google.golang.org/grpc => google.golang.org/grpc v1.33.2
replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1
```

Are perfectly valid and we previously discarded every one but the last of them.
2022-05-29 16:23:37 +08:00
adisbladis
33b65aa13e root: Use new format for building self 2022-05-28 22:56:52 +08:00
adisbladis
44bb5b9495 builder: Use new format for building 2022-05-28 22:56:52 +08:00
HuangYi
7f6bfc93a3
fix another edge case 2022-05-20 16:31:44 +08:00
HuangYi
e54afe9222
fix symlink nested package
- added a test case to demonstrate the fail scenario
2022-05-20 15:54:53 +08:00
HuangYi
c3f885a5b6
fix comments filter 2022-01-10 16:07:26 +08:00
Doron Behar
2428841585 builder: Use stdenv from arguments, not go.stdenv
It allows users to override the builder to use for example
`pkgsStatic.stdenv`.
2021-11-27 10:30:40 +02:00
yihuang
af2ff6eb58
fix regex expression on macos 2021-04-02 10:59:32 +08:00
adisbladis
442b4154e2
Add support for local replace directives
This fixes relative path modules not being correctly vendored by
parsing go.mod in Nix and vendoring them into the correct directory in
the Nix sandbox.

Ideally this should also come with a pluggable source filtering
mechanism and/or maybe use any present gitignore files like
poetry2nix does.

To use this new feature you have to pass a new `pwd` param to
`buildGoApplication` as such:
```
buildGoApplication {
  pname = "foo";
  version = "bar";
  pwd = ./.;
  src = lib.cleanSource ./.;
}
```

Fixes #2
2021-03-29 17:20:50 +02:00
adisbladis
f8ad3b8024
Remove Go vendor check relax patch
This is now in upstream nixpkgs
2021-02-10 15:50:58 +01:00
adisbladis
addf1164e9
Add comment from FreeBSD commit to vendor check patch
I want to port this patch into nixpkgs, and we need a good rationale.
2021-01-12 17:54:15 +01:00
adisbladis
929d740884
Format with nixpkgs-fmt 2020-12-03 16:23:40 +01:00
adisbladis
d331f4fd01
Factor out builder call 2020-10-29 13:26:17 +01:00
adisbladis
956903170b
Split builder into its own directory 2020-10-29 13:26:17 +01:00