Skip to content

Commit eed414c

Browse files
authored
Fix running NixOS tests on darwin (#405599)
2 parents 31f43a0 + a8dedd3 commit eed414c

File tree

3 files changed

+56
-44
lines changed

3 files changed

+56
-44
lines changed

nixos/doc/manual/redirects.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,9 @@
18741874
"test-opt-meta.platforms": [
18751875
"index.html#test-opt-meta.platforms"
18761876
],
1877+
"test-opt-meta.hydraPlatforms": [
1878+
"index.html#test-opt-meta.hydraPlatforms"
1879+
],
18771880
"test-opt-meta.timeout": [
18781881
"index.html#test-opt-meta.timeout"
18791882
],

nixos/lib/testing/default.nix

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ let
99
};
1010
runTest =
1111
module:
12-
# Infra issue: virtualization on darwin doesn't seem to work yet.
13-
lib.addMetaAttrs { hydraPlatforms = lib.platforms.linux; }
14-
(evalTest (
15-
{ config, ... }:
16-
{
17-
imports = [ module ];
18-
result = config.test;
19-
}
20-
)).config.result;
12+
(evalTest (
13+
{ config, ... }:
14+
{
15+
imports = [ module ];
16+
result = config.test;
17+
}
18+
)).config.result;
2119

2220
testModules = [
2321
./call-test.nix

nixos/lib/testing/meta.nix

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,61 @@
11
{ lib, ... }:
22
let
3-
inherit (lib) types mkOption;
3+
inherit (lib) types mkOption literalMD;
44
in
55
{
66
options = {
7-
meta = lib.mkOption {
7+
meta = mkOption {
88
description = ''
99
The [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes that will be set on the returned derivations.
1010
1111
Not all [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes are supported, but more can be added as desired.
1212
'';
1313
apply = lib.filterAttrs (k: v: v != null);
14-
type = types.submodule {
15-
options = {
16-
maintainers = lib.mkOption {
17-
type = types.listOf types.raw;
18-
default = [ ];
19-
description = ''
20-
The [list of maintainers](https://nixos.org/manual/nixpkgs/stable/#var-meta-maintainers) for this test.
21-
'';
14+
type = types.submodule (
15+
{ config, ... }:
16+
{
17+
options = {
18+
maintainers = mkOption {
19+
type = types.listOf types.raw;
20+
default = [ ];
21+
description = ''
22+
The [list of maintainers](https://nixos.org/manual/nixpkgs/stable/#var-meta-maintainers) for this test.
23+
'';
24+
};
25+
timeout = mkOption {
26+
type = types.nullOr types.int;
27+
default = 3600; # 1 hour
28+
description = ''
29+
The [{option}`test`](#test-opt-test)'s [`meta.timeout`](https://nixos.org/manual/nixpkgs/stable/#var-meta-timeout) in seconds.
30+
'';
31+
};
32+
broken = mkOption {
33+
type = types.bool;
34+
default = false;
35+
description = ''
36+
Sets the [`meta.broken`](https://nixos.org/manual/nixpkgs/stable/#var-meta-broken) attribute on the [{option}`test`](#test-opt-test) derivation.
37+
'';
38+
};
39+
platforms = mkOption {
40+
type = types.listOf types.raw;
41+
default = lib.platforms.linux ++ lib.platforms.darwin;
42+
description = ''
43+
Sets the [`meta.platforms`](https://nixos.org/manual/nixpkgs/stable/#var-meta-platforms) attribute on the [{option}`test`](#test-opt-test) derivation.
44+
'';
45+
};
46+
hydraPlatforms = mkOption {
47+
type = types.listOf types.raw;
48+
# Ideally this would default to `platforms` again:
49+
# default = config.platforms;
50+
default = lib.platforms.linux;
51+
defaultText = literalMD "`lib.platforms.linux` only, as the `hydra.nixos.org` build farm does not currently support virtualisation on Darwin.";
52+
description = ''
53+
Sets the [`meta.hydraPlatforms`](https://nixos.org/manual/nixpkgs/stable/#var-meta-hydraPlatforms) attribute on the [{option}`test`](#test-opt-test) derivation.
54+
'';
55+
};
2256
};
23-
timeout = lib.mkOption {
24-
type = types.nullOr types.int;
25-
default = 3600; # 1 hour
26-
description = ''
27-
The [{option}`test`](#test-opt-test)'s [`meta.timeout`](https://nixos.org/manual/nixpkgs/stable/#var-meta-timeout) in seconds.
28-
'';
29-
};
30-
broken = lib.mkOption {
31-
type = types.bool;
32-
default = false;
33-
description = ''
34-
Sets the [`meta.broken`](https://nixos.org/manual/nixpkgs/stable/#var-meta-broken) attribute on the [{option}`test`](#test-opt-test) derivation.
35-
'';
36-
};
37-
platforms = lib.mkOption {
38-
type = types.listOf types.raw;
39-
# darwin could be added, but it would add VM tests that don't work on Hydra.nixos.org (so far)
40-
# see https://github.com/NixOS/nixpkgs/pull/303597#issuecomment-2128782362
41-
default = lib.platforms.linux;
42-
description = ''
43-
Sets the [`meta.platforms`](https://nixos.org/manual/nixpkgs/stable/#var-meta-platforms) attribute on the [{option}`test`](#test-opt-test) derivation.
44-
'';
45-
};
46-
};
47-
};
57+
}
58+
);
4859
default = { };
4960
};
5061
};

0 commit comments

Comments
 (0)