mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-07-12 15:42:39 +02:00
feat: unit tests
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
name: Nix Flake Check
|
|
||||||
|
|
||||||
on: [push, pull_request, workflow_dispatch]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
checks:
|
|
||||||
name: Check expressions
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
# - name: Checkout repository
|
|
||||||
# uses: actions/checkout@v4
|
|
||||||
# - name: Install nix
|
|
||||||
# uses: cachix/install-nix-action@v24
|
|
||||||
# with:
|
|
||||||
# install_url: https://nixos.org/nix/install
|
|
||||||
# extra_nix_config: |
|
|
||||||
# access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
|
||||||
# experimental-features = nix-command flakes
|
|
||||||
|
|
||||||
- name: Run Nix Flake Check
|
|
||||||
run: |
|
|
||||||
echo 'TODO: nix flake check'
|
|
||||||
# nix flake check
|
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
name: Nix Flake Unit Tests
|
||||||
|
|
||||||
|
on: [push, pull_request, workflow_dispatch]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
checks:
|
||||||
|
name: Check expressions
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout repository
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
- name: Install nix
|
||||||
|
uses: cachix/install-nix-action@v24
|
||||||
|
with:
|
||||||
|
install_url: https://nixos.org/nix/install
|
||||||
|
extra_nix_config: |
|
||||||
|
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
|
||||||
|
experimental-features = nix-command flakes
|
||||||
|
|
||||||
|
- name: Run Nix Flake Unit Tests
|
||||||
|
run: |
|
||||||
|
echo 'Flake Unit Tests'
|
||||||
|
nix eval .#unitTests --show-trace --print-build-logs --verbose
|
||||||
+8
-2
@@ -7,6 +7,14 @@ There is no need to do this when you have a small number of machines.
|
|||||||
But when you have a large number of machines, it is necessary to manage them in a fine-grained way,
|
But when you have a large number of machines, it is necessary to manage them in a fine-grained way,
|
||||||
otherwise, it will be difficult to manage and maintain them.
|
otherwise, it will be difficult to manage and maintain them.
|
||||||
|
|
||||||
|
## Unit Tests
|
||||||
|
|
||||||
|
Unit Tests for all flake outputs(only NixOS systems currently).
|
||||||
|
|
||||||
|
```bash
|
||||||
|
nix eval .#unitTests --show-trace --print-build-logs --verbose
|
||||||
|
```
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
All the outputs of this flake are defined here.
|
All the outputs of this flake are defined here.
|
||||||
@@ -56,5 +64,3 @@ All the outputs of this flake are defined here.
|
|||||||
|
|
||||||
12 directories, 28 files
|
12 directories, 28 files
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -19,12 +19,3 @@
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
outputs
|
outputs
|
||||||
// {
|
|
||||||
inherit data; # for debugging purposes
|
|
||||||
|
|
||||||
# NixOS's unit tests.
|
|
||||||
# unit-tests = haumea.lib.loadEvalTests {
|
|
||||||
# src = ./tests;
|
|
||||||
# inputs = args;
|
|
||||||
# };
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ in
|
|||||||
inherit data; # for debugging purposes
|
inherit data; # for debugging purposes
|
||||||
|
|
||||||
# NixOS's unit tests.
|
# NixOS's unit tests.
|
||||||
# unit-tests = haumea.lib.loadEvalTests {
|
unitTests = haumea.lib.loadEvalTests {
|
||||||
# src = ./tests;
|
src = ./tests;
|
||||||
# inputs = args;
|
inputs = args // {inherit outputs;};
|
||||||
# };
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}: let
|
||||||
|
hostsNames = builtins.attrNames outputs.nixosConfigurations;
|
||||||
|
expected = lib.genAttrs hostsNames (name: name);
|
||||||
|
in
|
||||||
|
expected
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}:
|
||||||
|
lib.genAttrs
|
||||||
|
(builtins.attrNames outputs.nixosConfigurations)
|
||||||
|
(
|
||||||
|
name: outputs.nixosConfigurations.${name}.config.networking.hostName
|
||||||
|
)
|
||||||
+3
-3
@@ -52,6 +52,9 @@ in {
|
|||||||
# add attribute sets into outputs, for debugging
|
# add attribute sets into outputs, for debugging
|
||||||
debugAttrs = {inherit nixosSystems darwinSystems allSystems allSystemNames;};
|
debugAttrs = {inherit nixosSystems darwinSystems allSystems allSystemNames;};
|
||||||
|
|
||||||
|
# Unit Tests for all NixOS systems.
|
||||||
|
unitTests = lib.lists.all (it: it.unitTests == {}) nixosSystemValues;
|
||||||
|
|
||||||
# NixOS Hosts
|
# NixOS Hosts
|
||||||
nixosConfigurations =
|
nixosConfigurations =
|
||||||
lib.attrsets.mergeAttrsList (map (it: it.nixosConfigurations or {}) nixosSystemValues);
|
lib.attrsets.mergeAttrsList (map (it: it.nixosConfigurations or {}) nixosSystemValues);
|
||||||
@@ -89,9 +92,6 @@ in {
|
|||||||
# Unit Tests, Intergraded Tests, and Pre-commit checks
|
# Unit Tests, Intergraded Tests, and Pre-commit checks
|
||||||
checks = forAllSystems (
|
checks = forAllSystems (
|
||||||
system: {
|
system: {
|
||||||
# Unit Tests for the system
|
|
||||||
# unit-tests = allSystems.${system}.unit-tests;
|
|
||||||
|
|
||||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
hooks = {
|
hooks = {
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ in
|
|||||||
inherit data; # for debugging purposes
|
inherit data; # for debugging purposes
|
||||||
|
|
||||||
# NixOS's unit tests.
|
# NixOS's unit tests.
|
||||||
# unit-tests = haumea.lib.loadEvalTests {
|
unitTests = haumea.lib.loadEvalTests {
|
||||||
# src = ./tests;
|
src = ./tests;
|
||||||
# inputs = args;
|
inputs = args // {inherit outputs;};
|
||||||
# };
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}: let
|
||||||
|
hostsNames = builtins.attrNames outputs.nixosConfigurations;
|
||||||
|
expected = lib.genAttrs hostsNames (name: name);
|
||||||
|
in
|
||||||
|
expected
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}:
|
||||||
|
lib.genAttrs
|
||||||
|
(builtins.attrNames outputs.nixosConfigurations)
|
||||||
|
(
|
||||||
|
name: outputs.nixosConfigurations.${name}.config.networking.hostName
|
||||||
|
)
|
||||||
@@ -19,12 +19,3 @@
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
outputs
|
outputs
|
||||||
// {
|
|
||||||
inherit data; # for debugging purposes
|
|
||||||
|
|
||||||
# NixOS's unit tests.
|
|
||||||
# unit-tests = haumea.lib.loadEvalTests {
|
|
||||||
# src = ./tests;
|
|
||||||
# inputs = args;
|
|
||||||
# };
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ in
|
|||||||
inherit data; # for debugging purposes
|
inherit data; # for debugging purposes
|
||||||
|
|
||||||
# NixOS's unit tests.
|
# NixOS's unit tests.
|
||||||
# unit-tests = haumea.lib.loadEvalTests {
|
unitTests = haumea.lib.loadEvalTests {
|
||||||
# src = ./tests;
|
src = ./tests;
|
||||||
# inputs = args;
|
inputs = args // {inherit outputs;};
|
||||||
# };
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
myvars,
|
||||||
|
lib,
|
||||||
|
}: let
|
||||||
|
username = myvars.username;
|
||||||
|
hosts = [
|
||||||
|
"ai-hyprland"
|
||||||
|
"ai-i3"
|
||||||
|
"shoukei-hyprland"
|
||||||
|
"shoukei-i3"
|
||||||
|
"ruby"
|
||||||
|
"k3s-prod-1-master-1"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
lib.genAttrs hosts (_: "/home/${username}")
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
myvars,
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}: let
|
||||||
|
username = myvars.username;
|
||||||
|
hosts = [
|
||||||
|
"ai-hyprland"
|
||||||
|
"ai-i3"
|
||||||
|
"shoukei-hyprland"
|
||||||
|
"shoukei-i3"
|
||||||
|
"ruby"
|
||||||
|
"k3s-prod-1-master-1"
|
||||||
|
];
|
||||||
|
in
|
||||||
|
lib.genAttrs
|
||||||
|
hosts
|
||||||
|
(
|
||||||
|
name: outputs.nixosConfigurations.${name}.config.home-manager.users.${username}.home.homeDirectory
|
||||||
|
)
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}: let
|
||||||
|
specialExpected = {
|
||||||
|
"ai-hyprland" = "ai";
|
||||||
|
"ai-i3" = "ai";
|
||||||
|
"shoukei-hyprland" = "shoukei";
|
||||||
|
"shoukei-i3" = "shoukei";
|
||||||
|
};
|
||||||
|
specialHostNames = builtins.attrNames specialExpected;
|
||||||
|
|
||||||
|
otherHosts = builtins.removeAttrs outputs.nixosConfigurations specialHostNames;
|
||||||
|
otherHostsNames = builtins.attrNames otherHosts;
|
||||||
|
# other hosts's hostName is the same as the nixosConfigurations name
|
||||||
|
otherExpected = lib.genAttrs otherHostsNames (name: name);
|
||||||
|
in (specialExpected // otherExpected)
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}:
|
||||||
|
lib.genAttrs
|
||||||
|
(builtins.attrNames outputs.nixosConfigurations)
|
||||||
|
(
|
||||||
|
name: outputs.nixosConfigurations.${name}.config.networking.hostName
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user