From 59a9cbba4a0447285b85115f5274069044004e8a Mon Sep 17 00:00:00 2001 From: Philip Taron Date: Mon, 16 Feb 2026 12:52:38 -0800 Subject: [PATCH] nixosTests: extract readOnlyPkgs to its own module file Move the inline readOnlyPkgs module to nixos/tests/read-only-pkgs.nix so the module system sets _file automatically from the file path, removing the need for __curPos. --- nixos/tests/all-tests.nix | 20 +------------------- nixos/tests/read-only-pkgs.nix | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 19 deletions(-) create mode 100644 nixos/tests/read-only-pkgs.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index de66d01e1c09..cb52eac6c863 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -112,7 +112,7 @@ let ((import ../lib/testing-python.nix { inherit system pkgs; }).evalTest { imports = [ arg - readOnlyPkgs + ./read-only-pkgs.nix ]; }).config.result; findTests = @@ -140,24 +140,6 @@ let runTestOn ; - # Using a single instance of nixpkgs makes test evaluation faster. - # To make sure we don't accidentally depend on a modified pkgs, we make the - # related options read-only. We need to test the right configuration. - # - # If your service depends on a nixpkgs setting, first try to avoid that, but - # otherwise, you can remove the readOnlyPkgs import and test your service as - # usual. - readOnlyPkgs = - # TODO: We currently accept this for nixosTests, so that the `pkgs` argument - # is consistent with `pkgs` in `pkgs.nixosTests`. Can we reinitialize - # it with `allowAliases = false`? - # warnIf pkgs.config.allowAliases "nixosTests: pkgs includes aliases." - { - _file = "${__curPos.file} readOnlyPkgs"; - _class = "nixosTest"; - node.pkgs = pkgs.pkgsLinux; - }; - in { diff --git a/nixos/tests/read-only-pkgs.nix b/nixos/tests/read-only-pkgs.nix new file mode 100644 index 000000000000..54e0e69d5d9c --- /dev/null +++ b/nixos/tests/read-only-pkgs.nix @@ -0,0 +1,17 @@ +# Using a single instance of nixpkgs makes test evaluation faster. +# To make sure we don't accidentally depend on a modified pkgs, we make the +# related options read-only. We need to test the right configuration. +# +# If your service depends on a nixpkgs setting, first try to avoid that, but +# otherwise, you can remove the readOnlyPkgs import and test your service as +# usual. + +# TODO: We currently accept this for nixosTests, so that the `pkgs` argument +# is consistent with `pkgs` in `pkgs.nixosTests`. Can we reinitialize +# it with `allowAliases = false`? +# warnIf pkgs.config.allowAliases "nixosTests: pkgs includes aliases." +{ hostPkgs, ... }: +{ + _class = "nixosTest"; + node.pkgs = hostPkgs.pkgsLinux; +}