From 0b456d14a47b5807d5a69e09e0f96a971f9e8af4 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sat, 4 Jan 2025 22:26:07 -0600 Subject: [PATCH 01/14] nix: vms for testing ghostty --- .gitignore | 1 + flake.nix | 97 ++++++++++++++++++++++++++--------- nix/vm/common.nix | 33 ++++++++++++ nix/vm/wayland-gnome.nix | 107 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+), 25 deletions(-) create mode 100644 nix/vm/common.nix create mode 100644 nix/vm/wayland-gnome.nix diff --git a/.gitignore b/.gitignore index 0e301f8c4..db8457e1f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ test/cases/**/*.actual.png glad.zip /Box_test.ppm /Box_test_diff.ppm +/ghostty.qcow2 diff --git a/flake.nix b/flake.nix index 83d4af414..0b8a2f424 100644 --- a/flake.nix +++ b/flake.nix @@ -31,37 +31,84 @@ zig, ... }: - builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} (builtins.map (system: let - pkgs-stable = nixpkgs-stable.legacyPackages.${system}; - pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; - in { - devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix { - zig = zig.packages.${system}."0.13.0"; - wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {}; - }; + builtins.foldl' nixpkgs-stable.lib.recursiveUpdate {} ( + builtins.map ( + system: let + pkgs-stable = nixpkgs-stable.legacyPackages.${system}; + pkgs-unstable = nixpkgs-unstable.legacyPackages.${system}; + in { + devShell.${system} = pkgs-stable.callPackage ./nix/devShell.nix { + zig = zig.packages.${system}."0.13.0"; + wraptest = pkgs-stable.callPackage ./nix/wraptest.nix {}; + }; - packages.${system} = let - mkArgs = optimize: { - inherit optimize; + packages.${system} = let + mkArgs = optimize: { + inherit optimize; - revision = self.shortRev or self.dirtyShortRev or "dirty"; - }; - in rec { - ghostty-debug = pkgs-stable.callPackage ./nix/package.nix (mkArgs "Debug"); - ghostty-releasesafe = pkgs-stable.callPackage ./nix/package.nix (mkArgs "ReleaseSafe"); - ghostty-releasefast = pkgs-stable.callPackage ./nix/package.nix (mkArgs "ReleaseFast"); + revision = self.shortRev or self.dirtyShortRev or "dirty"; + }; + in rec { + ghostty-debug = pkgs-stable.callPackage ./nix/package.nix (mkArgs "Debug"); + ghostty-releasesafe = pkgs-stable.callPackage ./nix/package.nix (mkArgs "ReleaseSafe"); + ghostty-releasefast = pkgs-stable.callPackage ./nix/package.nix (mkArgs "ReleaseFast"); - ghostty = ghostty-releasefast; - default = ghostty; - }; + ghostty = ghostty-releasefast; + default = ghostty; + }; - formatter.${system} = pkgs-stable.alejandra; + formatter.${system} = pkgs-stable.alejandra; - # Our supported systems are the same supported systems as the Zig binaries. - }) (builtins.attrNames zig.packages)) + nixosConfigurations = let + makeVM = ( + path: + nixpkgs-stable.lib.nixosSystem { + inherit system; + modules = [ + { + nixpkgs.overlays = [ + self.overlays.debug + ]; + } + ./nix/vm/common.nix + path + ]; + } + ); + in { + "wayland-gnome-${system}" = makeVM ./nix/vm/wayland-gnome.nix; + }; + + apps.${system} = let + wrapVM = ( + name: let + program = pkgs-stable.writeShellScript "run-ghostty-vm" '' + SHARED_DIR=$(pwd) + export SHARED_DIR + + ${self.nixosConfigurations."${name}-${system}".config.system.build.vm}/bin/run-ghostty-vm + ''; + in { + type = "app"; + program = "${program}"; + } + ); + in { + wayland-gnome = wrapVM "wayland-gnome"; + }; + } + # Our supported systems are the same supported systems as the Zig binaries. + ) (builtins.attrNames zig.packages) + ) // { - overlays.default = final: prev: { - ghostty = self.packages.${prev.system}.default; + overlays = { + default = self.overlays.releasefast; + releasefast = final: prev: { + ghostty = self.packages.${prev.system}.ghostty-releasefast; + }; + debug = final: prev: { + ghostty = self.packages.${prev.system}.ghostty-debug; + }; }; }; diff --git a/nix/vm/common.nix b/nix/vm/common.nix new file mode 100644 index 000000000..08ee19e5b --- /dev/null +++ b/nix/vm/common.nix @@ -0,0 +1,33 @@ +{pkgs, ...}: { + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + networking.hostName = "ghostty"; + networking.domain = "mitchellh.com"; + + virtualisation.vmVariant = { + virtualisation.memorySize = 2048; + }; + + users.mutableUsers = true; + + users.groups.ghostty = { + gid = 1000; + }; + + users.users.ghostty = { + description = "Ghostty"; + uid = 1000; + group = "ghostty"; + extraGroups = ["wheel"]; + isNormalUser = true; + initialPassword = "ghostty"; + }; + + environment.systemPackages = [ + pkgs.kitty + pkgs.ghostty + ]; + + system.stateVersion = "24.11"; +} diff --git a/nix/vm/wayland-gnome.nix b/nix/vm/wayland-gnome.nix new file mode 100644 index 000000000..99e38808f --- /dev/null +++ b/nix/vm/wayland-gnome.nix @@ -0,0 +1,107 @@ +{ + config, + lib, + pkgs, + ... +}: { + services.displayManager = { + autoLogin = { + user = "ghostty"; + }; + }; + + services.xserver = { + enable = true; + displayManager = { + gdm = { + enable = true; + autoSuspend = false; + }; + }; + desktopManager = { + gnome = { + enable = true; + }; + }; + }; + + environment.etc = { + "xdg/autostart/com.mitchellh.ghostty.desktop" = { + source = "${pkgs.ghostty}/share/applications/com.mitchellh.ghostty.desktop"; + }; + }; + + environment.systemPackages = [ + pkgs.gnomeExtensions.no-overview + ]; + + environment.gnome.excludePackages = with pkgs; [ + atomix + cheese + epiphany + geary + gnome-music + gnome-photos + gnome-tour + hitori + iagno + tali + ]; + + system.activationScripts = { + face = { + text = '' + mkdir -p /var/lib/AccountsService/{icons,users} + + cp ${pkgs.ghostty}/share/icons/hicolor/1024x1024/apps/com.mitchellh.ghostty.png /var/lib/AccountsService/icons/ghostty + + echo -e "[User]\nIcon=/var/lib/AccountsService/icons/ghostty\n" > /var/lib/AccountsService/users/ghostty + + chown root:root /var/lib/AccountsService/users/ghostty + chmod 0600 /var/lib/AccountsService/users/ghostty + + chown root:root /var/lib/AccountsService/icons/ghostty + chmod 0444 /var/lib/AccountsService/icons/ghostty + ''; + }; + }; + + programs.dconf = { + enable = true; + profiles.user.databases = [ + { + settings = with lib.gvariant; { + "org/gnome/desktop/background" = { + picture-uri = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; + picture-uri-dark = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; + picture-options = "centered"; + primary-color = "#000000000000"; + secondary-color = "#000000000000"; + }; + "org/gnome/desktop/desktop" = { + interface = "prefer-dark"; + }; + "org/gnome/desktop/notifications" = { + show-in-lock-screen = false; + }; + "org/gnome/desktop/screensaver" = { + lock-enabled = false; + picture-uri = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; + picture-options = "centered"; + primary-color = "#000000000000"; + secondary-color = "#000000000000"; + }; + "org/gnome/desktop/session" = { + idle-delay = mkUint32 0; + }; + "org/gnome/shell" = { + disable-user-extensions = false; + enabled-extensions = builtins.map (x: x.extensionUuid) ( + lib.filter (p: p ? extensionUuid) config.environment.systemPackages + ); + }; + }; + } + ]; + }; +} From 4ff7f6df06bfb5996d620d3492892df61d0655cd Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 5 Jan 2025 01:31:30 -0600 Subject: [PATCH 02/14] nix: fix dark mode setting --- nix/vm/wayland-gnome.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nix/vm/wayland-gnome.nix b/nix/vm/wayland-gnome.nix index 99e38808f..ada48d9c2 100644 --- a/nix/vm/wayland-gnome.nix +++ b/nix/vm/wayland-gnome.nix @@ -78,8 +78,8 @@ primary-color = "#000000000000"; secondary-color = "#000000000000"; }; - "org/gnome/desktop/desktop" = { - interface = "prefer-dark"; + "org/gnome/desktop/interface" = { + color-scheme = "prefer-dark"; }; "org/gnome/desktop/notifications" = { show-in-lock-screen = false; From 4bfb1f616cae47053de2acebc312ba01067abaab Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 5 Jan 2025 01:31:52 -0600 Subject: [PATCH 03/14] nix: disable geary --- nix/vm/wayland-gnome.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nix/vm/wayland-gnome.nix b/nix/vm/wayland-gnome.nix index ada48d9c2..5d82b16d0 100644 --- a/nix/vm/wayland-gnome.nix +++ b/nix/vm/wayland-gnome.nix @@ -104,4 +104,6 @@ } ]; }; + + programs.geary.enable = false; } From dddc2a50a8585a4a6dd12aa807770089e37f0faa Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 5 Jan 2025 02:07:51 -0600 Subject: [PATCH 04/14] nix vm: more slimming --- flake.nix | 2 +- nix/vm/common.nix | 2 ++ nix/vm/wayland-gnome.nix | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 0b8a2f424..f49dddf8d 100644 --- a/flake.nix +++ b/flake.nix @@ -67,7 +67,7 @@ modules = [ { nixpkgs.overlays = [ - self.overlays.debug + self.overlays.releasefast ]; } ./nix/vm/common.nix diff --git a/nix/vm/common.nix b/nix/vm/common.nix index 08ee19e5b..3a19fe841 100644 --- a/nix/vm/common.nix +++ b/nix/vm/common.nix @@ -2,6 +2,8 @@ boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; + documentation.nixos.enable = false; + networking.hostName = "ghostty"; networking.domain = "mitchellh.com"; diff --git a/nix/vm/wayland-gnome.nix b/nix/vm/wayland-gnome.nix index 5d82b16d0..b480dc439 100644 --- a/nix/vm/wayland-gnome.nix +++ b/nix/vm/wayland-gnome.nix @@ -37,17 +37,53 @@ environment.gnome.excludePackages = with pkgs; [ atomix + baobab cheese epiphany + evince + file-roller geary + gnome-backgrounds + gnome-calculator + gnome-calendar + gnome-clocks + gnome-connections + gnome-contacts + gnome-disk-utility + gnome-extension-manager + gnome-logs + gnome-maps gnome-music gnome-photos + gnome-software + gnome-system-monitor + gnome-text-editor + gnome-themes-extra gnome-tour + gnome-user-docs + gnome-weather hitori iagno + loupe + nautilus + orca + seahorse + simple-scan + snapshot + sushi tali + totem + yelp ]; + services.gnome = { + gnome-browser-connector.enable = false; + gnome-initial-setup.enable = false; + gnome-online-accounts.enable = false; + gnome-remote-desktop.enable = false; + rygel.enable = false; + }; + system.activationScripts = { face = { text = '' From 0b16c1eeba49a68c106d0fc2bcf3007505fcc926 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 5 Jan 2025 10:08:04 -0600 Subject: [PATCH 05/14] nix vm: maybe get vms working on darwin --- flake.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index f49dddf8d..acbfb7a9f 100644 --- a/flake.nix +++ b/flake.nix @@ -63,9 +63,12 @@ makeVM = ( path: nixpkgs-stable.lib.nixosSystem { - inherit system; + system = builtins.replaceStrings ["darwin"] ["linux"] system; modules = [ { + virtualisation.vmVariant = { + virtualisation.host.pkgs = pkgs-stable; + }; nixpkgs.overlays = [ self.overlays.releasefast ]; From 6be0902c095c534f875009b0c2b42e355d51f9bb Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 5 Jan 2025 23:34:41 -0600 Subject: [PATCH 06/14] nix vm: add documentation, add Gnome/X11 VM --- CONTRIBUTING.md | 55 +++++++++++++++ flake.nix | 2 + nix/vm/common-gnome.nix | 133 +++++++++++++++++++++++++++++++++++ nix/vm/common.nix | 29 ++++++++ nix/vm/wayland-gnome.nix | 148 ++------------------------------------- nix/vm/x11-gnome.nix | 9 +++ 6 files changed, 234 insertions(+), 142 deletions(-) create mode 100644 nix/vm/common-gnome.nix create mode 100644 nix/vm/x11-gnome.nix diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index af3c30be7..25a7c532c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -77,3 +77,58 @@ pull request will be accepted with a high degree of certainty. > **Pull requests are NOT a place to discuss feature design.** Please do > not open a WIP pull request to discuss a feature. Instead, use a discussion > and link to your branch. + +## Nix Virtual Machines + +Several Nix virtual machine definitions are provided by the project for testing +and developing Ghostty against multiple different Linux desktop environments. + +Running these requires a working Nix installation, either Nix on your +favorite Linux distribution, NixOS, or macOS with nix-darwin installed. Futher +requirements for macOS are detailed below. + +VMs should only be run on your local desktop and then powered off when not in +use, which will discard any changes to the VM. + +The VM definitions provide minimal software "out of the box" but additional +software can be installed by using standard Nix mechanisms like `nix run nixpkgs#`. + +### Linux + +1. Check out the Ghostty source and change to the directory. +2. Run `nix run .#`. `` can be any of the VMs defined in the + `nix/vm` directory (without the `.nix` suffix) excluding any file prefixed + with `common`. +3. The VM will build and then launch. Depending on the speed of your system, this + can take a while, but eventually you should get a new VM window. +4. The Ghostty source directory should be mounted to `/tmp/shared` in the VM. Depending + on what UID and GID of the user that you launched the VM as, `/tmp/shared` _may_ be + writable by the VM user, so be careful! + +### macOS + +1. To run the VMs on macOS you will need to enable the Linux builder in your `nix-darwin` + config. This _should_ be as simple as adding `nix.linux-builder.enable=true` to your + configuration and then rebuilding. See [this](https://nixcademy.com/posts/macos-linux-builder/) + blog post for more information about the Linux builder and how to tune the performance. +2. Once the Linux builder has been enabled, you should be able to follow the Linux instructions + above to launch a VM. + +### Contributing new VM definitions + +#### Acceptance Criteria + +We welcome the contribution of new VM definitions, as long as they meet the following criteria: + +1. The should be different enough from existing VM definitions that they represent a distinct + user (and developer) experience. +2. There's a significant Ghostty user population that uses a similar environment. +3. The VMs can be built using only packages from the current stable NixOS release. + +#### VM Definition Criteria + +1. VMs should be as minimal as possible so that they build and launch quickly. + Additonal software can be added at runtime with a command like `nix run nixpkgs#`. +2. VMs should not expose any services to the network, or run any remote access + software like SSH, VNC or RDP. +3. VMs should auto-login using the "ghostty" user. diff --git a/flake.nix b/flake.nix index acbfb7a9f..c0fdd42c3 100644 --- a/flake.nix +++ b/flake.nix @@ -80,6 +80,7 @@ ); in { "wayland-gnome-${system}" = makeVM ./nix/vm/wayland-gnome.nix; + "x11-gnome-${system}" = makeVM ./nix/vm/x11-gnome.nix; }; apps.${system} = let @@ -98,6 +99,7 @@ ); in { wayland-gnome = wrapVM "wayland-gnome"; + x11-gnome = wrapVM "x11-gnome"; }; } # Our supported systems are the same supported systems as the Zig binaries. diff --git a/nix/vm/common-gnome.nix b/nix/vm/common-gnome.nix new file mode 100644 index 000000000..992a10d3a --- /dev/null +++ b/nix/vm/common-gnome.nix @@ -0,0 +1,133 @@ +{ + config, + lib, + pkgs, + ... +}: { + services.xserver = { + enable = true; + displayManager = { + gdm = { + enable = true; + autoSuspend = false; + }; + }; + desktopManager = { + gnome = { + enable = true; + }; + }; + }; + + environment.systemPackages = [ + pkgs.gnomeExtensions.no-overview + ]; + + environment.gnome.excludePackages = with pkgs; [ + atomix + baobab + cheese + epiphany + evince + file-roller + geary + gnome-backgrounds + gnome-calculator + gnome-calendar + gnome-clocks + gnome-connections + gnome-contacts + gnome-disk-utility + gnome-extension-manager + gnome-logs + gnome-maps + gnome-music + gnome-photos + gnome-software + gnome-system-monitor + gnome-text-editor + gnome-themes-extra + gnome-tour + gnome-user-docs + gnome-weather + hitori + iagno + loupe + nautilus + orca + seahorse + simple-scan + snapshot + sushi + tali + totem + yelp + ]; + + services.gnome = { + gnome-browser-connector.enable = false; + gnome-initial-setup.enable = false; + gnome-online-accounts.enable = false; + gnome-remote-desktop.enable = false; + rygel.enable = false; + }; + + system.activationScripts = { + face = { + text = '' + mkdir -p /var/lib/AccountsService/{icons,users} + + cp ${pkgs.ghostty}/share/icons/hicolor/1024x1024/apps/com.mitchellh.ghostty.png /var/lib/AccountsService/icons/ghostty + + echo -e "[User]\nIcon=/var/lib/AccountsService/icons/ghostty\n" > /var/lib/AccountsService/users/ghostty + + chown root:root /var/lib/AccountsService/users/ghostty + chmod 0600 /var/lib/AccountsService/users/ghostty + + chown root:root /var/lib/AccountsService/icons/ghostty + chmod 0444 /var/lib/AccountsService/icons/ghostty + ''; + }; + }; + + programs.dconf = { + enable = true; + profiles.user.databases = [ + { + settings = with lib.gvariant; { + "org/gnome/desktop/background" = { + picture-uri = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; + picture-uri-dark = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; + picture-options = "centered"; + primary-color = "#000000000000"; + secondary-color = "#000000000000"; + }; + "org/gnome/desktop/interface" = { + color-scheme = "prefer-dark"; + }; + "org/gnome/desktop/notifications" = { + show-in-lock-screen = false; + }; + "org/gnome/desktop/screensaver" = { + lock-enabled = false; + picture-uri = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; + picture-options = "centered"; + primary-color = "#000000000000"; + secondary-color = "#000000000000"; + }; + "org/gnome/desktop/session" = { + idle-delay = mkUint32 0; + }; + "org/gnome/shell" = { + disable-user-extensions = false; + enabled-extensions = builtins.map (x: x.extensionUuid) ( + lib.filter (p: p ? extensionUuid) config.environment.systemPackages + ); + }; + }; + } + ]; + }; + + programs.geary.enable = false; +} diff --git a/nix/vm/common.nix b/nix/vm/common.nix index 3a19fe841..9e05cce4a 100644 --- a/nix/vm/common.nix +++ b/nix/vm/common.nix @@ -11,6 +11,18 @@ virtualisation.memorySize = 2048; }; + nix = { + settings = { + trusted-users = [ + "root" + "ghostty" + ]; + }; + extraOptions = '' + experimental-features = nix-command flakes + ''; + }; + users.mutableUsers = true; users.groups.ghostty = { @@ -26,10 +38,27 @@ initialPassword = "ghostty"; }; + environment.etc = { + "xdg/autostart/com.mitchellh.ghostty.desktop" = { + source = "${pkgs.ghostty}/share/applications/com.mitchellh.ghostty.desktop"; + }; + }; + environment.systemPackages = [ pkgs.kitty pkgs.ghostty + pkgs.zig_0_13 ]; + services.displayManager = { + autoLogin = { + user = "ghostty"; + }; + }; + + services.xserver = { + enable = true; + }; + system.stateVersion = "24.11"; } diff --git a/nix/vm/wayland-gnome.nix b/nix/vm/wayland-gnome.nix index b480dc439..eb277d5d1 100644 --- a/nix/vm/wayland-gnome.nix +++ b/nix/vm/wayland-gnome.nix @@ -1,145 +1,9 @@ -{ - config, - lib, - pkgs, - ... -}: { +{...}: { + imports = [ + ./common-gnome.nix + ]; + services.displayManager = { - autoLogin = { - user = "ghostty"; - }; + defaultSession = "gnome"; }; - - services.xserver = { - enable = true; - displayManager = { - gdm = { - enable = true; - autoSuspend = false; - }; - }; - desktopManager = { - gnome = { - enable = true; - }; - }; - }; - - environment.etc = { - "xdg/autostart/com.mitchellh.ghostty.desktop" = { - source = "${pkgs.ghostty}/share/applications/com.mitchellh.ghostty.desktop"; - }; - }; - - environment.systemPackages = [ - pkgs.gnomeExtensions.no-overview - ]; - - environment.gnome.excludePackages = with pkgs; [ - atomix - baobab - cheese - epiphany - evince - file-roller - geary - gnome-backgrounds - gnome-calculator - gnome-calendar - gnome-clocks - gnome-connections - gnome-contacts - gnome-disk-utility - gnome-extension-manager - gnome-logs - gnome-maps - gnome-music - gnome-photos - gnome-software - gnome-system-monitor - gnome-text-editor - gnome-themes-extra - gnome-tour - gnome-user-docs - gnome-weather - hitori - iagno - loupe - nautilus - orca - seahorse - simple-scan - snapshot - sushi - tali - totem - yelp - ]; - - services.gnome = { - gnome-browser-connector.enable = false; - gnome-initial-setup.enable = false; - gnome-online-accounts.enable = false; - gnome-remote-desktop.enable = false; - rygel.enable = false; - }; - - system.activationScripts = { - face = { - text = '' - mkdir -p /var/lib/AccountsService/{icons,users} - - cp ${pkgs.ghostty}/share/icons/hicolor/1024x1024/apps/com.mitchellh.ghostty.png /var/lib/AccountsService/icons/ghostty - - echo -e "[User]\nIcon=/var/lib/AccountsService/icons/ghostty\n" > /var/lib/AccountsService/users/ghostty - - chown root:root /var/lib/AccountsService/users/ghostty - chmod 0600 /var/lib/AccountsService/users/ghostty - - chown root:root /var/lib/AccountsService/icons/ghostty - chmod 0444 /var/lib/AccountsService/icons/ghostty - ''; - }; - }; - - programs.dconf = { - enable = true; - profiles.user.databases = [ - { - settings = with lib.gvariant; { - "org/gnome/desktop/background" = { - picture-uri = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; - picture-uri-dark = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; - picture-options = "centered"; - primary-color = "#000000000000"; - secondary-color = "#000000000000"; - }; - "org/gnome/desktop/interface" = { - color-scheme = "prefer-dark"; - }; - "org/gnome/desktop/notifications" = { - show-in-lock-screen = false; - }; - "org/gnome/desktop/screensaver" = { - lock-enabled = false; - picture-uri = "file://${pkgs.ghostty}/share/icons/hicolor/512x512/apps/com.mitchellh.ghostty.png"; - picture-options = "centered"; - primary-color = "#000000000000"; - secondary-color = "#000000000000"; - }; - "org/gnome/desktop/session" = { - idle-delay = mkUint32 0; - }; - "org/gnome/shell" = { - disable-user-extensions = false; - enabled-extensions = builtins.map (x: x.extensionUuid) ( - lib.filter (p: p ? extensionUuid) config.environment.systemPackages - ); - }; - }; - } - ]; - }; - - programs.geary.enable = false; } diff --git a/nix/vm/x11-gnome.nix b/nix/vm/x11-gnome.nix new file mode 100644 index 000000000..1994aea82 --- /dev/null +++ b/nix/vm/x11-gnome.nix @@ -0,0 +1,9 @@ +{...}: { + imports = [ + ./common-gnome.nix + ]; + + services.displayManager = { + defaultSession = "gnome-xorg"; + }; +} From 26f6b3ea8226a231949087827ff5bb92b932f350 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Sun, 5 Jan 2025 23:39:36 -0600 Subject: [PATCH 07/14] fix typo --- CONTRIBUTING.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 25a7c532c..5013ced8a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -84,7 +84,7 @@ Several Nix virtual machine definitions are provided by the project for testing and developing Ghostty against multiple different Linux desktop environments. Running these requires a working Nix installation, either Nix on your -favorite Linux distribution, NixOS, or macOS with nix-darwin installed. Futher +favorite Linux distribution, NixOS, or macOS with nix-darwin installed. Further requirements for macOS are detailed below. VMs should only be run on your local desktop and then powered off when not in @@ -128,7 +128,7 @@ We welcome the contribution of new VM definitions, as long as they meet the foll #### VM Definition Criteria 1. VMs should be as minimal as possible so that they build and launch quickly. - Additonal software can be added at runtime with a command like `nix run nixpkgs#`. + Additional software can be added at runtime with a command like `nix run nixpkgs#`. 2. VMs should not expose any services to the network, or run any remote access software like SSH, VNC or RDP. 3. VMs should auto-login using the "ghostty" user. From 450c019b4e50a1a79d36858866eab0f71c6d6d5c Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Mon, 6 Jan 2025 23:42:23 -0600 Subject: [PATCH 08/14] nix vm: add plasma and cinnamon vms --- flake.nix | 8 ++++++++ nix/vm/common-cinnamon.nix | 14 ++++++++++++++ nix/vm/common-gnome.nix | 1 - nix/vm/common-plasma6.nix | 17 +++++++++++++++++ nix/vm/common.nix | 22 ++++++++++++++++++++++ nix/vm/wayland-cinnamon.nix | 7 +++++++ nix/vm/wayland-plasma6.nix | 6 ++++++ nix/vm/x11-cinnamon.nix | 7 +++++++ nix/vm/x11-plasma6.nix | 6 ++++++ 9 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 nix/vm/common-cinnamon.nix create mode 100644 nix/vm/common-plasma6.nix create mode 100644 nix/vm/wayland-cinnamon.nix create mode 100644 nix/vm/wayland-plasma6.nix create mode 100644 nix/vm/x11-cinnamon.nix create mode 100644 nix/vm/x11-plasma6.nix diff --git a/flake.nix b/flake.nix index c0fdd42c3..38aea5b80 100644 --- a/flake.nix +++ b/flake.nix @@ -79,8 +79,12 @@ } ); in { + "wayland-cinnamon-${system}" = makeVM ./nix/vm/wayland-cinnamon.nix; "wayland-gnome-${system}" = makeVM ./nix/vm/wayland-gnome.nix; + "wayland-plasma6-${system}" = makeVM ./nix/vm/wayland-plasma6.nix; + "x11-cinnamon-${system}" = makeVM ./nix/vm/x11-cinnamon.nix; "x11-gnome-${system}" = makeVM ./nix/vm/x11-gnome.nix; + "x11-plasma6-${system}" = makeVM ./nix/vm/x11-plasma6.nix; }; apps.${system} = let @@ -98,8 +102,12 @@ } ); in { + wayland-cinnamon = wrapVM "wayland-cinnamon"; wayland-gnome = wrapVM "wayland-gnome"; + wayland-plasma6 = wrapVM "wayland-plasma6"; + x11-cinnamon = wrapVM "x11-cinnamon"; x11-gnome = wrapVM "x11-gnome"; + x11-plasma6 = wrapVM "x11-plasma6"; }; } # Our supported systems are the same supported systems as the Zig binaries. diff --git a/nix/vm/common-cinnamon.nix b/nix/vm/common-cinnamon.nix new file mode 100644 index 000000000..a551321cf --- /dev/null +++ b/nix/vm/common-cinnamon.nix @@ -0,0 +1,14 @@ +{...}: { + services.xserver = { + displayManager = { + lightdm = { + enable = true; + }; + }; + desktopManager = { + cinnamon = { + enable = true; + }; + }; + }; +} diff --git a/nix/vm/common-gnome.nix b/nix/vm/common-gnome.nix index 992a10d3a..d5018b457 100644 --- a/nix/vm/common-gnome.nix +++ b/nix/vm/common-gnome.nix @@ -5,7 +5,6 @@ ... }: { services.xserver = { - enable = true; displayManager = { gdm = { enable = true; diff --git a/nix/vm/common-plasma6.nix b/nix/vm/common-plasma6.nix new file mode 100644 index 000000000..3b280184c --- /dev/null +++ b/nix/vm/common-plasma6.nix @@ -0,0 +1,17 @@ +{...}: { + services = { + displayManager = { + sddm = { + enable = true; + wayland = { + enable = true; + }; + }; + }; + desktopManager = { + plasma6 = { + enable = true; + }; + }; + }; +} diff --git a/nix/vm/common.nix b/nix/vm/common.nix index 9e05cce4a..fa0305ad0 100644 --- a/nix/vm/common.nix +++ b/nix/vm/common.nix @@ -47,15 +47,37 @@ environment.systemPackages = [ pkgs.kitty pkgs.ghostty + pkgs.helix + pkgs.neovim pkgs.zig_0_13 ]; + security.polkit = { + enable = true; + }; + + services.dbus = { + enable = true; + }; + services.displayManager = { autoLogin = { user = "ghostty"; }; }; + services.libinput = { + enable = true; + }; + + services.qemuGuest = { + enable = true; + }; + + services.spice-vdagentd = { + enable = true; + }; + services.xserver = { enable = true; }; diff --git a/nix/vm/wayland-cinnamon.nix b/nix/vm/wayland-cinnamon.nix new file mode 100644 index 000000000..531c882b6 --- /dev/null +++ b/nix/vm/wayland-cinnamon.nix @@ -0,0 +1,7 @@ +{...}: { + imports = [ + ./common-cinnamon.nix + ]; + + services.displayManager.defaultSession = "cinnamon-wayland"; +} diff --git a/nix/vm/wayland-plasma6.nix b/nix/vm/wayland-plasma6.nix new file mode 100644 index 000000000..6e5a253b8 --- /dev/null +++ b/nix/vm/wayland-plasma6.nix @@ -0,0 +1,6 @@ +{...}: { + imports = [ + ./common-plasma6.nix + ]; + services.displayManager.defaultSession = "plasma"; +} diff --git a/nix/vm/x11-cinnamon.nix b/nix/vm/x11-cinnamon.nix new file mode 100644 index 000000000..636f235a2 --- /dev/null +++ b/nix/vm/x11-cinnamon.nix @@ -0,0 +1,7 @@ +{...}: { + imports = [ + ./common-cinnamon.nix + ]; + + services.displayManager.defaultSession = "cinnamon"; +} diff --git a/nix/vm/x11-plasma6.nix b/nix/vm/x11-plasma6.nix new file mode 100644 index 000000000..7818a80ca --- /dev/null +++ b/nix/vm/x11-plasma6.nix @@ -0,0 +1,6 @@ +{...}: { + imports = [ + ./common-plasma6.nix + ]; + services.displayManager.defaultSession = "plasmax11"; +} From 268fc1a0405e159359d6f3f246707fbf80c04b0b Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Tue, 7 Jan 2025 08:42:30 -0600 Subject: [PATCH 09/14] nix vm: simplify vm definition --- CONTRIBUTING.md | 4 ++-- flake.nix | 45 ++++++++++++++++++----------------- nix/vm/common-gnome.nix | 52 ++++++++++++++++++++--------------------- nix/vm/common.nix | 8 ++----- 4 files changed, 53 insertions(+), 56 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5013ced8a..7415825f9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -116,7 +116,7 @@ software can be installed by using standard Nix mechanisms like `nix run nixpkgs ### Contributing new VM definitions -#### Acceptance Criteria +#### VM Acceptance Criteria We welcome the contribution of new VM definitions, as long as they meet the following criteria: @@ -130,5 +130,5 @@ We welcome the contribution of new VM definitions, as long as they meet the foll 1. VMs should be as minimal as possible so that they build and launch quickly. Additional software can be added at runtime with a command like `nix run nixpkgs#`. 2. VMs should not expose any services to the network, or run any remote access - software like SSH, VNC or RDP. + software like SSH daemons, VNC or RDP. 3. VMs should auto-login using the "ghostty" user. diff --git a/flake.nix b/flake.nix index 38aea5b80..81e9b422c 100644 --- a/flake.nix +++ b/flake.nix @@ -59,9 +59,9 @@ formatter.${system} = pkgs-stable.alejandra; - nixosConfigurations = let + apps.${system} = let makeVM = ( - path: + path: system: uid: gid: nixpkgs-stable.lib.nixosSystem { system = builtins.replaceStrings ["darwin"] ["linux"] system; modules = [ @@ -69,32 +69,33 @@ virtualisation.vmVariant = { virtualisation.host.pkgs = pkgs-stable; }; + nixpkgs.overlays = [ - self.overlays.releasefast + self.overlays.debug ]; + + users.groups.ghostty = { + gid = gid; + }; + + users.users.ghostty = { + uid = gid; + }; + + system.stateVersion = "24.11"; } ./nix/vm/common.nix path ]; } ); - in { - "wayland-cinnamon-${system}" = makeVM ./nix/vm/wayland-cinnamon.nix; - "wayland-gnome-${system}" = makeVM ./nix/vm/wayland-gnome.nix; - "wayland-plasma6-${system}" = makeVM ./nix/vm/wayland-plasma6.nix; - "x11-cinnamon-${system}" = makeVM ./nix/vm/x11-cinnamon.nix; - "x11-gnome-${system}" = makeVM ./nix/vm/x11-gnome.nix; - "x11-plasma6-${system}" = makeVM ./nix/vm/x11-plasma6.nix; - }; - - apps.${system} = let - wrapVM = ( - name: let + runVM = ( + path: let program = pkgs-stable.writeShellScript "run-ghostty-vm" '' SHARED_DIR=$(pwd) export SHARED_DIR - ${self.nixosConfigurations."${name}-${system}".config.system.build.vm}/bin/run-ghostty-vm + ${(makeVM path system 1000 1000).config.system.build.vm}/bin/run-ghostty-vm ''; in { type = "app"; @@ -102,12 +103,12 @@ } ); in { - wayland-cinnamon = wrapVM "wayland-cinnamon"; - wayland-gnome = wrapVM "wayland-gnome"; - wayland-plasma6 = wrapVM "wayland-plasma6"; - x11-cinnamon = wrapVM "x11-cinnamon"; - x11-gnome = wrapVM "x11-gnome"; - x11-plasma6 = wrapVM "x11-plasma6"; + wayland-cinnamon = runVM ./nix/vm/wayland-cinnamon.nix; + wayland-gnome = runVM ./nix/vm/wayland-gnome.nix; + wayland-plasma6 = runVM ./nix/vm/wayland-plasma6.nix; + x11-cinnamon = runVM ./nix/vm/x11-cinnamon.nix; + x11-gnome = runVM ./nix/vm/x11-gnome.nix; + x11-plasma6 = runVM ./nix/vm/x11-plasma6.nix; }; } # Our supported systems are the same supported systems as the Zig binaries. diff --git a/nix/vm/common-gnome.nix b/nix/vm/common-gnome.nix index d5018b457..d43f5dc9e 100644 --- a/nix/vm/common-gnome.nix +++ b/nix/vm/common-gnome.nix @@ -63,32 +63,6 @@ yelp ]; - services.gnome = { - gnome-browser-connector.enable = false; - gnome-initial-setup.enable = false; - gnome-online-accounts.enable = false; - gnome-remote-desktop.enable = false; - rygel.enable = false; - }; - - system.activationScripts = { - face = { - text = '' - mkdir -p /var/lib/AccountsService/{icons,users} - - cp ${pkgs.ghostty}/share/icons/hicolor/1024x1024/apps/com.mitchellh.ghostty.png /var/lib/AccountsService/icons/ghostty - - echo -e "[User]\nIcon=/var/lib/AccountsService/icons/ghostty\n" > /var/lib/AccountsService/users/ghostty - - chown root:root /var/lib/AccountsService/users/ghostty - chmod 0600 /var/lib/AccountsService/users/ghostty - - chown root:root /var/lib/AccountsService/icons/ghostty - chmod 0444 /var/lib/AccountsService/icons/ghostty - ''; - }; - }; - programs.dconf = { enable = true; profiles.user.databases = [ @@ -129,4 +103,30 @@ }; programs.geary.enable = false; + + services.gnome = { + gnome-browser-connector.enable = false; + gnome-initial-setup.enable = false; + gnome-online-accounts.enable = false; + gnome-remote-desktop.enable = false; + rygel.enable = false; + }; + + system.activationScripts = { + face = { + text = '' + mkdir -p /var/lib/AccountsService/{icons,users} + + cp ${pkgs.ghostty}/share/icons/hicolor/1024x1024/apps/com.mitchellh.ghostty.png /var/lib/AccountsService/icons/ghostty + + echo -e "[User]\nIcon=/var/lib/AccountsService/icons/ghostty\n" > /var/lib/AccountsService/users/ghostty + + chown root:root /var/lib/AccountsService/users/ghostty + chmod 0600 /var/lib/AccountsService/users/ghostty + + chown root:root /var/lib/AccountsService/icons/ghostty + chmod 0444 /var/lib/AccountsService/icons/ghostty + ''; + }; + }; } diff --git a/nix/vm/common.nix b/nix/vm/common.nix index fa0305ad0..6e80dd5b6 100644 --- a/nix/vm/common.nix +++ b/nix/vm/common.nix @@ -25,13 +25,10 @@ users.mutableUsers = true; - users.groups.ghostty = { - gid = 1000; - }; + users.groups.ghostty = {}; users.users.ghostty = { description = "Ghostty"; - uid = 1000; group = "ghostty"; extraGroups = ["wheel"]; isNormalUser = true; @@ -49,6 +46,7 @@ pkgs.ghostty pkgs.helix pkgs.neovim + pkgs.xterm pkgs.zig_0_13 ]; @@ -81,6 +79,4 @@ services.xserver = { enable = true; }; - - system.stateVersion = "24.11"; } From e1e2f94681d0b11a99c1a713a61fbfd36e6f9bb6 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Tue, 7 Jan 2025 21:46:21 -0600 Subject: [PATCH 10/14] nix vm: try and make vm creation more re-usable --- nix/vm/create.nix | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 nix/vm/create.nix diff --git a/nix/vm/create.nix b/nix/vm/create.nix new file mode 100644 index 000000000..8aea5d19d --- /dev/null +++ b/nix/vm/create.nix @@ -0,0 +1,41 @@ +{ + system, + nixpkgs, + overlay, + path, + uid ? 1000, + gid ? 1000, +}: let + pkgs = import nixpkgs { + inherit system; + overlays = [ + overlay + ]; + }; +in + nixpkgs.lib.nixosSystem { + system = builtins.replaceStrings ["darwin"] ["linux"] system; + modules = [ + { + virtualisation.vmVariant = { + virtualisation.host.pkgs = pkgs; + }; + + nixpkgs.overlays = [ + overlay + ]; + + users.groups.ghostty = { + gid = gid; + }; + + users.users.ghostty = { + uid = uid; + }; + + system.stateVersion = "24.11"; + } + ./common.nix + path + ]; + } From 321119e0010290fb6f702b87ca251e61a3899eb9 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Tue, 7 Jan 2025 22:03:04 -0600 Subject: [PATCH 11/14] nix vm: more reusability --- flake.nix | 40 ++++++++++---------------------------- nix/vm/common-cinnamon.nix | 4 ++++ nix/vm/common-gnome.nix | 4 ++++ nix/vm/common-plasma6.nix | 4 ++++ nix/vm/create-cinnamon.nix | 12 ++++++++++++ nix/vm/create-gnome.nix | 12 ++++++++++++ nix/vm/create-plasma6.nix | 12 ++++++++++++ nix/vm/create.nix | 5 +++-- 8 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 nix/vm/create-cinnamon.nix create mode 100644 nix/vm/create-gnome.nix create mode 100644 nix/vm/create-plasma6.nix diff --git a/flake.nix b/flake.nix index 81e9b422c..b3cd77087 100644 --- a/flake.nix +++ b/flake.nix @@ -60,42 +60,18 @@ formatter.${system} = pkgs-stable.alejandra; apps.${system} = let - makeVM = ( - path: system: uid: gid: - nixpkgs-stable.lib.nixosSystem { - system = builtins.replaceStrings ["darwin"] ["linux"] system; - modules = [ - { - virtualisation.vmVariant = { - virtualisation.host.pkgs = pkgs-stable; - }; - - nixpkgs.overlays = [ - self.overlays.debug - ]; - - users.groups.ghostty = { - gid = gid; - }; - - users.users.ghostty = { - uid = gid; - }; - - system.stateVersion = "24.11"; - } - ./nix/vm/common.nix - path - ]; - } - ); runVM = ( path: let + vm = import ./nix/vm/create.nix { + inherit system path; + nixpkgs = nixpkgs-stable; + overlay = self.overlays.debug; + }; program = pkgs-stable.writeShellScript "run-ghostty-vm" '' SHARED_DIR=$(pwd) export SHARED_DIR - ${(makeVM path system 1000 1000).config.system.build.vm}/bin/run-ghostty-vm + ${vm.config.system.build.vm}/bin/run-ghostty-vm ''; in { type = "app"; @@ -124,6 +100,10 @@ ghostty = self.packages.${prev.system}.ghostty-debug; }; }; + create-vm = import ./nix/vm/create.nix; + create-cinnamon-vm = import ./nix/vm/create-cinnamon.nix; + create-gnome-vm = import ./nix/vm/create-gnome.nix; + create-plasma6-vm = import ./nix/vm/create-plasma6.nix; }; nixConfig = { diff --git a/nix/vm/common-cinnamon.nix b/nix/vm/common-cinnamon.nix index a551321cf..dabe5e701 100644 --- a/nix/vm/common-cinnamon.nix +++ b/nix/vm/common-cinnamon.nix @@ -1,4 +1,8 @@ {...}: { + imports = [ + ./common.nix + ]; + services.xserver = { displayManager = { lightdm = { diff --git a/nix/vm/common-gnome.nix b/nix/vm/common-gnome.nix index d43f5dc9e..0c2bef150 100644 --- a/nix/vm/common-gnome.nix +++ b/nix/vm/common-gnome.nix @@ -4,6 +4,10 @@ pkgs, ... }: { + imports = [ + ./common.nix + ]; + services.xserver = { displayManager = { gdm = { diff --git a/nix/vm/common-plasma6.nix b/nix/vm/common-plasma6.nix index 3b280184c..e5c9bd4d8 100644 --- a/nix/vm/common-plasma6.nix +++ b/nix/vm/common-plasma6.nix @@ -1,4 +1,8 @@ {...}: { + imports = [ + ./common.nix + ]; + services = { displayManager = { sddm = { diff --git a/nix/vm/create-cinnamon.nix b/nix/vm/create-cinnamon.nix new file mode 100644 index 000000000..0efd3c72c --- /dev/null +++ b/nix/vm/create-cinnamon.nix @@ -0,0 +1,12 @@ +{ + system, + nixpkgs, + overlay, + path, + uid ? 1000, + gid ? 1000, +}: +import ./create.nix { + inherit system nixpkgs overlay path uid gid; + common = ./common-cinnamon.nix; +} diff --git a/nix/vm/create-gnome.nix b/nix/vm/create-gnome.nix new file mode 100644 index 000000000..9fb7f3914 --- /dev/null +++ b/nix/vm/create-gnome.nix @@ -0,0 +1,12 @@ +{ + system, + nixpkgs, + overlay, + path, + uid ? 1000, + gid ? 1000, +}: +import ./create.nix { + inherit system nixpkgs overlay path uid gid; + common = ./common-gnome.nix; +} diff --git a/nix/vm/create-plasma6.nix b/nix/vm/create-plasma6.nix new file mode 100644 index 000000000..47785899f --- /dev/null +++ b/nix/vm/create-plasma6.nix @@ -0,0 +1,12 @@ +{ + system, + nixpkgs, + overlay, + path, + uid ? 1000, + gid ? 1000, +}: +import ./create.nix { + inherit system nixpkgs overlay path uid gid; + common = ./common-plasma6.nix; +} diff --git a/nix/vm/create.nix b/nix/vm/create.nix index 8aea5d19d..4481d4345 100644 --- a/nix/vm/create.nix +++ b/nix/vm/create.nix @@ -3,6 +3,7 @@ nixpkgs, overlay, path, + common ? ./common.nix, uid ? 1000, gid ? 1000, }: let @@ -33,9 +34,9 @@ in uid = uid; }; - system.stateVersion = "24.11"; + system.stateVersion = nixpkgs.lib.trivial.release; } - ./common.nix + common path ]; } From 1ac56a7ac2552d2d9f2ee67f597a5c574670956a Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Tue, 7 Jan 2025 22:22:38 -0600 Subject: [PATCH 12/14] nix vm: +fish +zsh -zig --- nix/vm/common.nix | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nix/vm/common.nix b/nix/vm/common.nix index 6e80dd5b6..eefd7c1c0 100644 --- a/nix/vm/common.nix +++ b/nix/vm/common.nix @@ -23,7 +23,7 @@ ''; }; - users.mutableUsers = true; + users.mutableUsers = false; users.groups.ghostty = {}; @@ -43,11 +43,12 @@ environment.systemPackages = [ pkgs.kitty + pkgs.fish pkgs.ghostty pkgs.helix pkgs.neovim pkgs.xterm - pkgs.zig_0_13 + pkgs.zsh ]; security.polkit = { From 423133bc3c4151d2f289282b9c2bdf09bc84c9dd Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Wed, 15 Jan 2025 11:56:19 -0600 Subject: [PATCH 13/14] nix: document how to create custom vms --- CONTRIBUTING.md | 44 +++++++++++++++++++++++++++++++++++++- flake.nix | 6 +++--- nix/vm/create-cinnamon.nix | 4 ++-- nix/vm/create-gnome.nix | 4 ++-- nix/vm/create-plasma6.nix | 4 ++-- nix/vm/create.nix | 4 ++-- 6 files changed, 54 insertions(+), 12 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7415825f9..a7233b2c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -98,7 +98,7 @@ software can be installed by using standard Nix mechanisms like `nix run nixpkgs 1. Check out the Ghostty source and change to the directory. 2. Run `nix run .#`. `` can be any of the VMs defined in the `nix/vm` directory (without the `.nix` suffix) excluding any file prefixed - with `common`. + with `common` or `create`. 3. The VM will build and then launch. Depending on the speed of your system, this can take a while, but eventually you should get a new VM window. 4. The Ghostty source directory should be mounted to `/tmp/shared` in the VM. Depending @@ -114,6 +114,48 @@ software can be installed by using standard Nix mechanisms like `nix run nixpkgs 2. Once the Linux builder has been enabled, you should be able to follow the Linux instructions above to launch a VM. +### Custom VMs + +To easily create a custom VM without modifying the Ghostty source, create a new +directory, then create a file called `flake.nix` with the following text in the +new directory. + +``` +{ + inputs = { + nixpkgs.url = "nixpkgs/nixpkgs-unstable"; + ghostty.url = "github:ghostty-org/ghostty"; + }; + outputs = { + nixpkgs, + ghostty, + ... + }: { + nixosConfigurations.custom-vm = ghostty.create-gnome-vm { + nixpkgs = nixpkgs; + system = "x86_64-linux"; + overlay = ghostty.overlays.releasefast; + # module = ./configuration.nix # also works + module = {pkgs, ...}: { + environment.systemPackages = [ + pkgs.btop + ]; + }; + }; + }; +} +``` + +The custom VM can then be run with a command like this: + +``` +nix run .#nixosConfigurations.custom-vm.config.system.build.vm +``` + +A file named `ghostty.qcow2` will be created that is used to persist any changes +made in the VM. To "reset" the VM to default delete the file and it will be +recreated the next time you run the VM. + ### Contributing new VM definitions #### VM Acceptance Criteria diff --git a/flake.nix b/flake.nix index b3cd77087..d787c0609 100644 --- a/flake.nix +++ b/flake.nix @@ -61,9 +61,9 @@ apps.${system} = let runVM = ( - path: let + module: let vm = import ./nix/vm/create.nix { - inherit system path; + inherit system module; nixpkgs = nixpkgs-stable; overlay = self.overlays.debug; }; @@ -71,7 +71,7 @@ SHARED_DIR=$(pwd) export SHARED_DIR - ${vm.config.system.build.vm}/bin/run-ghostty-vm + ${pkgs-stable.lib.getExe vm.config.system.build.vm} "$@" ''; in { type = "app"; diff --git a/nix/vm/create-cinnamon.nix b/nix/vm/create-cinnamon.nix index 0efd3c72c..a9d9e44d7 100644 --- a/nix/vm/create-cinnamon.nix +++ b/nix/vm/create-cinnamon.nix @@ -2,11 +2,11 @@ system, nixpkgs, overlay, - path, + module, uid ? 1000, gid ? 1000, }: import ./create.nix { - inherit system nixpkgs overlay path uid gid; + inherit system nixpkgs overlay module uid gid; common = ./common-cinnamon.nix; } diff --git a/nix/vm/create-gnome.nix b/nix/vm/create-gnome.nix index 9fb7f3914..bcd31f2b6 100644 --- a/nix/vm/create-gnome.nix +++ b/nix/vm/create-gnome.nix @@ -2,11 +2,11 @@ system, nixpkgs, overlay, - path, + module, uid ? 1000, gid ? 1000, }: import ./create.nix { - inherit system nixpkgs overlay path uid gid; + inherit system nixpkgs overlay module uid gid; common = ./common-gnome.nix; } diff --git a/nix/vm/create-plasma6.nix b/nix/vm/create-plasma6.nix index 47785899f..ede5371f3 100644 --- a/nix/vm/create-plasma6.nix +++ b/nix/vm/create-plasma6.nix @@ -2,11 +2,11 @@ system, nixpkgs, overlay, - path, + module, uid ? 1000, gid ? 1000, }: import ./create.nix { - inherit system nixpkgs overlay path uid gid; + inherit system nixpkgs overlay module uid gid; common = ./common-plasma6.nix; } diff --git a/nix/vm/create.nix b/nix/vm/create.nix index 4481d4345..f8fe8500d 100644 --- a/nix/vm/create.nix +++ b/nix/vm/create.nix @@ -2,7 +2,7 @@ system, nixpkgs, overlay, - path, + module, common ? ./common.nix, uid ? 1000, gid ? 1000, @@ -37,6 +37,6 @@ in system.stateVersion = nixpkgs.lib.trivial.release; } common - path + module ]; } From 3159a7bec783f6a47b05c620c4550355729298f9 Mon Sep 17 00:00:00 2001 From: "Jeffrey C. Ollie" Date: Wed, 15 Jan 2025 20:37:31 -0600 Subject: [PATCH 14/14] nix: add x11 xfce vm --- flake.nix | 2 ++ nix/vm/common-xfce.nix | 18 ++++++++++++++++++ nix/vm/create-xfce.nix | 12 ++++++++++++ nix/vm/x11-xfce.nix | 7 +++++++ 4 files changed, 39 insertions(+) create mode 100644 nix/vm/common-xfce.nix create mode 100644 nix/vm/create-xfce.nix create mode 100644 nix/vm/x11-xfce.nix diff --git a/flake.nix b/flake.nix index d787c0609..3256c7c15 100644 --- a/flake.nix +++ b/flake.nix @@ -85,6 +85,7 @@ x11-cinnamon = runVM ./nix/vm/x11-cinnamon.nix; x11-gnome = runVM ./nix/vm/x11-gnome.nix; x11-plasma6 = runVM ./nix/vm/x11-plasma6.nix; + x11-xfce = runVM ./nix/vm/x11-xfce.nix; }; } # Our supported systems are the same supported systems as the Zig binaries. @@ -104,6 +105,7 @@ create-cinnamon-vm = import ./nix/vm/create-cinnamon.nix; create-gnome-vm = import ./nix/vm/create-gnome.nix; create-plasma6-vm = import ./nix/vm/create-plasma6.nix; + create-xfce-vm = import ./nix/vm/create-xfce.nix; }; nixConfig = { diff --git a/nix/vm/common-xfce.nix b/nix/vm/common-xfce.nix new file mode 100644 index 000000000..12a20d8d8 --- /dev/null +++ b/nix/vm/common-xfce.nix @@ -0,0 +1,18 @@ +{...}: { + imports = [ + ./common.nix + ]; + + services.xserver = { + displayManager = { + lightdm = { + enable = true; + }; + }; + desktopManager = { + xfce = { + enable = true; + }; + }; + }; +} diff --git a/nix/vm/create-xfce.nix b/nix/vm/create-xfce.nix new file mode 100644 index 000000000..d1789472d --- /dev/null +++ b/nix/vm/create-xfce.nix @@ -0,0 +1,12 @@ +{ + system, + nixpkgs, + overlay, + module, + uid ? 1000, + gid ? 1000, +}: +import ./create.nix { + inherit system nixpkgs overlay module uid gid; + common = ./common-xfce.nix; +} diff --git a/nix/vm/x11-xfce.nix b/nix/vm/x11-xfce.nix new file mode 100644 index 000000000..71eb87f2f --- /dev/null +++ b/nix/vm/x11-xfce.nix @@ -0,0 +1,7 @@ +{...}: { + imports = [ + ./common-xfce.nix + ]; + + services.displayManager.defaultSession = "xfce"; +}