From 0eec48c89a147ccc057d9512b6b51aef104ae952 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 22 May 2020 20:07:39 +0200 Subject: [PATCH 1/2] nixos-containers: add test checking that overlays work in containers --- nixos/tests/all-tests.nix | 1 + nixos/tests/containers-nixpkgs-overlays.nix | 43 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 nixos/tests/containers-nixpkgs-overlays.nix diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index b4a4f450ac4d..3977006c43cd 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -52,6 +52,7 @@ in consul = handleTest ./consul.nix {}; containers-bridge = handleTest ./containers-bridge.nix {}; containers-custom-pkgs.nix = handleTest ./containers-custom-pkgs.nix {}; + containers-nixpkgs-overlays.nix = handleTest ./containers-nixpkgs-overlays.nix {}; containers-ephemeral = handleTest ./containers-ephemeral.nix {}; containers-extra_veth = handleTest ./containers-extra_veth.nix {}; containers-hosts = handleTest ./containers-hosts.nix {}; diff --git a/nixos/tests/containers-nixpkgs-overlays.nix b/nixos/tests/containers-nixpkgs-overlays.nix new file mode 100644 index 000000000000..59c50f6ffb13 --- /dev/null +++ b/nixos/tests/containers-nixpkgs-overlays.nix @@ -0,0 +1,43 @@ +# Test for nixpkgs overlays inside NixOS containers. + +import ./make-test-python.nix ({ pkgs, lib, ...} : let + + customHello = pkgs.hello.overrideAttrs(old: { + name = "custom-hello"; + }); + +in { + name = "containers-hosts"; + meta = with lib.maintainers; { + maintainers = [ adisbladis ]; + }; + + machine = + { ... }: + { + virtualisation.memorySize = 256; + virtualisation.vlans = []; + + containers.simple = { + autoStart = true; + config = {pkgs, config, ... }: { + nixpkgs.overlays = [(self: super: { + hello = customHello; + })]; + + environment.systemPackages = [ + pkgs.hello + ]; + }; + }; + + }; + + testScript = '' + start_all() + machine.wait_for_unit("default.target") + machine.succeed( + "test $(nixos-container run simple -- readlink -f /run/current-system/sw/bin/hello) = ${customHello}/bin/hello" + ) + ''; +}) From 8d22d0f43af37842086beb9036ec6f6d3c55d612 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 22 May 2020 20:08:46 +0200 Subject: [PATCH 2/2] Revert "nixos-containers: Add support for custom nixpkgs argument" The referred changeset broke overlays inside NixOS containers. See nixos/tests/containers-nixpkgs-overlays.nix. This reverts commit aa72037b063f6d3e0335f13fa0aed9a65fada4cb. --- nixos/modules/virtualisation/containers.nix | 18 +-------- nixos/tests/all-tests.nix | 1 - nixos/tests/containers-custom-pkgs.nix | 42 --------------------- 3 files changed, 2 insertions(+), 59 deletions(-) delete mode 100644 nixos/tests/containers-custom-pkgs.nix diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index dc29e45b8c8f..02de5801da25 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -463,15 +463,10 @@ in A specification of the desired configuration of this container, as a NixOS module. ''; - type = let - confPkgs = if config.pkgs == null then pkgs else config.pkgs; - in lib.mkOptionType { + type = lib.mkOptionType { name = "Toplevel NixOS config"; - merge = loc: defs: (import (confPkgs.path + "/nixos/lib/eval-config.nix") { + merge = loc: defs: (import ../../lib/eval-config.nix { inherit system; - pkgs = confPkgs; - baseModules = import (confPkgs.path + "/nixos/modules/module-list.nix"); - inherit (confPkgs) lib; modules = let extraConfig = { @@ -520,15 +515,6 @@ in ''; }; - pkgs = mkOption { - type = types.nullOr types.attrs; - default = null; - example = literalExample "pkgs"; - description = '' - Customise which nixpkgs to use for this container. - ''; - }; - ephemeral = mkOption { type = types.bool; default = false; diff --git a/nixos/tests/all-tests.nix b/nixos/tests/all-tests.nix index 3977006c43cd..c16fbac05041 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -51,7 +51,6 @@ in codimd = handleTest ./codimd.nix {}; consul = handleTest ./consul.nix {}; containers-bridge = handleTest ./containers-bridge.nix {}; - containers-custom-pkgs.nix = handleTest ./containers-custom-pkgs.nix {}; containers-nixpkgs-overlays.nix = handleTest ./containers-nixpkgs-overlays.nix {}; containers-ephemeral = handleTest ./containers-ephemeral.nix {}; containers-extra_veth = handleTest ./containers-extra_veth.nix {}; diff --git a/nixos/tests/containers-custom-pkgs.nix b/nixos/tests/containers-custom-pkgs.nix deleted file mode 100644 index 397a4a905e6d..000000000000 --- a/nixos/tests/containers-custom-pkgs.nix +++ /dev/null @@ -1,42 +0,0 @@ -# Test for NixOS' container support. - -import ./make-test-python.nix ({ pkgs, lib, ...} : let - - customPkgs = pkgs // { - hello = pkgs.hello.overrideAttrs(old: { - name = "custom-hello"; - }); - }; - -in { - name = "containers-hosts"; - meta = with lib.maintainers; { - maintainers = [ adisbladis ]; - }; - - machine = - { ... }: - { - virtualisation.memorySize = 256; - virtualisation.vlans = []; - - containers.simple = { - autoStart = true; - pkgs = customPkgs; - config = {pkgs, config, ... }: { - environment.systemPackages = [ - pkgs.hello - ]; - }; - }; - - }; - - testScript = '' - start_all() - machine.wait_for_unit("default.target") - machine.succeed( - "test $(nixos-container run simple -- readlink -f /run/current-system/sw/bin/hello) = ${customPkgs.hello}/bin/hello" - ) - ''; -})