-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdefault.nix
More file actions
165 lines (158 loc) · 4.88 KB
/
default.nix
File metadata and controls
165 lines (158 loc) · 4.88 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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# SPDX-License-Identifier: MIT
let
inputs =
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
flake-compatish = import (builtins.fetchTree lock.nodes.flake-compatish.locked);
in
flake-compatish {
source = ./.;
overrides = {
self = ./.;
};
}
).inputs;
in
{
system ? builtins.currentSystem,
}:
rec {
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ (import ./pkgs) ];
};
inherit inputs;
lib = pkgs.lib;
easykubenix = import inputs.easykubenix;
kubenixApply = kubenixInstance { };
kubenixCI1 = kubenixInstance {
module.imports = [
./kubenix/ci
];
};
kubenixCI2 = kubenixInstance {
module.imports = [
./kubenix/ci
{
nix-csi.cache.enable = false;
nix-csi.builders.enable = false;
}
];
};
kubenixLocal = kubenixInstance {
module.imports = [
./kubenix/ci
(
{ config, ... }:
{
kluctl.preDeployScript = # bash
''
expected_context="kind"
current_context=$(kubectl config current-context)
if [[ "$current_context" != *"$expected_context" ]]; then
echo "Warning: Current context is $current_context, not *$expected_context"* >&2
read -rp "Continue anyway? [y/N] " confirm
if [[ ! "$confirm" =~ ^[Yy]$ ]]; then
echo "Aborted." >&2
exit 1
fi
fi
cachix push nix-csi ${config.internal.manifestJSONFile}
'';
nix-csi.cache.enable = true;
nix-csi.builders.enable = true;
nix-csi.push = true;
}
)
];
};
kubenixPush = kubenixInstance {
module.config = {
nix-csi.push = true;
};
};
kubenixInstance =
{
module ? { },
}:
easykubenix {
inherit pkgs;
modules = [
module
./kubenix
{
_module.args.inputs = inputs;
}
{
config = {
# Disabled by default so you can include the module in an easykubenix project
nix-csi.enable = true;
# Allow easily adding your pubkeys to the cache
nix-csi.authorizedKeys = lib.pipe (lib.filesystem.listFilesRecursive ./keys) [
(lib.filter (name: lib.hasSuffix ".pub" name))
(lib.map (name: builtins.readFile name))
(lib.map (key: lib.trim key))
];
};
}
];
};
push =
pkgs.writeScriptBin "push" # bash
''
#! ${pkgs.runtimeShell}
export PATH=${lib.makeBinPath [ pkgs.cachix ]}:$PATH
# ${lib.concatStrings (lib.attrValues inputs)}
nix-store -qR --include-outputs $(nix-store -qd ${kubenixPush.manifestJSONFile}) | grep -v '\.drv$' | cachix push nix-csi
'';
uploadScratch =
let
scratchVersion = "1.0.1";
scratchUrl = system: "ghcr.io/lillecarl/nix-csi/scratch:${scratchVersion}-${system}";
scratchManifest = "ghcr.io/lillecarl/nix-csi/scratch:${scratchVersion}";
in
pkgs.writeScriptBin "uploadScratch" # bash
''
#! ${pkgs.runtimeShell}
set -euo pipefail
set -x
export PATH=${lib.makeBinPath [ pkgs.buildah ]}:$PATH
# Build and publish scratch image(s)
buildah login -u="$REPO_USERNAME" -p="$REPO_TOKEN" ghcr.io
container=$(buildah from --platform linux/amd64 scratch)
buildah config --env "PATH=/nix/var/result/bin" $container
buildah commit $container ${scratchUrl "x86_64-linux"}
buildah push ${scratchUrl "x86_64-linux"}
container=$(buildah from --platform linux/arm64 scratch)
buildah config --env "PATH=/nix/var/result/bin" $container
buildah commit $container ${scratchUrl "aarch64-linux"}
buildah push ${scratchUrl "aarch64-linux"}
buildah manifest rm ${scratchManifest} &>/dev/null || true
buildah manifest create ${scratchManifest}
buildah manifest add ${scratchManifest} ${scratchUrl "x86_64-linux"}
buildah manifest add ${scratchManifest} ${scratchUrl "aarch64-linux"}
buildah manifest push ${scratchManifest}
'';
genModDoc =
let
optionsDocs = pkgs.nixosOptionsDoc {
inherit (kubenixCI1.eval) options;
warningsAreErrors = false;
transformOptions =
opt:
opt
// {
# Remove internal options, modify declarations, etc.
visible = opt.visible or true && lib.hasPrefix "nix-csi" opt.name;
};
};
in
pkgs.writeScriptBin "genModDoc" # bash
''
#! ${pkgs.runtimeShell}
cp --no-preserve=mode ${optionsDocs.optionsCommonMark} $GIT_ROOT/doc/options.md
'';
lixImage = pkgs.callPackage ./liximage.nix { };
scratchImage = pkgs.callPackage ./scratchimage.nix { };
}