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"; + }; +}