chore(modules): add tests for home-manager on darwin (#251)

* chore(modules): add tests for home-manager on darwin

* ci: use nix-fast-build for tests

this also enables the new darwin tests

* chore(tests): disable unsupported modules on darwin

* docs: add `tests` scope to CONTRIBUTING.md

* fix(home-manager): exclude `gtk.catppuccin.icon` from global enable

this was accidentally enabled by default only with `catppuccin.enable`

* fix(tests): build activationPackage for darwin
This commit is contained in:
seth 2024-06-29 14:09:49 +00:00 committed by GitHub
parent 63e0859743
commit 3fdc011242
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 280 additions and 213 deletions

View file

@ -54,6 +54,34 @@ jobs:
git push
fi
test:
name: Test Modules
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@V27
- name: Setup cache
uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Run tests
run: |
nix run \
--inputs-from ./dev \
github:Mic92/nix-fast-build -- \
--no-nom \
--flake "./dev#checks.$(nix eval --raw --impure --expr builtins.currentSystem)"
validate-sources:
name: Validate sources
@ -70,31 +98,3 @@ jobs:
run: |
set -e
nix eval --file ./.github/checkSources.nix
vm:
name: Test Modules
runs-on: ubuntu-latest
strategy:
matrix:
test: [unstable, stable]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@V27
- name: Setup cache
uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Run VM
env:
TEST: ${{ matrix.test }}
run: |
nix build \
--print-build-logs \
--show-trace \
"./dev#checks.x86_64-linux.module-test-$TEST"

View file

@ -54,8 +54,8 @@ describes the motivation and content of the commit.
### Commit scopes
Available commit scopes are port names, `nixos`, `home-manager`, and `modules`. If
none of these apply, omit the scope.
Available commit scopes are port names, `nixos`, `home-manager`, `modules`, and
`tests`. If none of these apply, omit the scope.
### Breaking changes

View file

@ -79,11 +79,10 @@
system,
...
}:
lib.optionalAttrs pkgs.stdenv.isLinux {
module-test-unstable = pkgs.callPackage ../test.nix { inherit home-manager; };
module-test-stable = nixpkgsFor.${system}.stable.callPackage ../test.nix {
home-manager = home-manager-stable;
};
import ../tests {
inherit lib home-manager home-manager-stable;
nixpkgs = pkgs;
nixpkgs-stable = nixpkgsFor.${system}.stable;
}
);

View file

@ -19,39 +19,48 @@ let
enable = cfg.enable && config.gtk.enable;
in
{
options.gtk.catppuccin = ctp.mkCatppuccinOpt { name = "gtk"; } // {
# NOTE: we are overriding the previous declaration of `enable` here
# as this module is deprecated and we do not want it to apply with
# the global `catppuccin.enable`
enable = mkEnableOption "Catppuccin theme";
options.gtk.catppuccin =
ctp.mkCatppuccinOpt {
name = "gtk";
enableDefault = false;
}
// {
accent = ctp.mkAccentOpt "gtk";
accent = ctp.mkAccentOpt "gtk";
size = mkOption {
type = types.enum [
"standard"
"compact"
];
default = "standard";
description = "Catppuccin size variant for gtk";
};
tweaks = mkOption {
type = types.listOf (
types.enum [
"black"
"rimless"
"normal"
]
);
default = [ "normal" ];
description = "Catppuccin tweaks for gtk";
};
size = mkOption {
type = types.enum [
"standard"
"compact"
];
default = "standard";
description = "Catppuccin size variant for gtk";
};
gnomeShellTheme = mkEnableOption "Catppuccin gtk theme for GNOME Shell";
tweaks = mkOption {
type = types.listOf (
types.enum [
"black"
"rimless"
"normal"
]
);
default = [ "normal" ];
description = "Catppuccin tweaks for gtk";
};
icon = ctp.mkCatppuccinOpt { name = "GTK modified Papirus icon theme"; } // {
accent = ctp.mkAccentOpt "GTK modified Papirus icon theme";
gnomeShellTheme = mkEnableOption "Catppuccin gtk theme for GNOME Shell";
icon =
ctp.mkCatppuccinOpt {
name = "GTK modified Papirus icon theme";
# NOTE: we exclude this from the global `catppuccin.enable` as there is no
# `enable` option in the upstream module to guard it
enableDefault = false;
}
// {
accent = ctp.mkAccentOpt "GTK modified Papirus icon theme";
};
};
};
imports = [
(mkRenamedOptionModule

149
test.nix
View file

@ -1,149 +0,0 @@
{
testers,
fetchFromGitHub,
home-manager,
}:
let
common = {
catppuccin = {
enable = true;
sources = {
# this is used to ensure that we are able to apply
# source overrides without breaking the other sources
palette = fetchFromGitHub {
owner = "catppuccin";
repo = "palette";
rev = "16726028c518b0b94841de57cf51f14c095d43d8"; # refs/tags/1.1.1~1
hash = "sha256-qZjMlZFTzJotOYjURRQMsiOdR2XGGba8XzXwx4+v9tk=";
};
};
};
};
# shorthand for enabling a module
enable = {
enable = true;
};
in
testers.runNixOSTest {
name = "module-test";
nodes.machine =
{ lib, pkgs, ... }:
{
imports = [
home-manager.nixosModules.default
./modules/nixos
common
];
boot = {
loader.grub = enable;
plymouth = enable;
};
services = {
displayManager.sddm = enable // {
package = pkgs.kdePackages.sddm; # our module/the upstream port requires the qt6 version
};
xserver.enable = true; # required for sddm
};
console = enable;
users.users.test = {
isNormalUser = true;
home = "/home/test";
};
virtualisation = {
memorySize = 4096;
writableStore = true;
};
home-manager.users.test = {
imports = [
./modules/home-manager
common
];
xdg.enable = true;
home = {
username = "test";
stateVersion = lib.mkDefault "23.11";
};
manual.manpages.enable = lib.mkDefault false;
i18n.inputMethod.enabled = "fcitx5";
programs = {
alacritty = enable;
bat = enable;
bottom = enable;
btop = enable;
cava = enable;
fish = enable;
foot = enable;
fzf = enable;
gh-dash = enable;
git = enable // {
delta = enable;
};
gitui = enable;
# this is enabled by default already, but still
# listing explicitly so we know it's tested
glamour.catppuccin.enable = true;
helix = enable;
imv = enable;
k9s = enable;
kitty = enable;
lazygit = enable;
micro = enable;
mpv = enable;
neovim = enable;
newsboat = enable;
rio = enable;
rofi = enable;
skim = enable;
starship = enable;
swaylock = enable;
tmux = enable;
tofi = enable;
waybar = enable;
yazi = enable;
zathura = enable;
zellij = enable;
zsh = enable // {
syntaxHighlighting = enable;
};
};
qt = enable // {
platformTheme.name = "kvantum";
style.name = "kvantum";
};
services = {
dunst = enable;
mako = enable;
polybar = enable // {
script = ''
polybar top &
'';
};
};
wayland.windowManager.sway = enable;
wayland.windowManager.hyprland = enable;
};
};
testScript = _: ''
machine.start()
machine.wait_for_unit("home-manager-test.service")
machine.wait_until_succeeds("systemctl status home-manager-test.service")
machine.succeed("echo \"system started!\"")
'';
}

16
tests/common.nix Normal file
View file

@ -0,0 +1,16 @@
{ pkgs, ... }:
{
catppuccin = {
enable = true;
sources = {
# this is used to ensure that we are able to apply
# source overrides without breaking the other sources
palette = pkgs.fetchFromGitHub {
owner = "catppuccin";
repo = "palette";
rev = "16726028c518b0b94841de57cf51f14c095d43d8"; # refs/tags/1.1.1~1
hash = "sha256-qZjMlZFTzJotOYjURRQMsiOdR2XGGba8XzXwx4+v9tk=";
};
};
};
}

43
tests/darwin.nix Normal file
View file

@ -0,0 +1,43 @@
{
lib,
pkgs,
home-manager,
}:
(home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
./home.nix
{
home = {
homeDirectory = "/Users/test";
};
i18n.inputMethod.enabled = lib.mkForce null;
programs = {
cava.enable = lib.mkForce false; # NOTE: this may actually work on darwin, but the package is currently not supported
foot.enable = lib.mkForce false;
imv.enable = lib.mkForce false;
mpv.enable = lib.mkForce false; # NOTE: same as cava, but `mpv` fails to build currently
rofi.enable = lib.mkForce false;
swaylock.enable = lib.mkForce false;
tofi.enable = lib.mkForce false;
waybar.enable = lib.mkForce false;
};
qt.enable = lib.mkForce false; # NOTE: same as cava
services = {
dunst.enable = lib.mkForce false;
mako.enable = lib.mkForce false;
polybar.enable = lib.mkForce false;
};
wayland.windowManager = {
hyprland.enable = lib.mkForce false;
sway.enable = lib.mkForce false;
};
}
];
}).activationPackage

17
tests/default.nix Normal file
View file

@ -0,0 +1,17 @@
{
lib,
nixpkgs,
nixpkgs-stable,
home-manager,
home-manager-stable,
}:
lib.optionalAttrs nixpkgs.stdenv.isLinux {
nixos-test-unstable = nixpkgs.callPackage ./nixos.nix { inherit home-manager; };
nixos-test-stable = nixpkgs-stable.callPackage ./nixos.nix { home-manager = home-manager-stable; };
}
// lib.optionalAttrs nixpkgs.stdenv.isDarwin {
darwin-test-unstable = nixpkgs.callPackage ./darwin.nix { inherit home-manager; };
darwin-test-stable = nixpkgs-stable.callPackage ./darwin.nix {
home-manager = home-manager-stable;
};
}

82
tests/home.nix Normal file
View file

@ -0,0 +1,82 @@
{ lib, ... }:
{
imports = [
../modules/home-manager
./common.nix
];
xdg.enable = true;
home = {
username = "test";
stateVersion = lib.mkDefault "23.11";
};
manual.manpages.enable = lib.mkDefault false;
i18n.inputMethod.enabled = "fcitx5";
programs = {
alacritty.enable = true;
bat.enable = true;
bottom.enable = true;
btop.enable = true;
cava.enable = true;
fish.enable = true;
foot.enable = true;
fzf.enable = true;
gh-dash.enable = true;
git = {
enable = true;
delta.enable = true;
};
gitui.enable = true;
# this is enabled by default already, but still
# listing explicitly so we know it's tested
glamour.catppuccin.enable = true;
helix.enable = true;
imv.enable = true;
k9s.enable = true;
kitty.enable = true;
lazygit.enable = true;
micro.enable = true;
mpv.enable = true;
neovim.enable = true;
newsboat.enable = true;
rio.enable = true;
rofi.enable = true;
skim.enable = true;
starship.enable = true;
swaylock.enable = true;
tmux.enable = true;
tofi.enable = true;
waybar.enable = true;
yazi.enable = true;
zathura.enable = true;
zellij.enable = true;
zsh = {
enable = true;
syntaxHighlighting.enable = true;
};
};
qt = {
enable = true;
platformTheme.name = "kvantum";
style.name = "kvantum";
};
services = {
dunst.enable = true;
mako.enable = true;
polybar = {
enable = true;
script = ''
polybar top &
'';
};
};
wayland.windowManager.sway.enable = true;
wayland.windowManager.hyprland.enable = true;
}

50
tests/nixos.nix Normal file
View file

@ -0,0 +1,50 @@
{ testers, home-manager }:
testers.runNixOSTest {
name = "module-test";
nodes.machine =
{ lib, pkgs, ... }:
{
imports = [
home-manager.nixosModules.default
../modules/nixos
./common.nix
];
boot = {
loader.grub.enable = true;
plymouth.enable = true;
};
services = {
displayManager.sddm = {
enable = true;
package = pkgs.kdePackages.sddm; # our module/the upstream port requires the qt6 version
};
xserver.enable = true; # required for sddm
};
console.enable = true;
users.users.test = {
isNormalUser = true;
home = "/home/test";
};
virtualisation = {
memorySize = 4096;
writableStore = true;
};
home-manager.users.test = {
imports = [ ./home.nix ];
};
};
testScript = _: ''
machine.start()
machine.wait_for_unit("home-manager-test.service")
machine.wait_until_succeeds("systemctl status home-manager-test.service")
machine.succeed("echo \"system started!\"")
'';
}