Skip to content

Commit 5b720fb

Browse files
authored
chore: Add shell.nix for all operators (#323)
* github-linguist: excluded from stats, hidden in diffs See: https://github.com/github-linguist/linguist/blob/master/docs/overrides.md#summary * commit files required in nix development environments (eg: nix-shell) * allow other nix files to inherit cargo, sources, packages * add shell.nix template * ci(misspell): ignore generated Cargo.nix * replace operator specific imports with BINDGEN_EXTRA_CLANG_ARGS * reorder nix shell packages * take `makr regenerate-nix` from stackabletech/stackable-cockpit@d885d3c * regenerate-nix on template run * use meta attribute set instead of jinja2 template variables
1 parent 4b836b9 commit 5b720fb

File tree

8 files changed

+69
-5
lines changed

8 files changed

+69
-5
lines changed

playbook/update_repo.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@
9494
argv: [make, regenerate-charts]
9595
chdir: "{{ work_dir }}/{{ operator.name }}"
9696

97+
- name: "Operator [{{ operator.name }}] regenerate crate2nix"
98+
command:
99+
argv: [make, regenerate-nix]
100+
chdir: "{{ work_dir }}/{{ operator.name }}"
101+
97102
- name: "Operator [{{ operator.name }}] re-render README"
98103
command:
99104
argv: [make, render-readme]

template/.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
nix/** linguist-generated
2+
Cargo.nix linguist-generated
3+
crate-hashes.json linguist-generated

template/.github/workflows/pr_reviewdog.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ jobs:
7575
with:
7676
github_token: ${{ secrets.GITHUB_TOKEN }}
7777
locale: "US"
78+
# Ignore spellchecking generated files
79+
exclude: |
80+
./Cargo.nix
7881
7982
languagetool:
8083
runs-on: ubuntu-latest

template/.gitignore.j2

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ target/
99

1010
*.tgz
1111

12-
Cargo.nix
13-
crate-hashes.json
1412
result
1513
image.tar
1614

17-
tilt_options.json
15+
tilt_options.json

template/Makefile.j2

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ clean: chart-clean
132132

133133
regenerate-charts: chart-clean compile-chart
134134

135-
build: regenerate-charts helm-package docker-build
135+
regenerate-nix:
136+
nix run -f . regenerateNixLockfiles
137+
138+
build: regenerate-charts regenerate-nix helm-package docker-build
136139

137140
publish: build docker-publish helm-publish
138141

template/Tiltfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ operator_name = meta['operator']['name']
1010

1111
custom_build(
1212
registry + '/' + operator_name,
13-
'nix shell -f . crate2nix -c crate2nix generate && nix-build . -A docker --argstr dockerName "${EXPECTED_REGISTRY}/' + operator_name + '" && ./result/load-image | docker load',
13+
'make regenerate-nix && nix-build . -A docker --argstr dockerName "${EXPECTED_REGISTRY}/' + operator_name + '" && ./result/load-image | docker load',
1414
deps=['rust', 'Cargo.toml', 'Cargo.lock', 'default.nix', "nix", 'build.rs', 'vendor'],
1515
ignore=['*.~undo-tree~'],
1616
# ignore=['result*', 'Cargo.nix', 'target', *.yaml],

template/default.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
, dockerTag ? null
4141
}:
4242
rec {
43+
inherit cargo sources pkgs meta;
4344
build = cargo.allWorkspaceMembers;
4445
entrypoint = build+"/bin/stackable-${meta.operator.name}";
4546
crds = pkgs.runCommand "${meta.operator.name}-crds.yaml" {}
@@ -95,4 +96,11 @@ rec {
9596
# need to use vendored crate2nix because of https://github.com/kolloch/crate2nix/issues/264
9697
crate2nix = import sources.crate2nix {};
9798
tilt = pkgs.tilt;
99+
100+
regenerateNixLockfiles = pkgs.writeScriptBin "regenerate-nix-lockfiles"
101+
''
102+
set -euo pipefail
103+
echo Running crate2nix
104+
${crate2nix}/bin/crate2nix generate
105+
'';
98106
}

template/shell.nix

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
let
2+
self = import ./. {};
3+
inherit (self) sources pkgs meta;
4+
5+
beku = pkgs.callPackage (sources."beku.py" + "/beku.nix") {};
6+
cargoDependencySetOfCrate = crate: [ crate ] ++ pkgs.lib.concatMap cargoDependencySetOfCrate (crate.dependencies ++ crate.buildDependencies);
7+
cargoDependencySet = pkgs.lib.unique (pkgs.lib.flatten (pkgs.lib.mapAttrsToList (crateName: crate: cargoDependencySetOfCrate crate.build) self.cargo.workspaceMembers));
8+
in pkgs.mkShell rec {
9+
name = meta.operator.name;
10+
11+
packages = with pkgs; [
12+
## cargo et-al
13+
rustup # this breaks pkg-config if it is in the nativeBuildInputs
14+
15+
## Extra dependencies for use in a pure env (nix-shell --pure)
16+
## These are mosuly useful for maintainers of this shell.nix
17+
## to ensure all the dependencies are caught.
18+
# cacert
19+
# vim nvim nano
20+
];
21+
22+
# derivation runtime dependencies
23+
buildInputs = pkgs.lib.concatMap (crate: crate.buildInputs) cargoDependencySet;
24+
25+
# build time dependencies
26+
nativeBuildInputs = pkgs.lib.concatMap (crate: crate.nativeBuildInputs) cargoDependencySet ++ (with pkgs; [
27+
beku
28+
docker
29+
gettext # for the proper envsubst
30+
git
31+
jq
32+
kind
33+
kubectl
34+
kubernetes-helm
35+
kuttl
36+
nix # this is implied, but needed in the pure env
37+
# tilt already defined in default.nix
38+
which
39+
yq-go
40+
]);
41+
42+
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
43+
BINDGEN_EXTRA_CLANG_ARGS = "-I${pkgs.glibc.dev}/include -I${pkgs.clang}/resource-root/include";
44+
}

0 commit comments

Comments
 (0)