From f24c2ec21640f10681404d7944f21d2ea46565c6 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 13 May 2025 21:49:21 +0100 Subject: [PATCH 1/3] docs: add hacking.md --- docs/hacking.md | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 docs/hacking.md diff --git a/docs/hacking.md b/docs/hacking.md new file mode 100644 index 0000000..265c930 --- /dev/null +++ b/docs/hacking.md @@ -0,0 +1,72 @@ +# hacking on tangled + +We highly recommend [installing +nix](https://nixos.org/download/) (the package manager) +before working on the codebase. The nix flake provides a lot +of helpers to get started and most importantly, builds and +dev shells are entirely deterministic. + +To set up your dev environment: + +```bash +nix develop +``` + +Non-nix users can look at the `devShell` attribute in the +`flake.nix` file to determine necessary dependencies. + +## running the appview + +The nix flake also exposes a few `app` attributes (run `nix +flake show` to see a full list of what the flake provides), +one of the apps runs the appview with the `air` +live-reloader: + +```bash +TANGLED_DEV=true nix run .#watch-appview + +# TANGLED_DB_PATH might be of interest to point to +# different sqlite DBs + +# in a separate shell, you can live-reload tailwind +nix run .#watch-tailwind +``` + +## running a knotserver + +An end-to-end knotserver setup requires setting up a machine +with `sshd`, `repoguard`, `keyfetch`, a git user, which is +quite cumbersome and so the nix flake provides a +`nixosConfiguration` to do so. + +To begin, head to `http://localhost:3000` in the browser and +generate a knotserver secret. Replace the existing secret in +`flake.nix` with the newly generated secret. + +You can now start a lightweight NixOS VM using +`nixos-shell` like so: + +```bash +QEMU_NET_OPTS="hostfwd=tcp::6000-:6000,hostfwd=tcp::2222-:22" nixos-shell --flake .#knotVM + +# hit Ctrl-a + c + q to exit the VM +``` + +This starts a knotserver on port 6000 with `ssh` exposed on +port 2222. You can push repositories to this VM with this +ssh config block on your main machine: + +```bash +Host nixos-shell + Hostname localhost + Port 2222 + User git + IdentityFile ~/.ssh/my_tangled_key +``` + +Set up a remote called `local-dev` on a git repo: + +```bash +git remote add local-dev git@nixos-shell:user/repo +git push local-dev main +``` -- 2.47.2 From 852fd73c3a595b3313d8c540a8db9496d566453e Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 13 May 2025 21:49:21 +0100 Subject: [PATCH 2/3] cmd/genjwks: print to stdout instead of writing to file also setup nix devshell to configure TANGLED_OAUTH_JWK in a shellhook for seamless local oauth dev. --- cmd/genjwks/main.go | 5 +---- flake.nix | 3 +++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/genjwks/main.go b/cmd/genjwks/main.go index cfa9c08..9ece76c 100644 --- a/cmd/genjwks/main.go +++ b/cmd/genjwks/main.go @@ -8,7 +8,6 @@ import ( "crypto/rand" "encoding/json" "fmt" - "os" "time" "github.com/lestrrat-go/jwx/v2/jwk" @@ -36,7 +35,5 @@ func main() { panic(err) } - if err := os.WriteFile("./jwks.json", b, 0644); err != nil { - panic(err) - } + fmt.Println(string(b)) } diff --git a/flake.nix b/flake.nix index 1a307c4..c5b7c08 100644 --- a/flake.nix +++ b/flake.nix @@ -123,6 +123,7 @@ }; repoguard = buildCmdPackage "repoguard"; keyfetch = buildCmdPackage "keyfetch"; + genjwks = buildCmdPackage "genjwks"; }; packages = forAllSystems (system: { inherit @@ -133,6 +134,7 @@ knotserver-unwrapped repoguard keyfetch + genjwks ; }); defaultPackage = forAllSystems (system: nixpkgsFor.${system}.appview); @@ -162,6 +164,7 @@ cp -f ${inter-fonts-src}/web/InterVariable*.woff2 appview/pages/static/fonts/ cp -f ${inter-fonts-src}/web/InterDisplay*.woff2 appview/pages/static/fonts/ cp -f ${ibm-plex-mono-src}/fonts/complete/woff2/IBMPlexMono-Regular.woff2 appview/pages/static/fonts/ + export TANGLED_OAUTH_JWKS="$(${pkgs.genjwks}/bin/genjwks)" ''; env.CGO_ENABLED = 1; }; -- 2.47.2 From ad875e10e55b1990297a8f4dda1728797804ca09 Mon Sep 17 00:00:00 2001 From: Divya Jain Date: Wed, 14 May 2025 13:55:00 +0530 Subject: [PATCH 3/3] scripts: add dev scripts --- .gitignore | 1 + scripts/run-knotserver-vm.sh | 7 +++++++ scripts/watch-appview.sh | 7 +++++++ scripts/watch-knotserver.sh | 11 +++++++++++ scripts/watch-tailwind.sh | 5 +++++ 5 files changed, 31 insertions(+) create mode 100755 scripts/run-knotserver-vm.sh create mode 100755 scripts/watch-appview.sh create mode 100755 scripts/watch-knotserver.sh create mode 100755 scripts/watch-tailwind.sh diff --git a/.gitignore b/.gitignore index 6651f18..371a053 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ patches *.qcow2 .DS_Store .env +repos/ diff --git a/scripts/run-knotserver-vm.sh b/scripts/run-knotserver-vm.sh new file mode 100755 index 0000000..7a956ce --- /dev/null +++ b/scripts/run-knotserver-vm.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +set -e + +export QEMU_NET_OPTS="hostfwd=tcp::6000-:6000,hostfwd=tcp::2222-:22" + +nix develop --command bash -c "nixos-shell --flake .#knotVM" diff --git a/scripts/watch-appview.sh b/scripts/watch-appview.sh new file mode 100755 index 0000000..8a5b335 --- /dev/null +++ b/scripts/watch-appview.sh @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +set -e + +export TANGLED_DEV=true + +nix develop --command nix run .#watch-appview diff --git a/scripts/watch-knotserver.sh b/scripts/watch-knotserver.sh new file mode 100755 index 0000000..36f388d --- /dev/null +++ b/scripts/watch-knotserver.sh @@ -0,0 +1,11 @@ +#! /usr/bin/env bash + +set -e + +export TANGLED_DEV=true +export KNOT_SERVER_SECRET=e63d7a46b5d9d6646d30562642986899aad755a2b3912bf748dfc7989e612770 +export KNOT_SERVER_HOSTNAME=localhost +export APPVIEW_ENDPOINT=http://127.0.0.1:3000 +export KNOT_REPO_SCAN_PATH=./repos + +nix develop --command nix run .#watch-knotserver diff --git a/scripts/watch-tailwind.sh b/scripts/watch-tailwind.sh new file mode 100755 index 0000000..2acf413 --- /dev/null +++ b/scripts/watch-tailwind.sh @@ -0,0 +1,5 @@ +#! /usr/bin/env bash + +set -e + +nix develop --command nix run .#watch-tailwind -- 2.47.2