stylix: move testbed modules to their own files
Introduce `user.toml` for storing shared user info.
This commit is contained in:
parent
c765b15fc3
commit
7afee8f85b
6 changed files with 194 additions and 180 deletions
|
|
@ -6,182 +6,6 @@
|
|||
}:
|
||||
|
||||
let
|
||||
username = "guest";
|
||||
|
||||
commonModule =
|
||||
{ config, ... }:
|
||||
{
|
||||
users.users.${username} = {
|
||||
description = "Guest";
|
||||
hashedPassword = "";
|
||||
isNormalUser = true;
|
||||
extraGroups = [ "wheel" ];
|
||||
};
|
||||
|
||||
security.sudo.wheelNeedsPassword = false;
|
||||
|
||||
services.getty.autologinUser = username;
|
||||
|
||||
nixpkgs.config.allowAliases = false;
|
||||
|
||||
# The state version can safely track the latest release because the disk
|
||||
# image is ephemeral.
|
||||
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;
|
||||
};
|
||||
};
|
||||
|
||||
enableModule =
|
||||
{ lib, config, ... }:
|
||||
{
|
||||
options.stylix.testbed.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
example = lib.literalExpression "lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.discord";
|
||||
description = ''
|
||||
Whether to enable this testbed.
|
||||
|
||||
The testbed will not be included as a flake output if set to false.
|
||||
|
||||
> [!CAUTION]
|
||||
>
|
||||
> This option can only access `lib` and `pkgs` inputs. Attempting to
|
||||
> read other inputs, like `config` or `options`, will cause the
|
||||
> testbed evaluation to fail.
|
||||
>
|
||||
> This is a performance-driven restriction, as noted in `isEnabled`.
|
||||
'';
|
||||
};
|
||||
|
||||
config.assertions = [
|
||||
{
|
||||
assertion = config.stylix.testbed.enable;
|
||||
message = "Building a disabled testbed. This testbed should have been filtered out!";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
applicationModule =
|
||||
{ config, lib, ... }:
|
||||
{
|
||||
options.stylix.testbed.ui = lib.mkOption {
|
||||
type = lib.types.nullOr (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable a standard configuration for testing graphical
|
||||
applications.
|
||||
|
||||
This will automatically log in as the `${username}` user and launch
|
||||
an application or command.
|
||||
|
||||
This is currently based on GNOME, but the specific desktop environment
|
||||
used may change in the future.
|
||||
'';
|
||||
};
|
||||
application = lib.mkOption {
|
||||
description = ''
|
||||
Options defining an application to be launched using its provided
|
||||
`.desktop` entry.
|
||||
'';
|
||||
type = lib.types.nullOr (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The name of the desktop entry for the application, without the
|
||||
`.desktop` extension.
|
||||
'';
|
||||
};
|
||||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
description = ''
|
||||
The package providing the binary and desktop entry of the
|
||||
application being tested.
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = null;
|
||||
};
|
||||
command = lib.mkOption {
|
||||
type = lib.types.nullOr (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
text = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The command which will be run once the graphical environment has
|
||||
loaded.
|
||||
'';
|
||||
};
|
||||
useTerminal = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Whether or not to spawn a terminal when running the command.
|
||||
'';
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = null;
|
||||
};
|
||||
|
||||
config = lib.mkIf (config.stylix.testbed.ui != null) {
|
||||
services.xserver = {
|
||||
enable = true;
|
||||
displayManager.gdm.enable = true;
|
||||
desktopManager.gnome.enable = true;
|
||||
};
|
||||
|
||||
services.displayManager.autoLogin = {
|
||||
enable = true;
|
||||
user = username;
|
||||
};
|
||||
|
||||
# Disable the GNOME tutorial which pops up on first login.
|
||||
environment.gnome.excludePackages = [ pkgs.gnome-tour ];
|
||||
|
||||
# for use when application is set
|
||||
environment.systemPackages =
|
||||
lib.optional (config.stylix.testbed.ui.command != null) (
|
||||
pkgs.makeAutostartItem {
|
||||
name = "stylix-testbed";
|
||||
package = pkgs.makeDesktopItem {
|
||||
name = "stylix-testbed";
|
||||
desktopName = "stylix-testbed";
|
||||
exec = toString (
|
||||
pkgs.writeShellScript "startup" config.stylix.testbed.ui.command.text
|
||||
);
|
||||
terminal = config.stylix.testbed.ui.command.useTerminal;
|
||||
};
|
||||
}
|
||||
)
|
||||
++ lib.optional (config.stylix.testbed.ui.application != null) (
|
||||
pkgs.makeAutostartItem {
|
||||
inherit (config.stylix.testbed.ui.application) name package;
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
# Creates a minimal configuration to extract the `stylix.testbed.enable`
|
||||
# option value.
|
||||
#
|
||||
|
|
@ -194,7 +18,7 @@ let
|
|||
minimal = lib.evalModules {
|
||||
modules = [
|
||||
module
|
||||
enableModule
|
||||
./modules/enable.nix
|
||||
{ _module.check = false; }
|
||||
{ _module.args = { inherit pkgs; }; }
|
||||
];
|
||||
|
|
@ -261,9 +85,9 @@ let
|
|||
inherit (pkgs) system;
|
||||
|
||||
modules = [
|
||||
commonModule
|
||||
enableModule
|
||||
applicationModule
|
||||
./modules/common.nix
|
||||
./modules/enable.nix
|
||||
./modules/application.nix
|
||||
inputs.self.nixosModules.stylix
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
testbed.path
|
||||
|
|
|
|||
10
stylix/testbed/modules/README.md
Normal file
10
stylix/testbed/modules/README.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# Testbed modules
|
||||
|
||||
This directory contains modules used by **all** testbeds.
|
||||
|
||||
If you want to introduce a new testbed for your target, you should instead add
|
||||
a file at `modules/«target»/testbeds/«target».nix`.
|
||||
|
||||
See [testbed documentation].
|
||||
|
||||
[testbed documentation]: https://nix-community.github.io/stylix/testbeds.html
|
||||
122
stylix/testbed/modules/application.nix
Normal file
122
stylix/testbed/modules/application.nix
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
{
|
||||
lib,
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
user = lib.importTOML ../user.toml;
|
||||
in
|
||||
{
|
||||
options.stylix.testbed.ui = lib.mkOption {
|
||||
type = lib.types.nullOr (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = ''
|
||||
Whether to enable a standard configuration for testing graphical
|
||||
applications.
|
||||
|
||||
This will automatically log in as the `${user.username}` user and launch
|
||||
an application or command.
|
||||
|
||||
This is currently based on GNOME, but the specific desktop environment
|
||||
used may change in the future.
|
||||
'';
|
||||
};
|
||||
application = lib.mkOption {
|
||||
description = ''
|
||||
Options defining an application to be launched using its provided
|
||||
`.desktop` entry.
|
||||
'';
|
||||
type = lib.types.nullOr (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
name = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The name of the desktop entry for the application, without the
|
||||
`.desktop` extension.
|
||||
'';
|
||||
};
|
||||
|
||||
package = lib.mkOption {
|
||||
type = lib.types.package;
|
||||
description = ''
|
||||
The package providing the binary and desktop entry of the
|
||||
application being tested.
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = null;
|
||||
};
|
||||
command = lib.mkOption {
|
||||
type = lib.types.nullOr (
|
||||
lib.types.submodule {
|
||||
options = {
|
||||
text = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = ''
|
||||
The command which will be run once the graphical environment has
|
||||
loaded.
|
||||
'';
|
||||
};
|
||||
useTerminal = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
description = ''
|
||||
Whether or not to spawn a terminal when running the command.
|
||||
'';
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
default = null;
|
||||
};
|
||||
|
||||
config = lib.mkIf (config.stylix.testbed.ui != null) {
|
||||
services.xserver = {
|
||||
enable = true;
|
||||
displayManager.gdm.enable = true;
|
||||
desktopManager.gnome.enable = true;
|
||||
};
|
||||
|
||||
services.displayManager.autoLogin = {
|
||||
enable = true;
|
||||
user = user.username;
|
||||
};
|
||||
|
||||
# Disable the GNOME tutorial which pops up on first login.
|
||||
environment.gnome.excludePackages = [ pkgs.gnome-tour ];
|
||||
|
||||
# for use when application is set
|
||||
environment.systemPackages =
|
||||
lib.optional (config.stylix.testbed.ui.command != null) (
|
||||
pkgs.makeAutostartItem {
|
||||
name = "stylix-testbed";
|
||||
package = pkgs.makeDesktopItem {
|
||||
name = "stylix-testbed";
|
||||
desktopName = "stylix-testbed";
|
||||
exec = toString (
|
||||
pkgs.writeShellScript "startup" config.stylix.testbed.ui.command.text
|
||||
);
|
||||
terminal = config.stylix.testbed.ui.command.useTerminal;
|
||||
};
|
||||
}
|
||||
)
|
||||
++ lib.optional (config.stylix.testbed.ui.application != null) (
|
||||
pkgs.makeAutostartItem {
|
||||
inherit (config.stylix.testbed.ui.application) name package;
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
25
stylix/testbed/modules/common.nix
Normal file
25
stylix/testbed/modules/common.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{ lib, config, ... }:
|
||||
let
|
||||
user = lib.importTOML ../user.toml;
|
||||
in
|
||||
{
|
||||
users.users.${user.username} = builtins.removeAttrs user [ "username" ];
|
||||
|
||||
security.sudo.wheelNeedsPassword = false;
|
||||
|
||||
services.getty.autologinUser = user.username;
|
||||
|
||||
nixpkgs.config.allowAliases = false;
|
||||
|
||||
# The state version can safely track the latest release because the disk
|
||||
# image is ephemeral.
|
||||
system.stateVersion = config.system.nixos.release;
|
||||
home-manager.users.${user.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;
|
||||
};
|
||||
}
|
||||
28
stylix/testbed/modules/enable.nix
Normal file
28
stylix/testbed/modules/enable.nix
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
{ lib, config, ... }:
|
||||
{
|
||||
options.stylix.testbed.enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
example = lib.literalExpression "lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.discord";
|
||||
description = ''
|
||||
Whether to enable this testbed.
|
||||
|
||||
The testbed will not be included as a flake output if set to false.
|
||||
|
||||
> [!CAUTION]
|
||||
>
|
||||
> This option can only access `lib` and `pkgs` inputs. Attempting to
|
||||
> read other inputs, like `config` or `options`, will cause the
|
||||
> testbed evaluation to fail.
|
||||
>
|
||||
> This is a performance-driven restriction, as noted in `isEnabled`.
|
||||
'';
|
||||
};
|
||||
|
||||
config.assertions = [
|
||||
{
|
||||
assertion = config.stylix.testbed.enable;
|
||||
message = "Building a disabled testbed. This testbed should have been filtered out!";
|
||||
}
|
||||
];
|
||||
}
|
||||
5
stylix/testbed/user.toml
Normal file
5
stylix/testbed/user.toml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
username = "guest"
|
||||
description = "Guest"
|
||||
hashedPassword = ""
|
||||
isNormalUser = true
|
||||
extraGroups = [ "wheel" ]
|
||||
Loading…
Add table
Add a link
Reference in a new issue