Skip to content

Commit

Permalink
stylix: add testbeds for desktop environments (#320)
Browse files Browse the repository at this point in the history
Co-authored-by: NAHO <[email protected]>
  • Loading branch information
danth and trueNAHO authored Apr 18, 2024
1 parent 83866ed commit b36fb34
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 13 deletions.
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,22 @@
"x86_64-linux"
] (
system:
let pkgs = nixpkgs.legacyPackages.${system};
in {
docs = import ./docs {
inherit pkgs inputs;
inherit (nixpkgs) lib;
let
inherit (nixpkgs) lib;
pkgs = nixpkgs.legacyPackages.${system};

universalPackages = {
docs = import ./docs { inherit pkgs inputs lib; };
palette-generator = pkgs.callPackage ./palette-generator { };
};

palette-generator = pkgs.callPackage ./palette-generator { };
}
# Testbeds are virtual machines based on NixOS, therefore they are
# only available for Linux systems.
testbedPackages = lib.optionalAttrs
(lib.hasSuffix "-linux" system)
(import ./stylix/testbed.nix { inherit pkgs inputs lib; });
in
universalPackages // testbedPackages
);

nixosModules.stylix = { pkgs, ... }@args: {
Expand Down
7 changes: 7 additions & 0 deletions modules/gnome/testbed.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
services.xserver = {
enable = true;
desktopManager.gnome.enable = true;
displayManager.gdm.enable = true;
};
}
7 changes: 7 additions & 0 deletions modules/kde/testbed.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
services.xserver = {
enable = true;
desktopManager.plasma5.enable = true;
displayManager.sddm.enable = true;
};
}
94 changes: 94 additions & 0 deletions stylix/testbed.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{ pkgs, inputs, lib, ... }:

let
username = "guest";

commonModule = { config, ... }: {
users.users.${username} = {
description = "Guest";
hashedPassword = "";
isNormalUser = true;
};

# The state version can safely track the latest release because the disk
# image is ephermal.
system.stateVersion = config.system.nixos.release;
home-manager.users.${username}.home.stateVersion = config.system.nixos.release;

virtualisation.vmVariant.virtualisation = {
# This is a maximum limit; the VM should still work if the host has fewer cores.
cores = 4;
memorySize = lib.mkDefault 2048;
};
};

autoload = builtins.concatLists
(lib.mapAttrsToList
(name: _:
let testbed = {
inherit name;
module = "${../modules}/${name}/testbed.nix";
};
in
lib.optional (builtins.pathExists testbed.module) testbed
)
(builtins.readDir ../modules));

makeTestbed =
testbed: stylix:
let
name = "testbed-${testbed.name}-${stylix.polarity}";

system = lib.nixosSystem {
inherit (pkgs) system;

modules = [
commonModule
inputs.self.nixosModules.stylix
inputs.home-manager.nixosModules.home-manager
testbed.module

{
inherit stylix;
system.name = name;
}
];
};

script = pkgs.writeShellApplication {
inherit name;
text = ''
cleanup() {
if rm --recursive "$directory"; then
printf '%s\n' 'Virtualisation disk image removed.'
fi
}
# We create a temporary directory rather than a temporary file, since
# temporary files are created empty and are not valid disk images.
directory="$(mktemp --directory)"
trap cleanup EXIT
NIX_DISK_IMAGE="$directory/nixos.qcow2" \
${lib.getExe system.config.system.build.vm}
'';
};
in
lib.nameValuePair name script;

# This generates a copy of each testbed for each of the following themes.
makeTestbeds = testbed: map (makeTestbed testbed) [
{
image = "${pkgs.pantheon.elementary-wallpapers}/share/backgrounds/Photo of Valley.jpg";
base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-latte.yaml";
polarity = "light";
}
{
image = "${pkgs.pantheon.elementary-wallpapers}/share/backgrounds/Snow-Capped Mountain.jpg";
base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-macchiato.yaml";
polarity = "dark";
}
];

in
lib.listToAttrs (lib.flatten (map makeTestbeds autoload))

0 comments on commit b36fb34

Please sign in to comment.