From 0943b8b8c45d42e7d82f8955f976c0958a52021b Mon Sep 17 00:00:00 2001 From: Jann Marc Villablanca <31008330+jfvillablanca@users.noreply.github.com> Date: Sun, 24 Dec 2023 12:27:54 +0800 Subject: [PATCH] :memo: Developer environment setup on NixOS (#454) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * πŸ§‘β€πŸ’»feat: update nix flake dev environment - This removes installing `docker`, `rust-analyzer`, `rustfmt` imperatively. `nodejs` is used to install dev dependencies `stylelint-config-standard` and `postcss-lit` - The `shellHook`s adds `rusty-hook` CLI to the PATH and the node dev dependencies to the NODE_PATH. * πŸ“ docs(developing): update NixOS dev environment setup * fix: remove nonvital guide and improve grammar --------- Co-authored-by: neon_arch --- docs/developing.md | 22 +++++++++++----------- flake.nix | 10 +++++++++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/docs/developing.md b/docs/developing.md index c8752e6..8b5301e 100644 --- a/docs/developing.md +++ b/docs/developing.md @@ -212,12 +212,6 @@ This section covers how to setup the project for development using the `NixOS de Before you start working on the project. You will need the following packages installed on your system: - `Git` installed on your system. The installation instructions for this can be found [here](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git). -- Finally, The latest version of `Docker` is installed on your system which will be used to avoid introducing unexpected issues when working on the project. The installation instructions for this can be found [here](https://docs.docker.com/engine/install/). - -> Optionally, On `NixOS` the above-mentioned required packages except for `stylelint` and `cargo-watch` could also be installed by following the link to the installation instructions provided below: -> -> - `Git`: https://search.nixos.org/packages?channel=23.05&show=git&from=0&size=50&sort=relevance&type=packages&query=git -> - `Docker`: https://search.nixos.org/packages?channel=23.05&show=docker&from=0&size=50&sort=relevance&type=packages&query=docker #### Setting up Pre-commit Checks @@ -234,7 +228,11 @@ Then run the following command to setup the `NixOS dev-shell`: nix develop ``` -Once you have finished running the above commands then run the following command to setup the `pre-commit` checks: +> You can use `nix-direnv` to simplify entering into the `nix-shell`. Its setup is beyond the scope of this guide. Read more about it here: [nix-direnv](https://github.com/nix-community/nix-direnv) + +This will add `docker`, `cargo-watch`, and other dev environment essentials to your `nix-shell` so you don't have to install everything imperatively. + +After finishing the commands above, run the following command to setup the `pre-commit` checks: ```shell cargo test @@ -244,14 +242,16 @@ By running the above-mentioned command, it will automatically set up all the pre #### Post Setup Requirements -After you have done setting up pre-commit checks, then you may need to fulfill a few more requirements to finish setting up the development environment with `NixOS dev-shell`. These include: - -- `Cargo-watch` installed on your system which will allow you to auto-build the project when any checks occur in the source code files in the codebase (`websurfx` directory). Before you install `cargo-watch` on your system, make sure you have `cargo` installed on your system. To install `cargo-watch` run the following command: +The final step is to run ```shell -cargo install cargo-watch +npm i -D stylelint-config-standard postcss-lit` ``` +This will add `node_modules` in the current directory. + +Run `git commit` and if every thing is setup correctly, it should say that your branch is up to date. + #### Running the Project If you have followed the above section then you should now be inside a `dev-shell` environment. In the same environment run the following command to run the project: diff --git a/flake.nix b/flake.nix index c6e49cf..ba804f1 100644 --- a/flake.nix +++ b/flake.nix @@ -32,24 +32,32 @@ buildInputs = [ actionlint cargo + docker haskellPackages.hadolint + nodejs nodePackages_latest.cspell nodePackages_latest.eslint nodePackages_latest.markdownlint-cli2 nodePackages_latest.stylelint redis rustPackages.clippy + rust-analyzer cargo-watch rustc + rustfmt yamllint openssl pkg-config ]; RUST_SRC_PATH = rustPlatform.rustLibSrc; + shellHook = '' + export PATH="$PATH:$HOME/.cargo/bin" + export NODE_PATH="$NODE_PATH:./node_modules" + ''; }; # Build via "nix build .#websurfx", which is basically just # calls the build function packages.websurfx = packages.default; }); -} +