forked from instana/instana-agent-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
53 lines (46 loc) · 1.73 KB
/
flake.nix
File metadata and controls
53 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{
description =
"A nix-flake-based Go/Kubernetes Controller development environment using operator-sdk";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { self, nixpkgs }:
let
regex = "go[[:space:]]+([0-9]+\\.[0-9]+)(\\.[0-9]+)?";
# Read and get all the lines of the go.mod files and filter the empty []
lines = builtins.filter (line: line != [ ])
(builtins.split "\n" (builtins.readFile ./go.mod));
# Get the line that has the `go xx.xx.xx` or `go xx.xx`
matchingLines =
builtins.filter (line: builtins.match regex line != null) lines;
# Get the version string i.e: "1.23"
versionString = builtins.elemAt
(builtins.match regex (builtins.concatStringsSep " " matchingLines)) 0;
# Get the string as "1_23"
versionForOverlay = builtins.replaceStrings [ "." ] [ "_" ] versionString;
supportedSystems =
[ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSupportedSystem = f:
nixpkgs.lib.genAttrs supportedSystems (system:
f {
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
});
in {
overlays.default = final: prev: { go = final."go_${versionForOverlay}"; };
devShells = forEachSupportedSystem ({ pkgs }: {
default = pkgs.mkShell {
packages = with pkgs; [
# go (version is specified by overlay)
go
# gopls (go language server)
gopls
# goimports, godoc, etc.
gotools
# SDK for building Kubernetes applications
operator-sdk
];
};
});
};
}