Skip to content

Commit

Permalink
chore: support nix shell dev environment (#17462)
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Chien <[email protected]>
Co-authored-by: Richard Chien <[email protected]>
  • Loading branch information
jetjinser and stdrc authored Jul 1, 2024
1 parent e3c3c0d commit fb60113
Show file tree
Hide file tree
Showing 6 changed files with 353 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ e2e_test/iceberg/spark-*-bin*
**/poetry.lock

*.slt.temp

.direnv/
60 changes: 60 additions & 0 deletions develop/nix/devshell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{ inputs
, ...
}:

{
perSystem = { pkgs, lib, ... }: {
devshells.default =
let
rust-toolchain = with pkgs;
[
((rust-bin.fromRustupToolchainFile ../../rust-toolchain).override {
extensions = [ "rust-src" "rust-analyzer" ];
})
];
in
{
imports = [
"${inputs.devshell}/extra/language/rust.nix"
];
language.rust.enableDefaultToolchain = false;
packages = rust-toolchain
# See the dependencies list in docs/developer-guide.md
++ (with pkgs; [
gcc
lld
protobuf
pkg-config
cyrus_sasl.out

gnumake
cmake
maven
jdk17_headless

tmux
postgresql
patchelf
]);
env = [
{
name = "PKG_CONFIG_PATH";
value = lib.concatStringsSep ":" (
map (pkg: "${pkg}/lib/pkgconfig") (with pkgs; [
openssl.dev
cyrus_sasl.dev
])
);
}
{
name = "LD_LIBRARY_PATH";
value = lib.makeLibraryPath (with pkgs; [
openssl
libgcc.lib
cyrus_sasl.out
]);
}
];
};
};
}
188 changes: 188 additions & 0 deletions develop/nix/flake.lock

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

64 changes: 64 additions & 0 deletions develop/nix/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# A nix flake that sets up a complete RisingWave development environment.
#
# You must have already installed Nix (https://nixos.org) on your system to use this.
# Nix can be installed on Linux or MacOS; NixOS is not required. Windows is not
# directly supported, but Nix can be installed inside of WSL2 or even Docker
# containers. Please refer to https://nixos.org/download for details.
#
# You must also enable support for flakes in Nix. See the following for how to
# do so permanently: https://nixos.wiki/wiki/Flakes#Enable_flakes
#
# Usage:
#
# With Nix installed, navigate to the directory containing this flake and run
# `nix develop ./develop/nix`.
#
# You should now be dropped into a new shell with all programs and dependencies
# available to you!
#
# You can exit the development shell by typing `exit`, or using Ctrl-D.
#
# If you would like this development environment to activate automatically
# upon entering this directory in your terminal, first install `direnv`
# (https://direnv.net/). Then run `echo 'use flake ./develop/nix' >> .envrc` at
# the root of the RisingWave repo. Finally, run `direnv allow` to allow the
# contents of '.envrc' to run every time you enter this directory. Voilà!
#
# note: If you don't want to see git untracked .envrc files bother you,
# you can run `echo '.envrc' >> .git/info/exclude` in the root of project
# to make it ignored locally.

{
description = ''
RisingWave the Cloud-native SQL stream processing, analytics, and management.
'';

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";

devshell.url = "github:numtide/devshell";

rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.devshell.flakeModule
./overlays.nix
./devshell.nix
];

systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
};
}

14 changes: 14 additions & 0 deletions develop/nix/overlays.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ inputs
, ...
}:

{
perSystem = { pkgs, system, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
(import inputs.rust-overlay)
];
};
};
}
25 changes: 25 additions & 0 deletions docs/developer-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ http://ecotrust-canada.github.io/markdown-toc/
- [Read the design docs](#read-the-design-docs)
- [Learn about the code structure](#learn-about-the-code-structure)
- [Set up the development environment](#set-up-the-development-environment)
* [macOS](#macos)
* [Debian-based Linux](#debian-based-linux)
* [nix shell](#nix-shell)
- [Start and monitor a dev cluster](#start-and-monitor-a-dev-cluster)
* [Tips for compilation](#tips-for-compilation)
* [Configure additional components](#configure-additional-components)
Expand Down Expand Up @@ -73,20 +76,42 @@ RisingWave can be built on macOS and Linux. To develop RisingWave, you need the
* LLVM (For macOS only, to workaround some bugs in macOS toolchain. See https://github.com/risingwavelabs/risingwave/issues/6205)
* Python (>= 3.12) (Optional, only required by `embedded-python-udf` feature)

### macOS

To install the dependencies on macOS, run:

```shell
brew install postgresql cmake protobuf tmux cyrus-sasl llvm openssl@3
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### Debian-based Linux

To install the dependencies on Debian-based Linux systems, run:

```shell
sudo apt install make build-essential cmake protobuf-compiler curl postgresql-client tmux lld pkg-config libssl-dev libsasl2-dev
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### nix shell

If you use nix, you can also enter the nix shell via:

```shell
nix develop ./develop/nix
```

All dependencies will be automatically downloaded and configured.

You can also use [direnv](https://github.com/direnv/direnv) to automatically enter the nix shell:

```shell
direnv allow
```

Check out [flake.nix](../develop/nix/flake.nix) to read more information!

Then you'll be able to compile and start RisingWave!

> [!NOTE]
Expand Down

0 comments on commit fb60113

Please sign in to comment.