From 794ca5a086ba05c6e11fbef73c77682bd179e7fe Mon Sep 17 00:00:00 2001 From: Willem Vanhulle Date: Wed, 21 Oct 2026 11:55:46 +0200 Subject: [PATCH] refactor: reorganise flake, tests and repo tasks --- .cargo/config.toml | 2 + .gitignore | 1 - rustfmt.toml => .rustfmt.toml | 0 CONTRIBUTING.md | 62 ++-- Cargo.lock | 25 ++ Cargo.toml | 10 +- README.md | 78 +++-- crane-builds.nix | 63 ++++ demo/demo-units.nu | 38 --- docs/passphrase.png | Bin 9933 -> 0 bytes flake.nix | 148 +++------ {docs => recordings}/boot.tape | 2 +- recordings/passphrase.png | Bin 0 -> 9916 bytes {docs => recordings}/shutdown.tape | 2 +- .../dracut/.shellcheckrc | 0 .../dracut/90bootvine/module-setup.sh | 0 .../mkinitcpio/install/sd-bootvine | 0 .../systemd/bootvine-shutdown.service | 0 .../systemd/bootvine.service | 0 tests/sample-machine/default.nix | 25 ++ .../sample-machine/interactive-vm.nix | 4 +- .../sample-machine/machine.nix | 8 +- .../sample-machine/sample-unit-files.nix | 27 +- .../sample-machine/sample-units.nix | 0 tests/{ => vm-checks}/boot.nix | 6 +- tests/{ => vm-checks}/boot.py | 0 tests/{ => vm-checks}/console.py | 0 tests/{ => vm-checks}/luks.nix | 2 +- tests/{ => vm-checks}/luks.py | 0 xtask/Cargo.toml | 15 + xtask/src/install_files.rs | 280 ++++++++++++++++++ xtask/src/main.rs | 49 +++ xtask/src/record_screencasts.rs | 30 ++ xtask/src/task_error.rs | 13 + 34 files changed, 670 insertions(+), 220 deletions(-) create mode 100644 .cargo/config.toml rename rustfmt.toml => .rustfmt.toml (100%) create mode 100644 crane-builds.nix delete mode 100755 demo/demo-units.nu delete mode 100644 docs/passphrase.png rename {docs => recordings}/boot.tape (91%) create mode 100644 recordings/passphrase.png rename {docs => recordings}/shutdown.tape (90%) rename {packaging => system-files}/dracut/.shellcheckrc (100%) rename {packaging => system-files}/dracut/90bootvine/module-setup.sh (100%) rename {packaging => system-files}/mkinitcpio/install/sd-bootvine (100%) rename {packaging => system-files}/systemd/bootvine-shutdown.service (100%) rename {packaging => system-files}/systemd/bootvine.service (100%) create mode 100644 tests/sample-machine/default.nix rename demo/interactive.nix => tests/sample-machine/interactive-vm.nix (68%) rename demo/host.nix => tests/sample-machine/machine.nix (91%) rename demo/user-units.nix => tests/sample-machine/sample-unit-files.nix (65%) rename demo/units.nix => tests/sample-machine/sample-units.nix (100%) rename tests/{ => vm-checks}/boot.nix (89%) rename tests/{ => vm-checks}/boot.py (100%) rename tests/{ => vm-checks}/console.py (100%) rename tests/{ => vm-checks}/luks.nix (97%) rename tests/{ => vm-checks}/luks.py (100%) create mode 100644 xtask/Cargo.toml create mode 100644 xtask/src/install_files.rs create mode 100644 xtask/src/main.rs create mode 100644 xtask/src/record_screencasts.rs create mode 100644 xtask/src/task_error.rs diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..9741f11 --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,2 @@ +[alias] +xtask = "run --quiet --package xtask --" diff --git a/.gitignore b/.gitignore index 3dec543..6963297 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ target result* -*.qcow2 diff --git a/rustfmt.toml b/.rustfmt.toml similarity index 100% rename from rustfmt.toml rename to .rustfmt.toml diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f1e081a..02cfe8a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -2,30 +2,52 @@ ## Workflow -Work inside the dev shell (`direnv allow` once). Run `cargo clippy ---all-targets` before committing (the crate warns on clippy pedantic plus -`absolute_paths`) and `cargo fmt`, which needs the nightly toolchain for -`rustfmt.toml`. Version control is jj, not the `git` CLI. +Work inside the dev shell (`direnv allow` once). Run `cargo clippy --workspace +--all-targets` before committing (the workspace warns on clippy pedantic plus +`absolute_paths`) and `cargo fmt --all`, which needs the nightly toolchain for +`.rustfmt.toml`. Version control is jj, not the `git` CLI. + +The workspace has two crates: `bootvine` itself and `xtask`, the repository +tasks behind `cargo xtask` (`record-screencasts`, `install`, `uninstall`). ## Testing -- `cargo test`: model and render snapshot tests. -- `nix run .#demo-units -- start`, then - `cargo run -- --user --target bootvine-demo.target --hold 3s`: live against - your user manager. -- `nix build .#checks.x86_64-linux.`: each `tests/.nix` boots a VM - and runs `tests/console.py` followed by `tests/.py`. `boot` follows - the initrd, stage 2 and a poweroff; `luks` answers a passphrase prompt in - the initrd. They read tty12 as text from `/dev/vcsu12`, hold the boot with - the initrd backdoor and gate files under `/run` instead of sleeping. Run one - by hand with `nix run .#checks.x86_64-linux.boot.driverInteractive`, then - `test_script()`. -- `nix run .#docs`, from the repository root: renders `docs/boot.tape` and - `docs/shutdown.tape` with VHS against the scripted examples into the README - GIFs, and copies the passphrase screenshot from the `luks` check. +Everything that boots a machine or a service manager lives under `tests/`: +`tests/sample-machine/` holds the sample host, its slow and failing sample units +and the interactive VM; `tests/vm-checks/` holds the NixOS tests that boot it. -Prefix the VM commands with `env -u LD_LIBRARY_PATH` when the shell exports -libraries that clash with QEMU's. +- `cargo test --workspace`: model and render snapshot tests. +- Live against your user manager, with the sample units: + + ```sh + units=$(nix build --no-link --print-out-paths .#sample-unit-files) + systemctl --user link --runtime $units/* + systemctl --user start --no-block bootvine-demo.target + cargo run -- --user --target bootvine-demo.target --hold 3s + systemctl --user stop $(ls $units) + systemctl --user disable --runtime $(ls $units) + ``` + +- `nix run .#sample-machine-vm`: the sample host in a QEMU window. Its disk + image goes to `~/.cache/bootvine-sample-machine.qcow2`. +- `nix build .#checks.x86_64-linux.`: each `tests/vm-checks/.nix` + boots a VM and runs `console.py` followed by `.py`. + `vm-boot-and-shutdown` follows the initrd, stage 2 and a poweroff; + `vm-luks-passphrase` answers a passphrase prompt in the initrd. They read + tty12 as text from `/dev/vcsu12`, hold the boot with the initrd backdoor and + gate files under `/run` instead of sleeping. Run one by hand with + `nix run .#checks.x86_64-linux.vm-boot-and-shutdown.driverInteractive`, then + `test_script()`. +- `nix run .#record-screencasts`, from the repository root: runs + `cargo xtask record-screencasts`, which records `recordings/boot.tape` and + `recordings/shutdown.tape` with VHS against the scripted examples into the README + GIFs and copies the passphrase screenshot from the `vm-luks-passphrase` check. +- `cargo xtask install --destdir --initrd dracut`: stages an install + without touching the system; `cargo xtask uninstall --destdir ` empties + it again. + +Prefix the VM and VHS commands with `env -u LD_LIBRARY_PATH` when the shell +exports libraries that clash with QEMU's or Chromium's. ## Conventions diff --git a/Cargo.lock b/Cargo.lock index bdd1a43..a93594b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2227,6 +2227,31 @@ version = "0.57.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" +[[package]] +name = "xshell" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e7290c623014758632efe00737145b6867b66292c42167f2ec381eb566a373d" +dependencies = [ + "xshell-macros", +] + +[[package]] +name = "xshell-macros" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32ac00cd3f8ec9c1d33fb3e7958a82df6989c42d747bd326c822b1d625283547" + +[[package]] +name = "xtask" +version = "0.1.0" +dependencies = [ + "clap", + "rustix 1.1.5", + "thiserror 2.0.21", + "xshell", +] + [[package]] name = "zeroize" version = "1.9.1" diff --git a/Cargo.toml b/Cargo.toml index 933d70a..dcc0f38 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,14 +9,20 @@ readme = "README.md" keywords = ["systemd", "boot", "initrd", "tui", "console"] categories = ["command-line-utilities", "os::linux-apis"] rust-version = "1.91" -include = ["/src", "/examples", "/packaging", "/README.md", "/LICENSE"] +include = ["/src", "/examples", "/system-files", "/README.md", "/LICENSE"] -[lints.clippy] +[workspace] +members = [".", "xtask"] + +[workspace.lints.clippy] absolute_paths = "warn" pedantic = { priority = -1, level = "warn" } needless_for_each = "allow" missing_errors_doc = "allow" +[lints] +workspace = true + [dependencies] clap = { version = "4.6.7", features = ["derive"] } crossterm = "0.29.0" diff --git a/README.md b/README.md index 0632997..7e10f03 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ nix-output-monitor. It replaces the scrolling kernel and systemd lines with the units still pending and, in the room the tree leaves, a timeline of the slowest ones that ran. -A boot through the initrd into stage 2, with one failed unit +A boot through the initrd into stage 2, with one failed unit It needs systemd ≥ 246 as PID 1, libdbus and a virtual terminal (it draws on tty12). With a systemd initrd it starts about a second after the kernel and @@ -19,25 +19,45 @@ It also follows shutdowns and reboots: the units being stopped, nested under the units that have to stop first, until systemd hands over to `systemd-shutdown`. -A poweroff: units stopping under the targets waiting on them +A poweroff: units stopping under the targets waiting on them Passphrase prompts, such as a LUKS unlock in the initrd, are answered in place over the tree. -A LUKS passphrase prompt floating over the initrd tree +A LUKS passphrase prompt floating over the initrd tree -## Try +## Try it without installing + +Neither of these touches your system's boot. + +### Scripted boots in your terminal + +From a clone, with Rust installed (see step 1 of the Ubuntu install below): ```sh +git clone https://codeberg.org/wvhulle/bootvine.git +cd bootvine cargo run --example boot cargo run --example shutdown cargo run --example luks ``` -play a scripted boot, poweroff or boot from an encrypted root without systemd; -`q` quits. The encrypted root unlocks with the passphrase `demo`; `Esc` quits -while it asks. `nix run .#vm` boots a demo -VM in a window. +These play a scripted boot, a poweroff and a boot from an encrypted root, with +no systemd involved. `q` quits. The encrypted root unlocks with the passphrase +`demo`; `Esc` quits while it asks. + +### A sample machine in a VM + +With Nix, and no clone needed: + +```sh +nix run git+https://codeberg.org/wvhulle/bootvine#sample-machine-vm +``` + +This boots a NixOS machine with bootvine and a set of slow and failing sample +units in a QEMU window, from the initrd through stage 2. It logs in as root; +`poweroff` shows the shutdown. Its disk image is kept in +`~/.cache/bootvine-sample-machine.qcow2`. ## Install @@ -98,45 +118,43 @@ VM in a window. curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -2. Build: +2. Clone, build and install the binary and the systemd units, and enable + them. `cargo xtask install` builds as you and asks `sudo` only for the + copying and `systemctl enable`: ```sh git clone https://codeberg.org/wvhulle/bootvine.git cd bootvine - cargo build --release + cargo xtask install ``` -3. Install the binary and the systemd units, and enable them: + This is enough for bootvine to show stage 2 and shutdown. It installs + `/usr/bin/bootvine` and `bootvine.service` and `bootvine-shutdown.service` + in `/usr/lib/systemd/system`. - ```sh - sudo install -Dm755 target/release/bootvine /usr/bin/bootvine - sudo install -Dm644 -t /usr/lib/systemd/system \ - packaging/systemd/bootvine.service packaging/systemd/bootvine-shutdown.service - sudo systemctl enable bootvine.service bootvine-shutdown.service - ``` - - This is enough for bootvine to show stage 2 and shutdown. - -4. Optionally, follow the boot from the initrd. This needs a dracut initramfs +3. Optionally, follow the boot from the initrd. This needs a dracut initramfs with systemd in it; initramfs-tools has no systemd, so on releases that use it bootvine starts in stage 2 only. ```sh - sudo install -Dm755 packaging/dracut/90bootvine/module-setup.sh \ - /usr/lib/dracut/modules.d/90bootvine/module-setup.sh - echo 'add_dracutmodules+=" bootvine "' | sudo tee /etc/dracut.conf.d/bootvine.conf + cargo xtask install --initrd dracut sudo dracut --force ``` -5. Reboot. + This adds the dracut module in `/usr/lib/dracut/modules.d/90bootvine` and + enables it in `/etc/dracut.conf.d/bootvine.conf`. + +4. Reboot. + +`cargo xtask uninstall` removes all of it again. ### Other distributions -Install the binary and units as in the Ubuntu steps. For the initrd, use the -dracut module as above, or on mkinitcpio install -`packaging/mkinitcpio/install/sd-bootvine` to `/usr/lib/initcpio/install/`, add -`sd-bootvine` after `systemd` in `HOOKS` in `/etc/mkinitcpio.conf`, and run -`sudo mkinitcpio -P`. +Install as in the Ubuntu steps. For the initrd, use the dracut module as above, +or on mkinitcpio run `cargo xtask install --initrd mkinitcpio`, which installs +`/usr/lib/initcpio/install/sd-bootvine`, then add `sd-bootvine` after `systemd` +in `HOOKS` in `/etc/mkinitcpio.conf` and run `sudo mkinitcpio -P`. +`--destdir ` stages the files under `` instead, for packaging. ## Configure diff --git a/crane-builds.nix b/crane-builds.nix new file mode 100644 index 0000000..81cabad --- /dev/null +++ b/crane-builds.nix @@ -0,0 +1,63 @@ +{ + lib, + pkgs, + craneLib, +}: +let + commonArgs = { + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + (craneLib.fileset.commonCargoSources ./.) + ./system-files + ]; + }; + strictDeps = true; + nativeBuildInputs = [ pkgs.pkg-config ]; + buildInputs = [ pkgs.dbus ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly (commonArgs // { pname = "bootvine-workspace"; }); + + buildWorkspaceMember = + args: craneLib.buildPackage (commonArgs // { inherit cargoArtifacts; } // args); +in +{ + bootvine = buildWorkspaceMember { + cargoExtraArgs = "-p bootvine"; + postInstall = '' + for unit in bootvine.service bootvine-shutdown.service; do + install -Dm644 system-files/systemd/$unit $out/lib/systemd/system/$unit + substituteInPlace $out/lib/systemd/system/$unit \ + --replace-fail /usr/bin/bootvine $out/bin/bootvine + done + install -Dm755 system-files/dracut/90bootvine/module-setup.sh \ + $out/lib/dracut/modules.d/90bootvine/module-setup.sh + install -Dm644 system-files/mkinitcpio/install/sd-bootvine \ + $out/lib/initcpio/install/sd-bootvine + ''; + meta = { + mainProgram = "bootvine"; + platforms = lib.platforms.linux; + license = lib.getLicenseFromSpdxId (lib.importTOML ./Cargo.toml).package.license; + }; + }; + + scripted-boot-examples = buildWorkspaceMember { + pname = "bootvine-scripted-boot-examples"; + cargoExtraArgs = "-p bootvine --examples"; + doCheck = false; + installPhaseCommand = '' + for example in boot shutdown; do + install -Dm755 target/release/examples/$example $out/bin/bootvine-$example-example + done + ''; + }; + + repo-tasks = buildWorkspaceMember { + pname = "xtask"; + cargoExtraArgs = "-p xtask"; + doCheck = false; + meta.mainProgram = "xtask"; + }; +} diff --git a/demo/demo-units.nu b/demo/demo-units.nu deleted file mode 100755 index de98c68..0000000 --- a/demo/demo-units.nu +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env nu - -def user-unit-dir []: nothing -> path { - $env.XDG_RUNTIME_DIR | path join systemd user -} - -def unit-names [units: path]: nothing -> list { - ls $units | get name | path basename -} - -def install-units [units: path] { - let target_dir = user-unit-dir - mkdir $target_dir - unit-names $units | each {|name| ^ln -sfn ($units | path join $name) ($target_dir | path join $name) } | ignore - ^systemctl --user daemon-reload -} - -def "main start" [--units: path, --target: string] { - install-units $units - ^systemctl --user stop ...(unit-names $units) - ^systemctl --user start --no-block $target - print $"started ($target); watch it with: bootvine --user --target ($target) --hold 3s" -} - -def "main stop" [--units: path, --target: string] { - ^systemctl --user stop --no-block ...(unit-names $units) - print $"stopping ($target); watch it with: bootvine --user --shutdown --target ($target)" -} - -def "main remove" [--units: path, --target: string] { - ^systemctl --user stop ...(unit-names $units) - unit-names $units | each {|name| rm -f (user-unit-dir | path join $name) } | ignore - ^systemctl --user daemon-reload -} - -def main [--units: path, --target: string] { - print "usage: bootvine-demo-units (start | stop | remove)" -} diff --git a/docs/passphrase.png b/docs/passphrase.png deleted file mode 100644 index cfa18da82ea824936b611c704cc0ded9ebcf2db2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9933 zcmeAS@N?(olHy`uVBq!ia0y~yU}a!nU{+vaW?*1o{HC74z`(#0;1lA?z`*eT|Nm8? z456W+W};6y85k58JY5_^D(1YM>)rSG*rvA65!=<-nJiY`b3T08+P5LjNwVPmac|8z z7hA&*vd%fmvOtsZUQb8OCsn&6DVs#&Z)<6KdL4|f`PX$Oz)OH@LFjh1JxsmpvsO5+ zl-_#h%@n;^>y6Im@t(W9^~aBEFI)~xV`1UFb;3pW>WLbu+tPE`MeO#OzWi1Gr6}eA zLte>N(SW_{8+5OvnO_MoxTrvam?lJj({+-vzuiP$tA=j-!OpWoS1V`HTxA~1q3)1}@HZW;@V7ljeKu%@B zwUdSdtV@_>xmLWC$XI^k=L?CB;)M<7+FxfksZWrKij@?-8+n7HO?{saw+qwTPttxzbrK;k} zxrmMP57)m~{Il(>FWWXBZSyd0vlp!9E!#SY(V?CqOGc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pA&ZXvB=JsXxrd##QZDqQ4XGx}yuC}}H z&lau#~D8#=nA}< z(Dz<(!MEK8+%K-pVhIUmI<%r;4>xmuqZf+^PqHM*k)HVoo)F;$-UF2tZP~M y_NDE%&3}E~PRQT1_+9#|b19c2T$&#IsGoP?ZC{0xR1*UO1B0ilpUXO@geCwN1!5)u diff --git a/flake.nix b/flake.nix index d7f66e7..40fa0ac 100644 --- a/flake.nix +++ b/flake.nix @@ -24,8 +24,7 @@ f: lib.genAttrs [ "x86_64-linux" "aarch64-linux" ] ( system: - f rec { - inherit system; + let pkgs = import nixpkgs { inherit system; overlays = [ (import rust-overlay) ]; @@ -33,120 +32,64 @@ craneLib = (crane.mkLib pkgs).overrideToolchain ( p: p.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml ); + in + f { + inherit system pkgs craneLib; + builds = import ./crane-builds.nix { inherit lib pkgs craneLib; }; } ); - buildInputsFor = pkgs: { - nativeBuildInputs = [ pkgs.pkg-config ]; - buildInputs = [ pkgs.dbus ]; + sampleMachine = import ./tests/sample-machine { + inherit lib; + bootvineModule = self.nixosModules.bootvine; }; - - demoUnits = import ./demo/units.nix; - - demoHost = { - imports = [ - self.nixosModules.default - ./demo/host.nix - ]; - _module.args = { inherit demoUnits; }; - }; - - demoSystem = - system: - lib.nixosSystem { - inherit system; - modules = [ - demoHost - ./demo/interactive.nix - ]; - }; in { packages = forEachSystem ( - { pkgs, craneLib, ... }: - let - commonArgs = { - inherit (buildInputsFor pkgs) nativeBuildInputs buildInputs; - src = lib.fileset.toSource { - root = ./.; - fileset = lib.fileset.unions [ - (craneLib.fileset.commonCargoSources ./.) - ./packaging - ]; - }; - strictDeps = true; - }; - in + { pkgs, builds, ... }: { - examples = craneLib.buildPackage ( - commonArgs - // { - pname = "bootvine-examples"; - cargoExtraArgs = "--examples"; - doCheck = false; - installPhaseCommand = '' - for example in boot shutdown; do - install -Dm755 target/release/examples/$example $out/bin/bootvine-$example-example - done - ''; - } - ); - default = craneLib.buildPackage ( - commonArgs - // { - postInstall = '' - for unit in bootvine.service bootvine-shutdown.service; do - install -Dm644 packaging/systemd/$unit $out/lib/systemd/system/$unit - substituteInPlace $out/lib/systemd/system/$unit \ - --replace-fail /usr/bin/bootvine $out/bin/bootvine - done - install -Dm755 packaging/dracut/90bootvine/module-setup.sh \ - $out/lib/dracut/modules.d/90bootvine/module-setup.sh - install -Dm644 packaging/mkinitcpio/install/sd-bootvine \ - $out/lib/initcpio/install/sd-bootvine - ''; - meta.mainProgram = "bootvine"; - meta.platforms = lib.platforms.linux; - meta.license = lib.getLicenseFromSpdxId (lib.importTOML ./Cargo.toml).package.license; - } - ); - demo-units = pkgs.callPackage ./demo/user-units.nix { inherit demoUnits; }; + default = builds.bootvine; + inherit (builds) bootvine scripted-boot-examples repo-tasks; + sample-unit-files = pkgs.callPackage ./tests/sample-machine/sample-unit-files.nix { + inherit (sampleMachine) sampleUnits; + }; } ); - nixosModules.default = import ./nixos-module.nix { inherit self; }; + nixosModules = { + default = self.nixosModules.bootvine; + bootvine = import ./nixos-module.nix { inherit self; }; + }; - nixosConfigurations.demo = demoSystem "x86_64-linux"; + nixosConfigurations.sample-machine = sampleMachine.nixosSystemFor "x86_64-linux"; apps = forEachSystem ( - { pkgs, system, ... }: { - vm = { + pkgs, + system, + builds, + ... + }: + { + sample-machine-vm = { type = "app"; - program = lib.getExe (demoSystem system).config.system.build.vm; + meta.description = "Boot a sample machine with bootvine and slow sample units in QEMU"; + program = lib.getExe (sampleMachine.nixosSystemFor system).config.system.build.vm; }; - demo-units = { - type = "app"; - program = lib.getExe self.packages.${system}.demo-units; - }; - docs = { + record-screencasts = { type = "app"; + meta.description = "Re-record the README screencasts and passphrase screenshot into recordings/"; program = lib.getExe ( pkgs.writeShellApplication { - name = "bootvine-docs"; + name = "record-screencasts"; runtimeInputs = [ pkgs.vhs - self.packages.${system}.examples + builds.scripted-boot-examples + builds.repo-tasks ]; - text = '' - if [ ! -d docs ]; then - echo "no docs directory here; run from the repository root" >&2 - exit 1 - fi - vhs ${./docs/boot.tape} - vhs ${./docs/shutdown.tape} - install -m644 -t docs ${self.checks.${system}.luks}/passphrase.png - ''; + text = "exec xtask record-screencasts --passphrase-png ${ + self.checks.${system}.vm-luks-passphrase + }/passphrase.png"; } ); }; @@ -154,22 +97,23 @@ ); checks = forEachSystem ( - { pkgs, system, ... }: + { pkgs, builds, ... }: { - package = self.packages.${system}.default; - boot = pkgs.testers.runNixOSTest (import ./tests/boot.nix { inherit demoHost; }); - luks = pkgs.testers.runNixOSTest ( - import ./tests/luks.nix { bootvineModule = self.nixosModules.default; } + bootvine-build = builds.bootvine; + repo-tasks-build = builds.repo-tasks; + vm-boot-and-shutdown = pkgs.testers.runNixOSTest ( + import ./tests/vm-checks/boot.nix { sampleMachine = sampleMachine.machine; } + ); + vm-luks-passphrase = pkgs.testers.runNixOSTest ( + import ./tests/vm-checks/luks.nix { bootvineModule = self.nixosModules.bootvine; } ); } ); devShells = forEachSystem ( - { pkgs, craneLib, ... }: + { craneLib, builds, ... }: { - default = craneLib.devShell { - packages = with buildInputsFor pkgs; nativeBuildInputs ++ buildInputs; - }; + default = craneLib.devShell { inputsFrom = [ builds.bootvine ]; }; } ); }; diff --git a/docs/boot.tape b/recordings/boot.tape similarity index 91% rename from docs/boot.tape rename to recordings/boot.tape index 579e5d7..a50b3ff 100644 --- a/docs/boot.tape +++ b/recordings/boot.tape @@ -1,4 +1,4 @@ -Output docs/boot.gif +Output recordings/boot.gif Require bootvine-boot-example diff --git a/recordings/passphrase.png b/recordings/passphrase.png new file mode 100644 index 0000000000000000000000000000000000000000..4824e57781e46d8df3b7b4a5cae31c5d9ff287a7 GIT binary patch literal 9916 zcmeAS@N?(olHy`uVBq!ia0y~yU}a!nU{+vaW?*1o{HC74z`(#0;1lA?z`*eT|Nm8? z456W+W};6y85k58JY5_^D(1YM>)rQy$EK~N{r~S;8Z7X8XPFc7y^M23+XVI%w)3UD z9&M|;qG8ftEy47T>q4r_1f`YJzi!ab+Pg3I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eC6E#A|`F~m{Vx1-8SXFl zci#R=4DXTtZqy9RD+wFF0-HsPskLG(gbne*jGr5*g zKFp!G{=QAbIq@~O931w!E*3Cde$FW;6B~pQB>T=hTQpgfnQ^Odz*$a@ z!{0g^^mkl4;dbEnjE1{W+E4K;U?8Fyak;P}zB@Z+7@hDhORb6yf5dm$_;>YUug!To#SU>KNTxmV*~IBH zX@A47&Ia{x_j6k(b-16qdbu!exs?&aFa!!l&7v;GFWq8gJ@2&RA={AK9Sym`BDxVi>I?MVh*f<1 zUTLfFz;8{11zXCvLCL?uWrlt9Iq~)V)#B zi+vWh{{NAp)Bjdn)4y!Cdiu=|nh!5U%?=IDY0-^st22xEYZ>iln|0Wz>Z?(-ooYl> zu3*96iQ)N{QLA}Rzqooj=jW7!%;GP}jQnb}Ky{-ew@GuP>gSa*6) zUpedR^R;D%jjpyCf6x8;Jm;qf0|Uc>;Q6u+ZdankK0SXp+lEd3S@Z`9qnw{|IlI(8 z&P%YYm~K?DhVAYBe&2r?w{2&O8|-;z=j>3-S@&cAw@L};TeG(5o$|>zTUvU!T=dE3 z%&!l`vabKx^(dS_uX3Xmw}(=~UPXgXUtiAiTYc$IuJkEArTORYJTKzjK3lxs?b)gw zsjjtm(=ismI~BQdT``4C*#)@ z4V$>LZ!&Rna4=2}D4T9rRlp-7JYm`8cbP09f0GsBk6AEYoy}44T5pLa_l17>h>H=c zSb4P;hFGjiIO-I-?5$X@`HARwUv%sshm dV+TXQANdKHyw?x<)Qf|H(9_k=Wt~$(697D6dG!DQ literal 0 HcmV?d00001 diff --git a/docs/shutdown.tape b/recordings/shutdown.tape similarity index 90% rename from docs/shutdown.tape rename to recordings/shutdown.tape index dec1fe5..3b92cf3 100644 --- a/docs/shutdown.tape +++ b/recordings/shutdown.tape @@ -1,4 +1,4 @@ -Output docs/shutdown.gif +Output recordings/shutdown.gif Require bootvine-shutdown-example diff --git a/packaging/dracut/.shellcheckrc b/system-files/dracut/.shellcheckrc similarity index 100% rename from packaging/dracut/.shellcheckrc rename to system-files/dracut/.shellcheckrc diff --git a/packaging/dracut/90bootvine/module-setup.sh b/system-files/dracut/90bootvine/module-setup.sh similarity index 100% rename from packaging/dracut/90bootvine/module-setup.sh rename to system-files/dracut/90bootvine/module-setup.sh diff --git a/packaging/mkinitcpio/install/sd-bootvine b/system-files/mkinitcpio/install/sd-bootvine similarity index 100% rename from packaging/mkinitcpio/install/sd-bootvine rename to system-files/mkinitcpio/install/sd-bootvine diff --git a/packaging/systemd/bootvine-shutdown.service b/system-files/systemd/bootvine-shutdown.service similarity index 100% rename from packaging/systemd/bootvine-shutdown.service rename to system-files/systemd/bootvine-shutdown.service diff --git a/packaging/systemd/bootvine.service b/system-files/systemd/bootvine.service similarity index 100% rename from packaging/systemd/bootvine.service rename to system-files/systemd/bootvine.service diff --git a/tests/sample-machine/default.nix b/tests/sample-machine/default.nix new file mode 100644 index 0000000..67c8dbb --- /dev/null +++ b/tests/sample-machine/default.nix @@ -0,0 +1,25 @@ +{ lib, bootvineModule }: +let + sampleUnits = import ./sample-units.nix; + + machine = { + imports = [ + bootvineModule + ./machine.nix + ]; + _module.args = { inherit sampleUnits; }; + }; +in +{ + inherit sampleUnits machine; + + nixosSystemFor = + system: + lib.nixosSystem { + inherit system; + modules = [ + machine + ./interactive-vm.nix + ]; + }; +} diff --git a/demo/interactive.nix b/tests/sample-machine/interactive-vm.nix similarity index 68% rename from demo/interactive.nix rename to tests/sample-machine/interactive-vm.nix index f0591f1..e876556 100644 --- a/demo/interactive.nix +++ b/tests/sample-machine/interactive-vm.nix @@ -1,7 +1,8 @@ { boot.loader.grub.enable = false; - services.getty.autologinUser = "root"; fileSystems."/" = { + services.getty.autologinUser = "root"; + fileSystems."/" = { device = "/dev/disk/by-label/nixos"; fsType = "ext4"; }; @@ -10,6 +11,7 @@ memorySize = 2048; cores = 2; graphics = true; + diskImage = "\${XDG_CACHE_HOME:-$HOME/.cache}/bootvine-sample-machine.qcow2"; qemu.options = [ "-vga none" "-device virtio-vga,xres=1920,yres=1080" diff --git a/demo/host.nix b/tests/sample-machine/machine.nix similarity index 91% rename from demo/host.nix rename to tests/sample-machine/machine.nix index 295dbd2..edf7b2b 100644 --- a/demo/host.nix +++ b/tests/sample-machine/machine.nix @@ -1,11 +1,11 @@ { - demoUnits, + sampleUnits, lib, pkgs, ... }: let - demoService = spec: { + sampleService = spec: { inherit (spec) description; after = map (dependency: "${dependency}.service") (spec.after or [ ]); wantedBy = [ "multi-user.target" ]; @@ -37,7 +37,7 @@ in unitConfig.DefaultDependencies = false; serviceConfig = { Type = "oneshot"; - ExecStart = "/bin/sleep ${demoUnits.initrdProbeSeconds}"; + ExecStart = "/bin/sleep ${sampleUnits.initrdProbeSeconds}"; }; }; }; @@ -76,7 +76,7 @@ in font = "${pkgs.terminus_font}/share/consolefonts/ter-v20n.psf.gz"; }; - systemd.services = lib.mapAttrs (_: demoService) demoUnits.services // { + systemd.services = lib.mapAttrs (_: sampleService) sampleUnits.services // { greetd.after = [ "multi-user.target" ]; }; diff --git a/demo/user-units.nix b/tests/sample-machine/sample-unit-files.nix similarity index 65% rename from demo/user-units.nix rename to tests/sample-machine/sample-unit-files.nix index a71b422..9e4a860 100644 --- a/demo/user-units.nix +++ b/tests/sample-machine/sample-unit-files.nix @@ -1,10 +1,8 @@ { - demoUnits, + sampleUnits, lib, coreutils, - linkFarm, - nushell, - writeShellApplication, + runCommand, writeText, }: let @@ -30,30 +28,27 @@ let }; }); - serviceNames = map (name: "${name}.service") (lib.attrNames demoUnits.services); + serviceNames = map (name: "${name}.service") (lib.attrNames sampleUnits.services); - targetFile = writeText "${demoUnits.target}.target" (toUnitFile { + targetFile = writeText "${sampleUnits.target}.target" (toUnitFile { Unit = { Description = "bootvine demo services"; Wants = serviceNames; After = serviceNames; }; }); - - units = linkFarm "bootvine-demo-units" ( + unitFiles = lib.mapAttrsToList (name: spec: { name = "${name}.service"; path = serviceFile name spec; - }) demoUnits.services + }) sampleUnits.services ++ [ { - name = "${demoUnits.target}.target"; + name = "${sampleUnits.target}.target"; path = targetFile; } - ] - ); + ]; in -writeShellApplication { - name = "bootvine-demo-units"; - text = ''exec ${lib.getExe nushell} ${./demo-units.nu} "$@" --units ${units} --target ${demoUnits.target}.target''; -} +runCommand "bootvine-sample-unit-files" { } ( + lib.concatMapStringsSep "\n" (unit: "install -Dm644 ${unit.path} $out/${unit.name}") unitFiles +) diff --git a/demo/units.nix b/tests/sample-machine/sample-units.nix similarity index 100% rename from demo/units.nix rename to tests/sample-machine/sample-units.nix diff --git a/tests/boot.nix b/tests/vm-checks/boot.nix similarity index 89% rename from tests/boot.nix rename to tests/vm-checks/boot.nix index 56635eb..ee19522 100644 --- a/tests/boot.nix +++ b/tests/vm-checks/boot.nix @@ -1,6 +1,6 @@ -{ demoHost }: +{ sampleMachine }: { - name = "bootvine"; + name = "bootvine-boot-and-shutdown"; nodes.machine = { lib, ... }: @@ -8,7 +8,7 @@ waitFor = flag: "/bin/sh -c 'until [ -e /run/${flag} ]; do sleep 0.1; done'"; in { - imports = [ demoHost ]; + imports = [ sampleMachine ]; testing.initrdBackdoor = true; boot.initrd.systemd.services.demo-initrd-probe.serviceConfig.ExecStart = lib.mkForce ( waitFor "release-initrd-probe" diff --git a/tests/boot.py b/tests/vm-checks/boot.py similarity index 100% rename from tests/boot.py rename to tests/vm-checks/boot.py diff --git a/tests/console.py b/tests/vm-checks/console.py similarity index 100% rename from tests/console.py rename to tests/vm-checks/console.py diff --git a/tests/luks.nix b/tests/vm-checks/luks.nix similarity index 97% rename from tests/luks.nix rename to tests/vm-checks/luks.nix index 2df1291..1b29e82 100644 --- a/tests/luks.nix +++ b/tests/vm-checks/luks.nix @@ -3,7 +3,7 @@ let passphrase = "quietly unlocked"; in { - name = "bootvine-luks"; + name = "bootvine-luks-passphrase"; nodes.machine = { lib, pkgs, ... }: let diff --git a/tests/luks.py b/tests/vm-checks/luks.py similarity index 100% rename from tests/luks.py rename to tests/vm-checks/luks.py diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml new file mode 100644 index 0000000..74ee7cc --- /dev/null +++ b/xtask/Cargo.toml @@ -0,0 +1,15 @@ +[package] +edition = "2024" +name = "xtask" +version = "0.1.0" +license = "GPL-3.0-or-later" +publish = false + +[dependencies] +clap = { version = "4.6.7", features = ["derive"] } +rustix = { version = "1.1.5", features = ["process"] } +thiserror = "2.0.12" +xshell = "0.2.7" + +[lints] +workspace = true diff --git a/xtask/src/install_files.rs b/xtask/src/install_files.rs new file mode 100644 index 0000000..9774025 --- /dev/null +++ b/xtask/src/install_files.rs @@ -0,0 +1,280 @@ +use std::{ + env, + ffi::OsString, + fs::{self, Permissions}, + io::ErrorKind, + iter::once, + os::unix::fs::PermissionsExt, + path::{Path, PathBuf}, +}; + +use clap::{Args, ValueEnum}; +use rustix::process::geteuid; +use xshell::{Shell, cmd}; + +use crate::task_error::TaskError; + +const UNIT_NAMES: [&str; 2] = ["bootvine.service", "bootvine-shutdown.service"]; +const DRACUT_MODULE_DIR: &str = "/usr/lib/dracut/modules.d/90bootvine"; +const DRACUT_CONF: &str = "/etc/dracut.conf.d/bootvine.conf"; +const MKINITCPIO_HOOK: &str = "/usr/lib/initcpio/install/sd-bootvine"; +const PACKAGED_BINARY_PATH: &str = "/usr/bin/bootvine"; + +#[derive(Args)] +pub struct InstallTarget { + #[arg( + long, + default_value = "/usr", + help = "Prefix for bin/bootvine and lib/systemd/system" + )] + prefix: PathBuf, + #[arg( + long, + help = "Stage the files under this directory instead of /; skips sudo and systemctl" + )] + destdir: Option, +} + +#[derive(Args)] +pub struct InstallOptions { + #[command(flatten)] + target: InstallTarget, + #[arg(long, value_enum, default_value_t = InitrdGenerator::None)] + initrd: InitrdGenerator, + #[arg(long, help = "Leave the units disabled")] + no_enable: bool, + #[arg(long, hide = true)] + built_binary: Option, +} + +#[derive(Args)] +pub struct UninstallOptions { + #[command(flatten)] + target: InstallTarget, +} + +#[derive(Clone, Copy, PartialEq, Eq, ValueEnum)] +pub enum InitrdGenerator { + None, + Dracut, + Mkinitcpio, +} + +struct InstalledFile { + destination: PathBuf, + contents: Vec, + mode: u32, +} + +impl InstallTarget { + fn staged(&self, path: &Path) -> PathBuf { + match &self.destdir { + Some(root) => root.join(path.strip_prefix("/").unwrap_or(path)), + None => path.to_owned(), + } + } + + fn changes_live_system(&self) -> bool { + self.destdir.is_none() + } + + fn needs_sudo(&self) -> bool { + self.changes_live_system() && !geteuid().is_root() + } + + fn binary_path(&self) -> PathBuf { + self.prefix.join("bin/bootvine") + } + + fn unit_path(&self, unit: &str) -> PathBuf { + self.prefix.join("lib/systemd/system").join(unit) + } + + fn every_installed_path(&self) -> Vec { + once(self.binary_path()) + .chain(UNIT_NAMES.iter().map(|unit| self.unit_path(unit))) + .chain([ + Path::new(DRACUT_MODULE_DIR).join("module-setup.sh"), + PathBuf::from(DRACUT_CONF), + PathBuf::from(MKINITCPIO_HOOK), + ]) + .collect() + } +} + +fn workspace_root() -> &'static Path { + let xtask_dir = Path::new(env!("CARGO_MANIFEST_DIR")); + xtask_dir.parent().unwrap_or(xtask_dir) +} + +fn release_binary() -> PathBuf { + env::var_os("CARGO_TARGET_DIR") + .map_or_else(|| workspace_root().join("target"), PathBuf::from) + .join("release/bootvine") +} + +fn read_file(path: &Path) -> Result, TaskError> { + fs::read(path).map_err(|source| TaskError::File { + path: path.to_owned(), + source, + }) +} + +fn read_system_file(relative: &str) -> Result, TaskError> { + read_file(&workspace_root().join("system-files").join(relative)) +} + +fn unit_files(target: &InstallTarget) -> Result, TaskError> { + UNIT_NAMES + .iter() + .map(|unit| { + let packaged = read_system_file(&format!("systemd/{unit}"))?; + let rewritten = String::from_utf8_lossy(&packaged).replace( + PACKAGED_BINARY_PATH, + &target.binary_path().to_string_lossy(), + ); + Ok(InstalledFile { + destination: target.unit_path(unit), + contents: rewritten.into_bytes(), + mode: 0o644, + }) + }) + .collect() +} + +fn initrd_hook_files(initrd: InitrdGenerator) -> Result, TaskError> { + Ok(match initrd { + InitrdGenerator::None => Vec::new(), + InitrdGenerator::Dracut => vec![ + InstalledFile { + destination: Path::new(DRACUT_MODULE_DIR).join("module-setup.sh"), + contents: read_system_file("dracut/90bootvine/module-setup.sh")?, + mode: 0o755, + }, + InstalledFile { + destination: PathBuf::from(DRACUT_CONF), + contents: b"add_dracutmodules+=\" bootvine \"\n".to_vec(), + mode: 0o644, + }, + ], + InitrdGenerator::Mkinitcpio => vec![InstalledFile { + destination: PathBuf::from(MKINITCPIO_HOOK), + contents: read_system_file("mkinitcpio/install/sd-bootvine")?, + mode: 0o644, + }], + }) +} + +fn write_installed_file(target: &InstallTarget, file: &InstalledFile) -> Result<(), TaskError> { + let path = target.staged(&file.destination); + path.parent() + .map_or(Ok(()), fs::create_dir_all) + .and_then(|()| fs::write(&path, &file.contents)) + .and_then(|()| fs::set_permissions(&path, Permissions::from_mode(file.mode))) + .map_err(|source| TaskError::File { path, source }) +} + +fn remove_if_present(path: PathBuf) -> Result<(), TaskError> { + match fs::remove_file(&path) { + Err(error) if error.kind() != ErrorKind::NotFound => Err(TaskError::File { + path, + source: error, + }), + _ => Ok(()), + } +} + +fn rerun_with_sudo(shell: &Shell, extra_arguments: &[OsString]) -> Result<(), TaskError> { + let this_task = env::current_exe().map_err(|source| TaskError::File { + path: PathBuf::from("/proc/self/exe"), + source, + })?; + let task_arguments = env::args_os().skip(1); + cmd!( + shell, + "sudo {this_task} {task_arguments...} {extra_arguments...}" + ) + .run()?; + Ok(()) +} + +fn print_initramfs_hint(initrd: InitrdGenerator) { + match initrd { + InitrdGenerator::None => {} + InitrdGenerator::Dracut => println!("rebuild the initramfs: sudo dracut --force"), + InitrdGenerator::Mkinitcpio => println!( + "add sd-bootvine after systemd in HOOKS in /etc/mkinitcpio.conf, then run: sudo \ + mkinitcpio -P" + ), + } +} + +fn build_release_binary(shell: &Shell) -> Result { + let cargo = env::var_os("CARGO").unwrap_or_else(|| "cargo".into()); + let _in_workspace = shell.push_dir(workspace_root()); + cmd!(shell, "{cargo} build --release --package bootvine").run()?; + Ok(release_binary()) +} + +pub fn install_files(options: &InstallOptions) -> Result<(), TaskError> { + let shell = Shell::new()?; + let target = &options.target; + let binary = match &options.built_binary { + Some(built) => built.clone(), + None => build_release_binary(&shell)?, + }; + if target.needs_sudo() { + return rerun_with_sudo(&shell, &["--built-binary".into(), binary.into_os_string()]); + } + let binary_file = InstalledFile { + destination: target.binary_path(), + contents: read_file(&binary)?, + mode: 0o755, + }; + once(binary_file) + .chain(unit_files(target)?) + .chain(initrd_hook_files(options.initrd)?) + .try_for_each(|file| write_installed_file(target, &file))?; + if target.changes_live_system() { + cmd!(shell, "systemctl daemon-reload").run()?; + if !options.no_enable { + cmd!(shell, "systemctl enable {UNIT_NAMES...}").run()?; + } + print_initramfs_hint(options.initrd); + } + Ok(()) +} + +pub fn uninstall_files(options: &UninstallOptions) -> Result<(), TaskError> { + let shell = Shell::new()?; + let target = &options.target; + if target.needs_sudo() { + return rerun_with_sudo(&shell, &[]); + } + if target.changes_live_system() { + let enabled_units: Vec<&str> = UNIT_NAMES + .into_iter() + .filter(|unit| target.unit_path(unit).exists()) + .collect(); + if !enabled_units.is_empty() { + cmd!(shell, "systemctl disable {enabled_units...}").run()?; + } + } + target + .every_installed_path() + .iter() + .try_for_each(|path| remove_if_present(target.staged(path)))?; + match fs::remove_dir(target.staged(Path::new(DRACUT_MODULE_DIR))) { + Err(error) if error.kind() == ErrorKind::DirectoryNotEmpty => { + return Err(TaskError::File { + path: target.staged(Path::new(DRACUT_MODULE_DIR)), + source: error, + }); + } + _ => {} + } + if target.changes_live_system() { + cmd!(shell, "systemctl daemon-reload").run()?; + } + Ok(()) +} diff --git a/xtask/src/main.rs b/xtask/src/main.rs new file mode 100644 index 0000000..730b6ad --- /dev/null +++ b/xtask/src/main.rs @@ -0,0 +1,49 @@ +mod install_files; +mod record_screencasts; +mod task_error; + +use std::{path::PathBuf, process::ExitCode}; + +use clap::{Parser, Subcommand}; + +use crate::install_files::{InstallOptions, UninstallOptions, install_files, uninstall_files}; + +#[derive(Parser)] +#[command(about = "Repository tasks for bootvine")] +struct RepoTasks { + #[command(subcommand)] + task: Task, +} + +#[derive(Subcommand)] +enum Task { + #[command( + about = "Record the README screencasts with vhs and copy the passphrase screenshot into \ + recordings/" + )] + RecordScreencasts { + #[arg(long, help = "passphrase.png produced by the vm-luks-passphrase check")] + passphrase_png: PathBuf, + }, + #[command(about = "Build bootvine and install the binary, units and initrd hook")] + Install(InstallOptions), + #[command(about = "Remove what install put in place")] + Uninstall(UninstallOptions), +} + +fn main() -> ExitCode { + let outcome = match RepoTasks::parse().task { + Task::RecordScreencasts { passphrase_png } => { + record_screencasts::record_screencasts(&passphrase_png) + } + Task::Install(options) => install_files(&options), + Task::Uninstall(options) => uninstall_files(&options), + }; + match outcome { + Ok(()) => ExitCode::SUCCESS, + Err(error) => { + eprintln!("xtask: {error}"); + ExitCode::FAILURE + } + } +} diff --git a/xtask/src/record_screencasts.rs b/xtask/src/record_screencasts.rs new file mode 100644 index 0000000..3c77800 --- /dev/null +++ b/xtask/src/record_screencasts.rs @@ -0,0 +1,30 @@ +use std::{ + fs::{self, Permissions}, + os::unix::fs::PermissionsExt, + path::Path, +}; + +use xshell::{Shell, cmd}; + +use crate::task_error::TaskError; + +const TAPES: [&str; 2] = ["boot.tape", "shutdown.tape"]; + +pub fn record_screencasts(passphrase_png: &Path) -> Result<(), TaskError> { + let recordings = Path::new("recordings"); + if !recordings.is_dir() { + return Err(TaskError::NotInRepositoryRoot); + } + let shell = Shell::new()?; + TAPES.iter().try_for_each(|tape| { + let tape_path = recordings.join(tape); + cmd!(shell, "vhs {tape_path}").run() + })?; + let copied_png = recordings.join("passphrase.png"); + fs::copy(passphrase_png, &copied_png) + .and_then(|_| fs::set_permissions(&copied_png, Permissions::from_mode(0o644))) + .map_err(|source| TaskError::File { + path: copied_png, + source, + }) +} diff --git a/xtask/src/task_error.rs b/xtask/src/task_error.rs new file mode 100644 index 0000000..72b3379 --- /dev/null +++ b/xtask/src/task_error.rs @@ -0,0 +1,13 @@ +use std::{io, path::PathBuf}; + +use thiserror::Error; + +#[derive(Debug, Error)] +pub enum TaskError { + #[error(transparent)] + Shell(#[from] xshell::Error), + #[error("{}: {source}", path.display())] + File { path: PathBuf, source: io::Error }, + #[error("no recordings directory here; run from the repository root")] + NotInRepositoryRoot, +}