Skip to content

Commit 77b1abb

Browse files
committed
flake: Only use hardcoded go version if it's newer than what's in nixpkgs
1 parent 777962a commit 77b1abb

File tree

2 files changed

+78
-37
lines changed

2 files changed

+78
-37
lines changed

flake.lock

+34
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+44-37
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,51 @@
22
description = "naiserator";
33

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

6-
outputs = { nixpkgs, ... }:
7-
let
8-
goOverlay = final: prev: {
9-
go = prev.go.overrideAttrs (old: {
10-
version = "1.23.0";
11-
src = prev.fetchurl {
12-
url = "https://go.dev/dl/go1.23.0.src.tar.gz";
13-
hash = "sha256-Qreo6A2AXaoDAi7T/eQyHUw78smQoUQWXQHu7Nb2mcY=";
7+
outputs = inputs: inputs.flake-utils.lib.eachSystem
8+
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]
9+
(
10+
system:
11+
let
12+
pkgs = import inputs.nixpkgs {
13+
localSystem = { inherit system; };
14+
overlays = [
15+
(
16+
final: prev:
17+
let
18+
version = "1.23.0";
19+
newerGoVersion = prev.go.overrideAttrs (old: {
20+
inherit version;
21+
src = prev.fetchurl {
22+
url = "https://go.dev/dl/go${version}.src.tar.gz";
23+
hash = "sha256-Qreo6A2AXaoDAi7T/eQyHUw78smQoUQWXQHu7Nb2mcY=";
24+
};
25+
});
26+
nixpkgsVersion = prev.go.version;
27+
newVersionNotInNixpkgs = -1 == builtins.compareVersions nixpkgsVersion version;
28+
in
29+
{
30+
go = if newVersionNotInNixpkgs then newerGoVersion else prev.go;
31+
buildGoModule = prev.buildGoModule.override { go = final.go; };
32+
}
33+
)
34+
];
35+
};
36+
in
37+
{
38+
devShells.default = pkgs.mkShell {
39+
buildInputs = with pkgs; [
40+
go
41+
gopls
42+
gotools
43+
go-tools
44+
gnumake
45+
gofumpt
46+
];
1447
};
15-
});
16-
};
17-
withSystem = nixpkgs.lib.genAttrs [
18-
"x86_64-linux"
19-
"x86_64-darwin"
20-
"aarch64-linux"
21-
"aarch64-darwin"
22-
];
23-
withPkgs = callback:
24-
withSystem (system:
25-
callback (import nixpkgs {
26-
inherit system;
27-
overlays = [ goOverlay ];
28-
}));
29-
in {
30-
devShells = withPkgs (pkgs: {
31-
default = pkgs.mkShell {
32-
buildInputs = with pkgs; [
33-
go
34-
gopls
35-
gotools
36-
go-tools
37-
gnumake
38-
gofumpt
39-
];
40-
};
41-
});
4248

43-
formatter = withPkgs (pkgs: pkgs.nixfmt-rfc-style);
44-
};
49+
formatter = pkgs.nixfmt-rfc-style;
50+
}
51+
);
4552
}

0 commit comments

Comments
 (0)