-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
127 lines (117 loc) · 4.32 KB
/
flake.nix
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{
description = "Unleasherator";
inputs = {
nixpkgs.url = # Pick a some commit
"github:NixOS/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
gitignore = {
url = "github:hercules-ci/gitignore.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, gitignore }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
kubetools-1_27_1 = let
nixToKubebuilderTools = let
platformMapping = {
x86_64-linux = "linux-amd64";
aarch64-linux = "linux-arm64";
x86_64-darwin = "darwin-amd64";
aarch64-darwin = "darwin-arm64";
};
shaMapping = {
aarch64-linux =
"sha256-M9CgiHugLh7t7ulWGp4psRCtihBDxmBxqmSw5UHxKj4=";
aarch64-darwin =
"sha256-ohXx4OPoEmBBojHmuS8V+V1JbXkKud8kKPjniQhKv1w=";
x86_64-linux =
"sha256-gJ/BvTbzKa8Wx2Hleyy2GEe+EOnlKvqT/6xuPu1nvB0=";
};
in {
sha = builtins.getAttr system shaMapping;
path = builtins.getAttr system platformMapping;
};
in pkgs.fetchzip {
url =
"https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-1.27.1-${nixToKubebuilderTools.path}.tar.gz";
sha256 = nixToKubebuilderTools.sha;
};
unleasherator = pkgs.buildGoModule {
name = "unleasherator";
nativeBuildInputs = with pkgs; [
golangci-lint
helmify
kubebuilder
kubernetes-controller-tools
kubetools-1_27_1
kustomize
];
KUBEBUILDER_ASSETS = "${kubetools-1_27_1}/bin";
GOLANGCI_LINT = "${pkgs.golangci-lint}";
src = gitignore.lib.gitignoreSource ./.;
vendorSha256 =
"sha256-h2x22TJkOrRzkU8TAV6OUJTSxIPWGyccDzKeacj43B4="; # nixpkgs.lib.fakeSha256;
};
helmify = pkgs.buildGoModule {
name = "helmify";
src = pkgs.fetchFromGitHub {
owner = "arttor";
repo = "helmify";
rev = "9e709ee1587ab637bf811837213670c1f1125ba4";
sha256 = "sha256-7BYarYamPAPx9kmaGyJt9Kd6kwIw99loSLY0vIyexy8=";
};
vendorSha256 = "sha256-6Tue+5KaLvjc+6ql/gXVhnQzc7gWQA5YtwXNKhCI6Os=";
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name =
"europe-north1-docker.pkg.dev/nais-io/nais/images/unleasherator";
tag = "latest";
contents = [ unleasherator ];
config = {
Entrypoint = [ "${unleasherator}/bin/cmd" ];
User = "65532:65532";
};
};
scripts = with pkgs; [
(writeScriptBin "unleasherator-restart" ''
kubectl rollout restart deployment/unleasherator-controller-manager -n unleasherator-system
kubectl rollout status deployment/unleasherator-controller-manager -n unleasherator-system --timeout=60s
'')
(writeScriptBin "unleasherator-logs" ''
kubectl logs deployment/unleasherator-controller-manager -n unleasherator-system -f
'')
(writeScriptBin "unleasherator-undeploy" ''
kustomize build config/default | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
'')
(writeScriptBin "unleasherator-uninstall" ''
kustomize build config/crd | kubectl delete --ignore-not-found=$(ignore-not-found) -f -
'')
(writeScriptBin "unleasherator-install" ''
kubectl logs deployment/unleasherator-controller-manager -n unleasherator-system -f
'')
];
in {
defaultPackage = unleasherator;
docker = dockerImage;
devShell = pkgs.mkShell {
packages = with pkgs; [
go_1_21
golangci-lint
gopls
gotools
helmify
kubernetes-controller-tools
kubetools-1_27_1
kustomize
scripts
];
shellHook = ''
export KUBEBUILDER_ASSETS=${kubetools-1_27_1}/bin
'';
GOLANGCI_LINT = "${pkgs.golangci-lint}/bin/golangci-lint";
};
kubetools = kubetools-1_27_1;
});
}