From ef826d46331f52636b9a8ea6ea0a814e46235ee6 Mon Sep 17 00:00:00 2001 From: Abel Lucas Date: Thu, 7 Nov 2024 15:21:15 +0100 Subject: [PATCH] feat: add `nix` documentation + flake cleanups --- README.md | 2 ++ flake.nix | 79 ++++++++++++++++++++++-------------------- frontend/README_DEV.md | 44 +++++++++++++++++++++++ 3 files changed, 88 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index eb6c64ee2ae7d..e85d34111b92c 100644 --- a/README.md +++ b/README.md @@ -355,6 +355,8 @@ you to have it being synced automatically everyday. See the [./frontend/README_DEV.md](./frontend/README_DEV.md) file for all running options. +Using [Nix](./frontend/README_DEV.md#nix). + ### only Frontend This will use the backend of but your own frontend with hot-code reloading. Note that you will need to use a username / password login due to CSRF checks using a different auth provider. diff --git a/flake.nix b/flake.nix index d6fbd0fdf2c79..cca085448d94b 100644 --- a/flake.nix +++ b/flake.nix @@ -14,30 +14,19 @@ }; buildInputs = with pkgs; [ openssl.dev libxml2.dev xmlsec.dev libxslt.dev - rust-bin.beta.latest.default nodejs go - xcaddy sqlx-cli pkg-config + rust-bin.stable.latest.default nodejs + postgresql + pkg-config ]; - environment = { - NODE_ENV = "development"; - NODE_OPTIONS = "--max-old-space-size=16384"; - DATABASE_URL = "postgres://postgres:changeme@127.0.0.1:5432/"; - PKG_CONFIG_PATH = pkgs.lib.makeSearchPath "lib/pkgconfig" (with pkgs; [ - openssl.dev - libxml2.dev - xmlsec.dev - libxslt.dev - ]); - }; - rustcTarget = pkgs.hostPlatform.rust.rustcTarget; - fetch_librusty_v8 = { version, shas }: pkgs.fetchurl { - name = "librusty_v8-${version}"; - url = "https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${rustcTarget}.a.gz"; - sha256 = shas.${system}; - }; + PKG_CONFIG_PATH = pkgs.lib.makeSearchPath "lib/pkgconfig" (with pkgs; [ + openssl.dev + libxml2.dev + xmlsec.dev + libxslt.dev + ]); in { devShell = pkgs.mkShell { - inherit (environment) NODE_ENV NODE_OPTIONS DATABASE_URL PKG_CONFIG_PATH; - buildInputs = buildInputs; + buildInputs = buildInputs ++ (with pkgs; [ git go xcaddy sqlx-cli ]); packages = [ (pkgs.writeScriptBin "wm-caddy" '' cd ./frontend @@ -54,27 +43,39 @@ '') (pkgs.writeScriptBin "wm-migrate" '' cd ./backend - sqlx database reset - sqlx database create sqlx migrate run '') (pkgs.writeScriptBin "wm-setup" '' + sqlx database create wm-build wm-caddy wm-migrate '') + (pkgs.writeScriptBin "wm-reset" '' + sqlx database drop -f + sqlx database create + wm-migrate + '') (pkgs.writeScriptBin "wm" '' cd ./frontend npm run dev $* '') ]; + + inherit PKG_CONFIG_PATH; + NODE_ENV = "development"; + NODE_OPTIONS = "--max-old-space-size=16384"; + DATABASE_URL = "postgres://postgres:changeme@127.0.0.1:5432/"; + REMOTE = "http://127.0.0.1:8000"; + REMOTE_LSP = "http://127.0.0.1:3001"; }; + packages.default = self.packages.${system}.windmill; packages.windmill-client = pkgs.stdenv.mkDerivation { pname = "windmill-client"; version = (pkgs.lib.strings.trim (builtins.readFile ./version.txt)); src = ./.; - buildInputs = with pkgs; [ nodejs go ]; + buildInputs = with pkgs; [ nodejs ]; buildPhase = '' export HOME=$(pwd) @@ -91,8 +92,6 @@ ''; }; packages.windmill = pkgs.rustPlatform.buildRustPackage { - inherit (environment) DATABASE_URL PKG_CONFIG_PATH; - pname = "windmill"; version = (pkgs.lib.strings.trim (builtins.readFile ./version.txt)); @@ -111,26 +110,32 @@ }; }; - buildFeatures = [ "enterprise" ]; + buildFeatures = [ ]; doCheck = false; preBuild = '' export HOME=$(pwd) npm config set strict-ssl false cd backend - sqlx database create - sqlx migrate run ''; + inherit PKG_CONFIG_PATH; + SQLX_OFFLINE = true; FRONTEND_BUILD_DIR = "${self.packages.${system}.windmill-client}/build"; - RUSTY_V8_ARCHIVE = (fetch_librusty_v8 { - version = "130.0.1"; - shas = { - x86_64-linux = pkgs.lib.fakeHash; - aarch64-linux = pkgs.lib.fakeHash; - x86_64-darwin = pkgs.lib.fakeHash; - aarch64-darwin = "sha256-d1QTLt8gOUFxACes4oyIYgDF/srLOEk+5p5Oj1ECajQ="; + RUSTY_V8_ARCHIVE = + let + version = "130.0.1"; + target = pkgs.hostPlatform.rust.rustcTarget; + sha256 = { + x86_64-linux = pkgs.lib.fakeHash; + aarch64-linux = pkgs.lib.fakeHash; + x86_64-darwin = pkgs.lib.fakeHash; + aarch64-darwin = "sha256-d1QTLt8gOUFxACes4oyIYgDF/srLOEk+5p5Oj1ECajQ="; + }.${system}; + in pkgs.fetchurl { + name = "librusty_v8-${version}"; + url = "https://github.com/denoland/rusty_v8/releases/download/v${version}/librusty_v8_release_${target}.a.gz"; + inherit sha256; }; - }); }; }); } diff --git a/frontend/README_DEV.md b/frontend/README_DEV.md index 198657d3af444..ba90278be4f82 100644 --- a/frontend/README_DEV.md +++ b/frontend/README_DEV.md @@ -1,5 +1,7 @@ # Developing +[Using Nix](#nix), otherwise: + In the `frontend/` directory: - install the dependencies with `npm install` (or `pnpm install` or `yarn`) @@ -136,3 +138,45 @@ NOTCATCHALL=true npm run build which will generate an index.html and allow you to serve the frontend with any static server. Env variables used for build are set in .env file. See [https://vitejs.dev/guide/env-and-mode.html#env-files](https://vitejs.dev/guide/env-and-mode.html#env-files) for more details. + +## Nix + +Windmill use [nix flakes](https://nixos.wiki/wiki/Flakes): +```bash +nix run github:windmill-labs/windmill +``` + +### Development +```bash +nix develop # enter a dev shell containing all necessary packages. + +wm-setup # build the frontend and setup the database. +wm # run the frontend. + +# In an other shell: +nix develop +cd backend +cargo run +``` + +### Updating [`flake.nix`](../flake.nix) + +```bash +nix flake update # update the lock file. +``` + +Some cargo dependencies use fixed git revisions, which are also fixed in `flake.nix`: +```nix +outputHashes = { + "php-parser-rs-0.1.3" = "sha256-ZeI3KgUPmtjlRfq6eAYveqt8Ay35gwj6B9iOQRjQa9A="; + # ... +}; +``` + +When updating a revision, replace the incorrect `sha256` with `pkgs.lib.fakeHash`: +```diff +- "php-parser-rs-0.1.3" = "sha256-ZeI3KgUPmtjlRfq6eAYveqt8Ay35gwj6B9iOQRjQa9A="; ++ "php-parser-rs-0.1.3" = pkgs.lib.fakeHash; +``` + +Then run `nix build .#windmill` and update with the correct sha.