diff --git a/.gitignore b/.gitignore index 5b384e9..8342d2d 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,9 @@ go.work .direnv +.vagrant debug.log result -/examples/vagrant-demo/.vagrant /labcoat +/examples/vagrant-demo/labcoat +/examples/vagrant-demo/*.mp4 diff --git a/README.md b/README.md index e38e9f0..52b159e 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ know if your configuration works correctly. For production NixOS environments with many instances of the same configuration, you will be better served by a parallel deployment tool such as [Colmena]. +![Demo Screencast](/examples/vagrant-demo/demo.gif) + ## Features diff --git a/examples/vagrant-demo/Makefile b/examples/vagrant-demo/Makefile new file mode 100644 index 0000000..89ca61c --- /dev/null +++ b/examples/vagrant-demo/Makefile @@ -0,0 +1,53 @@ +SHELL = /bin/sh +.PHONY = build clean destroy prepare + +configs = flake.nix +srcs = demo.tape +tapes = $(srcs:.tape=.mp4) + +db_ip = 192.168.33.10 +web_ip = 192.168.33.11 +host_ips = $(db_ip) $(web_ip) + +all: clean build + +clean: + git restore $(configs) + rm -f labcoat $(tapes) + nixos-rebuild \ + --flake ".#db-lab" \ + --target-host root@$(db_ip) \ + --build-host localhost switch + ssh root@$(db_ip) nix-collect-garbage -d || true + +destroy: + vagrant destroy --force + for ip in $(host_ips); do \ + ssh-keygen -R $$ip; \ + done + +prepare: + git restore $(configs) + vagrant up + ssh-keyscan $(host_ips) >> $$HOME/.ssh/known_hosts + nixos-rebuild \ + --flake ".#db-lab" \ + --target-host root@$(db_ip) \ + --build-host localhost boot + # Kernel upgrade, reboot. + ssh root@$(db_ip) reboot || true + nixos-rebuild \ + --flake ".#web-lab" \ + --target-host root@$(web_ip) \ + --build-host localhost boot + # Kernel upgrade, reboot. + ssh root@$(web_ip) reboot || true + +build: labcoat $(tapes) + +labcoat: + go build ../.. + +%.mp4: %.tape + vhs $< + git restore $(configs) diff --git a/examples/vagrant-demo/README.md b/examples/vagrant-demo/README.md new file mode 100644 index 0000000..91c3e55 --- /dev/null +++ b/examples/vagrant-demo/README.md @@ -0,0 +1,18 @@ +# vagrant-demo + +Used to generated screen recordings of labcoat. + +## Usage + +Warning: The `Makefile` will make changes to your SSH `known_hosts` file. + +```sh +# Setup VMs +make prepare + +# Generate recordings +make + +# Teardown VMs +make destroy +``` diff --git a/examples/vagrant-demo/demo.gif b/examples/vagrant-demo/demo.gif new file mode 100644 index 0000000..366f7b8 Binary files /dev/null and b/examples/vagrant-demo/demo.gif differ diff --git a/examples/vagrant-demo/demo.tape b/examples/vagrant-demo/demo.tape new file mode 100644 index 0000000..d79547d --- /dev/null +++ b/examples/vagrant-demo/demo.tape @@ -0,0 +1,109 @@ +Output demo.gif + +Set Width 1600 +Set Height 850 +Set WindowBar Colorful +Set FontSize 14 +Set PlaybackSpeed 0.75 + +Set Shell fish + +# Show off UI. +Sleep 500ms +Type "./labcoat -config labcoat-config.toml" +Enter +Sleep 5s +Type "j" +Sleep 3s +Type "j" +Sleep 3s +Type "j" +Sleep 3s +Type "/" +Sleep 1s +Type "lab" +Sleep 500ms +Enter +Sleep 1.5s +Type "fd" +Sleep 3s +Type "!" +Sleep 500ms +Type "systemctl status " +Sleep 500ms +Type "postgresql" +Sleep 1.5s +Enter +Sleep 3.5s +Type "q" +Sleep 2s + +# Add PostgreSQL to db-lab config. +Type "vim flake.nix" +Enter +Sleep 3s +Type "/d" +Sleep 500ms +Type "b-lab" +Sleep 1.5s +Enter +Sleep 500ms +Type "zz" +Sleep 1.5s +Type "jjo" +Sleep 500ms +Type "{ services.postgresql.enable" +Sleep 200ms +Type " = true; }" +Sleep 500ms +Escape +Type ":wq" +Sleep 500ms +Enter +Sleep 2s + +# Deploy db-lab. +Up +Up +Sleep 500ms +Enter +Sleep 3s +Type "d" +Sleep 10.5s +Type "s" +Sleep 2.5s +Type "!systemctl status " +Sleep 200ms +Type "postgresql" +Enter +Sleep 3s + +# SSH demo. +Type "i" +Sleep 2s +Type "# <<< on the db-lab host; one touch SSH!" +Enter +Sleep 1s +Type "su - postgres" +Enter +Sleep 500ms +Type "psql" +Enter +Sleep 1s +Type "\conninfo" +Enter +Sleep 2s +Type "\q" +Enter +Ctrl+D +Sleep 500ms +Ctrl+D +Sleep 3s +Tab +Sleep 3s +Tab +Sleep 3s +Tab +Sleep 3s +Tab +Sleep 5s diff --git a/examples/vagrant-demo/flake.nix b/examples/vagrant-demo/flake.nix index ee4a842..0c263e1 100644 --- a/examples/vagrant-demo/flake.nix +++ b/examples/vagrant-demo/flake.nix @@ -59,6 +59,25 @@ (networkModule { hostName = "web-lab"; ipAddr = "192.168.33.11"; }) ]; }; + + # Fake systems to pad the labcoat host list. + fake-host-1 = lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + commonModule + ./hardware-configuration.nix + (networkModule { hostName = "fake-host-1"; ipAddr = "192.168.33.11"; }) + ]; + }; + + fake-host-2 = lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + commonModule + ./hardware-configuration.nix + (networkModule { hostName = "fake-host-2"; ipAddr = "192.168.33.10"; }) + ]; + }; }; }; } diff --git a/examples/vagrant-demo/xdg-config/labcoat/config.toml b/examples/vagrant-demo/labcoat-config.toml similarity index 100% rename from examples/vagrant-demo/xdg-config/labcoat/config.toml rename to examples/vagrant-demo/labcoat-config.toml diff --git a/flake.lock b/flake.lock index 7888bbb..9b7c3da 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1719745305, - "narHash": "sha256-xwgjVUpqSviudEkpQnioeez1Uo2wzrsMaJKJClh+Bls=", + "lastModified": 1726153070, + "narHash": "sha256-HO4zgY0ekfwO5bX0QH/3kJ/h4KvUDFZg8YpkNwIbg1U=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "c3c5ecc05edc7dafba779c6c1a61cd08ac6583e9", + "rev": "bcef6817a8b2aa20a5a6dbb19b43e63c5bf8619a", "type": "github" }, "original": { @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1713128889, - "narHash": "sha256-aB90ZqzosyRDpBh+rILIcyP5lao8SKz8Sr2PSWvZrzk=", + "lastModified": 1726871744, + "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=", "owner": "nixos", "repo": "nixpkgs", - "rev": "2748d22b45a99fb2deafa5f11c7531c212b2cefa", + "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 4894ea1..498d274 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,7 @@ flake-parts.lib.mkFlake { inherit inputs; } { systems = [ "x86_64-linux" "aarch64-linux" ]; - perSystem = { config, self', inputs', pkgs, system, ... }: + perSystem = { self', pkgs, ... }: let # Generate a user-friendly version number. version = builtins.substring 0 8 self.lastModifiedDate; @@ -37,6 +37,7 @@ go_1_22 golint gopls + vhs ]; hardeningDisable = [ "fortify" ];