Fix running NixOS tests on darwin (#405599)

This commit is contained in:
Robert Hensing
2025-05-15 09:47:30 +02:00
committed by GitHub
3 changed files with 56 additions and 44 deletions

View File

@@ -1874,6 +1874,9 @@
"test-opt-meta.platforms": [ "test-opt-meta.platforms": [
"index.html#test-opt-meta.platforms" "index.html#test-opt-meta.platforms"
], ],
"test-opt-meta.hydraPlatforms": [
"index.html#test-opt-meta.hydraPlatforms"
],
"test-opt-meta.timeout": [ "test-opt-meta.timeout": [
"index.html#test-opt-meta.timeout" "index.html#test-opt-meta.timeout"
], ],

View File

@@ -9,15 +9,13 @@ let
}; };
runTest = runTest =
module: module:
# Infra issue: virtualization on darwin doesn't seem to work yet. (evalTest (
lib.addMetaAttrs { hydraPlatforms = lib.platforms.linux; } { config, ... }:
(evalTest ( {
{ config, ... }: imports = [ module ];
{ result = config.test;
imports = [ module ]; }
result = config.test; )).config.result;
}
)).config.result;
testModules = [ testModules = [
./call-test.nix ./call-test.nix

View File

@@ -1,50 +1,61 @@
{ lib, ... }: { lib, ... }:
let let
inherit (lib) types mkOption; inherit (lib) types mkOption literalMD;
in in
{ {
options = { options = {
meta = lib.mkOption { meta = mkOption {
description = '' description = ''
The [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes that will be set on the returned derivations. The [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes that will be set on the returned derivations.
Not all [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes are supported, but more can be added as desired. Not all [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes are supported, but more can be added as desired.
''; '';
apply = lib.filterAttrs (k: v: v != null); apply = lib.filterAttrs (k: v: v != null);
type = types.submodule { type = types.submodule (
options = { { config, ... }:
maintainers = lib.mkOption { {
type = types.listOf types.raw; options = {
default = [ ]; maintainers = mkOption {
description = '' type = types.listOf types.raw;
The [list of maintainers](https://nixos.org/manual/nixpkgs/stable/#var-meta-maintainers) for this test. default = [ ];
''; description = ''
The [list of maintainers](https://nixos.org/manual/nixpkgs/stable/#var-meta-maintainers) for this test.
'';
};
timeout = mkOption {
type = types.nullOr types.int;
default = 3600; # 1 hour
description = ''
The [{option}`test`](#test-opt-test)'s [`meta.timeout`](https://nixos.org/manual/nixpkgs/stable/#var-meta-timeout) in seconds.
'';
};
broken = mkOption {
type = types.bool;
default = false;
description = ''
Sets the [`meta.broken`](https://nixos.org/manual/nixpkgs/stable/#var-meta-broken) attribute on the [{option}`test`](#test-opt-test) derivation.
'';
};
platforms = mkOption {
type = types.listOf types.raw;
default = lib.platforms.linux ++ lib.platforms.darwin;
description = ''
Sets the [`meta.platforms`](https://nixos.org/manual/nixpkgs/stable/#var-meta-platforms) attribute on the [{option}`test`](#test-opt-test) derivation.
'';
};
hydraPlatforms = mkOption {
type = types.listOf types.raw;
# Ideally this would default to `platforms` again:
# default = config.platforms;
default = lib.platforms.linux;
defaultText = literalMD "`lib.platforms.linux` only, as the `hydra.nixos.org` build farm does not currently support virtualisation on Darwin.";
description = ''
Sets the [`meta.hydraPlatforms`](https://nixos.org/manual/nixpkgs/stable/#var-meta-hydraPlatforms) attribute on the [{option}`test`](#test-opt-test) derivation.
'';
};
}; };
timeout = lib.mkOption { }
type = types.nullOr types.int; );
default = 3600; # 1 hour
description = ''
The [{option}`test`](#test-opt-test)'s [`meta.timeout`](https://nixos.org/manual/nixpkgs/stable/#var-meta-timeout) in seconds.
'';
};
broken = lib.mkOption {
type = types.bool;
default = false;
description = ''
Sets the [`meta.broken`](https://nixos.org/manual/nixpkgs/stable/#var-meta-broken) attribute on the [{option}`test`](#test-opt-test) derivation.
'';
};
platforms = lib.mkOption {
type = types.listOf types.raw;
# darwin could be added, but it would add VM tests that don't work on Hydra.nixos.org (so far)
# see https://github.com/NixOS/nixpkgs/pull/303597#issuecomment-2128782362
default = lib.platforms.linux;
description = ''
Sets the [`meta.platforms`](https://nixos.org/manual/nixpkgs/stable/#var-meta-platforms) attribute on the [{option}`test`](#test-opt-test) derivation.
'';
};
};
};
default = { }; default = { };
}; };
}; };