git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #85570 from adisbladis/nixos-containers-pkgs

nixos-containers: Add support for custom nixpkgs argument

commitd79c2dd4d4772c26ee95c4980764b56a5e46e4aa authoradisbladis <adisbladis@gmail.com> dateMon 20 Apr 2020, 09:46 (7 years ago) parent636a5a6ab37d7e
3 files changed+59−2
nixos/modules/virtualisation/containers.nix+16−2 nixos/tests/all-tests.nix+1 nixos/tests/containers-custom-pkgs.nix+42
nixos/modules/virtualisation/containers.nix+16−2
@@ -463,10 +463,15 @@ in
463463 A specification of the desired configuration of this
464464 container, as a NixOS module.
465465 '';
466− type = lib.mkOptionType {
466+ type = let
467+ confPkgs = if config.pkgs == null then pkgs else config.pkgs;
468+ in lib.mkOptionType {
467469 name = "Toplevel NixOS config";
468− merge = loc: defs: (import ../../lib/eval-config.nix {
470+ merge = loc: defs: (import (confPkgs.path + "/nixos/lib/eval-config.nix") {
469471 inherit system;
472+ pkgs = confPkgs;
473+ baseModules = import (confPkgs.path + "/nixos/modules/module-list.nix");
474+ inherit (confPkgs) lib;
470475 modules =
471476 let
472477 extraConfig = {
@@ -515,6 +520,15 @@ in
515520 '';
516521 };
517522
523+ pkgs = mkOption {
524+ type = types.nullOr types.attrs;
525+ default = null;
526+ example = literalExample "pkgs";
527+ description = ''
528+ Customise which nixpkgs to use for this container.
529+ '';
530+ };
531+
518532 ephemeral = mkOption {
519533 type = types.bool;
520534 default = false;
nixos/tests/all-tests.nix+1
@@ -53,6 +53,7 @@ in
5353 consul = handleTest ./consul.nix {};
5454 cockroachdb = handleTestOn ["x86_64-linux"] ./cockroachdb.nix {};
5555 containers-bridge = handleTest ./containers-bridge.nix {};
56+ containers-custom-pkgs.nix = handleTest ./containers-custom-pkgs.nix {};
5657 containers-ephemeral = handleTest ./containers-ephemeral.nix {};
5758 containers-extra_veth = handleTest ./containers-extra_veth.nix {};
5859 containers-hosts = handleTest ./containers-hosts.nix {};
nixos/tests/containers-custom-pkgs.nixnew file+42
@@ -0,0 +1,42 @@
1+# Test for NixOS' container support.
2+
3+import ./make-test-python.nix ({ pkgs, lib, ...} : let
4+
5+ customPkgs = pkgs // {
6+ hello = pkgs.hello.overrideAttrs(old: {
7+ name = "custom-hello";
8+ });
9+ };
10+
11+in {
12+ name = "containers-hosts";
13+ meta = with lib.maintainers; {
14+ maintainers = [ adisbladis ];
15+ };
16+
17+ machine =
18+ { ... }:
19+ {
20+ virtualisation.memorySize = 256;
21+ virtualisation.vlans = [];
22+
23+ containers.simple = {
24+ autoStart = true;
25+ pkgs = customPkgs;
26+ config = {pkgs, config, ... }: {
27+ environment.systemPackages = [
28+ pkgs.hello
29+ ];
30+ };
31+ };
32+
33+ };
34+
35+ testScript = ''
36+ start_all()
37+ machine.wait_for_unit("default.target")
38+ machine.succeed(
39+ "test $(nixos-container run simple -- readlink -f /run/current-system/sw/bin/hello) = ${customPkgs.hello}/bin/hello"
40+ )
41+ '';
42+})