Skip to content

Commit 6326b1f

Browse files
committed
flake: Update vendorHash and optimize flake
Make go-building only happen when version not in nixpkgs
1 parent 83ae462 commit 6326b1f

File tree

1 file changed

+58
-53
lines changed

1 file changed

+58
-53
lines changed

flake.nix

+58-53
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,68 @@
11
{
22
description = "NAIS CLI";
33

4-
inputs.nixpkgs.url = "nixpkgs/nixos-unstable";
4+
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
5+
inputs.flake-utils.url = "github:numtide/flake-utils";
56

6-
outputs = { self, nixpkgs, }:
7-
let
8-
version = builtins.substring 0 8
9-
(self.lastModifiedDate or self.lastModified or "19700101");
10-
withSystem = nixpkgs.lib.genAttrs [
11-
"x86_64-linux"
12-
"x86_64-darwin"
13-
"aarch64-linux"
14-
"aarch64-darwin"
15-
];
16-
withPkgs = callback:
17-
withSystem (system:
18-
callback (import nixpkgs {
19-
inherit system;
7+
outputs =
8+
{ self, ... }@inputs:
9+
inputs.flake-utils.lib.eachSystem
10+
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]
11+
(
12+
system:
13+
let
14+
version = builtins.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101");
15+
pkgs = import inputs.nixpkgs {
16+
localSystem = { inherit system; };
2017
overlays = [
21-
(final: prev: {
22-
go = (prev.go.overrideAttrs {
18+
(
19+
final: prev:
20+
let
2321
version = "1.23.6";
24-
src = prev.fetchurl {
25-
url = "https://go.dev/dl/go1.23.6.src.tar.gz";
26-
hash =
27-
"sha256-A5xbBOZSedrO7opvcecL0Fz1uAF4K293xuGeLtBREiI=";
28-
};
29-
});
30-
})
22+
newerGoVersion = prev.go.overrideAttrs (old: {
23+
inherit version;
24+
src = prev.fetchurl {
25+
url = "https://go.dev/dl/go${version}.src.tar.gz";
26+
hash = "sha256-A5xbBOZSedrO7opvcecL0Fz1uAF4K293xuGeLtBREiI=";
27+
};
28+
});
29+
nixpkgsVersion = prev.go.version;
30+
newVersionNotInNixpkgs = -1 == builtins.compareVersions nixpkgsVersion version;
31+
in
32+
{
33+
go = if newVersionNotInNixpkgs then newerGoVersion else prev.go;
34+
buildGoModule = prev.buildGoModule.override { go = final.go; };
35+
}
36+
)
3137
];
32-
}));
33-
in {
34-
packages = withPkgs (pkgs: rec {
35-
nais = pkgs.buildGoModule.override { go = pkgs.go; } {
36-
pname = "nais-cli";
37-
inherit version;
38-
src = ./.;
39-
vendorHash = "sha256-kr9VARylPRphfrBEf8KgY1mCV+a1lwQpT/lpur1T3tQ=";
38+
};
39+
in
40+
{
41+
packages = rec {
42+
nais = pkgs.buildGoModule {
43+
pname = "nais-cli";
44+
inherit version;
45+
src = ./.;
46+
vendorHash = "sha256-PqaPtcH2Mc8YS4aV3ctM7o0+7yAk7IZ4wB3GBmhtIsQ=";
47+
postInstall = ''
48+
mv $out/bin/cli $out/bin/nais
49+
'';
50+
};
51+
default = nais;
52+
};
4053

41-
postInstall = ''
42-
mv $out/bin/cli $out/bin/nais
43-
'';
44-
};
45-
default = nais;
46-
});
47-
48-
devShells = withPkgs (pkgs: {
49-
default = pkgs.mkShell {
50-
buildInputs = with pkgs; [
51-
go
52-
gopls
53-
gotools
54-
go-tools
55-
nodejs_20
56-
nodePackages.prettier
57-
];
58-
};
59-
});
54+
devShells.default = pkgs.mkShell {
55+
packages = with pkgs; [
56+
go
57+
gopls
58+
gotools
59+
go-tools
60+
nodejs_20
61+
nodePackages.prettier
62+
];
63+
};
6064

61-
formatter = withPkgs (pkgs: pkgs.nixfmt-rfc-style);
62-
};
65+
formatter = pkgs.nixfmt-rfc-style;
66+
}
67+
);
6368
}

0 commit comments

Comments
 (0)