tests/lib: init env-specific subset

This commit is contained in:
Gabriel Arazas 2024-03-08 16:39:13 +08:00
parent d5b4cfe3ba
commit 5d7859abb1
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
4 changed files with 120 additions and 2 deletions

View File

@ -1,4 +1,5 @@
{ pkgs }: # For the environment-specific subset, we'll be simulating the configurations
# as a simple attribute set since that's what they are anyways.
let let
inherit (pkgs) lib; inherit (pkgs) lib;
@ -16,5 +17,9 @@ let
in in
{ {
trivial = callLib ./trivial.nix; trivial = callLib ./trivial.nix;
#home-manager = callLib ./home-manager.nix;
# Environment-specific subset.
home-manager = callLib ./home-manager.nix;
nixos = callLib ./nixos.nix;
nixvim = callLib ./nixvim.nix;
} }

View File

@ -0,0 +1,57 @@
{ pkgs, lib, self }:
let
# We're just using stub configurations instead.
nixosConfig = {
programs = {
firefox = {
enable = true;
};
};
services = {
pipewire = {
enable = true;
wireplumber.enable = true;
alsa.enable = true;
alsa.support32Bit = true;
pulse.enable = true;
jack.enable = true;
};
};
};
hmConfig = {
services = {
activitywatch.enable = true;
bleachbit = {
enable = true;
cleaners = [
"firefox.cookies"
"discord.cache"
];
};
};
};
hmConfig' = {
inherit nixosConfig;
osConfig = nixosConfig;
} // hmConfig;
in
lib.runTests {
testHomeManagerStandaloneEmpty = {
expr = self.home-manager.hasNixOSConfigAttr { } [ "programs" "firefox" "enable" ] false;
expected = false;
};
testHomeManagerStandalone = {
expr = self.home-manager.hasNixOSConfigAttr hmConfig [ "programs" "firefox" "enable" ] false;
expected = false;
};
testHomeManagerWithinNixOS = {
expr = self.home-manager.hasNixOSConfigAttr hmConfig' [ "programs" "firefox" "enable" ] false;
expected = true;
};
}

28
tests/lib/nixos.nix Normal file
View File

@ -0,0 +1,28 @@
{ pkgs, lib, self }:
let
testConfig = {
formatAttr = "isoImage";
};
in
lib.runTests {
testNixSystemHasFormat = {
expr = self.nixos.hasNixosFormat testConfig;
expected = true;
};
testNixSystemNoFormat = {
expr = self.nixos.hasNixosFormat { };
expected = false;
};
testNixSystemFormatCompare = {
expr = self.nixos.isFormat testConfig "isoImage";
expected = true;
};
testNixSystemFormatCompare2 = {
expr = self.nixos.isFormat { } "isoImage";
expected = false;
};
}

28
tests/lib/nixvim.nix Normal file
View File

@ -0,0 +1,28 @@
{ pkgs, lib, self }:
let
nixvimConfig = {
plugins.lightline.enable = true;
plugins.neorg.enable = true;
};
nixosConfig = {
programs.firefox.enable = true;
};
nixvimConfig' = {
inherit nixosConfig;
} // nixvimConfig;
in
lib.runTests {
testNixvimIsStandalone = {
expr = self.nixvim.isStandalone nixvimConfig;
expected = true;
};
testNixvimIsStandalone2 = {
expr = self.nixvim.isStandalone nixvimConfig';
expected = false;
};
}