Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nix flake for setting up dev env #1641

Merged
merged 4 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# direnv files
.direnv
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<nixpkgs>' -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.
Expand Down
78 changes: 78 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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
'
'';
};
});
}
9 changes: 7 additions & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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


# ==================================================================================================
Expand Down
6 changes: 6 additions & 0 deletions scripts/set_ktdev.sh
Original file line number Diff line number Diff line change
@@ -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