From 62e0ded409c84f55d37b39df797b41033f41500b Mon Sep 17 00:00:00 2001 From: Pyrox Date: Thu, 11 May 2023 09:11:28 -0400 Subject: [PATCH] flake: Cleanup devenv on clean, add helper scripts, and run dev server on `devenv up` Also adds a new config example for use with the devenv scripts, as well as a developer's guide for setting up the Nix environment. This could also have steps for speific distros, such as what packages to install, and specific notes. --- .config/devenv.yml | 38 ++++++++++++++++++++++++++++++++++++++ .gitignore | 1 + docs/development.md | 22 ++++++++++++++++++++++ flake.nix | 14 ++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 .config/devenv.yml create mode 100644 docs/development.md diff --git a/.config/devenv.yml b/.config/devenv.yml new file mode 100644 index 0000000000..6c60f338ae --- /dev/null +++ b/.config/devenv.yml @@ -0,0 +1,38 @@ +url: http://localhost:3000 +port: 3000 + +db: + host: 127.0.0.1 + port: 5432 + + db: calckey + + user: calckey + pass: calckey + +redis: + host: localhost + port: 6379 + family: 4 +#sonic: +# host: localhost +# port: 1491 +# auth: SecretPassword +# collection: notes +# bucket: default + +#elasticsearch: +# host: localhost +# port: 9200 +# ssl: false +# user: +# pass: + +id: 'aid' + +reservedUsernames: + - root + - admin + - administrator + - me + - system diff --git a/.gitignore b/.gitignore index 1fadce4317..63ee4f35fc 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ coverage # config /.config/* !/.config/example.yml +!/.config/devenv.yml !/.config/docker_example.env !/.config/helm_values_example.yml diff --git a/docs/development.md b/docs/development.md new file mode 100644 index 0000000000..41d1b34699 --- /dev/null +++ b/docs/development.md @@ -0,0 +1,22 @@ +# 🌎 Calckey Developer Docs + +## Nix Dev Environment +The Calckey repo comes with a Nix-based shell environment to help make development as easy as possible! + +Please note, however, that this environment will not work on Windows outside of a WSL2 environment. + +### Prerequisites + +- Installed the [Nix Package Manager](https://nixos.org/download.html) +- Installed [direnv](https://direnv.net/docs/installation.html) and added its hook to your shell. + +Once the repo is cloned to your computer, follow these next few steps inside the Calckey folder: + +- Run `direnv allow`. This will build the environment and install all needed tools. +- Run `install-deps`, then `prepare-config`, to install the node dependencies and prepare the needed config files. +- In a second terminal, run `devenv up`. This will spawn a **Redis** server, a **Postgres** server, and the **Calckey** server in dev mode. +- Once you see the Calckey banner printed in your second terminal, run `migrate` in the first. +- Once migrations finish, open http://localhost:3000 in your web browser. +- You should now see the admin user creation screen! + +Note: When you want to restart a dev server, all you need to do is run `devenv up`, no other steps are necessary. diff --git a/flake.nix b/flake.nix index fd9098f0dd..73d8fe02f1 100644 --- a/flake.nix +++ b/flake.nix @@ -32,6 +32,8 @@ # Add additional packages to our environment packages = [ pkgs.nodePackages.pnpm + + pkgs.python3 ]; # No need to warn on a new version, we'll update as needed. devenv.warnOnNewVersion = false; @@ -43,6 +45,18 @@ # Enable stable Rust for the backend languages.rust.enable = true; languages.rust.version = "stable"; + processes = { + dev-server.exec = "pnpm run dev"; + }; + scripts = { + build.exec = "pnpm run build"; + clean.exec = "pnpm run clean"; + clear-state.exec = "rm -rf .devenv/state/redis .devenv/state/postgres"; + format.exec = "pnpm run format"; + install-deps.exec = "pnpm install"; + migrate.exec = "pnpm run migrate"; + prepare-config.exec = "cp .config/devenv.yml .config/default.yml"; + }; services = { postgres = { enable = true;