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: 55efeef4f674
Choose a base ref
...
head repository: NixOS/nixpkgs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: dd32831b3057
Choose a head ref
  • 5 commits
  • 4 files changed
  • 3 contributors

Commits on Nov 7, 2018

  1. Copy the full SHA
    4259f75 View commit details

Commits on Nov 14, 2018

  1. Copy the full SHA
    ceececb View commit details

Commits on Nov 23, 2018

  1. Copy the full SHA
    50daffc View commit details

Commits on Nov 26, 2018

  1. Copy the full SHA
    b011049 View commit details
  2. Merge pull request #49855 from dingxiangfei2009/tarball-closureinfo

    Use closureInfo for building system tarballs and Docker container
    Mic92 authored Nov 26, 2018
    Copy the full SHA
    dd32831 View commit details
Showing with 63 additions and 20 deletions.
  1. +12 −8 nixos/lib/make-system-tarball.nix
  2. +3 −6 nixos/lib/make-system-tarball.sh
  3. +10 −6 nixos/modules/profiles/docker-container.nix
  4. +38 −0 nixos/modules/virtualisation/docker-image.nix
20 changes: 12 additions & 8 deletions nixos/lib/make-system-tarball.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, perl, pixz, pathsFromGraph
{ stdenv, closureInfo, pixz

, # The file name of the resulting tarball
fileName ? "nixos-system-${stdenv.hostPlatform.system}"
@@ -29,24 +29,28 @@
, extraInputs ? [ pixz ]
}:

let
symlinks = map (x: x.symlink) storeContents;
objects = map (x: x.object) storeContents;
in

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

inherit fileName pathsFromGraph extraArgs extraCommands compressCommand;
inherit fileName extraArgs extraCommands compressCommand;

# !!! should use XML.
sources = map (x: x.source) contents;
targets = map (x: x.target) contents;

# !!! should use XML.
objects = map (x: x.object) storeContents;
symlinks = map (x: x.symlink) storeContents;
inherit symlinks objects;

# For obtaining the closure of `storeContents'.
exportReferencesGraph =
map (x: [("closure-" + baseNameOf x.object) x.object]) storeContents;
closureInfo = closureInfo {
rootPaths = objects;
};

extension = compressionExtension;
}
9 changes: 3 additions & 6 deletions nixos/lib/make-system-tarball.sh
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@ source $stdenv/setup
sources_=($sources)
targets_=($targets)

echo $objects
objects=($objects)
symlinks=($symlinks)

@@ -14,8 +13,6 @@ stripSlash() {
if test "${res:0:1}" = /; then res=${res:1}; fi
}

touch pathlist

# Add the individual files.
for ((i = 0; i < ${#targets_[@]}; i++)); do
stripSlash "${targets_[$i]}"
@@ -25,17 +22,17 @@ done


# Add the closures of the top-level store objects.
chmod +w .
mkdir -p nix/store
storePaths=$(perl $pathsFromGraph closure-*)
for i in $storePaths; do
for i in $(< $closureInfo/store-paths); do
cp -a "$i" "${i:1}"
done


# TODO tar ruxo
# Also include a manifest of the closures in a format suitable for
# nix-store --load-db.
printRegistration=1 perl $pathsFromGraph closure-* > nix-path-registration
cp $closureInfo/registration nix-path-registration

# Add symlinks to the top-level store objects.
for ((n = 0; n < ${#objects[*]}; n++)); do
16 changes: 10 additions & 6 deletions nixos/modules/profiles/docker-container.nix
Original file line number Diff line number Diff line change
@@ -15,15 +15,19 @@ in {

# Create the tarball
system.build.tarball = pkgs.callPackage ../../lib/make-system-tarball.nix {
contents = [];
contents = [
{
source = "${config.system.build.toplevel}/.";
target = "./";
}
];
extraArgs = "--owner=0";

# Add init script to image
storeContents = [
{ object = config.system.build.toplevel + "/init";
symlink = "/init";
}
] ++ (pkgs2storeContents [ pkgs.stdenv ]);
storeContents = pkgs2storeContents [
config.system.build.toplevel
pkgs.stdenv
];

# Some container managers like lxc need these
extraCommands = "mkdir -p proc sys dev";
38 changes: 38 additions & 0 deletions nixos/modules/virtualisation/docker-image.nix
Original file line number Diff line number Diff line change
@@ -17,3 +17,41 @@
# Socket activated ssh presents problem in Docker.
services.openssh.startWhenNeeded = false;
}

# Example usage:
#
## default.nix
# let
# nixos = import <nixpkgs/nixos> {
# configuration = ./configuration.nix;
# system = "x86_64-linux";
# };
# in
# nixos.config.system.build.tarball
#
## configuration.nix
# { pkgs, config, lib, ... }:
# {
# imports = [
# <nixpkgs/nixos/modules/virtualisation/docker-image.nix>
# <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix>
# ];
#
# documentation.doc.enable = false;
#
# environment.systemPackages = with pkgs; [
# bashInteractive
# cacert
# nix
# ];
# }
#
## Run
# Build the tarball:
# $ nix-build default.nix
# Load into docker:
# $ docker import result/tarball/nixos-system-*.tar.xz nixos-docker
# Boots into systemd
# $ docker run --privileged -it nixos-docker /init
# Log into the container
# $ docker exec -it <container-name> /run/current-system/sw/bin/bash