nix vm: simplify vm definition

This commit is contained in:
Jeffrey C. Ollie
2025-01-07 08:42:30 -06:00
parent 450c019b4e
commit 268fc1a040
4 changed files with 53 additions and 56 deletions

View File

@ -116,7 +116,7 @@ software can be installed by using standard Nix mechanisms like `nix run nixpkgs
### Contributing new VM definitions ### 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: 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. 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#<package name>`. Additional software can be added at runtime with a command like `nix run nixpkgs#<package name>`.
2. VMs should not expose any services to the network, or run any remote access 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. 3. VMs should auto-login using the "ghostty" user.

View File

@ -59,9 +59,9 @@
formatter.${system} = pkgs-stable.alejandra; formatter.${system} = pkgs-stable.alejandra;
nixosConfigurations = let apps.${system} = let
makeVM = ( makeVM = (
path: path: system: uid: gid:
nixpkgs-stable.lib.nixosSystem { nixpkgs-stable.lib.nixosSystem {
system = builtins.replaceStrings ["darwin"] ["linux"] system; system = builtins.replaceStrings ["darwin"] ["linux"] system;
modules = [ modules = [
@ -69,32 +69,33 @@
virtualisation.vmVariant = { virtualisation.vmVariant = {
virtualisation.host.pkgs = pkgs-stable; virtualisation.host.pkgs = pkgs-stable;
}; };
nixpkgs.overlays = [ 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 ./nix/vm/common.nix
path path
]; ];
} }
); );
in { runVM = (
"wayland-cinnamon-${system}" = makeVM ./nix/vm/wayland-cinnamon.nix; path: let
"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
program = pkgs-stable.writeShellScript "run-ghostty-vm" '' program = pkgs-stable.writeShellScript "run-ghostty-vm" ''
SHARED_DIR=$(pwd) SHARED_DIR=$(pwd)
export SHARED_DIR 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 { in {
type = "app"; type = "app";
@ -102,12 +103,12 @@
} }
); );
in { in {
wayland-cinnamon = wrapVM "wayland-cinnamon"; wayland-cinnamon = runVM ./nix/vm/wayland-cinnamon.nix;
wayland-gnome = wrapVM "wayland-gnome"; wayland-gnome = runVM ./nix/vm/wayland-gnome.nix;
wayland-plasma6 = wrapVM "wayland-plasma6"; wayland-plasma6 = runVM ./nix/vm/wayland-plasma6.nix;
x11-cinnamon = wrapVM "x11-cinnamon"; x11-cinnamon = runVM ./nix/vm/x11-cinnamon.nix;
x11-gnome = wrapVM "x11-gnome"; x11-gnome = runVM ./nix/vm/x11-gnome.nix;
x11-plasma6 = wrapVM "x11-plasma6"; x11-plasma6 = runVM ./nix/vm/x11-plasma6.nix;
}; };
} }
# Our supported systems are the same supported systems as the Zig binaries. # Our supported systems are the same supported systems as the Zig binaries.

View File

@ -63,32 +63,6 @@
yelp 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 = { programs.dconf = {
enable = true; enable = true;
profiles.user.databases = [ profiles.user.databases = [
@ -129,4 +103,30 @@
}; };
programs.geary.enable = false; 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
'';
};
};
} }

View File

@ -25,13 +25,10 @@
users.mutableUsers = true; users.mutableUsers = true;
users.groups.ghostty = { users.groups.ghostty = {};
gid = 1000;
};
users.users.ghostty = { users.users.ghostty = {
description = "Ghostty"; description = "Ghostty";
uid = 1000;
group = "ghostty"; group = "ghostty";
extraGroups = ["wheel"]; extraGroups = ["wheel"];
isNormalUser = true; isNormalUser = true;
@ -49,6 +46,7 @@
pkgs.ghostty pkgs.ghostty
pkgs.helix pkgs.helix
pkgs.neovim pkgs.neovim
pkgs.xterm
pkgs.zig_0_13 pkgs.zig_0_13
]; ];
@ -81,6 +79,4 @@
services.xserver = { services.xserver = {
enable = true; enable = true;
}; };
system.stateVersion = "24.11";
} }