From d647b79133aeedb8c4fc5583f2ad86ed2d01552b Mon Sep 17 00:00:00 2001 From: Tiago Castro Date: Mon, 13 Jan 2025 12:53:06 +0000 Subject: [PATCH] refactor(nix): make shell nix depend on other shells Signed-off-by: Tiago Castro --- .github/workflows/k8s-ci.yml | 3 ++- chart/shell.nix | 18 ++++++---------- scripts/k8s/shell.nix | 8 +++---- scripts/python/shell.nix | 1 + shell.nix | 41 +++++++++++++++--------------------- tests/bdd/shell.nix | 22 +++++++++++++++++++ 6 files changed, 52 insertions(+), 41 deletions(-) create mode 120000 scripts/python/shell.nix create mode 100644 tests/bdd/shell.nix diff --git a/.github/workflows/k8s-ci.yml b/.github/workflows/k8s-ci.yml index c7f184b66..b585daeaf 100644 --- a/.github/workflows/k8s-ci.yml +++ b/.github/workflows/k8s-ci.yml @@ -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: | @@ -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: | diff --git a/chart/shell.nix b/chart/shell.nix index bc228e1fd..6df345629 100644 --- a/chart/shell.nix +++ b/chart/shell.nix @@ -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 diff --git a/scripts/k8s/shell.nix b/scripts/k8s/shell.nix index a7bb34f55..c129b5f86 100644 --- a/scripts/k8s/shell.nix +++ b/scripts/k8s/shell.nix @@ -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 { diff --git a/scripts/python/shell.nix b/scripts/python/shell.nix new file mode 120000 index 000000000..7bef29a76 --- /dev/null +++ b/scripts/python/shell.nix @@ -0,0 +1 @@ +../../tests/bdd/shell.nix \ No newline at end of file diff --git a/shell.nix b/shell.nix index dafbd1ea3..c8b2b830f 100644 --- a/shell.nix +++ b/shell.nix @@ -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!"; @@ -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 @@ -28,10 +26,6 @@ mkShell { coreutils cowsay git - helm-docs - isort - kubectl - kubernetes-helm-wrapped llvmPackages.libclang niv nixpkgs-fmt @@ -39,19 +33,18 @@ mkShell { 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)}"; @@ -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 diff --git a/tests/bdd/shell.nix b/tests/bdd/shell.nix new file mode 100644 index 000000000..21f066a7d --- /dev/null +++ b/tests/bdd/shell.nix @@ -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; +}