From dad6f2480dcc3bc3692562320eb3232e391054b4 Mon Sep 17 00:00:00 2001 From: cameron Date: Fri, 19 Dec 2025 21:39:04 +0000 Subject: [PATCH] initial test setup --- flake.nix | 8 +++++- nix/shell.nix | 4 +++ nix/test/common.nix | 54 ++++++++++++++++++++++++++++++++++++ nix/test/simple.nix | 41 +++++++++++++++++++++++++++ script/bootstrap | 67 +++++++++++++++++++++++---------------------- 5 files changed, 141 insertions(+), 33 deletions(-) create mode 100644 nix/test/common.nix create mode 100644 nix/test/simple.nix diff --git a/flake.nix b/flake.nix index 744ca708a3a2104f0050cd85e8ee05f04e49a713..1fb2333227413c51c2c0874b4c894ca53a6fca95 100644 --- a/flake.nix +++ b/flake.nix @@ -17,7 +17,7 @@ rust-overlay, crane, ... - }: + } @ inputs: let systems = [ "x86_64-linux" @@ -51,6 +51,12 @@ overlays.default = final: _: { zed-editor = mkZed final; }; + checks = forAllSystems (pkgs: { + simple = (import ./nix/test/simple.nix) { + inherit pkgs; + zed = mkZed pkgs; + }; + }); }; nixConfig = { diff --git a/nix/shell.nix b/nix/shell.nix index 6956de8e8abb55e404f62ed9e377ff79aface5bd..0b792929f29e0013377b9e56060b4e1c29e4487f 100644 --- a/nix/shell.nix +++ b/nix/shell.nix @@ -15,6 +15,8 @@ protobuf, nodejs_22, zig, + + livekit, }: (mkShell.override { inherit (zed-editor) stdenv; }) { inputsFrom = [ zed-editor ]; @@ -33,6 +35,8 @@ # we'll just put it on `$PATH`: nodejs_22 zig + + livekit ]; env = diff --git a/nix/test/common.nix b/nix/test/common.nix new file mode 100644 index 0000000000000000000000000000000000000000..81eb84bca32fa4eb9d9fdad18fc5a5d9afddbd12 --- /dev/null +++ b/nix/test/common.nix @@ -0,0 +1,54 @@ +{ + config, + lib, + ... +}: let + cfg = config.test-support; +in { + options.test-support = with lib; { + user = mkOption { + default = "alice"; + type = types.str; + }; + desktop-environment = mkOption { + default = "icewm"; + type = types.enum ["icewm"]; + }; + }; + + config = let + de = cfg.desktop-environment; + displayManager = + if de == "icewm" + then "lightdm" + else throw "unreachable"; + windowManager = + if de == "icewm" + then "icewm" + else throw "unreachable"; + in { + virtualisation.memorySize = lib.mkDefault 2000; # 2gb + services.displayManager.autoLogin.enable = true; + services.displayManager.autoLogin.user = "alice"; + services.displayManager.defaultSession = + if de == "icewm" + then "none+icewm" + else null; + + services.xserver.enable = true; + services.xserver.windowManager.${windowManager}.enable = true; + services.xserver.displayManager.${displayManager}.enable = true; + + environment.sessionVariables = { + "ZED_ALLOW_EMULATED_GPU" = 1; + }; + + users.users.${cfg.user} = { + createHome = true; + home = "/home/${cfg.user}"; + group = "users"; + isNormalUser = true; + password = "password"; + }; + }; +} diff --git a/nix/test/simple.nix b/nix/test/simple.nix new file mode 100644 index 0000000000000000000000000000000000000000..061676e926864cda8799afcd47f0eefa0d02d540 --- /dev/null +++ b/nix/test/simple.nix @@ -0,0 +1,41 @@ +{ + pkgs, + zed, + ... +}: let + user = "alice"; + run = command: "sudo -u ${user} ${command}"; +in + pkgs.testers.runNixOSTest { + name = "simple file reading"; + + # sshBackdoor.enable = true; + # enableDebugHook = true; + enableOCR = true; + + nodes.machine = {config, ...}: { + imports = [./common.nix]; + + test-support.user = user; + test-support.desktop-environment = "icewm"; + + environment.systemPackages = [zed]; + }; + + testScript = + /* + python + */ + '' + machine.wait_for_x() + + machine.succeed("${run "zeditor /home/${user}/foo.md"}") + machine.wait_for_text("foo.md") + + machine.send_chars("hello world\n"); + machine.wait_for_text("hello world"); + + machine.send_key("ctrl-s"); + machine.wait_for_file("/home/${user}/foo.md"); + ''; + } diff --git a/script/bootstrap b/script/bootstrap index 68888e04c1e70bfcb831cf873b7017765ac2dd82..1f1d7ec5ef218515d1f27c269dd21db477d187f3 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -8,40 +8,43 @@ then maysudo='' else maysudo="$(command -v sudo || command -v doas || true)" fi -if [[ "$OSTYPE" == "linux-gnu"* ]]; then - echo "Linux dependencies..." - script/linux -else - echo "installing foreman..." - which foreman > /dev/null || brew install foreman +if [[ ! -v OFFLINE ]]; then + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "Linux dependencies..." + script/linux + else + echo "installing foreman..." + which foreman > /dev/null || brew install foreman + fi + + # Install minio if needed + if ! which minio > /dev/null; then + if command -v brew > /dev/null; then + echo "minio not found. Installing via brew" + brew install minio/stable/minio + elif command -v apt > /dev/null; then + echo "minio not found. Installing via apt from https://dl.min.io/server/minio/release/linux-amd64/minio.deb" + wget -q https://dl.min.io/server/minio/release/linux-amd64/minio.deb -O /tmp/minio.deb + $maysudo apt install /tmp/minio.deb + rm -f /tmp/minio.deb + elif command -v dnf > /dev/null; then + echo "minio not found. Installing via dnf from https://dl.min.io/server/minio/release/linux-amd64/minio.rpm" + wget -q https://dl.min.io/server/minio/release/linux-amd64/minio.rpm -O /tmp/minio.rpm + $maysudo dnf install /tmp/minio.rpm + rm -f /tmp/minio.rpm + else + echo "No supported package manager found (brew, apt, or dnf)" + exit 1 + fi + fi + + # Install sqlx-cli if needed + if ! [[ "$(command -v sqlx)" && "$(sqlx --version)" == "sqlx-cli 0.7.2" ]]; then + echo "sqlx-cli not found or not the required version, installing version 0.7.2..." + cargo install sqlx-cli --version 0.7.2 + fi fi -# Install minio if needed -if ! which minio > /dev/null; then - if command -v brew > /dev/null; then - echo "minio not found. Installing via brew" - brew install minio/stable/minio - elif command -v apt > /dev/null; then - echo "minio not found. Installing via apt from https://dl.min.io/server/minio/release/linux-amd64/minio.deb" - wget -q https://dl.min.io/server/minio/release/linux-amd64/minio.deb -O /tmp/minio.deb - $maysudo apt install /tmp/minio.deb - rm -f /tmp/minio.deb - elif command -v dnf > /dev/null; then - echo "minio not found. Installing via dnf from https://dl.min.io/server/minio/release/linux-amd64/minio.rpm" - wget -q https://dl.min.io/server/minio/release/linux-amd64/minio.rpm -O /tmp/minio.rpm - $maysudo dnf install /tmp/minio.rpm - rm -f /tmp/minio.rpm - else - echo "No supported package manager found (brew, apt, or dnf)" - exit 1 - fi -fi - -# Install sqlx-cli if needed -if ! [[ "$(command -v sqlx)" && "$(sqlx --version)" == "sqlx-cli 0.7.2" ]]; then - echo "sqlx-cli not found or not the required version, installing version 0.7.2..." - cargo install sqlx-cli --version 0.7.2 -fi cd crates/collab