diff options
author | adisbladis <adisbladis@gmail.com> | 2020-04-19 14:41:18 +0100 |
---|---|---|
committer | adisbladis <adisbladis@gmail.com> | 2020-04-20 07:33:46 +0100 |
commit | ab37d7e7ea6fa44bba109c30dd006037c93cbc52 (patch) | |
tree | d9d5e14be74b9454bac94b184df4313cc016fcb8 | |
parent | 53c14c4e65cc5d58525fc9ec310d2e49d16d0283 (diff) | |
download | nixpkgs-ab37d7e7ea6fa44bba109c30dd006037c93cbc52.tar nixpkgs-ab37d7e7ea6fa44bba109c30dd006037c93cbc52.tar.gz nixpkgs-ab37d7e7ea6fa44bba109c30dd006037c93cbc52.tar.bz2 nixpkgs-ab37d7e7ea6fa44bba109c30dd006037c93cbc52.tar.lz nixpkgs-ab37d7e7ea6fa44bba109c30dd006037c93cbc52.tar.xz nixpkgs-ab37d7e7ea6fa44bba109c30dd006037c93cbc52.tar.zst nixpkgs-ab37d7e7ea6fa44bba109c30dd006037c93cbc52.zip |
nixos-containers: Add support for custom nixpkgs argument
-rw-r--r-- | nixos/modules/virtualisation/containers.nix | 18 | ||||
-rw-r--r-- | nixos/tests/all-tests.nix | 1 | ||||
-rw-r--r-- | nixos/tests/containers-custom-pkgs.nix | 42 |
3 files changed, 59 insertions, 2 deletions
diff --git a/nixos/modules/virtualisation/containers.nix b/nixos/modules/virtualisation/containers.nix index dad211ef55b..2db5c117aa7 100644 --- a/nixos/modules/virtualisation/containers.nix +++ b/nixos/modules/virtualisation/containers.nix @@ -463,10 +463,15 @@ in A specification of the desired configuration of this container, as a NixOS module. ''; - type = lib.mkOptionType { + type = let + confPkgs = if config.pkgs == null then pkgs else config.pkgs; + in lib.mkOptionType { name = "Toplevel NixOS config"; - merge = loc: defs: (import ../../lib/eval-config.nix { + merge = loc: defs: (import (confPkgs.path + "/nixos/lib/eval-config.nix") { inherit system; + pkgs = confPkgs; + baseModules = import (confPkgs.path + "/nixos/modules/module-list.nix"); + inherit (confPkgs) lib; modules = let extraConfig = { @@ -515,6 +520,15 @@ 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 b0c9c7bc225..30229a3a5b2 100644 --- a/nixos/tests/all-tests.nix +++ b/nixos/tests/all-tests.nix @@ -53,6 +53,7 @@ in consul = handleTest ./consul.nix {}; cockroachdb = handleTestOn ["x86_64-linux"] ./cockroachdb.nix {}; containers-bridge = handleTest ./containers-bridge.nix {}; + containers-custom-pkgs.nix = handleTest ./containers-custom-pkgs.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-custom-pkgs.nix b/nixos/tests/containers-custom-pkgs.nix new file mode 100644 index 00000000000..397a4a905e6 --- /dev/null +++ b/nixos/tests/containers-custom-pkgs.nix @@ -0,0 +1,42 @@ +# 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" + ) + ''; +}) |