diff --git a/.envrc b/.envrc new file mode 100644 index 0000000000..8392d159f2 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake \ No newline at end of file diff --git a/.gitignore b/.gitignore index cdf2794667..1a5b95acd2 100644 --- a/.gitignore +++ b/.gitignore @@ -120,3 +120,6 @@ Cargo.lock # MSVC Windows builds of rustc generate these, which store debugging information *.pdb + +# direnv files +.direnv \ No newline at end of file diff --git a/README.md b/README.md index 804f744234..842c8e7f1f 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,46 @@ This repository is structured as a monorepo, containing the following projects: - `docs`: Documentation that is published to [docs.kurtosis.com](docs) - `internal_testsuites`: End to end tests -Dev Dependencies +Dev Dependencies (Nix) +---------------- + +Install the [Nix package manager](https://nixos.org/download). +```bash +sh <(curl -L https://nixos.org/nix/install) +``` + +And enable some Nix flags (alternatively you can add `--extra-experimental-features 'nix-command flakes'` every time calling the `nix` command): +```bash +mkdir -p ~/.config/nix +echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf +``` + +And to bring the environment up, just open a new shell terminal, go to the root folder of the repo and run: +```bash +nix develop +``` + +This will download all dev deps and setup the environment accordingly. + +You can also use the [`direnv`](https://direnv.net/) to automatically load the environment when entering the main folder or using a plugin in your preferred IDE: +- `vscode`: [mkhl.direnv](https://github.com/direnv/direnv-vscode) +- `jet brains`: [Direnv integration](https://plugins.jetbrains.com/plugin/15285-direnv-integration) + +Direnv can also be easily installed with Nix (or [HomeBrew](https://formulae.brew.sh/formula/direnv) if you prefer): +```bash +nix-env -f '' -iA direnv +``` + +Now you just to add the direnv hook to your shell: +```bash +echo 'eval "$(direnv hook bash)"' >> ~/.bashrc +# or for ZSH +echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc +``` + +Now next time you open a new shell terminal and go to repo's folder you environment will update and load automatically. + +Dev Dependencies (Manual install) ---------------- The commands below assume that the env variable BREW_PREFIX contains the brew prefix. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000000..54bb92f617 --- /dev/null +++ b/flake.lock @@ -0,0 +1,78 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1694529238, + "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1697655685, + "narHash": "sha256-79Kuv+QdgsVc+rkibuAgWHnh8IXrLBTOKg5nM0Qvux0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "80c1aab725151632ddc2a20caeb914e76dd0673c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "unstable": "unstable" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "unstable": { + "locked": { + "lastModified": 1697723726, + "narHash": "sha256-SaTWPkI8a5xSHX/rrKzUe+/uVNy6zCGMXgoeMb7T9rg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7c9cc5a6e5d38010801741ac830a3f8fd667a7a0", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000000..d4cf271ab5 --- /dev/null +++ b/flake.nix @@ -0,0 +1,104 @@ +{ + description = "Kurtosis dev flake"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; + unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { nixpkgs, unstable, flake-utils, ... }: + let utils = flake-utils; + in utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + unstable_pkgs = unstable.legacyPackages.${system}; + in { + formatter = pkgs.nixpkgs-fmt; + + devShell = pkgs.mkShell { + nativeBuildInputs = with pkgs; + let + + renamed_grpc_tools = stdenv.mkDerivation { + name = "renamed-grpc-tools"; + version = "0.1"; + phases = [ "installPhase" ]; + installPhase = '' + mkdir -p $out/bin + cp -r ${protobuf}/include/ $out/bin/ + cp "${grpc-tools}/bin/protoc" $out/bin/grpc_tools_node_protoc + cp "${grpc-tools}/bin/grpc_node_plugin" $out/bin/grpc_tools_node_protoc_plugin + ''; + }; + + ts_protoc = stdenv.mkDerivation rec { + name = "protoc-gen-ts-wksp"; + src = fetchFromGitHub { + owner = "thesayyn"; + repo = "protoc-gen-ts"; + rev = "0.8.7"; + hash = "sha256-PGprtSPMRTodt/SD6gpEr/n22jiNqB1/C6HJGlDndLg="; + }; + buildInputs = [ git cacert nodejs bazel ]; + buildPhase = '' + export HOME=$(pwd) + mkdir -p $out/bin + npm ci + bazel build package + ''; + installPhase = '' + cp bazel-bin/package/package/protoc-gen-ts.js $out/bin/protoc-gen-ts + ''; + }; + + in [ + goreleaser + go_1_19 + gopls + golangci-lint + delve + enumer + nodejs_20 + yarn + protobuf + protoc-gen-go + protoc-gen-go-grpc + protoc-gen-connect-go + protoc-gen-grpc-web + grpc-tools + rustc + cargo + rustfmt + rust-analyzer + clippy + libiconv + bash-completion + # local definition (see above) + renamed_grpc_tools + ts_protoc + ]; + + shellHook = '' + export CARGO_NET_GIT_FETCH_WITH_CLI=true + printf '\u001b[32m + @@@@@@@@ + @@@ @@ @@@ @@@ + @@@ @@ @@ @@ + @ @@ @@ @@ + @@ @@ @@ + @@ @@ @@ + @ @@ @@ @@ + @ @@ @@ @@ + @@ @@@ @@@ @@ + @@@ @@@@@@@@ + \u001b[0m + Starting Kurtosis dev shell. Setup the alias to local compiled Kurtosis cli command "ktdev" by running: + \e[32m + source ./scripts/set_ktdev.sh + \e[0m + ' + ''; + }; + }); +} diff --git a/scripts/build.sh b/scripts/build.sh index ef61ab09ea..f70b5f175f 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -5,9 +5,14 @@ set -euo pipefail # Bash "strict mode" script_dirpath="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" root_dirpath="$(dirname "${script_dirpath}")" -if ! bash "${script_dirpath}/versions_check.sh"; then - exit 1 +set +u +# Check if it's running inside a nix shell env so there is no need to check versions +if [ -z "${IN_NIX_SHELL}" ]; then + if ! bash "${script_dirpath}/versions_check.sh"; then + exit 1 + fi fi +set -u # ================================================================================================== diff --git a/scripts/set_ktdev.sh b/scripts/set_ktdev.sh new file mode 100644 index 0000000000..0ac9209afa --- /dev/null +++ b/scripts/set_ktdev.sh @@ -0,0 +1,6 @@ +# Add alias to compiled CLI +alias ktdev="$(pwd)/cli/cli/scripts/launch-cli.sh" + +# Setup bash completion +source <(ktdev completion bash) +complete -F __start_kurtosis ktdev \ No newline at end of file