Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 636a5a6fee34
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: d79c2dd4d477
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Apr 20, 2020

  1. Verified

    This commit was signed with the committer’s verified signature.
    woodruffw William Woodruff
    Copy the full SHA
    ab37d7e View commit details
  2. Merge pull request #85570 from adisbladis/nixos-containers-pkgs

    nixos-containers: Add support for custom nixpkgs argument
    adisbladis authored Apr 20, 2020
    Copy the full SHA
    d79c2dd View commit details
Showing with 59 additions and 2 deletions.
  1. +16 −2 nixos/modules/virtualisation/containers.nix
  2. +1 −0 nixos/tests/all-tests.nix
  3. +42 −0 nixos/tests/containers-custom-pkgs.nix
18 changes: 16 additions & 2 deletions nixos/modules/virtualisation/containers.nix
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
@@ -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 {};
42 changes: 42 additions & 0 deletions nixos/tests/containers-custom-pkgs.nix
Original file line number Diff line number Diff line change
@@ -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"
)
'';
})