Skip to content

Commit

Permalink
refactor(nix): make shell nix depend on other shells
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Jan 13, 2025
1 parent 6f8e127 commit d647b79
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 41 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/k8s-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
echo "NIX_PATH=$NIX_PATH" >> $GITHUB_ENV
nix-shell ./scripts/k8s/shell.nix --run "echo"
nix-shell ./scripts/helm/shell.nix --run "echo"
nix-shell ./scripts/python/shell.nix --run "echo"
- name: Build binaries and images
id: build
run: |
Expand All @@ -45,7 +46,7 @@ jobs:
run: |
export UPGRADE_TARGET_VERSION=${{ steps.build.outputs.tag }}
export TEST_DIR=${{ steps.build.outputs.bin }}
nix-shell ./shell.nix --run "./scripts/python/test.sh"
nix-shell ./scripts/python/shell.nix --run "./scripts/python/test.sh"
- name: The job has failed
if: ${{ failure() }}
run: |
Expand Down
18 changes: 6 additions & 12 deletions chart/shell.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
{}:
let
sources = import ../nix/sources.nix;
pkgs = import sources.nixpkgs {
overlays = [ (_: _: { inherit sources; }) (import ../nix/overlay.nix { }) ];
};
in
with pkgs;
let
in
mkShell {
{ pkgs ? import (import ../nix/sources.nix).nixpkgs {
overlays = [ (_: _: { inherit (import ../nix/sources.nix); }) (import ../nix/overlay.nix { }) ];
}
}:
pkgs.mkShell {
name = "helm-scripts-shell";
buildInputs = [
buildInputs = with pkgs; [
coreutils
git
helm-docs
Expand Down
8 changes: 4 additions & 4 deletions scripts/k8s/shell.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{ pkgs ? import (import ../../nix/sources.nix).nixpkgs {
overlays = [ (_: _: { inherit (import ../../nix/sources.nix); }) (import ../../nix/overlay.nix { }) ];
}
}:
let
sources = import ../../nix/sources.nix;
pkgs = import sources.nixpkgs {
overlays = [ (_: _: { inherit sources; }) (import ../../nix/overlay.nix { }) ];
};
inPureNixShell = builtins.getEnv "IN_NIX_SHELL" == "pure";
in
pkgs.mkShell {
Expand Down
1 change: 1 addition & 0 deletions scripts/python/shell.nix
41 changes: 17 additions & 24 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ let
pkgs = import sources.nixpkgs {
overlays = [ (_: _: { inherit sources; }) (import ./nix/overlay.nix { }) (import sources.rust-overlay) ];
};
lib = pkgs.lib;
in
with pkgs;
let
norust_moth =
"You have requested an environment without rust, you should provide it!";
Expand All @@ -14,12 +14,10 @@ let
channel = import ./nix/lib/rust.nix { inherit pkgs; };
rust_chan = channel.default_src;
rust = rust_chan.${rust-profile};
in
mkShell {
name = "extensions-shell";
buildInputs = [
autoflake
black
k8sShellAttrs = import ./scripts/k8s/shell.nix { inherit pkgs; };
helmShellAttrs = import ./chart/shell.nix { inherit pkgs; };
bddShellAttrs = import ./tests/bdd/shell.nix { inherit pkgs; };
buildInputs = with pkgs; [
cacert
cargo-expand
cargo-udeps
Expand All @@ -28,30 +26,25 @@ mkShell {
coreutils
cowsay
git
helm-docs
isort
kubectl
kubernetes-helm-wrapped
llvmPackages.libclang
niv
nixpkgs-fmt
paperclip
openssl
pkg-config
pre-commit
python3
semver-tool
utillinux
virtualenv
which
yq-go
kind
] ++ pkgs.lib.optional (!norust) rust
++ pkgs.lib.optional (system == "aarch64-darwin") darwin.apple_sdk.frameworks.Security;
];
in
pkgs.mkShell {
name = "extensions-shell";
buildInputs = buildInputs ++ pkgs.lib.optional (!norust) rust
++ k8sShellAttrs.buildInputs ++ helmShellAttrs.buildInputs ++ bddShellAttrs.buildInputs
++ pkgs.lib.optional (pkgs.system == "aarch64-darwin") pkgs.darwin.apple_sdk.frameworks.Security;

PROTOC = "${protobuf}/bin/protoc";
PROTOC_INCLUDE = "${protobuf}/include";
NODE_PATH = "${nodePackages."@commitlint/config-conventional"}/lib/node_modules";
PROTOC = "${pkgs.protobuf}/bin/protoc";
PROTOC_INCLUDE = "${pkgs.protobuf}/include";
NODE_PATH = "${pkgs.nodePackages."@commitlint/config-conventional"}/lib/node_modules";

# using the nix rust toolchain
USE_NIX_RUST = "${toString (!norust)}";
Expand All @@ -71,8 +64,8 @@ mkShell {
export CTRL_SRC="$EXTENSIONS_SRC"/dependencies/control-plane
export PATH="$PATH:$(pwd)/target/debug"
${pkgs.lib.optionalString (norust) "cowsay ${norust_moth}"}
${pkgs.lib.optionalString (norust) "echo"}
${lib.optionalString (norust) "cowsay ${norust_moth}"}
${lib.optionalString (norust) "echo"}
rust_version="${rust.version}" rustup_channel="${lib.strings.concatMapStringsSep "-" (x: x) (lib.lists.drop 1 (lib.strings.splitString "-" rust.version))}" \
dev_rustup="${toString (devrustup)}" devrustup_moth="${devrustup_moth}" . "$CTRL_SRC"/scripts/rust/env-setup.sh
Expand Down
22 changes: 22 additions & 0 deletions tests/bdd/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{ pkgs ? import (import ../../nix/sources.nix).nixpkgs {
overlays = [ (_: _: { inherit (import ../nix/../sources.nix); }) (import ../../nix/overlay.nix { }) ];
}
}:
let
k8sShellAttrs = import ../../scripts/k8s/shell.nix { inherit pkgs; };
helmShellAttrs = import ../../chart/shell.nix { inherit pkgs; };
bddBuildInputs = with pkgs; [
autoflake
black
isort
python3
utillinux
virtualenv
which
];
in
pkgs.mkShell {
name = "pytest-shell";
buildInputs = k8sShellAttrs.buildInputs ++ helmShellAttrs.buildInputs ++
bddBuildInputs;
}

0 comments on commit d647b79

Please sign in to comment.