diff --git a/flake.lock b/flake.lock index 708c9b3c1..72f49b092 100644 --- a/flake.lock +++ b/flake.lock @@ -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": { diff --git a/flake.nix b/flake.nix index 8e2128527..eefa18851 100644 --- a/flake.nix +++ b/flake.nix @@ -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: { diff --git a/modules/gnome/testbed.nix b/modules/gnome/testbed.nix new file mode 100644 index 000000000..fa3a15cd7 --- /dev/null +++ b/modules/gnome/testbed.nix @@ -0,0 +1,7 @@ +{ + services.xserver = { + enable = true; + desktopManager.gnome.enable = true; + displayManager.gdm.enable = true; + }; +} diff --git a/modules/kde/testbed.nix b/modules/kde/testbed.nix new file mode 100644 index 000000000..a4a62dfb7 --- /dev/null +++ b/modules/kde/testbed.nix @@ -0,0 +1,7 @@ +{ + services.xserver = { + enable = true; + desktopManager.plasma5.enable = true; + displayManager.sddm.enable = true; + }; +} diff --git a/stylix/testbed.nix b/stylix/testbed.nix new file mode 100644 index 000000000..d060e07c5 --- /dev/null +++ b/stylix/testbed.nix @@ -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))