Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

full nixos inside docker #3779

Merged
merged 3 commits into from
Sep 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion nixos/lib/make-system-tarball.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
# store path whose closure will be copied, and `symlink' is a
# symlink to `object' that will be added to the tarball.
storeContents ? []

# Extra tar arguments
, extraArgs ? ""
}:

stdenv.mkDerivation {
name = "tarball";
builder = ./make-system-tarball.sh;
buildInputs = [perl xz];

inherit fileName pathsFromGraph;
inherit fileName pathsFromGraph extraArgs;

# !!! should use XML.
sources = map (x: x.source) contents;
Expand Down
2 changes: 1 addition & 1 deletion nixos/lib/make-system-tarball.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ done

mkdir -p $out/tarball

tar cvJf $out/tarball/$fileName.tar.xz *
tar cvJf $out/tarball/$fileName.tar.xz * $extraArgs

mkdir -p $out/nix-support
echo $system > $out/nix-support/system
Expand Down
6 changes: 6 additions & 0 deletions nixos/modules/services/ttys/agetty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ with lib;
restartIfChanged = false;
};

systemd.services."console-getty" =
{ serviceConfig.ExecStart = "@${pkgs.utillinux}/sbin/agetty agetty --noclear --login-program ${pkgs.shadow}/bin/login --keep-baud console 115200,38400,9600 $TERM";
serviceConfig.Restart = "always";
restartIfChanged = false;
};

environment.etc = singleton
{ # Friendly greeting on the virtual consoles.
source = pkgs.writeText "issue" ''
Expand Down
67 changes: 67 additions & 0 deletions nixos/modules/virtualisation/docker-image.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{ config, lib, pkgs, ... }:

with lib;

let
pkgs2storeContents = l : map (x: { object = x; symlink = "none"; }) l;

in {
# Create the tarball
system.build.dockerImage = import ../../lib/make-system-tarball.nix {
inherit (pkgs) stdenv perl xz pathsFromGraph;

contents = [];
extraArgs = "--owner=0";
storeContents = [
{ object = config.system.build.toplevel + "/init";
symlink = "/bin/init";
}
] ++ (pkgs2storeContents [ pkgs.stdenv ]);
};

boot.postBootCommands =
''
# After booting, register the contents of the Nix store in the Nix
# database.
if [ -f /nix-path-registration ]; then
${config.nix.package}/bin/nix-store --load-db < /nix-path-registration &&
rm /nix-path-registration
fi

# nixos-rebuild also requires a "system" profile and an
# /etc/NIXOS tag.
touch /etc/NIXOS
${config.nix.package}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system

# Set virtualisation to docker
echo "docker" > /run/systemd/container
'';


# docker image config
require = [
../installer/cd-dvd/channel.nix
../profiles/minimal.nix
../profiles/clone-config.nix
];

boot.isContainer = true;

# Iptables do not work in docker
networking.firewall.enable = false;

services.openssh.enable = true;

# Socket activated ssh presents problem in docker
services.openssh.startWhenNeeded = false;

# Allow the user to login as root without password
security.initialRootPassword = "";

# Some more help text.
services.mingetty.helpLine =
''

Log in as "root" with an empty password.
'';
}