Skip to content

Commit

Permalink
speed-up builds with buildGoCache
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Nov 1, 2023
1 parent af320b4 commit b2153fb
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
35 changes: 34 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
inputs.nix-editor.url = "github:replit/nix-editor";
inputs.nix-editor.inputs.nixpkgs.follows = "nixpkgs";

inputs.build-go-cache.url = "github:numtide/build-go-cache";

outputs = {
self,
nixpkgs,
nix-editor,
build-go-cache,
}: let
systems = [
"aarch64-darwin"
Expand All @@ -27,6 +30,7 @@
packages = eachSystem (system:
import ./nix {
inherit self nixpkgs rev system nix-editor;
inherit (build-go-cache.legacyPackages.${system}) buildGoCache;
});
devShells = eachSystem (system: {
default = self.packages.${system}.devShell;
Expand Down
3 changes: 2 additions & 1 deletion nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
rev,
self,
system,
buildGoCache
}: let
pkgs = nixpkgs.legacyPackages.${system};
nix-editor-pkg = nix-editor.packages.${system}.nix-editor;
in rec {
default = upm;
devShell = pkgs.callPackage ./devshell {nix-editor = nix-editor-pkg;};
fmt = pkgs.callPackage ./fmt {};
upm = pkgs.callPackage ./upm {inherit rev;};
upm = pkgs.callPackage ./upm {inherit rev; inherit buildGoCache;};
}
28 changes: 23 additions & 5 deletions nix/upm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
buildGoModule,
rev,
makeWrapper,
buildGoCache,
lib,
runCommand,
}:
let
vendorHash = "sha256-x7T7TREB5Hk2yf6rhh9uDH+C6rQfRWHO8hN36LRJu7s=";

goCache = buildGoCache {
# keep this up-to-date in CI with:
# $ nix run 'github:numtide/build-go-cache#get-external-imports' -- ./. imported-packages
importPackagesFile = ./imported-packages;
# FIXME: Somehow we get cache invalidation everytime if we don't do this, also the we use a source filter
src = runCommand "go-mod" {} ''
install -D ${../../go.mod} $out/go.mod
install -D ${../../go.sum} $out/go.sum
'';
inherit vendorHash;
};
in
buildGoModule rec {
pname = "upm";
version = rev;

src = builtins.path {
name = "${pname}-${version}-src";
name = "${pname}-src";
path = ../../.;
filter = path: _:
builtins.all (block: (builtins.baseNameOf path) != block) [
Expand All @@ -23,8 +40,6 @@ buildGoModule rec {
];
};

vendorHash = "sha256-0gxWP7qBheFjZoHi+EhPNHAkg1Y8LEwG+uc1VyR6v+4=";

ldflags = [
"-X github.com/replit/upm/internal/cli.version=${rev}"
];
Expand All @@ -33,7 +48,7 @@ buildGoModule rec {
go generate ./internal/backends/python
'';

buildInputs = [makeWrapper];
buildInputs = [makeWrapper goCache];

subPackages = ["cmd/upm"];

Expand All @@ -45,5 +60,8 @@ buildGoModule rec {
--set PYPI_MAP_DB "$out/pypi_map.sqlite"
'';

inherit vendorHash;
proxyVendor = true; # we only support proxyVendor with buildGoCache just now

doCheck = false;
}
46 changes: 46 additions & 0 deletions nix/upm/imported-packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
archive/tar
archive/zip
bufio
bytes
cloud.google.com/go/bigquery
compress/gzip
context
crypto/md5
database/sql
embed
encoding/hex
encoding/json
encoding/xml
errors
flag
fmt
github.com/BurntSushi/toml
github.com/hashicorp/go-version
github.com/kballard/go-shellquote
github.com/mattn/go-sqlite3
github.com/natefinch/atomic
github.com/smacker/go-tree-sitter
github.com/smacker/go-tree-sitter/javascript
github.com/spf13/cobra
golang.org/x/net/context
golang.org/x/net/html
golang.org/x/term
google.golang.org/api/iterator
gopkg.in/yaml.v2
io
log
net/http
net/url
os
os/exec
path
path/filepath
reflect
regexp
runtime
sort
strconv
strings
sync
testing
time

0 comments on commit b2153fb

Please sign in to comment.