summary refs log tree commit diff
path: root/nixos/tests/containers-custom-pkgs.nix
diff options
context:
space:
mode:
authorErik Arvstedt <erik.arvstedt@gmail.com>2020-12-15 20:25:00 +0100
committerErik Arvstedt <erik.arvstedt@gmail.com>2021-01-15 12:49:42 +0100
commit9a283a038d3c028f8b067c6b2e56f2e38bd93192 (patch)
tree9e6ff2d99e921093f19cfa684f2d7f7f6d16c743 /nixos/tests/containers-custom-pkgs.nix
parent77c4fc2e89eca27e7ba559ed5b0f053a5ef122ce (diff)
downloadnixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar
nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.gz
nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.bz2
nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.lz
nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.xz
nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.tar.zst
nixpkgs-9a283a038d3c028f8b067c6b2e56f2e38bd93192.zip
nixos-container: fix `nixpkgs` container options being ignored
Since the introduction of option `containers.<name>.pkgs`, the
`nixpkgs.*` options (including `nixpkgs.pkgs`, `nixpkgs.config`, ...) were always
ignored in container configs, which broke existing containers.

This was due to `containers.<name>.pkgs` having two separate effects:
(1) It sets the source for the modules that are used to evaluate the container.
(2) It sets the `pkgs` arg (`_module.args.pkgs`) that is used inside the container
    modules.
    This happens even when the default value of `containers.<name>.pkgs` is unchanged, in which
    case the container `pkgs` arg is set to the pkgs of the host system.
    Previously, the `pkgs` arg was determined by the `containers.<name>.config.nixpkgs.*` options.

This commit reverts the breaking change (2) while adding a backwards-compatible way to achieve (1).
It removes option `pkgs` and adds option `nixpkgs` which implements (1).
Existing users of `pkgs` are informed by an error message to use option
`nixpkgs` or to achieve only (2) by setting option `containers.<name>.config.nixpkgs.pkgs`.
Diffstat (limited to 'nixos/tests/containers-custom-pkgs.nix')
-rw-r--r--nixos/tests/containers-custom-pkgs.nix35
1 files changed, 18 insertions, 17 deletions
diff --git a/nixos/tests/containers-custom-pkgs.nix b/nixos/tests/containers-custom-pkgs.nix
index 47509892e52..1412c32bfb5 100644
--- a/nixos/tests/containers-custom-pkgs.nix
+++ b/nixos/tests/containers-custom-pkgs.nix
@@ -1,33 +1,34 @@
 import ./make-test-python.nix ({ pkgs, lib, ...} : let
 
-  customPkgs = pkgs // {
-    hello = pkgs.hello.overrideAttrs(old: {
-      name = "custom-hello";
+  customPkgs = pkgs.appendOverlays [ (self: super: {
+    hello = super.hello.overrideAttrs (old: {
+       name = "custom-hello";
     });
-  };
+  }) ];
 
 in {
   name = "containers-custom-pkgs";
   meta = with lib.maintainers; {
-    maintainers = [ adisbladis ];
+    maintainers = [ adisbladis earvstedt ];
   };
 
-  machine = { ... }: {
+  machine = { config, ... }: {
+    assertions = let
+      helloName = (builtins.head config.containers.test.config.system.extraDependencies).name;
+    in [ {
+      assertion = helloName == "custom-hello";
+      message = "Unexpected value: ${helloName}";
+    } ];
+
     containers.test = {
       autoStart = true;
-      pkgs = customPkgs;
-      config = {pkgs, config, ... }: {
-        environment.systemPackages = [
-          pkgs.hello
-        ];
+      config = { pkgs, config, ... }: {
+        nixpkgs.pkgs = customPkgs;
+        system.extraDependencies = [ pkgs.hello ];
       };
     };
   };
 
-  testScript = ''
-    machine.wait_for_unit("default.target")
-    machine.succeed(
-        "test $(nixos-container run test -- readlink -f /run/current-system/sw/bin/hello) = ${customPkgs.hello}/bin/hello"
-    )
-  '';
+  # This test only consists of evaluating the test machine
+  testScript = "";
 })