Files
pinpox 179ede09ae Replace deprecated stdenv.isLinux/isDarwin/isAarch64 with stdenv.hostPlatform equivalents
Fixes evaluation warnings like:
  stdenv.isLinux is deprecated, use stdenv.hostPlatform.isLinux instead
emitted while evaluating most checks.
2026-09-19 09:25:56 +02:00

180 lines
6.9 KiB
Nix

{
self,
lib,
inputs,
...
}:
let
inherit (lib)
attrNames
attrValues
elem
filter
filterAttrs
genAttrs
hasPrefix
pathExists
;
nixosLib = import (self.inputs.nixpkgs + "/nixos/lib") { };
in
{
imports = filter pathExists [
./devshell/flake-module.nix
./flash/flake-module.nix
./installation/flake-module.nix
./update/flake-module.nix
./ssh-agent-forwarding/flake-module.nix
./nixos-documentation/flake-module.nix
./dont-depend-on-repo-root.nix
# clan core submodule tests
../nixosModules/clanCore/machine-id/tests/flake-module.nix
../nixosModules/clanCore/postgresql/tests/flake-module.nix
../nixosModules/clanCore/state-version/tests/flake-module.nix
../nixosModules/clanCore/vars/tests/flake-module.nix
../nixosModules/clanCore/vars/tests/age-test-flake-module.nix
];
flake.check = genAttrs [ "x86_64-linux" "aarch64-darwin" ] (
system:
let
checks = filterAttrs (
name: _check:
!(hasPrefix "nixos-test-" name)
&& !(hasPrefix "nixos-" name)
&& !(hasPrefix "darwin-test-" name)
&& !(hasPrefix "service-" name)
&& !(hasPrefix "clan-test-" name)
&& !(hasPrefix "vars-check-" name)
&& !(hasPrefix "devShell-" name)
&& !(elem name [
"clan-deps"
])
) self.checks.${system};
in
inputs.nixpkgs.legacyPackages.${system}.runCommand "fast-flake-checks-${system}"
{ passthru.checks = checks; }
''
echo "Executed the following checks for ${system}..."
echo " - ${lib.concatStringsSep "\n" (map (n: " - " + n) (attrNames checks))}"
echo ${toString (attrValues checks)} >/dev/null
echo "All checks succeeded"
touch $out
''
);
perSystem =
{
pkgs,
lib,
self',
system,
...
}:
{
checks =
let
nixosTestArgs = {
# reference to nixpkgs for the current system
inherit pkgs lib nixosLib;
# this gives us a reference to our flake but also all flake inputs
inherit self;
inherit (self) clanLib;
clan-core = self;
};
nixosTests = lib.optionalAttrs (pkgs.stdenv.hostPlatform.isLinux) {
# Base Tests
nixos-test-secrets = self.clanLib.test.baseTest ./secrets nixosTestArgs;
nixos-test-wayland-proxy-virtwl = self.clanLib.test.baseTest ./wayland-proxy-virtwl nixosTestArgs;
# Container Tests
nixos-test-container = self.clanLib.test.containerTest ./container nixosTestArgs;
nixos-test-user-firewall-iptables = self.clanLib.test.containerTest ./user-firewall/iptables.nix nixosTestArgs;
nixos-test-user-firewall-nftables = self.clanLib.test.containerTest ./user-firewall/nftables.nix nixosTestArgs;
nixos-test-extra-python-packages = self.clanLib.test.containerTest ./test-extra-python-packages nixosTestArgs;
service-dummy-test = import ./service-dummy-test nixosTestArgs;
service-dummy-test-from-flake = import ./service-dummy-test-from-flake nixosTestArgs;
clan-test-iso = import ./clan-test-iso nixosTestArgs;
};
packagesToBuild = lib.removeAttrs self'.packages (
[
# exclude the check that checks that nothing depends on the repo root
# We might want to include this later once everything is fixed
"dont-depend-on-repo-root"
]
++ lib.optionals (pkgs.stdenv.hostPlatform.isDarwin) [
"docs"
"deploy-docs-v2"
# Our darwin CI is unable to run a headless browser, which is
# needed for rendering clan site's mermaid
"clan-site"
]
);
# Temporary workaround: Filter out docs package and devshell for aarch64-darwin due to CI builder hangs
# TODO: Remove this filter once macOS CI builder is updated
flakeOutputs =
lib.mapAttrs' (
name: config: lib.nameValuePair "nixos-${name}" config.config.system.build.toplevel
) (lib.filterAttrs (n: _: !lib.hasPrefix "test-" n) self.nixosConfigurations)
// lib.mapAttrs' (
name: config: lib.nameValuePair "darwin-${name}" config.config.system.build.toplevel
) (self.darwinConfigurations or { })
// {
all-packages = pkgs.runCommand "all-packages" { passthru.packages = packagesToBuild; } ''
echo "Built all packages for ${system}:"
${lib.concatMapStringsSep "\n" (n: "echo ' - ${n}'") (lib.attrNames packagesToBuild)}
echo ${toString (lib.attrValues packagesToBuild)} >/dev/null
touch $out
'';
}
// lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") (
if system == "aarch64-darwin" then
lib.filterAttrs (n: _: n != "docs") self'.devShells
else
self'.devShells
)
// lib.mapAttrs' (name: config: lib.nameValuePair "home-manager-${name}" config.activation-script) (
self'.legacyPackages.homeConfigurations or { }
);
# Unified eval-tests check: builds all nix-unit eval checks in one derivation.
# Individual eval checks are defined across the codebase as legacyPackages.evalCheck-<name>
# and collected here into a single check. To run a single failing test manually:
# nix build .#legacyPackages.<system>.evalCheck-<testName>
evalChecks =
let
allEvalChecks = lib.filterAttrs (n: _: lib.hasPrefix "evalCheck-" n) self'.legacyPackages;
in
{
eval-tests = pkgs.runCommand "eval-tests-${system}" { } ''
echo "Executed the following eval checks for ${system}:"
${lib.concatMapStringsSep "\n" (n: "echo ' - ${n}'") (lib.attrNames allEvalChecks)}
echo ${toString (lib.attrValues allEvalChecks)} >/dev/null
echo ""
echo "All eval checks succeeded."
echo "To re-run a specific test:"
echo " nix build .#legacyPackages.${system}.evalCheck-<testName>"
touch $out
'';
};
in
nixosTests // flakeOutputs // evalChecks;
legacyPackages = {
nixosTests =
let
nixosTestArgs = {
# reference to nixpkgs for the current system
inherit pkgs;
# this gives us a reference to our flake but also all flake inputs
inherit self;
};
in
lib.optionalAttrs (pkgs.stdenv.hostPlatform.isLinux) {
# import our test
nixos-test-secrets = import ./secrets nixosTestArgs;
nixos-test-container = self.clanLib.test.containerTest ./container nixosTestArgs;
};
};
};
}