stylix: add testbeds for desktop environments (#320)

Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
This commit is contained in:
Daniel Thwaites 2024-04-18 09:10:23 +01:00 committed by GitHub
parent 83866ed880
commit b36fb34a9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 128 additions and 13 deletions

12
flake.lock generated
View file

@ -203,11 +203,11 @@
]
},
"locked": {
"lastModified": 1706001011,
"narHash": "sha256-J7Bs9LHdZubgNHZ6+eE/7C18lZ1P6S5/zdJSdXFItI4=",
"lastModified": 1711915616,
"narHash": "sha256-co6LoFA+j6BZEeJNSR8nZ4oOort5qYPskjrDHBaJgmo=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "3df2a80f3f85f91ea06e5e91071fa74ba92e5084",
"rev": "820be197ccf3adaad9a8856ef255c13b6cc561a6",
"type": "github"
},
"original": {
@ -218,11 +218,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1700856099,
"narHash": "sha256-RnEA7iJ36Ay9jI0WwP+/y4zjEhmeN6Cjs9VOFBH7eVQ=",
"lastModified": 1711715736,
"narHash": "sha256-9slQ609YqT9bT/MNX9+5k5jltL9zgpn36DpFB7TkttM=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0bd59c54ef06bc34eca01e37d689f5e46b3fe2f1",
"rev": "807c549feabce7eddbf259dbdcec9e0600a0660d",
"type": "github"
},
"original": {

View file

@ -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: {

View file

@ -0,0 +1,7 @@
{
services.xserver = {
enable = true;
desktopManager.gnome.enable = true;
displayManager.gdm.enable = true;
};
}

7
modules/kde/testbed.nix Normal file
View file

@ -0,0 +1,7 @@
{
services.xserver = {
enable = true;
desktopManager.plasma5.enable = true;
displayManager.sddm.enable = true;
};
}

94
stylix/testbed.nix Normal file
View file

@ -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))