From 18e2327aa788d7885d65769ec5b566fdbe434f73 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 9 May 2025 16:00:18 +0200 Subject: [PATCH 1/6] Revert "nixos/lib/testing: avoid generating darwin VM tests" This reverts commit 72155225aa62c6ac9bc67a1253079f140045511f. --- nixos/lib/testing/default.nix | 16 +++++++--------- nixos/lib/testing/meta.nix | 4 +--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/nixos/lib/testing/default.nix b/nixos/lib/testing/default.nix index 7d511619e32d..7fdd454c22b8 100644 --- a/nixos/lib/testing/default.nix +++ b/nixos/lib/testing/default.nix @@ -9,15 +9,13 @@ let }; runTest = module: - # Infra issue: virtualization on darwin doesn't seem to work yet. - lib.addMetaAttrs { hydraPlatforms = lib.platforms.linux; } - (evalTest ( - { config, ... }: - { - imports = [ module ]; - result = config.test; - } - )).config.result; + (evalTest ( + { config, ... }: + { + imports = [ module ]; + result = config.test; + } + )).config.result; testModules = [ ./call-test.nix diff --git a/nixos/lib/testing/meta.nix b/nixos/lib/testing/meta.nix index 6c6cfc49f141..0a4c89ed4b06 100644 --- a/nixos/lib/testing/meta.nix +++ b/nixos/lib/testing/meta.nix @@ -36,9 +36,7 @@ in }; 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; + 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. ''; From 51d915e451bf889b4d16a1502fa3f6b653f71959 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 9 May 2025 16:11:14 +0200 Subject: [PATCH 2/6] nixos/testing: Add meta.hydraPlatforms --- nixos/doc/manual/redirects.json | 3 ++ nixos/lib/testing/meta.nix | 75 +++++++++++++++++++-------------- 2 files changed, 46 insertions(+), 32 deletions(-) diff --git a/nixos/doc/manual/redirects.json b/nixos/doc/manual/redirects.json index 2c9b0242e9e8..b828c0d2913d 100644 --- a/nixos/doc/manual/redirects.json +++ b/nixos/doc/manual/redirects.json @@ -1865,6 +1865,9 @@ "test-opt-meta.platforms": [ "index.html#test-opt-meta.platforms" ], + "test-opt-meta.hydraPlatforms": [ + "index.html#test-opt-meta.hydraPlatforms" + ], "test-opt-meta.timeout": [ "index.html#test-opt-meta.timeout" ], diff --git a/nixos/lib/testing/meta.nix b/nixos/lib/testing/meta.nix index 0a4c89ed4b06..d5c6de3e1e5c 100644 --- a/nixos/lib/testing/meta.nix +++ b/nixos/lib/testing/meta.nix @@ -1,6 +1,6 @@ { lib, ... }: let - inherit (lib) types mkOption; + inherit (lib) types mkOption literalExpression; in { options = { @@ -11,38 +11,49 @@ in 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); - type = types.submodule { - options = { - maintainers = lib.mkOption { - type = types.listOf types.raw; - default = [ ]; - description = '' - The [list of maintainers](https://nixos.org/manual/nixpkgs/stable/#var-meta-maintainers) for this test. - ''; + type = types.submodule ( + { config, ... }: + { + options = { + maintainers = lib.mkOption { + type = types.listOf types.raw; + default = [ ]; + description = '' + The [list of maintainers](https://nixos.org/manual/nixpkgs/stable/#var-meta-maintainers) for this test. + ''; + }; + 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; + 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 = lib.mkOption { + type = types.listOf types.raw; + default = config.platforms; + defaultText = literalExpression "meta.platforms"; + 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; - 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. - ''; - }; - }; - }; + } + ); default = { }; }; }; From 8c9fc4a76c2b4300cf83fde1c50407865ae5a2de Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 9 May 2025 16:03:40 +0200 Subject: [PATCH 3/6] nixos/all-tests: Set hydraPlatforms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This only sets hydraPlatforms for the in-tree tests. See the preceding revert commit which reverts the previous solution. Co-Authored-By: Vladimír Čunát --- nixos/tests/all-tests.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 22058134ecb2..4d7fc2ab0d53 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -90,12 +90,22 @@ let inherit (rec { + + metaModule = { + _file = "${__curPos.file}##metaModule"; + meta = { + # Infra issue: virtualization on darwin doesn't seem to work yet. + hydraPlatforms = platforms.linux; + }; + }; + doRunTest = arg: ((import ../lib/testing-python.nix { inherit system pkgs; }).evalTest { imports = [ arg readOnlyPkgs + metaModule ]; }).config.result; findTests = From 0433bf6a907a7ab77478ea7431af4ee29e47b695 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 9 May 2025 16:17:17 +0200 Subject: [PATCH 4/6] nixos/testing/meta.nix: lib.mkOption -> mkOption --- nixos/lib/testing/meta.nix | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nixos/lib/testing/meta.nix b/nixos/lib/testing/meta.nix index d5c6de3e1e5c..b1c59f325cd9 100644 --- a/nixos/lib/testing/meta.nix +++ b/nixos/lib/testing/meta.nix @@ -4,7 +4,7 @@ let in { options = { - meta = lib.mkOption { + meta = mkOption { description = '' The [`meta`](https://nixos.org/manual/nixpkgs/stable/#chap-meta) attributes that will be set on the returned derivations. @@ -15,35 +15,35 @@ in { config, ... }: { options = { - maintainers = lib.mkOption { + maintainers = mkOption { type = types.listOf types.raw; default = [ ]; description = '' The [list of maintainers](https://nixos.org/manual/nixpkgs/stable/#var-meta-maintainers) for this test. ''; }; - timeout = lib.mkOption { + 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 = lib.mkOption { + 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 = lib.mkOption { + 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 = lib.mkOption { + hydraPlatforms = mkOption { type = types.listOf types.raw; default = config.platforms; defaultText = literalExpression "meta.platforms"; From ee83bfa8790131651994d77fc28b10d7f761c8d2 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 9 May 2025 19:25:21 +0200 Subject: [PATCH 5/6] nixos/testing: Drop darwin from default hydraPlatforms Litmus test: the following attribute disappears nix eval -f pkgs/top-level/release.nix tests.testers.nixosTest-example.x86_64-darwin.outPath --- nixos/lib/testing/meta.nix | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/nixos/lib/testing/meta.nix b/nixos/lib/testing/meta.nix index b1c59f325cd9..1e8f37cf9b51 100644 --- a/nixos/lib/testing/meta.nix +++ b/nixos/lib/testing/meta.nix @@ -1,6 +1,6 @@ { lib, ... }: let - inherit (lib) types mkOption literalExpression; + inherit (lib) types mkOption literalMD; in { options = { @@ -45,8 +45,10 @@ in }; hydraPlatforms = mkOption { type = types.listOf types.raw; - default = config.platforms; - defaultText = literalExpression "meta.platforms"; + # 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. ''; From a8dedd3d97e85d66c577b2f7c1eae34977b4c887 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 9 May 2025 19:27:26 +0200 Subject: [PATCH 6/6] nixos/all-tests: Rely on general hydraPlatforms override It is documented to be about `hydra.nixos.org`, so this is actually acceptable. If your own hydra can do it, you may set `meta.hydraPlatforms` in your tests if you want that. (e.g. set it in a common module that's imported in all your tests) --- nixos/tests/all-tests.nix | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 4d7fc2ab0d53..22058134ecb2 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -90,22 +90,12 @@ let inherit (rec { - - metaModule = { - _file = "${__curPos.file}##metaModule"; - meta = { - # Infra issue: virtualization on darwin doesn't seem to work yet. - hydraPlatforms = platforms.linux; - }; - }; - doRunTest = arg: ((import ../lib/testing-python.nix { inherit system pkgs; }).evalTest { imports = [ arg readOnlyPkgs - metaModule ]; }).config.result; findTests =