summary refs log tree commit diff
path: root/pkgs/os-specific
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/os-specific')
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/default.nix6
-rw-r--r--pkgs/os-specific/darwin/apple-sdk/frameworks.nix76
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/CF/default.nix8
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix4
-rw-r--r--pkgs/os-specific/darwin/cctools/port.nix4
-rw-r--r--pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix16
-rw-r--r--pkgs/os-specific/linux/apparmor/2.9/default.nix183
-rw-r--r--pkgs/os-specific/linux/apparmor/capability.patch16
-rw-r--r--pkgs/os-specific/linux/apparmor/default.nix249
-rw-r--r--pkgs/os-specific/linux/ati-drivers/default.nix6
-rw-r--r--pkgs/os-specific/linux/audit/default.nix4
-rw-r--r--pkgs/os-specific/linux/autofs/create-patches-v5.sh19
-rw-r--r--pkgs/os-specific/linux/autofs/default.nix (renamed from pkgs/os-specific/linux/autofs/autofs-v5.nix)25
-rw-r--r--pkgs/os-specific/linux/autofs/patches-v5.nix7
-rw-r--r--pkgs/os-specific/linux/blcr/default.nix5
-rw-r--r--pkgs/os-specific/linux/broadcom-sta/linux-recent.patch16
-rw-r--r--pkgs/os-specific/linux/can-utils/default.nix2
-rw-r--r--pkgs/os-specific/linux/cgmanager/default.nix9
-rw-r--r--pkgs/os-specific/linux/conky/default.nix88
-rw-r--r--pkgs/os-specific/linux/conntrack-tools/default.nix5
-rw-r--r--pkgs/os-specific/linux/directvnc/default.nix8
-rw-r--r--pkgs/os-specific/linux/dmidecode/default.nix6
-rw-r--r--pkgs/os-specific/linux/dstat/default.nix12
-rw-r--r--pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix4
-rw-r--r--pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix7
-rw-r--r--pkgs/os-specific/linux/firmware/zd1211/default.nix8
-rw-r--r--pkgs/os-specific/linux/freefall/default.nix32
-rw-r--r--pkgs/os-specific/linux/htop/default.nix10
-rw-r--r--pkgs/os-specific/linux/iproute/default.nix4
-rw-r--r--pkgs/os-specific/linux/ipset/default.nix7
-rw-r--r--pkgs/os-specific/linux/kbd/default.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/common-config.nix8
-rw-r--r--pkgs/os-specific/linux/kernel/flush_workqueue-export.patch13
-rw-r--r--pkgs/os-specific/linux/kernel/linux-3.10.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/linux-3.12.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/linux-3.14.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/linux-3.18.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/linux-4.0.nix17
-rw-r--r--pkgs/os-specific/linux/kernel/linux-4.1.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/linux-4.2.nix25
-rw-r--r--pkgs/os-specific/linux/kernel/linux-rpi.nix2
-rw-r--r--pkgs/os-specific/linux/kernel/linux-testing.nix10
-rw-r--r--pkgs/os-specific/linux/kernel/manual-config.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/patches.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/perf.nix7
-rw-r--r--pkgs/os-specific/linux/kmod-debian-aliases/default.nix23
-rw-r--r--pkgs/os-specific/linux/lttng-modules/default.nix13
-rw-r--r--pkgs/os-specific/linux/lvm2/default.nix4
-rw-r--r--pkgs/os-specific/linux/mcelog/default.nix4
-rw-r--r--pkgs/os-specific/linux/musl/default.nix4
-rw-r--r--pkgs/os-specific/linux/nftables/default.nix4
-rw-r--r--pkgs/os-specific/linux/nvidia-x11/beta.nix8
-rwxr-xr-xpkgs/os-specific/linux/nvidia-x11/builder-legacy340.sh3
-rwxr-xr-xpkgs/os-specific/linux/nvidia-x11/builder.sh3
-rw-r--r--pkgs/os-specific/linux/nvidia-x11/default.nix17
-rw-r--r--pkgs/os-specific/linux/nvidia-x11/legacy173.nix6
-rw-r--r--pkgs/os-specific/linux/nvidia-x11/legacy304.nix6
-rw-r--r--pkgs/os-specific/linux/nvidia-x11/legacy340.nix8
-rw-r--r--pkgs/os-specific/linux/nvidia-x11/nvidia-4.2.patch26
-rw-r--r--pkgs/os-specific/linux/open-iscsi/default.nix12
-rw-r--r--pkgs/os-specific/linux/open-iscsi/kernel.patch12
-rw-r--r--pkgs/os-specific/linux/opengl/xorg-sys/default.nix4
-rw-r--r--pkgs/os-specific/linux/pam_u2f/default.nix21
-rw-r--r--pkgs/os-specific/linux/pax-utils/default.nix4
-rw-r--r--pkgs/os-specific/linux/phc-intel/default.nix50
-rw-r--r--pkgs/os-specific/linux/policycoreutils/default.nix2
-rw-r--r--pkgs/os-specific/linux/policycoreutils/fix-printf-type.patch12
-rw-r--r--pkgs/os-specific/linux/prl-tools/default.nix2
-rw-r--r--pkgs/os-specific/linux/reptyr/default.nix4
-rw-r--r--pkgs/os-specific/linux/rtl8812au/default.nix31
-rw-r--r--pkgs/os-specific/linux/spl/default.nix4
-rw-r--r--pkgs/os-specific/linux/spl/git.nix6
-rw-r--r--pkgs/os-specific/linux/systemd/default.nix2
-rw-r--r--pkgs/os-specific/linux/systemd/fixes.patch1402
-rw-r--r--pkgs/os-specific/linux/trace-cmd/default.nix4
-rw-r--r--pkgs/os-specific/linux/udisks/2-default.nix2
-rw-r--r--pkgs/os-specific/linux/upower/0.99.nix51
-rw-r--r--pkgs/os-specific/linux/upower/default.nix37
-rw-r--r--pkgs/os-specific/linux/util-linux/default.nix1
-rw-r--r--pkgs/os-specific/linux/wis-go7007/default.nix2
-rw-r--r--pkgs/os-specific/linux/xf86-input-wacom/default.nix4
-rw-r--r--pkgs/os-specific/linux/zfs/default.nix4
-rw-r--r--pkgs/os-specific/linux/zfs/git.nix6
-rw-r--r--pkgs/os-specific/linux/zfs/kernel-4.1-compat.patch149
84 files changed, 2045 insertions, 884 deletions
diff --git a/pkgs/os-specific/darwin/apple-sdk/default.nix b/pkgs/os-specific/darwin/apple-sdk/default.nix
index 33d0e5eb385..fd578cf33d6 100644
--- a/pkgs/os-specific/darwin/apple-sdk/default.nix
+++ b/pkgs/os-specific/darwin/apple-sdk/default.nix
@@ -120,7 +120,7 @@ in rec {
       __propagatedImpureHostDeps = [ "/usr/lib/libXplugin.1.dylib" ];
 
       propagatedBuildInputs = with frameworks; [
-        OpenGL ApplicationServices Carbon IOKit CoreFoundation CoreGraphics CoreServices CoreText
+        OpenGL ApplicationServices Carbon IOKit CF CoreGraphics CoreServices CoreText
       ];
 
       installPhase = ''
@@ -144,9 +144,7 @@ in rec {
     };
   };
 
-  frameworks = (stdenv.lib.mapAttrs framework (import ./frameworks.nix { inherit frameworks libs; })) // {
-    CoreFoundation = CF;
-  };
+  frameworks = stdenv.lib.mapAttrs framework (import ./frameworks.nix { inherit frameworks libs CF; });
 
   inherit sdk;
 }
diff --git a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
index 9da2dd74c71..f6bf51f9443 100644
--- a/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
+++ b/pkgs/os-specific/darwin/apple-sdk/frameworks.nix
@@ -2,76 +2,76 @@
 # Epic weird knot-tying happening here.
 # TODO: clean up the process for generating this and include it
 
-{ frameworks, libs }:
+{ frameworks, libs, CF }:
 
 with frameworks; with libs; {
   AGL                     = [ Carbon OpenGL ];
   AVFoundation            = [ ApplicationServices CoreGraphics ];
   AVKit                   = [];
   Accounts                = [];
-  AddressBook             = [ Carbon CoreFoundation ];
+  AddressBook             = [ Carbon CF ];
   AppKit                  = [ AudioToolbox QuartzCore ];
   AppKitScripting         = [];
   AppleScriptKit          = [];
   AppleScriptObjC         = [];
   AppleShareClientCore    = [ CoreServices ];
-  AudioToolbox            = [ AudioUnit CoreAudio CoreFoundation CoreMIDI ];
-  AudioUnit               = [ Carbon CoreAudio CoreFoundation ];
+  AudioToolbox            = [ AudioUnit CoreAudio CF CoreMIDI ];
+  AudioUnit               = [ Carbon CoreAudio CF ];
   AudioVideoBridging      = [ Foundation ];
   Automator               = [];
-  CFNetwork               = [ CoreFoundation ];
+  CFNetwork               = [ CF ];
   CalendarStore           = [];
   Cocoa                   = [];
   Collaboration           = [];
-  CoreAudio               = [ CoreFoundation IOKit ];
+  CoreAudio               = [ CF IOKit ];
   CoreAudioKit            = [ AudioUnit ];
   CoreData                = [];
-  CoreGraphics            = [ Accelerate CoreFoundation IOKit IOSurface SystemConfiguration ];
+  CoreGraphics            = [ Accelerate CF IOKit IOSurface SystemConfiguration ];
   CoreLocation            = [];
-  CoreMIDI                = [ CoreFoundation ];
+  CoreMIDI                = [ CF ];
   CoreMIDIServer          = [];
-  CoreMedia               = [ ApplicationServices AudioToolbox CoreAudio CoreFoundation CoreGraphics CoreVideo ];
-  CoreMediaIO             = [ CoreFoundation CoreMedia ];
-  CoreText                = [ CoreFoundation CoreGraphics ];
-  CoreVideo               = [ ApplicationServices CoreFoundation CoreGraphics IOSurface OpenGL ];
+  CoreMedia               = [ ApplicationServices AudioToolbox CoreAudio CF CoreGraphics CoreVideo ];
+  CoreMediaIO             = [ CF CoreMedia ];
+  CoreText                = [ CF CoreGraphics ];
+  CoreVideo               = [ ApplicationServices CF CoreGraphics IOSurface OpenGL ];
   CoreWLAN                = [ SecurityFoundation ];
   DVComponentGlue         = [ CoreServices QuickTime ];
   DVDPlayback             = [];
-  DirectoryService        = [ CoreFoundation ];
-  DiscRecording           = [ CoreFoundation CoreServices IOKit ];
+  DirectoryService        = [ CF ];
+  DiscRecording           = [ CF CoreServices IOKit ];
   DiscRecordingUI         = [];
-  DiskArbitration         = [ CoreFoundation IOKit ];
+  DiskArbitration         = [ CF IOKit ];
   DrawSprocket            = [ Carbon ];
   EventKit                = [];
   ExceptionHandling       = [];
   FWAUserLib              = [];
-  ForceFeedback           = [ CoreFoundation IOKit ];
-  Foundation              = [ CoreFoundation Security ApplicationServices AppKit SystemConfiguration ];
-  GLKit                   = [ CoreFoundation ];
+  ForceFeedback           = [ CF IOKit ];
+  Foundation              = [ CF Security ApplicationServices AppKit SystemConfiguration ];
+  GLKit                   = [ CF ];
   GLUT                    = [ GL OpenGL ];
   GSS                     = [];
   GameController          = [];
   GameKit                 = [ Foundation ];
-  ICADevices              = [ Carbon CoreFoundation IOBluetooth ];
+  ICADevices              = [ Carbon CF IOBluetooth ];
   IMServicePlugIn         = [];
   IOBluetoothUI           = [ IOBluetooth ];
-  IOKit                   = [ CoreFoundation ];
-  IOSurface               = [ CoreFoundation IOKit xpc ];
+  IOKit                   = [ CF ];
+  IOSurface               = [ CF IOKit xpc ];
   ImageCaptureCore        = [];
-  ImageIO                 = [ CoreFoundation CoreGraphics ];
+  ImageIO                 = [ CF CoreGraphics ];
   InputMethodKit          = [ Carbon ];
   InstallerPlugins        = [];
   InstantMessage          = [];
   JavaFrameEmbedding      = [];
-  JavaScriptCore          = [ CoreFoundation ];
+  JavaScriptCore          = [ CF ];
   Kerberos                = [];
-  Kernel                  = [ CoreFoundation IOKit ];
+  Kernel                  = [ CF IOKit ];
   LDAP                    = [];
-  LatentSemanticMapping   = [ Carbon CoreFoundation ];
+  LatentSemanticMapping   = [ Carbon CF ];
   MapKit                  = [];
-  MediaAccessibility      = [ CoreFoundation CoreGraphics CoreText QuartzCore ];
-  MediaToolbox            = [ AudioToolbox CoreFoundation CoreMedia ];
-  NetFS                   = [ CoreFoundation ];
+  MediaAccessibility      = [ CF CoreGraphics CoreText QuartzCore ];
+  MediaToolbox            = [ AudioToolbox CF CoreMedia ];
+  NetFS                   = [ CF ];
   OSAKit                  = [ Carbon ];
   OpenAL                  = [];
   OpenCL                  = [ IOSurface OpenGL ];
@@ -81,7 +81,7 @@ with frameworks; with libs; {
   PubSub                  = [];
   Python                  = [ ApplicationServices ];
   QTKit                   = [ QuickTime ];
-  QuickLook               = [ ApplicationServices CoreFoundation ];
+  QuickLook               = [ ApplicationServices CF ];
   QuickTime               = [ ApplicationServices AudioUnit Carbon CoreAudio CoreServices OpenGL QuartzCore ];
   Ruby                    = [];
   RubyCocoa               = [];
@@ -89,31 +89,31 @@ with frameworks; with libs; {
   ScreenSaver             = [];
   Scripting               = [];
   ScriptingBridge         = [];
-  Security                = [ CoreFoundation IOKit ];
+  Security                = [ CF IOKit ];
   SecurityFoundation      = [];
   SecurityInterface       = [ Security ];
-  ServiceManagement       = [ CoreFoundation Security ];
+  ServiceManagement       = [ CF Security ];
   Social                  = [];
   SpriteKit               = [];
   StoreKit                = [];
   SyncServices            = [];
-  SystemConfiguration     = [ CoreFoundation Security ];
+  SystemConfiguration     = [ CF Security ];
   TWAIN                   = [ Carbon ];
   Tcl                     = [];
   Tk                      = [ ApplicationServices Carbon X11 ];
-  VideoDecodeAcceleration = [ CoreFoundation CoreVideo ];
-  VideoToolbox            = [ CoreFoundation CoreMedia CoreVideo ];
+  VideoDecodeAcceleration = [ CF CoreVideo ];
+  VideoToolbox            = [ CF CoreMedia CoreVideo ];
   WebKit                  = [ ApplicationServices Carbon JavaScriptCore OpenGL X11 ];
 
   # Umbrellas
   Accelerate          = [ CoreWLAN IOBluetooth ];
-  ApplicationServices = [ CoreFoundation CoreServices CoreText ImageIO ];
-  Carbon              = [ ApplicationServices CoreFoundation CoreServices IOKit Security QuartzCore ];
+  ApplicationServices = [ CF CoreServices CoreText ImageIO ];
+  Carbon              = [ ApplicationServices CF CoreServices IOKit Security QuartzCore ];
   CoreBluetooth       = [];
-  CoreServices        = [ CFNetwork CoreAudio CoreData CoreFoundation DiskArbitration Security NetFS OpenDirectory ServiceManagement ];
+  CoreServices        = [ CFNetwork CoreAudio CoreData CF DiskArbitration Security NetFS OpenDirectory ServiceManagement ];
   IOBluetooth         = [ IOKit ];
   JavaVM              = [];
   OpenDirectory       = [];
   Quartz              = [ QuickLook ];
-  QuartzCore          = [ ApplicationServices CoreFoundation CoreVideo OpenCL ];
+  QuartzCore          = [ ApplicationServices CF CoreVideo OpenCL ];
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix b/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix
index f919dde7f69..c7fcbb0aabb 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/CF/default.nix
@@ -1,5 +1,8 @@
 { stdenv, appleDerivation, icu, dyld, libdispatch, launchd, libclosure }:
 
+# this project uses blocks, a clang-only extension
+assert stdenv.cc.isClang;
+
 appleDerivation {
   buildInputs = [ dyld icu libdispatch launchd libclosure ];
 
@@ -44,8 +47,9 @@ appleDerivation {
   '';
 
   postInstall = ''
-    # gross! convince apple to release this as part of CF
-    cp /System/Library/Frameworks/CoreFoundation.framework/Headers/CFAttributedString.h "$out/System/Library/Frameworks/CoreFoundation.framework/Headers"
+    # gross! convince apple to release these as part of CF
+    cp /System/Library/Frameworks/CoreFoundation.framework/Headers/{CFAttributedString,CFNotificationCenter}.h \
+      "$out/System/Library/Frameworks/CoreFoundation.framework/Headers"
 
     mv $out/System/* $out
     rmdir $out/System
diff --git a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
index ecab0941332..108b430d783 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
@@ -34,7 +34,9 @@ appleDerivation rec {
                  "system_platform"
                  "system_pthread"
                  "system_sandbox"
-                 "system_stats"
+                 # does not exist in El Capitan beta
+                 # FIXME: does anything on yosemite actually need this?
+                 # "system_stats"
                  "unc"
                  "unwind"
                  "xpc"
diff --git a/pkgs/os-specific/darwin/cctools/port.nix b/pkgs/os-specific/darwin/cctools/port.nix
index bfb389ef37c..e7165875aa4 100644
--- a/pkgs/os-specific/darwin/cctools/port.nix
+++ b/pkgs/os-specific/darwin/cctools/port.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, autoconf, automake, libtool
+{ stdenv, fetchurl, autoconf, automake, libtool_2
 , llvm, libcxx, libcxxabi, clang, openssl, libuuid
 , libobjc ? null
 }:
@@ -18,7 +18,7 @@ let
       sha256 = "01f31ijpnplbiyp7ldwzy8vbkn3j3m56n5blsvsav5nlp4lp2g71";
     };
 
-    buildInputs = [ autoconf automake libtool openssl libuuid ] ++
+    buildInputs = [ autoconf automake libtool_2 openssl libuuid ] ++
       # Only need llvm and clang if the stdenv isn't already clang-based (TODO: just make a stdenv.cc.isClang)
       stdenv.lib.optionals (!stdenv.isDarwin) [ llvm clang ] ++
       stdenv.lib.optionals stdenv.isDarwin [ libcxxabi libobjc ];
diff --git a/pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix b/pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix
new file mode 100644
index 00000000000..0460c516d29
--- /dev/null
+++ b/pkgs/os-specific/darwin/reattach-to-user-namespace/default.nix
@@ -0,0 +1,16 @@
+{ stdenv, fetchgit }:
+
+stdenv.mkDerivation {
+  name = "reattach-to-user-namespace-2.4";
+  src = fetchgit {
+    url = "https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard.git";
+    sha256 = "1f9q1wxq764zidnx5hbdkbbyxxzfih0l0cjpgr0pxzwbmd2q6cvv";
+    rev = "2765aeab8f337c29e260a912bf4267a2732d8640";
+  };
+  buildFlags = "ARCHES=x86_64";
+  installPhase = ''
+    mkdir -p $out/bin
+    cp reattach-to-user-namespace $out/bin/
+  '';
+}
+
diff --git a/pkgs/os-specific/linux/apparmor/2.9/default.nix b/pkgs/os-specific/linux/apparmor/2.9/default.nix
deleted file mode 100644
index 1b1d9a3d1ca..00000000000
--- a/pkgs/os-specific/linux/apparmor/2.9/default.nix
+++ /dev/null
@@ -1,183 +0,0 @@
-{ stdenv, fetchurl, autoconf, automake, libtool, pkgconfig, perl, which
-, glibc, flex, bison, python27, swig, dbus, pam
-}:
-
-let
-  apparmor-series = "2.9";
-  apparmor-patchver = "2";
-  apparmor-version = "${apparmor-series}.${apparmor-patchver}";
-
-  apparmor-meta = component: with stdenv.lib; {
-      homepage = http://apparmor.net/;
-      description = "Linux application security system - ${component}";
-      license = licenses.gpl2;
-      maintainers = with maintainers; [ phreedom thoughtpolice joachifm ];
-      platforms = platforms.linux;
-  };
-
-  apparmor-sources = fetchurl {
-    url = "https://launchpad.net/apparmor/${apparmor-series}/${apparmor-version}/+download/apparmor-${apparmor-version}.tar.gz";
-    sha256 = "1mayly7d7w959fya7z8q6kab2x3jcwhqhkpx36jsvpjhxkhmc4fh";
-  };
-
-  prePatchCommon = ''
-    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${perl}/bin/pod2man"
-    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${perl}/bin/pod2html"
-    substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
-    substituteInPlace ./common/Make.rules --replace "/usr/share/man" "share/man"
-  '';
-
-  libapparmor = stdenv.mkDerivation {
-    name = "libapparmor-${apparmor-version}";
-    src = apparmor-sources;
-
-    buildInputs = [
-      autoconf
-      automake
-      bison
-      flex
-      dbus # requires patch to dbus ...
-      glibc
-      libtool
-      perl
-      pkgconfig
-      python27
-      swig
-      which
-    ];
-
-    prePatch = prePatchCommon + ''
-      substituteInPlace ./libraries/libapparmor/src/Makefile.am --replace "/usr/include/netinet/in.h" "${glibc}/include/netinet/in.h"
-      substituteInPlace ./libraries/libapparmor/src/Makefile.in --replace "/usr/include/netinet/in.h" "${glibc}/include/netinet/in.h"
-      '';
-
-    buildPhase = ''
-      cd ./libraries/libapparmor
-      ./autogen.sh
-      ./configure --prefix="$out" --with-python --with-perl
-      make
-      '';
-
-    installPhase = ''
-      make install
-    '';
-
-    meta = apparmor-meta "library";
-  };
-
-  apparmor-utils = stdenv.mkDerivation {
-    name = "apparmor-utils-${apparmor-version}";
-    src = apparmor-sources;
-
-    buildInputs = [
-      python27
-      libapparmor
-      which
-    ];
-
-    prePatch = prePatchCommon;
-
-    buildPhase = ''
-      cd ./utils
-      make LANGS=""
-    '';
-
-    installPhase = ''
-      make install LANGS="" DESTDIR="$out" BINDIR="$out/bin" VIM_INSTALL_PATH="$out/share" PYPREFIX=""
-    '';
-
-    meta = apparmor-meta "user-land utilities";
-  };
-
-  apparmor-parser = stdenv.mkDerivation {
-    name = "apparmor-parser-${apparmor-version}";
-    src = apparmor-sources;
-
-    buildInputs = [
-      libapparmor
-      bison
-      flex
-      which
-    ];
-
-    prePatch = prePatchCommon + ''
-      substituteInPlace ./parser/Makefile --replace "/usr/bin/bison" "${bison}/bin/bison"
-      substituteInPlace ./parser/Makefile --replace "/usr/bin/flex" "${flex}/bin/flex"
-      substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
-      ## techdoc.pdf still doesn't build ...
-      substituteInPlace ./parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages"
-    '';
-
-    buildPhase = ''
-      cd ./parser
-      make LANGS="" USE_SYSTEM=1 INCLUDEDIR=${libapparmor}/include
-    '';
-
-    installPhase = ''
-      make install LANGS="" USE_SYSTEM=1 INCLUDEDIR=${libapparmor}/include DESTDIR="$out" DISTRO="unknown"
-    '';
-
-    meta = apparmor-meta "rule parser";
-  };
-
-  apparmor-pam = stdenv.mkDerivation {
-    name = "apparmor-pam-${apparmor-version}";
-    src = apparmor-sources;
-
-    buildInputs = [
-      libapparmor
-      pam
-      pkgconfig
-      which
-    ];
-
-    buildPhase = ''
-      cd ./changehat/pam_apparmor
-      make USE_SYSTEM=1
-    '';
-
-    installPhase = ''
-      make install DESTDIR="$out"
-    '';
-
-    meta = apparmor-meta "PAM service";
-  };
-
-  apparmor-profiles = stdenv.mkDerivation {
-    name = "apparmor-profiles-${apparmor-version}";
-    src = apparmor-sources;
-
-    buildInputs = [ which ];
-
-    buildPhase = ''
-      cd ./profiles
-      make
-    '';
-
-    installPhase = ''
-      make install DESTDIR="$out" EXTRAS_DEST="$out/share/apparmor/extra-profiles"
-    '';
-
-    meta = apparmor-meta "profiles";
-  };
-
-  apparmor-kernel-patches = stdenv.mkDerivation {
-    name = "apparmor-kernel-patches-${apparmor-version}";
-    src = apparmor-sources;
-
-    phases = ''unpackPhase installPhase'';
-
-    installPhase = ''
-      mkdir "$out"
-      cp -R ./kernel-patches "$out"
-    '';
-
-    meta = apparmor-meta "kernel patches";
-  };
-
-in
-
-{
-  inherit libapparmor apparmor-utils apparmor-parser apparmor-pam
-  apparmor-profiles apparmor-kernel-patches;
-}
diff --git a/pkgs/os-specific/linux/apparmor/capability.patch b/pkgs/os-specific/linux/apparmor/capability.patch
deleted file mode 100644
index c8f2b511d95..00000000000
--- a/pkgs/os-specific/linux/apparmor/capability.patch
+++ /dev/null
@@ -1,16 +0,0 @@
-Description: allow parser to build even when not on Linux.
-Author: Kees Cook <kees@debian.org>
-
-Index: apparmor-debian/common/Make.rules
-===================================================================
---- apparmor-debian.orig/common/Make.rules	2012-05-05 14:41:25.967259523 -0700
-+++ apparmor-debian/common/Make.rules	2012-05-05 14:41:28.451291053 -0700
-@@ -160,7 +160,7 @@
- CAPABILITIES=$(shell echo "\#include <linux/capability.h>" | cpp -dM | LC_ALL=C sed -n -e '/CAP_EMPTY_SET/d' -e 's/^\#define[ \t]\+CAP_\([A-Z0-9_]\+\)[ \t]\+\([0-9xa-f]\+\)\(.*\)$$/CAP_\1/p' | sort)
- 
- .PHONY: list_capabilities
--list_capabilities: /usr/include/linux/capability.h
-+list_capabilities:
- 	@echo "$(CAPABILITIES)"
- 
- # =====================
diff --git a/pkgs/os-specific/linux/apparmor/default.nix b/pkgs/os-specific/linux/apparmor/default.nix
index f68b436bed1..64c6f66575b 100644
--- a/pkgs/os-specific/linux/apparmor/default.nix
+++ b/pkgs/os-specific/linux/apparmor/default.nix
@@ -1,98 +1,167 @@
-{ stdenv, fetchurl
-, autoconf, automake, libtool, makeWrapper
-, perl, bison, flex, glibc, gettext, which, rpm, tetex, LocaleGettext
-, bash, pam, TermReadKey, RpcXML, swig, python}:
-stdenv.mkDerivation rec {
-
-  name = "apparmor-${version}";
-  version = "2.8.4";
-
-  src = fetchurl {
-    url = "http://launchpad.net/apparmor/2.8/${version}/+download/${name}.tar.gz";
-    sha256 = "1mki4c44ljmr7dpn55grzn33929kdjx149jx00s80yp1war83jwq";
+{ stdenv, fetchurl, makeWrapper, autoconf, autoreconfHook, automake, libtool, pkgconfig, perl, which
+, glibc, flex, bison, python27Packages, swig, pam
+}:
+
+let
+  apparmor-series = "2.10";
+  apparmor-version = apparmor-series;
+
+  apparmor-meta = component: with stdenv.lib; {
+    homepage = http://apparmor.net/;
+    description = "Linux application security system - ${component}";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ phreedom thoughtpolice joachifm ];
+    platforms = platforms.linux;
   };
 
-  buildInputs = [
-    autoconf automake libtool perl bison flex gettext which rpm tetex
-    LocaleGettext pam TermReadKey RpcXML swig makeWrapper python ];
-
-  prePatch = ''
-    substituteInPlace libraries/libapparmor/src/Makefile.in --replace "/usr/include" "${glibc}/include"
-    substituteInPlace libraries/libapparmor/src/Makefile.am --replace "/usr/include" "${glibc}/include"
-    substituteInPlace common/Make.rules --replace "/usr/bin/pod2man" "${perl}/bin/pod2man"
-    substituteInPlace common/Make.rules --replace "/usr/bin/pod2html" "${perl}/bin/pod2html"
-    substituteInPlace common/Make.rules --replace "cpp -dM" "cpp -dM -I${glibc}/include"
-
-    substituteInPlace parser/Makefile --replace "/usr/bin/bison" "${bison}/bin/bison"
-    substituteInPlace parser/Makefile --replace "/usr/bin/flex" "${flex}/bin/flex"
-    substituteInPlace parser/Makefile --replace "/usr/include/bits/socket.h" "${glibc}/include/bits/socket.h"
-    substituteInPlace parser/Makefile --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
-    #substituteInPlace parser/utils/vim/Makefile --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
-
-    # for some reason pdf documentation doesn't build
-    substituteInPlace parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages"
-
-    substituteInPlace parser/tst/gen-xtrans.pl --replace "/usr/bin/perl" "${perl}/bin/perl"
-    substituteInPlace parser/tst/Makefile --replace "/usr/bin/prove" "${perl}/bin/prove"
-    substituteInPlace parser/tst/Makefile --replace "./caching.sh" "${bash}/bin/bash ./caching.sh"
-  '';
+  apparmor-sources = fetchurl {
+    url = "https://launchpad.net/apparmor/${apparmor-series}/${apparmor-version}/+download/apparmor-${apparmor-version}.tar.gz";
+    sha256 = "1x06qmmbha9krx7880pxj2k3l8fxy3nm945xjjv735m2ax1243jd";
+  };
 
-  patches = ./capability.patch;
-
-  buildPhase =''
-    PERL5LIB=$PERL5LIB:$out/lib/perl5/site_perl:$out/lib
-
-    cd libraries/libapparmor
-    ./autogen.sh
-    ./configure --prefix=$out --with-perl	# see below
-    make
-    make check
-    make install
-    mkdir -p $out/lib/perl5/site_perl/
-    cp swig/perl/LibAppArmor.pm $out/lib/perl5/site_perl/
-    cp swig/perl/LibAppArmor.bs $out/lib/perl5/site_perl/
-    # this is automatically copied elsewhere....
-
-    cd ../../utils
-    make
-    make install DESTDIR=$out BINDIR=$out/bin VENDOR_PERL=/lib/perl5/site_perl
-
-    cd ../parser
-    make
-    make install DESTDIR=$out DISTRO=unknown
-
-#    cd ../changehat/mod_apparmor
-#    make		# depends on libapparmor having been built first
-#    make install
-
-    cd ../changehat/pam_apparmor
-    make		# depends on libapparmor having been built first
-    make install DESTDIR=$out
-
-    cd ../../profiles
-    LD_LIBRARY_PATH=$out/lib    make
-    #LD_LIBRARY_PATH=$out/lib    make check	# depends on the parser having been built first
-    make install DESTDIR=$out
-
-    cd ..
-    cp -r  kernel-patches $out
+  prePatchCommon = ''
+    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${perl}/bin/pod2man"
+    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${perl}/bin/pod2html"
+    substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
+    substituteInPlace ./common/Make.rules --replace "/usr/share/man" "share/man"
   '';
 
-  installPhase = let
-    perlVersion = (builtins.parseDrvName perl.name).version;
-  in ''
-    for i in $out/bin/*;  do
-      wrapProgram $i --prefix PERL5LIB : \
-        "$PERL5LIB:$out/lib/perl5/${perlVersion}/${stdenv.system}-thread-multi/"
-    done
-  '';
+  libapparmor = stdenv.mkDerivation {
+    name = "libapparmor-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      autoconf
+      automake
+      autoreconfHook
+      bison
+      flex
+      glibc
+      libtool
+      perl
+      pkgconfig
+      python27Packages.python
+      swig
+      which
+    ];
+
+    # required to build apparmor-parser
+    dontDisableStatic = true;
+
+    prePatch = prePatchCommon + ''
+      substituteInPlace ./libraries/libapparmor/src/Makefile.am --replace "/usr/include/netinet/in.h" "${glibc}/include/netinet/in.h"
+      substituteInPlace ./libraries/libapparmor/src/Makefile.in --replace "/usr/include/netinet/in.h" "${glibc}/include/netinet/in.h"
+      '';
+
+    postPatch = "cd ./libraries/libapparmor";
+    configureFlags = "--with-python --with-perl";
+
+    meta = apparmor-meta "library";
+  };
 
-  meta = with stdenv.lib; {
-    homepage = http://apparmor.net/;
-    description = "Linux application security system";
-    license = licenses.gpl2;
-    maintainers = [ maintainers.phreedom maintainers.thoughtpolice ];
-    platforms = platforms.linux;
+  apparmor-utils = stdenv.mkDerivation {
+    name = "apparmor-utils-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      perl
+      python27Packages.python
+      python27Packages.readline
+      libapparmor
+      makeWrapper
+      which
+    ];
+
+    prePatch = prePatchCommon;
+    postPatch = "cd ./utils";
+    makeFlags = ''LANGS='';
+    installFlags = ''DESTDIR=$(out) BINDIR=$(out)/bin VIM_INSTALL_PATH=$(out)/share PYPREFIX='';
+
+    postInstall = ''
+      for prog in aa-audit aa-autodep aa-cleanprof aa-complain aa-disable aa-enforce aa-genprof aa-logprof aa-mergeprof aa-status aa-unconfined ; do
+        wrapProgram $out/bin/$prog --prefix PYTHONPATH : "$out/lib/${python27Packages.python.libPrefix}/site-packages:$PYTHONPATH"
+      done
+
+      for prog in aa-exec aa-notify ; do
+        wrapProgram $out/bin/$prog --prefix PERL5LIB : "${libapparmor}/lib/perl5:$PERL5LIB"
+      done
+    '';
+
+    meta = apparmor-meta "user-land utilities";
   };
-}
 
+  apparmor-parser = stdenv.mkDerivation {
+    name = "apparmor-parser-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      libapparmor
+      bison
+      flex
+      which
+    ];
+
+    prePatch = prePatchCommon + ''
+      substituteInPlace ./parser/Makefile --replace "/usr/bin/bison" "${bison}/bin/bison"
+      substituteInPlace ./parser/Makefile --replace "/usr/bin/flex" "${flex}/bin/flex"
+      substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${glibc}/include/linux/capability.h"
+      ## techdoc.pdf still doesn't build ...
+      substituteInPlace ./parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages"
+    '';
+    postPatch = "cd ./parser";
+    makeFlags = ''LANGS= USE_SYSTEM=1 INCLUDEDIR=${libapparmor}/include'';
+    installFlags = ''DESTDIR=$(out) DISTRO=unknown'';
+
+    meta = apparmor-meta "rule parser";
+  };
+
+  apparmor-pam = stdenv.mkDerivation {
+    name = "apparmor-pam-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [
+      libapparmor
+      pam
+      pkgconfig
+      which
+    ];
+
+    postPatch = "cd ./changehat/pam_apparmor";
+    makeFlags = ''USE_SYSTEM=1'';
+    installFlags = ''DESTDIR=$(out)'';
+
+    meta = apparmor-meta "PAM service";
+  };
+
+  apparmor-profiles = stdenv.mkDerivation {
+    name = "apparmor-profiles-${apparmor-version}";
+    src = apparmor-sources;
+
+    buildInputs = [ which ];
+
+    postPatch = "cd ./profiles";
+    installFlags = ''DESTDIR=$(out) EXTRAS_DEST=$(out)/share/apparmor/extra-profiles'';
+
+    meta = apparmor-meta "profiles";
+  };
+
+  apparmor-kernel-patches = stdenv.mkDerivation {
+    name = "apparmor-kernel-patches-${apparmor-version}";
+    src = apparmor-sources;
+
+    phases = ''unpackPhase installPhase'';
+
+    installPhase = ''
+      mkdir "$out"
+      cp -R ./kernel-patches "$out"
+    '';
+
+    meta = apparmor-meta "kernel patches";
+  };
+
+in
+
+{
+  inherit libapparmor apparmor-utils apparmor-parser apparmor-pam
+  apparmor-profiles apparmor-kernel-patches;
+}
diff --git a/pkgs/os-specific/linux/ati-drivers/default.nix b/pkgs/os-specific/linux/ati-drivers/default.nix
index 834e798e8d1..bb088885509 100644
--- a/pkgs/os-specific/linux/ati-drivers/default.nix
+++ b/pkgs/os-specific/linux/ati-drivers/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, kernel ? null, xlibs, which, imake
+{ stdenv, fetchurl, kernel ? null, which, imake
 , mesa # for fgl_glxgears
 , libXxf86vm, xf86vidmodeproto # for fglrx_gamma
 , xorg, makeWrapper, glibc, patchelf
@@ -48,8 +48,8 @@ stdenv.mkDerivation {
   patchPhaseSamples = "patch -p2 < ${./patch-samples.patch}";
 
   buildInputs =
-    [ xlibs.libXext xlibs.libX11 xlibs.libXinerama
-      xlibs.libXrandr which imake makeWrapper
+    [ xorg.libXext xorg.libX11 xorg.libXinerama
+      xorg.libXrandr which imake makeWrapper
       patchelf
       unzip
       mesa
diff --git a/pkgs/os-specific/linux/audit/default.nix b/pkgs/os-specific/linux/audit/default.nix
index 8a7c573ac0e..da27d3ed9d4 100644
--- a/pkgs/os-specific/linux/audit/default.nix
+++ b/pkgs/os-specific/linux/audit/default.nix
@@ -5,11 +5,11 @@
 assert enablePython -> python != null;
 
 stdenv.mkDerivation rec {
-  name = "audit-2.4.2";
+  name = "audit-2.4.4";
 
   src = fetchurl {
     url = "http://people.redhat.com/sgrubb/audit/${name}.tar.gz";
-    sha256 = "08j134s4509rxfi3hwsp8yyxzlqqxl8kqgv2rfv6p3qng5pjd80j";
+    sha256 = "08sfcx8ykcn5jsryil15q8yqm0a8czymyqbb2sqxfc1jbx37zx95";
   };
 
   buildInputs = [ openldap ]
diff --git a/pkgs/os-specific/linux/autofs/create-patches-v5.sh b/pkgs/os-specific/linux/autofs/create-patches-v5.sh
deleted file mode 100644
index 1fe6b503288..00000000000
--- a/pkgs/os-specific/linux/autofs/create-patches-v5.sh
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh
-#
-# Use this script with the upstream sorted list of patches
-# curl ftp://ftp.kernel.org/pub/linux/daemons/autofs/v5/patches-5.0.{x+1}/patch_order-5.0.x | 
-#   grep -v '^#' | sh create-patches-v5.sh
-
-BASEURL=mirror://kernel/linux/daemons/autofs/v5/patches-5.0.9;
-
-echo '# File created automatically' > patches-v5.nix
-echo 'fetchurl :' >> patches-v5.nix
-echo '[' >> patches-v5.nix
-
-while read a; do
-  URL=$BASEURL/$a
-  HASH=`nix-prefetch-url $URL`
-  echo "(fetchurl { url = $URL; sha256 = \"$HASH\"; })" >> patches-v5.nix
-done
-
-echo ']' >> patches-v5.nix
diff --git a/pkgs/os-specific/linux/autofs/autofs-v5.nix b/pkgs/os-specific/linux/autofs/default.nix
index 787cd34180e..3a8aa08d8a3 100644
--- a/pkgs/os-specific/linux/autofs/autofs-v5.nix
+++ b/pkgs/os-specific/linux/autofs/default.nix
@@ -1,18 +1,16 @@
-{stdenv, fetchurl, flex, bison, linuxHeaders}:
+{ stdenv, fetchurl, flex, bison, linuxHeaders }:
 
 let
-  baseURL = mirror://kernel/linux/daemons/autofs/v5;
-in
-stdenv.mkDerivation {
-  name = "autofs-5.0.8";
+  version = "5.1.1";
+  name = "autofs-${version}";
+in stdenv.mkDerivation {
+  inherit name;
 
   src = fetchurl {
-    url = "${baseURL}/autofs-5.0.8.tar.bz2";
-    sha256 = "0zczihrqdamj43401v2pczf7zi94f8qk20gc6l92nxmpak3443if";
+    url = "mirror://kernel/linux/daemons/autofs/v5/${name}.tar.xz";
+    sha256 = "1hr1f11wp538h7r298wpa5khfkhfs8va3p1kdixxhrgkkzpz13z0";
   };
 
-  patches = import ./patches-v5.nix fetchurl;
-
   preConfigure = ''
     configureFlags="--disable-move-mount --with-path=$PATH"
     export MOUNT=/var/run/current-system/sw/bin/mount
@@ -31,11 +29,12 @@ stdenv.mkDerivation {
     #make install SUBDIRS="samples" # impure!
   '';
 
-  buildInputs = [flex bison linuxHeaders];
+  buildInputs = [ flex bison linuxHeaders ];
 
-  meta = { 
-    description="Kernel based automounter";
-    homepage="http://www.linux-consulting.com/Amd_AutoFS/autofs.html";
+  meta = {
+    inherit version;
+    description = "Kernel-based automounter";
+    homepage = http://www.linux-consulting.com/Amd_AutoFS/autofs.html;
     license = stdenv.lib.licenses.gpl2;
     executables = [ "automount" ];
   };
diff --git a/pkgs/os-specific/linux/autofs/patches-v5.nix b/pkgs/os-specific/linux/autofs/patches-v5.nix
deleted file mode 100644
index a577beefbe7..00000000000
--- a/pkgs/os-specific/linux/autofs/patches-v5.nix
+++ /dev/null
@@ -1,7 +0,0 @@
-# File created automatically
-fetchurl :
-[
-(fetchurl { url = mirror://kernel/linux/daemons/autofs/v5/patches-5.0.9/autofs-5.0.8-fix-undefined-authtype_requires_creds-err-if-ldap-en.patch; sha256 = "11v1a32rx57ylp8scswpk41jl9n4kfx55nvdlzhvfs4rhws18rpx"; })
-(fetchurl { url = mirror://kernel/linux/daemons/autofs/v5/patches-5.0.9/autofs-5.0.8-fix-master-map-type-check.patch; sha256 = "1nkq0y6j7dc6214af3q9bxvy7pv9kak0q9chijxcj6zkhfzwrjy3"; })
-(fetchurl { url = mirror://kernel/linux/daemons/autofs/v5/patches-5.0.9/autofs-5.0.8-fix-task-manager-not-getting-signaled.patch; sha256 = "17h06wk4x0rqiky6pm9dglbc5ycxxrd3438a9snnlysl4zzgrqhx"; })
-]
diff --git a/pkgs/os-specific/linux/blcr/default.nix b/pkgs/os-specific/linux/blcr/default.nix
index 7681e8e3c31..bc7523858fe 100644
--- a/pkgs/os-specific/linux/blcr/default.nix
+++ b/pkgs/os-specific/linux/blcr/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, kernel, perl, makeWrapper }:
+{ stdenv, lib, fetchurl, kernel, perl, makeWrapper }:
 
 # BLCR 0.8.5 should works for kernel version up to 3.7.1
 # BLCR 0.8.6 should works for kernel version up to 3.17.x
@@ -6,6 +6,9 @@
 assert stdenv.isLinux;
 assert builtins.compareVersions "3.18" kernel.version == 1;
 
+# it doesn't compile anymore on 3.12
+assert lib.versionAtLeast kernel.version "3.14";
+
 stdenv.mkDerivation {
   name = "blcr_${kernel.version}-0.8.6pre4";
 
diff --git a/pkgs/os-specific/linux/broadcom-sta/linux-recent.patch b/pkgs/os-specific/linux/broadcom-sta/linux-recent.patch
index 81d27204b4e..a690558eb5b 100644
--- a/pkgs/os-specific/linux/broadcom-sta/linux-recent.patch
+++ b/pkgs/os-specific/linux/broadcom-sta/linux-recent.patch
@@ -79,7 +79,19 @@
  
  	if (unlikely(!cbss))
  		return -ENOMEM;
-@@ -2071,7 +2096,26 @@
+@@ -2047,7 +2072,11 @@
+ 		}
+ 		else if ((event == WLC_E_LINK && ~(flags & WLC_EVENT_MSG_LINK)) ||
+ 			event == WLC_E_DEAUTH_IND || event == WLC_E_DISASSOC_IND) {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 2, 0)
++			cfg80211_disconnected(ndev, 0, NULL, 0, false, GFP_KERNEL);
++#else
+ 			cfg80211_disconnected(ndev, 0, NULL, 0, GFP_KERNEL);
++#endif
+ 			clear_bit(WL_STATUS_CONNECTED, &wl->status);
+ 			wl_link_down(wl);
+ 			wl_init_prof(wl->profile);
+@@ -2071,7 +2100,26 @@
  			wl_get_assoc_ies(wl);
  			memcpy(&wl->bssid, &e->addr, ETHER_ADDR_LEN);
  			wl_update_bss_info(wl);
@@ -106,7 +118,7 @@
  			set_bit(WL_STATUS_CONNECTED, &wl->status);
  			wl->profile->active = true;
  		}
-@@ -2629,7 +2673,15 @@
+@@ -2629,7 +2677,15 @@
  
  void wl_cfg80211_detach(struct net_device *ndev)
  {
diff --git a/pkgs/os-specific/linux/can-utils/default.nix b/pkgs/os-specific/linux/can-utils/default.nix
index f181db0c5e3..9da2b755fd5 100644
--- a/pkgs/os-specific/linux/can-utils/default.nix
+++ b/pkgs/os-specific/linux/can-utils/default.nix
@@ -17,7 +17,7 @@ stdenv.mkDerivation rec {
 
   meta = with stdenv.lib; {
     description = "CAN userspace utilities and tools (for use with Linux SocketCAN)";
-    homepage = "https://gitorious.org/linux-can/can-utils";
+    homepage = "https://github.com/linux-can/can-utils";
     license = licenses.gpl2Plus;
     platforms = platforms.linux;
     maintainers = [ maintainers.bjornfor ];
diff --git a/pkgs/os-specific/linux/cgmanager/default.nix b/pkgs/os-specific/linux/cgmanager/default.nix
index 8f56eda3a1b..1c79fddeca9 100644
--- a/pkgs/os-specific/linux/cgmanager/default.nix
+++ b/pkgs/os-specific/linux/cgmanager/default.nix
@@ -1,14 +1,15 @@
-{ stdenv, fetchurl, pkgconfig, libnih, dbus }:
+{ stdenv, fetchurl, pkgconfig, libnih, dbus, pam }:
 
 stdenv.mkDerivation rec {
-  name = "cgmanager-0.37";
+  name = "cgmanager-0.39";
 
   src = fetchurl {
     url = "https://linuxcontainers.org/downloads/cgmanager/${name}.tar.gz";
-    sha256 = "0vkv8am6h3x89c1rqb6a1glwz3mik3065jigri96njjzmvrff2c3";
+    sha256 = "0ysv8klnybp727aad2k0aa67s05q027pzfl7rmm0map4nizlhrcy";
   };
 
-  buildInputs = [ pkgconfig libnih dbus ];
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libnih dbus pam ];
 
   configureFlags = [
     "--with-init-script=systemd"
diff --git a/pkgs/os-specific/linux/conky/default.nix b/pkgs/os-specific/linux/conky/default.nix
index c54d4aa6319..b857d5ece45 100644
--- a/pkgs/os-specific/linux/conky/default.nix
+++ b/pkgs/os-specific/linux/conky/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, pkgconfig
+{ stdenv, fetchFromGitHub, pkgconfig, cmake
 
 # dependencies
 , glib
@@ -7,23 +7,17 @@
 , mpdSupport          ? true
 , ibmSupport          ? true # IBM/Lenovo notebooks
 
-# This should be optional, but it is not due to a bug in conky
-# Please, try to make it optional again on update
-, ncurses
-#, ncursesSupport      ? true      , ncurses       ? null
-
 # optional features with extra dependencies
-, x11Support          ? true      , x11           ? null
+, ncursesSupport      ? true      , ncurses       ? null
+, x11Support          ? true      , xlibsWrapper           ? null
 , xdamageSupport      ? x11Support, libXdamage    ? null
 , imlib2Support       ? x11Support, imlib2        ? null
-, luaSupport          ? true      , lua           ? null
 
+, luaSupport          ? true      , lua           ? null
 , luaImlib2Support    ? luaSupport && imlib2Support
 , luaCairoSupport     ? luaSupport && x11Support, cairo ? null
 , toluapp ? null
 
-, alsaSupport         ? true      , alsaLib       ? null
-
 , wirelessSupport     ? true      , wirelesstools ? null
 
 , curlSupport         ? true      , curl ? null
@@ -33,9 +27,9 @@
 , libxml2 ? null
 }:
 
-#assert ncursesSupport      -> ncurses != null;
+assert ncursesSupport      -> ncurses != null;
 
-assert x11Support          -> x11 != null;
+assert x11Support          -> xlibsWrapper != null;
 assert xdamageSupport      -> x11Support && libXdamage != null;
 assert imlib2Support       -> x11Support && imlib2     != null;
 assert luaSupport          -> lua != null;
@@ -46,8 +40,6 @@ assert luaCairoSupport     -> luaSupport && toluapp != null
 assert luaCairoSupport || luaImlib2Support
                            -> lua.luaversion == "5.1";
 
-assert alsaSupport         -> alsaLib != null;
-
 assert wirelessSupport     -> wirelesstools != null;
 
 assert curlSupport         -> curl != null;
@@ -58,62 +50,52 @@ assert weatherXoapSupport  -> curlSupport && libxml2 != null;
 with stdenv.lib;
 
 stdenv.mkDerivation rec {
-  name = "conky-1.9.0";
-
-  src = fetchurl {
-    url = "mirror://sourceforge/conky/${name}.tar.bz2";
-    sha256 = "0vxvjmi3cdvnp994sv5zcdyncfn0mlxa71p2wm9zpyrmy58bbwds";
+  name = "conky-${version}";
+  version = "1.10.0";
+
+  src = fetchFromGitHub {
+    owner = "brndnmtthws";
+    repo = "conky";
+    rev = "v${version}";
+    sha256 = "00vyrf72l54j3majqmn6vykqvvb15vygsaby644nsb5vpma6b1cn";
   };
 
   NIX_LDFLAGS = "-lgcc_s";
 
-  buildInputs = [ pkgconfig glib ]
-    ++ [ ncurses ]
-    #++ optional  ncursesSupport     ncurses
-    ++ optional  x11Support         x11
+  buildInputs = [ pkgconfig glib cmake ]
+    ++ optional  ncursesSupport     ncurses
+    ++ optional  x11Support         xlibsWrapper
     ++ optional  xdamageSupport     libXdamage
     ++ optional  imlib2Support      imlib2
     ++ optional  luaSupport         lua
     ++ optionals luaImlib2Support   [ toluapp imlib2 ]
     ++ optionals luaCairoSupport    [ toluapp cairo ]
-
-    ++ optional  alsaSupport        alsaLib
-
     ++ optional  wirelessSupport    wirelesstools
-
     ++ optional  curlSupport        curl
     ++ optional  rssSupport         libxml2
     ++ optional  weatherXoapSupport libxml2
     ;
 
-  configureFlags =
-    let flag = state: flags: if state then map (x: "--enable-${x}")  flags
-                                      else map (x: "--disable-${x}") flags;
-     in flag mpdSupport          [ "mpd" ]
-     ++ flag ibmSupport          [ "ibm" ]
-
-     #++ flag ncursesSupport      [ "ncurses" ]
-     ++ flag x11Support          [ "x11" "xft" "argb" "double-buffer" "own-window" ] # conky won't compile without --enable-own-window
-     ++ flag xdamageSupport      [ "xdamage" ]
-     ++ flag imlib2Support       [ "imlib2" ]
-     ++ flag luaSupport          [ "lua" ]
-     ++ flag luaImlib2Support    [ "lua-imlib2" ]
-     ++ flag luaCairoSupport     [ "lua-cairo" ]
-
-     ++ flag alsaSupport         [ "alsa" ]
-
-     ++ flag wirelessSupport     [ "wlan" ]
-
-     ++ flag curlSupport         [ "curl" ]
-     ++ flag rssSupport          [ "rss" ]
-     ++ flag weatherMetarSupport [ "weather-metar" ]
-     ++ flag weatherXoapSupport  [ "weather-xoap" ]
-     ;
+  cmakeFlags = [ "-DCMAKE_BUILD_TYPE=Release" ]
+    ++ optional curlSupport         "-DBUILD_CURL=ON"
+    ++ optional (!ibmSupport)       "-DBUILD_IBM=OFF"
+    ++ optional imlib2Support       "-DBUILD_IMLIB2=ON"
+    ++ optional luaCairoSupport     "-DBUILD_LUA_CAIRO=ON"
+    ++ optional luaImlib2Support    "-DBUILD_LUA_IMLIB2=ON"
+    ++ optional (!mpdSupport)       "-DBUILD_MPD=OFF"
+    ++ optional (!ncursesSupport)   "-DBUILD_NCURSES=OFF"
+    ++ optional rssSupport          "-DBUILD_RSS=ON"
+    ++ optional (!x11Support)       "-DBUILD_X11=OFF"
+    ++ optional xdamageSupport      "-DBUILD_XDAMAGE=ON"
+    ++ optional weatherMetarSupport "-DBUILD_WEATHER_METAR=ON"
+    ++ optional weatherXoapSupport  "-DBUILD_WEATHER_XOAP=ON"
+    ++ optional wirelessSupport     "-DBUILD_WLAN=ON"
+    ;
 
-  meta = {
+  meta = with stdenv.lib; {
     homepage = http://conky.sourceforge.net/;
     description = "Advanced, highly configurable system monitor based on torsmo";
-    maintainers = [ stdenv.lib.maintainers.guibert ];
-    license = stdenv.lib.licenses.gpl3Plus;
+    maintainers = [ maintainers.guibert ];
+    license = licenses.gpl3Plus;
   };
 }
diff --git a/pkgs/os-specific/linux/conntrack-tools/default.nix b/pkgs/os-specific/linux/conntrack-tools/default.nix
index 51358628ff1..f0988759bc4 100644
--- a/pkgs/os-specific/linux/conntrack-tools/default.nix
+++ b/pkgs/os-specific/linux/conntrack-tools/default.nix
@@ -4,11 +4,11 @@
 
 stdenv.mkDerivation rec {
   name = "conntrack-tools-${version}";
-  version = "1.4.2";
+  version = "1.4.3";
 
   src = fetchurl {
     url = "http://www.netfilter.org/projects/conntrack-tools/files/${name}.tar.bz2";
-    sha256 = "e5c423dc077f9ca8767eaa6cf40446943905711c6a8fe27f9cc1977d4d6aa11e";
+    sha256 = "0mrzrzp6y41pmxc6ixc4fkgz6layrpwsmzb522adzzkc6mhcqg5g";
   };
 
   buildInputs = [ libmnl libnfnetlink libnetfilter_conntrack libnetfilter_queue
@@ -20,5 +20,6 @@ stdenv.mkDerivation rec {
     description = "Connection tracking userspace tools";
     platforms = platforms.linux;
     license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ nckx ];
   };
 }
diff --git a/pkgs/os-specific/linux/directvnc/default.nix b/pkgs/os-specific/linux/directvnc/default.nix
index 33ebd28d55e..b6f221b8ea4 100644
--- a/pkgs/os-specific/linux/directvnc/default.nix
+++ b/pkgs/os-specific/linux/directvnc/default.nix
@@ -1,5 +1,5 @@
-a :  
-let 
+a @ { libjpeg, pkgconfig, zlib, directfb, xproto, ... } :
+let
   s = import ./src-for-default.nix;
   buildInputs = with a; [
     directfb zlib libjpeg pkgconfig xproto
@@ -14,13 +14,13 @@ rec {
 
   /* doConfigure should be removed if not needed */
   phaseNames = ["doConfigure" "doMakeInstall"];
-      
+
   meta = {
     description = "DirectFB VNC client";
     maintainers = [
       a.lib.maintainers.raskin
     ];
-    platforms = with a.lib.platforms; 
+    platforms = with a.lib.platforms;
       linux;
   };
 }
diff --git a/pkgs/os-specific/linux/dmidecode/default.nix b/pkgs/os-specific/linux/dmidecode/default.nix
index 19d4092ba78..7ba8dffcc31 100644
--- a/pkgs/os-specific/linux/dmidecode/default.nix
+++ b/pkgs/os-specific/linux/dmidecode/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl }:
 
 stdenv.mkDerivation rec {
-  name = "dmidecode-2.12";
+  name = "dmidecode-3.0";
 
   src = fetchurl {
-    url = "mirror://savannah/dmidecode/${name}.tar.bz2";
-    sha256 = "122hgaw8mpqdfra159lfl6pyk3837giqx6vq42j64fjnbl2z6gwi";
+    url = "mirror://savannah/dmidecode/${name}.tar.xz";
+    sha256 = "0iby0xfk5x3cdr0x0gxj5888jjyjhafvaq0l79civ73jjfqmphvy";
   };
 
   makeFlags = "prefix=$(out)";
diff --git a/pkgs/os-specific/linux/dstat/default.nix b/pkgs/os-specific/linux/dstat/default.nix
index b12ed2ee6ec..6b3b7fac8f3 100644
--- a/pkgs/os-specific/linux/dstat/default.nix
+++ b/pkgs/os-specific/linux/dstat/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, python }:
+{ stdenv, fetchurl, python, pythonPackages }:
 
 stdenv.mkDerivation rec {
   name = "dstat-0.7.2";
@@ -8,7 +8,9 @@ stdenv.mkDerivation rec {
     sha256 = "1bivnciwlamnl9q6i5ygr7jhs8pp833z2bkbrffvsa60szcqda9l";
   };
 
-  buildInputs = [ ];
+  buildInputs = with pythonPackages; [ python-wifi wrapPython ];
+
+  pythonPath = with pythonPackages; [ python-wifi ];
 
   patchPhase = ''
     sed -i -e 's|/usr/bin/env python|${python}/bin/python|' \
@@ -17,11 +19,15 @@ stdenv.mkDerivation rec {
 
   makeFlags = "prefix=$(out)";
 
+  postInstall = ''
+    wrapPythonProgramsIn $out/bin "$out $pythonPath"
+  '';
+
   meta = with stdenv.lib; {
     homepage = http://dag.wieers.com/home-made/dstat/;
     description = "Versatile resource statistics tool";
     license = licenses.gpl2;
     platforms = platforms.linux;
-    maintainers = with maintainers; [ jgeerds ];
+    maintainers = with maintainers; [ jgeerds nckx ];
   };
 }
diff --git a/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix b/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix
index 436f40712fc..1cc0e7ae4ca 100644
--- a/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix
+++ b/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix
@@ -15,8 +15,8 @@ stdenv.mkDerivation {
   phases = [ "unpackPhase" "installPhase" ];
 
   installPhase = ''
-    mkdir $out
-    b43-fwcutter -w $out linux/wl_apsta.o
+    mkdir -p $out/lib/firmware
+    b43-fwcutter -w $out/lib/firmware linux/wl_apsta.o
   '';
 
   meta = {
diff --git a/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix b/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix
index 259c5acdf87..9c4e0f3990c 100644
--- a/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix
+++ b/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix
@@ -2,7 +2,7 @@
 
 stdenv.mkDerivation rec {
   name = "firmware-linux-nonfree-${version}";
-  version = "2015-07-23";
+  version = "2015-09-07";
 
   # This repo is built by merging the latest versions of
   # http://git.kernel.org/cgit/linux/kernel/git/firmware/linux-firmware.git/
@@ -14,8 +14,8 @@ stdenv.mkDerivation rec {
   src = fetchFromGitHub {
     owner = "wkennington";
     repo = "linux-firmware";
-    rev = "854b7f33e839ceea41034b45d6f755ea70c85486";
-    sha256 = "1hhqvb96adk64ljf6hp5qss8fhpic28y985gbggh5p2w9bsgs5zq";
+    rev = "0c3ac7434235f57967df4046ceafc0e4a08bb139";
+    sha256 = "1jhcgf0anjfi2998nzplr9l1q0b1yi306a2w1k2r4civsmfgm08r";
   };
 
   preInstall = ''
@@ -30,6 +30,7 @@ stdenv.mkDerivation rec {
     license = licenses.unfreeRedistributableFirmware;
     platforms = platforms.linux;
     maintainers = with maintainers; [ wkennington ];
+    priority = 6; # give precedence to kernel firmware
   };
 
   passthru = { inherit version; };
diff --git a/pkgs/os-specific/linux/firmware/zd1211/default.nix b/pkgs/os-specific/linux/firmware/zd1211/default.nix
index 96e534e3b80..19cbdecca0c 100644
--- a/pkgs/os-specific/linux/firmware/zd1211/default.nix
+++ b/pkgs/os-specific/linux/firmware/zd1211/default.nix
@@ -5,16 +5,16 @@ stdenv.mkDerivation rec {
   version = "1.5";
 
   name = "${pname}-${version}";
-  
+
   src = fetchurl {
     url = "mirror://sourceforge/zd1211/${name}.tar.bz2";
     sha256 = "04ibs0qw8bh6h6zmm5iz6lddgknwhsjq8ib3gyck6a7psw83h7gi";
   };
-  
+
   buildPhase = "true";
 
-  installPhase = "mkdir -p $out/zd1211; cp * $out/zd1211";
-  
+  installPhase = "mkdir -p $out/lib/firmware/zd1211; cp * $out/lib/firmware/zd1211";
+
   meta = {
     description = "Firmware for the ZyDAS ZD1211(b) 802.11a/b/g USB WLAN chip";
     homepage = http://sourceforge.net/projects/zd1211/;
diff --git a/pkgs/os-specific/linux/freefall/default.nix b/pkgs/os-specific/linux/freefall/default.nix
index 34d0f3881e4..683ec9f6155 100644
--- a/pkgs/os-specific/linux/freefall/default.nix
+++ b/pkgs/os-specific/linux/freefall/default.nix
@@ -1,39 +1,33 @@
 { stdenv, fetchurl }:
 
-let version = "3.19"; in
+let version = "4.2"; in
 stdenv.mkDerivation {
   name = "freefall-${version}";
 
   src = fetchurl {
-    sha256 = "0v40b5l6dcviqgl47bxlcbimz7kawmy1c2909axi441jwlgm2hmy";
-    url = "mirror://kernel/linux/kernel/v3.x/linux-${version}.tar.xz";
+    sha256 = "1syv8n5hwzdbx69rsj4vayyzskfq1w5laalg5jjd523my52f086g";
+    url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
   };
 
-  buildPhase = ''
-    cd Documentation/laptops
+  postPatch = ''
+    cd tools/laptop/freefall
 
     # Default time-out is a little low, probably because the AC/lid status
     # functions were never implemented. Because no-one still uses HDDs, right?
-    substituteInPlace freefall.c --replace "alarm(2)" "alarm(5)"
-
-    cc -o freefall freefall.c
+    substituteInPlace freefall.c --replace "alarm(2)" "alarm(7)"
   '';
 
-  installPhase = ''
-    mkdir -p $out/bin
-    install freefall $out/bin
-  '';
+  makeFlags = "PREFIX=$(out)";
 
   meta = with stdenv.lib; {
     description = "Free-fall protection for spinning HP/Dell laptop hard drives";
     longDescription = ''
-      ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with unload feature.
-      Issuing this command should cause the drive to switch to idle mode and
-      unload disk heads. This feature is being used in modern laptops in
-      conjunction with accelerometers and appropriate software to implement
-      a shock protection facility. The idea is to stop all I/O operations on
-      the internal hard drive and park its heads on the ramp when critical
-      situations are anticipated. This has no effect on SSD devices!
+      Provides a shock protection facility in modern laptops with spinning hard
+      drives, by stopping all input/output operations on the internal hard drive
+      and parking its heads on the ramp when critical situations are anticipated.
+      Requires support for the ATA/ATAPI-7 IDLE IMMEDIATE command with unload
+      feature, which should cause the drive to switch to idle mode and unload the
+      disk heads, and an accelerometer device. It has no effect on SSD devices!
     '';
     license = licenses.gpl2;
     platforms = with platforms; linux;
diff --git a/pkgs/os-specific/linux/htop/default.nix b/pkgs/os-specific/linux/htop/default.nix
index 873795c9752..da41c95dda2 100644
--- a/pkgs/os-specific/linux/htop/default.nix
+++ b/pkgs/os-specific/linux/htop/default.nix
@@ -1,11 +1,11 @@
 { fetchFromGitHub, stdenv, autoreconfHook, ncurses }:
 
 stdenv.mkDerivation rec {
-  name = "htop-1.0.3-584-8f07868f";
+  name = "htop-1.0.3-239-229d0058";
 
   src = fetchFromGitHub {
-    sha256 = "0s7l9v7n7hw32hznvdq2sykyxgb30hmzycwcjxw8f0c2mww61xcd";
-    rev = "8f07868fefeb844a852fab704c0763b0e9a9bf01";
+    sha256 = "1bym6ligd8db4iyv2m1y7aylh7f9fmk71v67rkhird05hx1xb80r";
+    rev = "229d005851af8dca595b3df8e385375fb9c382b4";
     repo = "htop";
     owner = "hishamhm";
   };
@@ -13,6 +13,10 @@ stdenv.mkDerivation rec {
   buildInputs = [ ncurses ];
   nativeBuildInputs = [ autoreconfHook ];
 
+  postPatch = ''
+    touch *.h */*.h # unnecessary regeneration requires Python
+  '';
+
   meta = {
     description = "An interactive process viewer for Linux";
     homepage = "http://htop.sourceforge.net";
diff --git a/pkgs/os-specific/linux/iproute/default.nix b/pkgs/os-specific/linux/iproute/default.nix
index 6f5ec27c638..287b83b637f 100644
--- a/pkgs/os-specific/linux/iproute/default.nix
+++ b/pkgs/os-specific/linux/iproute/default.nix
@@ -3,11 +3,11 @@
 }:
 
 stdenv.mkDerivation rec {
-  name = "iproute2-4.1.1";
+  name = "iproute2-4.2.0";
 
   src = fetchurl {
     url = "mirror://kernel/linux/utils/net/iproute2/${name}.tar.xz";
-    sha256 = "0vz6m2k6hdrjlg4x0r3cd75lg9ysmndbsp35pm8494zvksc7l1vk";
+    sha256 = "0c0gyf46ad3jlalm9a7c9iiwvpcrjr4gylrkyranp8qd7rs1w454";
   };
 
   patches = lib.optionals enableFan [ ./ubuntu-fan.patch ];
diff --git a/pkgs/os-specific/linux/ipset/default.nix b/pkgs/os-specific/linux/ipset/default.nix
index b76ce583b23..2db57ecef92 100644
--- a/pkgs/os-specific/linux/ipset/default.nix
+++ b/pkgs/os-specific/linux/ipset/default.nix
@@ -1,14 +1,15 @@
 { stdenv, fetchurl, pkgconfig, libmnl }:
 
 stdenv.mkDerivation rec {
-  name = "ipset-6.24";
+  name = "ipset-6.26";
 
   src = fetchurl {
     url = "http://ipset.netfilter.org/${name}.tar.bz2";
-    sha256 = "1l4mx78473azf7cb19fxf37gmj95k1zzabimbcmlg9h07wlgqw9h";
+    sha256 = "0lbsg1fbiw9m959lgqziyivmx32z3vbnp3jhgnprkq31ia7a29kn";
   };
 
-  buildInputs = [ pkgconfig libmnl ];
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libmnl ];
 
   configureFlags = [ "--with-kmod=no" ];
 
diff --git a/pkgs/os-specific/linux/kbd/default.nix b/pkgs/os-specific/linux/kbd/default.nix
index 4c6f33b1d80..bb2915958f7 100644
--- a/pkgs/os-specific/linux/kbd/default.nix
+++ b/pkgs/os-specific/linux/kbd/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, autoreconfHook, gzip, bzip2, pkgconfig, check, pam }:
 
 stdenv.mkDerivation rec {
-  name = "kbd-2.0.2";
+  name = "kbd-2.0.3";
 
   src = fetchurl {
     url = "mirror://kernel/linux/utils/kbd/${name}.tar.xz";
-    sha256 = "04mrms12nm5sas0nxs94yrr3hz7gmqhnmfgb9ff34bh1jszxmzcx";
+    sha256 = "0ppv953gn2zylcagr4z6zg5y2x93dxrml29plypg6xgbq3hrv2bs";
   };
 
   /* Get the dvorak programmer keymap (present in X but not in kbd) */
diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix
index 386004dad43..ef35757fdb2 100644
--- a/pkgs/os-specific/linux/kernel/common-config.nix
+++ b/pkgs/os-specific/linux/kernel/common-config.nix
@@ -140,7 +140,9 @@ with stdenv.lib;
 
   # Video configuration.
   # Enable KMS for devices whose X.org driver supports it.
-  DRM_I915_KMS y
+  ${optionalString (versionOlder version "4.3") ''
+    DRM_I915_KMS y
+  ''}
   # Allow specifying custom EDID on the kernel command line
   DRM_LOAD_EDID_FIRMWARE y
   ${optionalString (versionOlder version "3.9") ''
@@ -327,6 +329,7 @@ with stdenv.lib;
   SERIAL_8250 y # 8250/16550 and compatible serial support
   SLIP_COMPRESSED y # CSLIP compressed headers
   SLIP_SMART y
+  HWMON y
   THERMAL_HWMON y # Hardware monitoring support
   ${optionalString (versionAtLeast version "3.15") ''
     UEVENT_HELPER n
@@ -477,8 +480,7 @@ with stdenv.lib;
 
   ${optionalString (versionAtLeast version "3.17") "NFC? n"}
 
-  # Enable firmware loading via udev. Only needed for non-declarative
-  # firmware in /root/test-firmware.
+  # Enable firmware loading via udev (legacy).
   ${optionalString (versionAtLeast version "3.17") ''
     FW_LOADER_USER_HELPER_FALLBACK y
   ''}
diff --git a/pkgs/os-specific/linux/kernel/flush_workqueue-export.patch b/pkgs/os-specific/linux/kernel/flush_workqueue-export.patch
new file mode 100644
index 00000000000..17583e31730
--- /dev/null
+++ b/pkgs/os-specific/linux/kernel/flush_workqueue-export.patch
@@ -0,0 +1,13 @@
+diff --git a/kernel/workqueue.c b/kernel/workqueue.c
+index 4c4f061..a413acb 100644
+--- a/kernel/workqueue.c
++++ b/kernel/workqueue.c
+@@ -2614,7 +2614,7 @@ void flush_workqueue(struct workqueue_struct *wq)
+ out_unlock:
+ 	mutex_unlock(&wq->mutex);
+ }
+-EXPORT_SYMBOL_GPL(flush_workqueue);
++EXPORT_SYMBOL(flush_workqueue);
+ 
+ /**
+  * drain_workqueue - drain a workqueue
diff --git a/pkgs/os-specific/linux/kernel/linux-3.10.nix b/pkgs/os-specific/linux/kernel/linux-3.10.nix
index 81c2b28c593..a66397f689b 100644
--- a/pkgs/os-specific/linux/kernel/linux-3.10.nix
+++ b/pkgs/os-specific/linux/kernel/linux-3.10.nix
@@ -1,12 +1,12 @@
-{ stdenv, fetchurl, ... } @ args:
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
-  version = "3.10.87";
+  version = "3.10.89";
   extraMeta.branch = "3.10";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v3.x/linux-${version}.tar.xz";
-    sha256 = "01lax9c6j2gw33pr7dla1ly1d89970mkbwh2hnmysgzsyh136rvg";
+    sha256 = "13697akpdkv7xyyprysb4017q7j1ccynppb6wwllmhz1g2ichpii";
   };
 
   features.iwlwifi = true;
diff --git a/pkgs/os-specific/linux/kernel/linux-3.12.nix b/pkgs/os-specific/linux/kernel/linux-3.12.nix
index 904aebd75be..da520d13a02 100644
--- a/pkgs/os-specific/linux/kernel/linux-3.12.nix
+++ b/pkgs/os-specific/linux/kernel/linux-3.12.nix
@@ -1,12 +1,12 @@
-{ stdenv, fetchurl, ... } @ args:
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
-  version = "3.12.46";
+  version = "3.12.48";
   extraMeta.branch = "3.12";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v3.x/linux-${version}.tar.xz";
-    sha256 = "01w0b1sifzivbagm724bz0mlfrm7hpbj5a3lx1yrv8xg64gni3m1";
+    sha256 = "1mvvpi2s8avg629y72miak8mdbv0mwb5dz0m7b48aah6dg866hiz";
   };
 
   features.iwlwifi = true;
diff --git a/pkgs/os-specific/linux/kernel/linux-3.14.nix b/pkgs/os-specific/linux/kernel/linux-3.14.nix
index 6bf0065c09d..5ea214c9eb3 100644
--- a/pkgs/os-specific/linux/kernel/linux-3.14.nix
+++ b/pkgs/os-specific/linux/kernel/linux-3.14.nix
@@ -1,13 +1,13 @@
-{ stdenv, fetchurl, ... } @ args:
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
-  version = "3.14.51";
+  version = "3.14.53";
   # Remember to update grsecurity!
   extraMeta.branch = "3.14";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v3.x/linux-${version}.tar.xz";
-    sha256 = "1gqsd69cqijff4c4br4ydmcjl226d0yy6vrmgfvy16xiraavq1mk";
+    sha256 = "0zqaqa7gs895p521c82jggak9zlmiwmkfarh2ykvh423sxjbvs5i";
   };
 
   features.iwlwifi = true;
diff --git a/pkgs/os-specific/linux/kernel/linux-3.18.nix b/pkgs/os-specific/linux/kernel/linux-3.18.nix
index 05c4b989f39..c1171cecab5 100644
--- a/pkgs/os-specific/linux/kernel/linux-3.18.nix
+++ b/pkgs/os-specific/linux/kernel/linux-3.18.nix
@@ -1,12 +1,12 @@
-{ stdenv, fetchurl, ... } @ args:
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
-  version = "3.18.20";
+  version = "3.18.21";
   extraMeta.branch = "3.18";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v3.x/linux-${version}.tar.xz";
-    sha256 = "1mwm9xgilsqnj95v3jn94dz9a108ggfm4ifb3kxsfsx5rcl5yy8d";
+    sha256 = "0y54kh55grgbyw4k8fa9vx8b426bq9lz12bpvwvzfjs7vimachyw";
   };
 
   features.iwlwifi = true;
diff --git a/pkgs/os-specific/linux/kernel/linux-4.0.nix b/pkgs/os-specific/linux/kernel/linux-4.0.nix
deleted file mode 100644
index eee052ad3bb..00000000000
--- a/pkgs/os-specific/linux/kernel/linux-4.0.nix
+++ /dev/null
@@ -1,17 +0,0 @@
-{ stdenv, fetchurl, ... } @ args:
-
-import ./generic.nix (args // rec {
-  version = "4.0.9";
-  extraMeta.branch = "4.0";
-
-  src = fetchurl {
-    url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
-    sha256 = "0k42blafzd954fncc0b78vi9x1h2k0jhfvkjqxmpv64i7xwwdhsx";
-  };
-
-  features.iwlwifi = true;
-  features.efiBootStub = true;
-  features.needsCifsUtils = true;
-  features.canDisableNetfilterConntrackHelpers = true;
-  features.netfilterRPFilter = true;
-} // (args.argsOverride or {}))
diff --git a/pkgs/os-specific/linux/kernel/linux-4.1.nix b/pkgs/os-specific/linux/kernel/linux-4.1.nix
index d50fd24e86d..1a84e00f788 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.1.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.1.nix
@@ -1,13 +1,13 @@
-{ stdenv, fetchurl, ... } @ args:
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
-  version = "4.1.6";
+  version = "4.1.8";
   # Remember to update grsecurity!
   extraMeta.branch = "4.1";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
-    sha256 = "1zlr7d5d7rhcbpwsi0svmv0zwj50n6mj6xgfzwwi336f5p26wbci";
+    sha256 = "1zhck5892c3anbifq3d0ngy40zm9q4c651kgkjk9wf32jjpnngar";
   };
 
   features.iwlwifi = true;
diff --git a/pkgs/os-specific/linux/kernel/linux-4.2.nix b/pkgs/os-specific/linux/kernel/linux-4.2.nix
new file mode 100644
index 00000000000..d82e567de8f
--- /dev/null
+++ b/pkgs/os-specific/linux/kernel/linux-4.2.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
+
+import ./generic.nix (args // rec {
+  version = "4.2.1";
+  extraMeta.branch = "4.2";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
+    sha256 = "1b4dpf3rhr1sb1hpz4qx3h1swlcr1xnbrh6sjybqmj2c6szkbpvz";
+  };
+
+  features.iwlwifi = true;
+  features.efiBootStub = true;
+  features.needsCifsUtils = true;
+  features.canDisableNetfilterConntrackHelpers = true;
+  features.netfilterRPFilter = true;
+
+  # cherry-pick from upstream to resolve a licensing problem that prevents
+  # compiling the broadcom-sta wireless driver on kernels >= 4.2
+  # see: https://github.com/longsleep/bcmwl-ubuntu/issues/6
+  kernelPatches = [ {
+    name = "flush-workqueue-export";
+    patch = ./flush_workqueue-export.patch;
+  } ];
+} // (args.argsOverride or {}))
diff --git a/pkgs/os-specific/linux/kernel/linux-rpi.nix b/pkgs/os-specific/linux/kernel/linux-rpi.nix
index 02b29708131..320d4994cf2 100644
--- a/pkgs/os-specific/linux/kernel/linux-rpi.nix
+++ b/pkgs/os-specific/linux/kernel/linux-rpi.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, ... } @ args:
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
 
 let
 
diff --git a/pkgs/os-specific/linux/kernel/linux-testing.nix b/pkgs/os-specific/linux/kernel/linux-testing.nix
index 216f74caa34..d13357825a5 100644
--- a/pkgs/os-specific/linux/kernel/linux-testing.nix
+++ b/pkgs/os-specific/linux/kernel/linux-testing.nix
@@ -1,13 +1,13 @@
-{ stdenv, fetchurl, ... } @ args:
+{ stdenv, fetchurl, perl, buildLinux, ... } @ args:
 
 import ./generic.nix (args // rec {
-  version = "4.2-rc5";
-  modDirVersion = "4.2.0-rc5";
-  extraMeta.branch = "4.2";
+  version = "4.3-rc2";
+  modDirVersion = "4.3.0-rc2";
+  extraMeta.branch = "4.3";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v4.x/testing/linux-${version}.tar.xz";
-    sha256 = "1ir3g5in53qq50ygnwgkzjkl1pzb12ar8k1zvfzcxapddvnhayr0";
+    sha256 = "1mgm3r0vz0jbfbqxcjfw0wv5ix6qhwymjz1chh543lvb0729ayb4";
   };
 
   features.iwlwifi = true;
diff --git a/pkgs/os-specific/linux/kernel/manual-config.nix b/pkgs/os-specific/linux/kernel/manual-config.nix
index a14088c81ef..49880e0ecdd 100644
--- a/pkgs/os-specific/linux/kernel/manual-config.nix
+++ b/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -1,4 +1,4 @@
-{ stdenv, runCommand, nettools, bc, perl, kmod, writeTextFile, ubootChooser }:
+{ stdenv, runCommand, nettools, bc, perl, kmod, openssl, writeTextFile, ubootChooser }:
 
 let
   readConfig = configfile: import (runCommand "config.nix" {} ''
@@ -221,7 +221,7 @@ stdenv.mkDerivation ((drvAttrs config stdenv.platform (kernelPatches ++ nativeKe
 
   enableParallelBuilding = true;
 
-  nativeBuildInputs = [ perl bc nettools ] ++ optional (stdenv.platform.uboot != null)
+  nativeBuildInputs = [ perl bc nettools openssl ] ++ optional (stdenv.platform.uboot != null)
     (ubootChooser stdenv.platform.uboot);
 
   makeFlags = commonMakeFlags ++ [
diff --git a/pkgs/os-specific/linux/kernel/patches.nix b/pkgs/os-specific/linux/kernel/patches.nix
index b3c51dc6306..18e73ae68d4 100644
--- a/pkgs/os-specific/linux/kernel/patches.nix
+++ b/pkgs/os-specific/linux/kernel/patches.nix
@@ -82,10 +82,10 @@ rec {
     };
 
   grsecurity_unstable = grsecPatch
-    { kversion  = "4.1.6";
-      revision  = "201508181953";
+    { kversion  = "4.1.7";
+      revision  = "201509131604";
       branch    = "test";
-      sha256    = "1m227k1wb1q588vkgmngcz86k0wpzan6vra67pcx2478mabm3s89";
+      sha256    = "1frfyi1pkiqc3awri3sr7xv41qxc8m2kb1yhfvj6xkrwb9li2bki";
     };
 
   grsec_fix_path =
diff --git a/pkgs/os-specific/linux/kernel/perf.nix b/pkgs/os-specific/linux/kernel/perf.nix
index efd3515ff24..2dcdcdc4a91 100644
--- a/pkgs/os-specific/linux/kernel/perf.nix
+++ b/pkgs/os-specific/linux/kernel/perf.nix
@@ -23,10 +23,13 @@ stdenv.mkDerivation {
   # perf refers both to newt and slang
   # binutils is required for libbfd.
   nativeBuildInputs = [ asciidoc xmlto docbook_xsl docbook_xml_dtd_45 libxslt flex bison ];
-  buildInputs = [ elfutils python perl newt slang pkgconfig libunwind binutils ] ++
+  buildInputs = [ python perl newt slang pkgconfig libunwind binutils ] ++
     stdenv.lib.optional withGtk gtk;
 
-  NIX_CFLAGS_COMPILE = "-Wno-error=cpp";
+  # Note: we don't add elfutils to buildInputs, since it provides a
+  # bad `ld' and other stuff.
+  NIX_CFLAGS_COMPILE = "-I${elfutils}/include -Wno-error=cpp";
+  NIX_CFLAGS_LINK = "-L${elfutils}/lib";
 
   installFlags = "install install-man ASCIIDOC8=1";
 
diff --git a/pkgs/os-specific/linux/kmod-debian-aliases/default.nix b/pkgs/os-specific/linux/kmod-debian-aliases/default.nix
new file mode 100644
index 00000000000..13fe500286d
--- /dev/null
+++ b/pkgs/os-specific/linux/kmod-debian-aliases/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, fetchurl, lib }:
+let
+  version = "21-1";
+in
+stdenv.mkDerivation {
+  name = "kmod-debian-aliases-${version}.conf";
+
+  src = fetchurl {
+    url = "mirror://debian/pool/main/k/kmod/kmod_${version}.debian.tar.xz";
+    sha256 = "1abpf8g3yx972by2xpmz6dwwyc1pgh6gjbvrivmrsws69vs0xjsy";
+  };
+
+  installPhase = ''
+    patch -i patches/aliases_conf
+    cp aliases.conf $out
+  '';
+
+  meta = {
+    homepage = https://packages.debian.org/source/sid/kmod;
+    description = "Linux configuration file for modprobe";
+    maintainers = with lib.maintainers; [ mathnerd314 ];
+  };
+}
diff --git a/pkgs/os-specific/linux/lttng-modules/default.nix b/pkgs/os-specific/linux/lttng-modules/default.nix
index 5fe065d3cc6..dc21176fa3c 100644
--- a/pkgs/os-specific/linux/lttng-modules/default.nix
+++ b/pkgs/os-specific/linux/lttng-modules/default.nix
@@ -1,16 +1,13 @@
-{ stdenv, fetchgit, kernel }:
-
-assert stdenv.lib.versionAtLeast kernel.version "3.4";  # fails on 3.2
+{ stdenv, fetchurl, kernel }:
 
 stdenv.mkDerivation rec {
   pname = "lttng-modules-${version}";
   name = "${pname}-${kernel.version}";
-  version = "2.6.0-5-g1b2a542";
+  version = "2.6.3";
 
-  src = fetchgit {
-    url = "https://github.com/lttng/lttng-modules.git";
-    rev = "1b2a5429de815c95643df2eadf91253909708728";
-    sha256 = "0zccaiadnk0xl6xrqaqlg9rpkwjgbq2fiyc3psylzqimnx0ydxc2";
+  src = fetchurl {
+    url = "http://lttng.org/files/lttng-modules/lttng-modules-${version}.tar.bz2";
+    sha256 = "0sk7cyjf5ylmxqrrrz5zmmw4c0dmxh1f98aj870gmcnxfa76y4mx";
   };
 
   preConfigure = ''
diff --git a/pkgs/os-specific/linux/lvm2/default.nix b/pkgs/os-specific/linux/lvm2/default.nix
index 6ddbbc9340f..0e6bf512aa2 100644
--- a/pkgs/os-specific/linux/lvm2/default.nix
+++ b/pkgs/os-specific/linux/lvm2/default.nix
@@ -1,7 +1,7 @@
 { stdenv, fetchurl, pkgconfig, udev, utillinux, coreutils, enable_dmeventd ? false }:
 
 let
-  version = "2.02.128";
+  version = "2.02.132";
 in
 
 stdenv.mkDerivation {
@@ -9,7 +9,7 @@ stdenv.mkDerivation {
 
   src = fetchurl {
     url = "ftp://sources.redhat.com/pub/lvm2/releases/LVM2.${version}.tgz";
-    sha256 = "0a5m63b729ranbnmg964b36jlbfc140bs92di37w2gq54hzp1v97";
+    sha256 = "0ac8izssflj371zzar16965zlia6a6zd97i0n00jxfxssnfa0fj1";
   };
 
   configureFlags = [
diff --git a/pkgs/os-specific/linux/mcelog/default.nix b/pkgs/os-specific/linux/mcelog/default.nix
index aa1b197e83f..a13931b1b22 100644
--- a/pkgs/os-specific/linux/mcelog/default.nix
+++ b/pkgs/os-specific/linux/mcelog/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchFromGitHub }:
 
-let version = "123"; in
+let version = "126"; in
 stdenv.mkDerivation {
   name = "mcelog-${version}";
 
   src = fetchFromGitHub {
-    sha256 = "0hrpqx0wfwribzm3j132k0869xbh5wa89pzhwcych5w2w0n2i890";
+    sha256 = "13vf3qrar9j4pp6zpspgsff0kbp7zj21mq33ywqa7ljq4v3szi8x";
     rev = "v${version}";
     repo = "mcelog";
     owner = "andikleen";
diff --git a/pkgs/os-specific/linux/musl/default.nix b/pkgs/os-specific/linux/musl/default.nix
index db7017edd43..abe96e9b9ae 100644
--- a/pkgs/os-specific/linux/musl/default.nix
+++ b/pkgs/os-specific/linux/musl/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   name    = "musl-${version}";
-  version = "1.1.10";
+  version = "1.1.11";
 
   src = fetchurl {
     url    = "http://www.musl-libc.org/releases/${name}.tar.gz";
-    sha256 = "0z4b3j1r0v4zr3v1cpl1v56zx6w8nq1y3wbs8x1zg87pqyqykfs5";
+    sha256 = "0grmmah3d9wajii26010plpinv3cbiq3kfqsblgn84kv3fjnv7mv";
   };
 
   enableParallelBuilding = true;
diff --git a/pkgs/os-specific/linux/nftables/default.nix b/pkgs/os-specific/linux/nftables/default.nix
index 9834443a74d..e0b16eb24f5 100644
--- a/pkgs/os-specific/linux/nftables/default.nix
+++ b/pkgs/os-specific/linux/nftables/default.nix
@@ -2,11 +2,11 @@
 , flex, bison, libmnl, libnftnl, gmp, readline }:
 
 stdenv.mkDerivation rec {
-  name = "nftables-0.4";
+  name = "nftables-0.5";
 
   src = fetchurl {
     url = "http://netfilter.org/projects/nftables/files/${name}.tar.bz2";
-    sha256 = "0g0x6mf5580kr1azrff0ryxxym43qr72fwir7agmz4b8bjvnkjpn";
+    sha256 = "1mhaw7ys7ma5786xyfccgar389jsj2zp7qmvghsgr96q6grxzdhz";
   };
 
   configureFlags = [
diff --git a/pkgs/os-specific/linux/nvidia-x11/beta.nix b/pkgs/os-specific/linux/nvidia-x11/beta.nix
index dc6af818837..d3111a4f75a 100644
--- a/pkgs/os-specific/linux/nvidia-x11/beta.nix
+++ b/pkgs/os-specific/linux/nvidia-x11/beta.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, kernel ? null, xlibs, zlib, perl
+{ stdenv, fetchurl, kernel ? null, xorg, zlib, perl
 , gtk, atk, pango, glib, gdk_pixbuf, cairo, nukeReferences
 , # Whether to build the libraries only (i.e. not the kernel module or
   # nvidia-settings).  Used to support 32-bit binaries on 64-bit
@@ -43,14 +43,14 @@ stdenv.mkDerivation {
 
   dontStrip = true;
 
-  glPath      = makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr];
+  glPath      = makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr];
   cudaPath    = makeLibraryPath [zlib stdenv.cc.cc];
   openclPath  = makeLibraryPath [zlib];
-  allLibPath  = makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr zlib stdenv.cc.cc];
+  allLibPath  = makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr zlib stdenv.cc.cc];
 
   gtkPath = optionalString (!libsOnly) (makeLibraryPath
     [ gtk atk pango glib gdk_pixbuf cairo ] );
-  programPath = makeLibraryPath [ xlibs.libXv ];
+  programPath = makeLibraryPath [ xorg.libXv ];
 
   buildInputs = [ perl nukeReferences ];
 
diff --git a/pkgs/os-specific/linux/nvidia-x11/builder-legacy340.sh b/pkgs/os-specific/linux/nvidia-x11/builder-legacy340.sh
index 07cc1a85de0..d0eec0f7403 100755
--- a/pkgs/os-specific/linux/nvidia-x11/builder-legacy340.sh
+++ b/pkgs/os-specific/linux/nvidia-x11/builder-legacy340.sh
@@ -107,6 +107,9 @@ installPhase() {
     #patchelf --set-rpath $out/lib:$glPath $out/lib/libvdpau_nvidia.so.*.*
     #patchelf --set-rpath $cudaPath $out/lib/libcuda.so.*.*
     #patchelf --set-rpath $openclPath $out/lib/libnvidia-opencl.so.*.*
+
+    # we distribute these separately in `libvdpau`
+    rm "$out"/lib/libvdpau{.*,_trace.*}
 }
 
 
diff --git a/pkgs/os-specific/linux/nvidia-x11/builder.sh b/pkgs/os-specific/linux/nvidia-x11/builder.sh
index 1198208c9da..ba65089a4f7 100755
--- a/pkgs/os-specific/linux/nvidia-x11/builder.sh
+++ b/pkgs/os-specific/linux/nvidia-x11/builder.sh
@@ -122,6 +122,9 @@ installPhase() {
 
     # For simplicity and dependency reduction, don't support the gtk3 interface.
     rm $out/lib/libnvidia-gtk3.*
+
+    # we distribute these separately in `libvdpau`
+    rm "$out"/lib/libvdpau{.*,_trace.*}
 }
 
 
diff --git a/pkgs/os-specific/linux/nvidia-x11/default.nix b/pkgs/os-specific/linux/nvidia-x11/default.nix
index ab564c10e2e..4390d5bdf3c 100644
--- a/pkgs/os-specific/linux/nvidia-x11/default.nix
+++ b/pkgs/os-specific/linux/nvidia-x11/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, kernel ? null, xlibs, zlib, perl
+{ stdenv, fetchurl, kernel ? null, xorg, zlib, perl
 , gtk, atk, pango, glib, gdk_pixbuf, cairo, nukeReferences
 , # Whether to build the libraries only (i.e. not the kernel module or
   # nvidia-settings).  Used to support 32-bit binaries on 64-bit
@@ -12,7 +12,7 @@ assert (!libsOnly) -> kernel != null;
 
 let
 
-  versionNumber = "352.30";
+  versionNumber = "352.41";
 
   # Policy: use the highest stable version as the default (on our master).
   inherit (stdenv.lib) makeLibraryPath;
@@ -28,15 +28,17 @@ stdenv.mkDerivation {
     if stdenv.system == "i686-linux" then
       fetchurl {
         url = "http://us.download.nvidia.com/XFree86/Linux-x86/${versionNumber}/NVIDIA-Linux-x86-${versionNumber}.run";
-        sha256 = "1qrjvf41zk50hw7gjiwg9jxwgpaarlwm019py4wfqgjgb1cbhgjn";
+        sha256 = "1qzn6dhkrpkx015f7y9adafn7fmz7zbxbczzf9930li8pgvmmz5k";
       }
     else if stdenv.system == "x86_64-linux" then
       fetchurl {
         url = "http://us.download.nvidia.com/XFree86/Linux-x86_64/${versionNumber}/NVIDIA-Linux-x86_64-${versionNumber}-no-compat32.run";
-        sha256 = "1h7ghmykhdyy3n853s8yjzc0qbh50qb2kc0khz672b1rna4wqyhg";
+        sha256 = "1k9hmmn5x9snzyggx23km64kjdqjh2kva090ha6mlayyyxrclz56";
       }
     else throw "nvidia-x11 does not support platform ${stdenv.system}";
 
+  patches = [ ./nvidia-4.2.patch ];
+
   inherit versionNumber libsOnly;
   inherit (stdenv) system;
 
@@ -44,14 +46,14 @@ stdenv.mkDerivation {
 
   dontStrip = true;
 
-  glPath      = makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr];
+  glPath      = makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr];
   cudaPath    = makeLibraryPath [zlib stdenv.cc.cc];
   openclPath  = makeLibraryPath [zlib];
-  allLibPath  = makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr zlib stdenv.cc.cc];
+  allLibPath  = makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr zlib stdenv.cc.cc];
 
   gtkPath = optionalString (!libsOnly) (makeLibraryPath
     [ gtk atk pango glib gdk_pixbuf cairo ] );
-  programPath = makeLibraryPath [ xlibs.libXv ];
+  programPath = makeLibraryPath [ xorg.libXv ];
 
   buildInputs = [ perl nukeReferences ];
 
@@ -63,5 +65,6 @@ stdenv.mkDerivation {
     license = licenses.unfreeRedistributable;
     platforms = platforms.linux;
     maintainers = [ maintainers.vcunat ];
+    priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so"
   };
 }
diff --git a/pkgs/os-specific/linux/nvidia-x11/legacy173.nix b/pkgs/os-specific/linux/nvidia-x11/legacy173.nix
index 432a756b6f6..6bde91d0ffc 100644
--- a/pkgs/os-specific/linux/nvidia-x11/legacy173.nix
+++ b/pkgs/os-specific/linux/nvidia-x11/legacy173.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, kernel, xlibs, zlib, gtk, atk, pango, glib, gdk_pixbuf}:
+{stdenv, fetchurl, kernel, xorg, zlib, gtk, atk, pango, glib, gdk_pixbuf}:
 
 let
 
@@ -30,11 +30,11 @@ stdenv.mkDerivation {
 
   dontStrip = true;
 
-  glPath = stdenv.lib.makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr];
+  glPath = stdenv.lib.makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr];
 
   cudaPath = stdenv.lib.makeLibraryPath [zlib stdenv.cc.cc];
 
-  programPath = stdenv.lib.makeLibraryPath [ gtk atk pango glib gdk_pixbuf xlibs.libXv ];
+  programPath = stdenv.lib.makeLibraryPath [ gtk atk pango glib gdk_pixbuf xorg.libXv ];
 
   meta = {
     homepage = http://www.nvidia.com/object/unix.html;
diff --git a/pkgs/os-specific/linux/nvidia-x11/legacy304.nix b/pkgs/os-specific/linux/nvidia-x11/legacy304.nix
index 7f13b6795d4..42e65f927b3 100644
--- a/pkgs/os-specific/linux/nvidia-x11/legacy304.nix
+++ b/pkgs/os-specific/linux/nvidia-x11/legacy304.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, kernel ? null, xlibs, zlib, perl
+{ stdenv, fetchurl, kernel ? null, xorg, zlib, perl
 , gtk, atk, pango, glib, gdk_pixbuf
 , # Whether to build the libraries only (i.e. not the kernel module or
   # nvidia-settings).  Used to support 32-bit binaries on 64-bit
@@ -36,12 +36,12 @@ stdenv.mkDerivation {
 
   dontStrip = true;
 
-  glPath = stdenv.lib.makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr];
+  glPath = stdenv.lib.makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr];
 
   cudaPath = stdenv.lib.makeLibraryPath [zlib stdenv.cc.cc];
 
   programPath = optionalString (!libsOnly) (stdenv.lib.makeLibraryPath
-    [ gtk atk pango glib gdk_pixbuf xlibs.libXv ] );
+    [ gtk atk pango glib gdk_pixbuf xorg.libXv ] );
 
   buildInputs = [ perl ];
 
diff --git a/pkgs/os-specific/linux/nvidia-x11/legacy340.nix b/pkgs/os-specific/linux/nvidia-x11/legacy340.nix
index a53906ed020..bb974410e37 100644
--- a/pkgs/os-specific/linux/nvidia-x11/legacy340.nix
+++ b/pkgs/os-specific/linux/nvidia-x11/legacy340.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, kernel ? null, xlibs, zlib, perl
+{ stdenv, fetchurl, kernel ? null, xorg, zlib, perl
 , gtk, atk, pango, glib, gdk_pixbuf
 , # Whether to build the libraries only (i.e. not the kernel module or
   # nvidia-settings).  Used to support 32-bit binaries on 64-bit
@@ -46,13 +46,13 @@ stdenv.mkDerivation {
 
   dontStrip = true;
 
-  glPath      = makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr];
+  glPath      = makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr];
   cudaPath    = makeLibraryPath [zlib stdenv.cc.cc];
   openclPath  = makeLibraryPath [zlib];
-  allLibPath  = makeLibraryPath [xlibs.libXext xlibs.libX11 xlibs.libXrandr zlib stdenv.cc.cc];
+  allLibPath  = makeLibraryPath [xorg.libXext xorg.libX11 xorg.libXrandr zlib stdenv.cc.cc];
 
   programPath = optionalString (!libsOnly) (makeLibraryPath
-    [ gtk atk pango glib gdk_pixbuf xlibs.libXv ] );
+    [ gtk atk pango glib gdk_pixbuf xorg.libXv ] );
 
   buildInputs = [ perl ];
 
diff --git a/pkgs/os-specific/linux/nvidia-x11/nvidia-4.2.patch b/pkgs/os-specific/linux/nvidia-x11/nvidia-4.2.patch
new file mode 100644
index 00000000000..412b786179a
--- /dev/null
+++ b/pkgs/os-specific/linux/nvidia-x11/nvidia-4.2.patch
@@ -0,0 +1,26 @@
+diff --git a/kernel/nv-frontend.c b/kernel/nv-frontend.c
+index 65bbb1b..be39c8d 100644
+--- a/kernel/nv-frontend.c
++++ b/kernel/nv-frontend.c
+@@ -15,7 +15,7 @@
+ #include "nv-frontend.h"
+ 
+ #if defined(MODULE_LICENSE)
+-MODULE_LICENSE("NVIDIA");
++MODULE_LICENSE("GPL\0NVIDIA");
+ #endif
+ #if defined(MODULE_INFO)
+ MODULE_INFO(supported, "external");
+diff --git a/kernel/nv.c b/kernel/nv.c
+index abe81ed..05945b5 100644
+--- a/kernel/nv.c
++++ b/kernel/nv.c
+@@ -31,7 +31,7 @@
+ 
+ #if defined(NV_VMWARE) || (NV_BUILD_MODULE_INSTANCES != 0)
+ #if defined(MODULE_LICENSE)
+-MODULE_LICENSE("NVIDIA");
++MODULE_LICENSE("GPL\0NVIDIA");
+ #endif
+ #if defined(MODULE_INFO)
+ MODULE_INFO(supported, "external");
diff --git a/pkgs/os-specific/linux/open-iscsi/default.nix b/pkgs/os-specific/linux/open-iscsi/default.nix
index 88ab08e6c3d..c4e39e45cad 100644
--- a/pkgs/os-specific/linux/open-iscsi/default.nix
+++ b/pkgs/os-specific/linux/open-iscsi/default.nix
@@ -1,27 +1,23 @@
-{ stdenv, fetchurl, kernel}:
+{ stdenv, fetchurl }:
 let
-  pname = "open-iscsi-2.0-871";
+  pname = "open-iscsi-2.0-873";
 in stdenv.mkDerivation {
-  name = "${pname}-${kernel.version}";
+  name = "${pname}";
   
   src = fetchurl {
     url = "http://www.open-iscsi.org/bits/${pname}.tar.gz";
-    sha256 = "1jvx1agybaj4czhz41bz37as076spicsmlh5pjksvwl2mr38gsmw";
+    sha256 = "1nbwmj48xzy45h52917jbvyqpsfg9zm49nm8941mc5x4gpwz5nbx";
   };
   
-  KSRC = "${kernel.dev}/lib/modules/*/build";
   DESTDIR = "$(out)";
   
   preConfigure = ''
     sed -i 's|/usr/|/|' Makefile
   '';
   
-  patches = [./kernel.patch];
-  
   meta = {
     description = "A high performance, transport independent, multi-platform implementation of RFC3720";
     license = stdenv.lib.licenses.gpl2Plus;
     homepage = http://www.open-iscsi.org;
-    broken = true;
   };
 }
diff --git a/pkgs/os-specific/linux/open-iscsi/kernel.patch b/pkgs/os-specific/linux/open-iscsi/kernel.patch
deleted file mode 100644
index 48dfa195400..00000000000
--- a/pkgs/os-specific/linux/open-iscsi/kernel.patch
+++ /dev/null
@@ -1,12 +0,0 @@
-*** open-iscsi-2.0-871/kernel/Makefile	2009-07-11 05:55:58.000000000 +0200
---- open-iscsi-2.0-871-new/kernel/Makefile	2010-08-30 11:37:56.000000000 +0200
-***************
-*** 101,106 ****
---- 101,107 ----
-  linux_2_6_29: $(unpatch_code)
-  
-  linux_2_6_30: $(unpatch_code)
-+ linux_2_6_32: $(unpatch_code)
-  
-  
-  do_unpatch_code:
diff --git a/pkgs/os-specific/linux/opengl/xorg-sys/default.nix b/pkgs/os-specific/linux/opengl/xorg-sys/default.nix
index 2cebb8d9dcc..5bb757a73a0 100644
--- a/pkgs/os-specific/linux/opengl/xorg-sys/default.nix
+++ b/pkgs/os-specific/linux/opengl/xorg-sys/default.nix
@@ -6,11 +6,11 @@
 # Of course, use of the driver in /usr/lib is highly impure.  But it
 # might actually work ;-)
 
-{stdenv, xlibs, expat, libdrm}:
+{stdenv, xorg, expat, libdrm}:
 
 stdenv.mkDerivation {
   name = "xorg-sys-opengl-3";
   builder = ./builder.sh;
-  neededLibs = [xlibs.libXxf86vm xlibs.libXext expat libdrm stdenv.cc.cc];
+  neededLibs = [xorg.libXxf86vm xorg.libXext expat libdrm stdenv.cc.cc];
 }
 
diff --git a/pkgs/os-specific/linux/pam_u2f/default.nix b/pkgs/os-specific/linux/pam_u2f/default.nix
index 458d171ec68..ecffa7bec59 100644
--- a/pkgs/os-specific/linux/pam_u2f/default.nix
+++ b/pkgs/os-specific/linux/pam_u2f/default.nix
@@ -1,16 +1,23 @@
-{ pkgs, fetchurl, stdenv }:
+{ stdenv, fetchurl, pkgconfig, libu2f-host, libu2f-server, pam }:
+
 stdenv.mkDerivation rec {
   name    = "pam_u2f-${version}";
-  version = "0.0.1";
+  version = "1.0.1";
+
   src     = fetchurl {
     url = "https://developers.yubico.com/pam-u2f/Releases/${name}.tar.gz";
-    sha256 = "0p1wia4nfw5h0pmy1lcgwsbrlm7z39v1n37692lgqfzyg1kmpv7l";
+    sha256 = "08lmc2il877k7djkjmza3k0n6ij8b4hx4x9dl6wwfdjqsr8d2zfp";
   };
-  buildInputs = with pkgs; [ asciidoc autoconf automake docbook_xml_dtd_45 libtool libu2f-host libu2f-server libxml2 libxslt pkgconfig pam ];
 
-  installFlags = [
-    "PAMDIR=$(out)/lib/security"
-  ];
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libu2f-host libu2f-server pam ];
+
+  # Fix the broken include in 1.0.1
+  CFLAGS = "-I${libu2f-host}/include/u2f-host";
+
+  preConfigure = ''
+    configureFlagsArray+=("--with-pam-dir=$out/lib/security")
+  '';
 
   meta = with stdenv.lib; {
     homepage = https://developers.yubico.com/pam-u2f/;
diff --git a/pkgs/os-specific/linux/pax-utils/default.nix b/pkgs/os-specific/linux/pax-utils/default.nix
index 13d144c54b0..fe517a71021 100644
--- a/pkgs/os-specific/linux/pax-utils/default.nix
+++ b/pkgs/os-specific/linux/pax-utils/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   name = "pax-utils-${version}";
-  version = "1.0.5";
+  version = "1.1.1";
 
   src = fetchurl {
     url = "http://dev.gentoo.org/~vapier/dist/${name}.tar.xz";
-    sha256 = "0vwhmnwai24h654d1zchm5qkbr030ay98l2qdp914ydgwhw9k6pn";
+    sha256 = "0gldvyr96jgbcahq7rl3k4krzyhvlz95ckiqh3yhink56s5z58cy";
   };
 
   makeFlags = [
diff --git a/pkgs/os-specific/linux/phc-intel/default.nix b/pkgs/os-specific/linux/phc-intel/default.nix
index 4c47047ff74..dd5a2741267 100644
--- a/pkgs/os-specific/linux/phc-intel/default.nix
+++ b/pkgs/os-specific/linux/phc-intel/default.nix
@@ -2,20 +2,41 @@
 
 assert stdenv.isLinux;
 # Don't bother with older versions, though some would probably work:
-assert stdenv.lib.versionAtLeast kernel.version "4.0";
+assert stdenv.lib.versionAtLeast kernel.version "4.2";
 # Disable on grsecurity kernels, which break module building:
 assert !kernel.features ? grsecurity;
 
-let version = "0.4.0-rev17"; in
-stdenv.mkDerivation {
+let
+  release = "0.4.0";
+  revbump = "rev18"; # don't forget to change forum download id...
+  version = "${release}-${revbump}";
+in stdenv.mkDerivation {
   name = "linux-phc-intel-${version}-${kernel.version}";
 
   src = fetchurl {
-    sha256 = "1fdfpghnsa5s98lisd2sn0vplrq0n54l0pkyyzkyb77z4fa6bs4p";
-    url = "http://www.linux-phc.org/forum/download/file.php?id=166";
-    name = "phc-intel-pack-rev17.tar.bz2";
+    sha256 = "1480y75yid4nw7dhzm97yb10dykinzjz34abvavsrqpq7qclhv27";
+    url = "http://www.linux-phc.org/forum/download/file.php?id=167";
+    name = "phc-intel-pack-${revbump}.tar.bz2";
   };
 
+  buildInputs = [ which ];
+
+  makeFlags = with kernel; [
+    "DESTDIR=$(out)"
+    "KERNELSRC=${dev}/lib/modules/${modDirVersion}/build"
+  ];
+
+  configurePhase = ''
+    make $makeFlags brave
+  '';
+
+  enableParallelBuilding = false;
+
+  installPhase = ''
+    install -m 755   -d $out/lib/modules/${kernel.version}/extra/
+    install -m 644 *.ko $out/lib/modules/${kernel.version}/extra/
+  '';
+
   meta = with stdenv.lib; {
     inherit version;
     description = "Undervolting kernel driver for Intel processors";
@@ -28,22 +49,7 @@ stdenv.mkDerivation {
     homepage = http://www.linux-phc.org/;
     downloadPage = "http://www.linux-phc.org/forum/viewtopic.php?f=7&t=267";
     license = licenses.gpl2;
-    platforms = with platforms; linux;
+    platforms = platforms.linux;
     maintainers = with maintainers; [ nckx ];
   };
-
-  buildInputs = [ which ];
-
-  makeFlags = "KERNELSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build DESTDIR=$(out)";
-
-  configurePhase = ''
-    echo make $makeFlags brave
-  '';
-
-  enableParallelBuilding = false;
-
-  installPhase = ''
-    install -m 755   -d $out/lib/modules/${kernel.version}/extra/
-    install -m 644 *.ko $out/lib/modules/${kernel.version}/extra/
-  '';
 }
diff --git a/pkgs/os-specific/linux/policycoreutils/default.nix b/pkgs/os-specific/linux/policycoreutils/default.nix
index 4eb8394a4d3..1933523d9c2 100644
--- a/pkgs/os-specific/linux/policycoreutils/default.nix
+++ b/pkgs/os-specific/linux/policycoreutils/default.nix
@@ -12,6 +12,8 @@ stdenv.mkDerivation rec {
     sha256 = "0y9l9k60iy21hj0lcvfdfxs1fxydg6d3pxp9rhy7hwr4y5vgh6dq";
   };
 
+  patches = [ ./fix-printf-type.patch ];
+
   postPatch = ''
     # Fix references to libsepol.a
     find . -name Makefile -exec sed -i 's,[^ ]*/libsepol.a,${libsepol}/lib/libsepol.a,g' {} \;
diff --git a/pkgs/os-specific/linux/policycoreutils/fix-printf-type.patch b/pkgs/os-specific/linux/policycoreutils/fix-printf-type.patch
new file mode 100644
index 00000000000..6ab2d6dccc7
--- /dev/null
+++ b/pkgs/os-specific/linux/policycoreutils/fix-printf-type.patch
@@ -0,0 +1,12 @@
+diff -Nru policycoreutils-2.4/setfiles/restore.c policycoreutils-2.4.new/setfiles/restore.c
+--- policycoreutils-2.4/setfiles/restore.c	2015-02-02 09:38:10.000000000 -0500
++++ policycoreutils-2.4.new/setfiles/restore.c	2015-08-29 20:44:13.693023222 -0400
+@@ -118,7 +118,7 @@
+ 		r_opts->count++;
+ 		if (r_opts->count % STAR_COUNT == 0) {
+ 			if (r_opts->progress == 1) {
+-				fprintf(stdout, "\r%luk", (size_t) r_opts->count / STAR_COUNT );
++				fprintf(stdout, "\r%zuk", (size_t) r_opts->count / STAR_COUNT );
+ 			} else {
+ 				if (r_opts->nfile > 0) {
+ 					progress = (r_opts->count < r_opts->nfile) ? (100.0 * r_opts->count / r_opts->nfile) : 100;
diff --git a/pkgs/os-specific/linux/prl-tools/default.nix b/pkgs/os-specific/linux/prl-tools/default.nix
index 0dac7c4358d..da5d7d5f607 100644
--- a/pkgs/os-specific/linux/prl-tools/default.nix
+++ b/pkgs/os-specific/linux/prl-tools/default.nix
@@ -39,7 +39,7 @@ stdenv.mkDerivation rec {
     name = "prl-tools-lin.iso";
     sha256 = "07960jvyv7gihjlg922znjm6db6l6bd23x9mg6ympwibzf2mylmx";
     message = ''
-      Please, place Parallel Tools for Linux image into Nix store
+      Please, place Parallels Tools for Linux image into Nix store
       using either
         nix-store --add-fixed sha256 ${name}
       or
diff --git a/pkgs/os-specific/linux/reptyr/default.nix b/pkgs/os-specific/linux/reptyr/default.nix
index e5e579081f6..99f52dc5aed 100644
--- a/pkgs/os-specific/linux/reptyr/default.nix
+++ b/pkgs/os-specific/linux/reptyr/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl }:
 
 stdenv.mkDerivation rec {
-  version = "0.5";
+  version = "0.6.2";
   name = "reptyr-${version}";
   src = fetchurl {
     url = "https://github.com/nelhage/reptyr/archive/reptyr-${version}.tar.gz";
-    sha256 = "077cvjjf534nxh7qqisw27a0wa61mdgyik43k50f8v090rggz2xm";
+    sha256 = "07pfl0rkgm8m3f3jy8r9l2yvnhf8lgllpsk3mh57mhzdxq8fagf7";
   };
   makeFlags = ["PREFIX=$(out)"];
   meta = {
diff --git a/pkgs/os-specific/linux/rtl8812au/default.nix b/pkgs/os-specific/linux/rtl8812au/default.nix
new file mode 100644
index 00000000000..a16e102bc08
--- /dev/null
+++ b/pkgs/os-specific/linux/rtl8812au/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+stdenv.mkDerivation rec {
+  name = "rtl8812au-${kernel.version}-${version}";
+  version = "4.2.2-1";
+  
+  src = fetchFromGitHub {
+    owner = "csssuf";
+    repo = "rtl8812au";
+    rev = "874906aec694c800bfc29b146737b88dae767832";
+    sha256 = "14ifhplawipfd6971mxw76dv3ygwc0n8sbz2l3f0vvkin6x88bsj";
+  };
+  
+  patchPhase = ''
+    substituteInPlace ./Makefile --replace /lib/modules/ "${kernel.dev}/lib/modules/"
+    substituteInPlace ./Makefile --replace '$(shell uname -r)' "${kernel.modDirVersion}"
+    substituteInPlace ./Makefile --replace /sbin/depmod #
+    substituteInPlace ./Makefile --replace '$(MODDESTDIR)' "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+  
+  preInstall = ''
+    mkdir -p "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+   
+  meta = {
+    description = "Driver for Realtek 802.11ac, rtl8812au, provides the 8812au mod.";
+    homepage = "https://github.com/csssuf/rtl8812au";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+  };
+}
\ No newline at end of file
diff --git a/pkgs/os-specific/linux/spl/default.nix b/pkgs/os-specific/linux/spl/default.nix
index e28412a2904..42ea1ad4d8b 100644
--- a/pkgs/os-specific/linux/spl/default.nix
+++ b/pkgs/os-specific/linux/spl/default.nix
@@ -1,13 +1,13 @@
 { callPackage, fetchFromGitHub, ... } @ args:
 
 callPackage ./generic.nix (args // rec {
-  version = "0.6.4.2";
+  version = "0.6.5";
 
   src = fetchFromGitHub {
     owner = "zfsonlinux";
     repo = "spl";
     rev = "spl-${version}";
-    sha256 = "101c5fzhnz67ix5w33rb2pwazxmyz6rfvyszbwy1kgh6rz75bjr4";
+    sha256 = "0ryw2vh3px0q38skm53g83p46011ndrdxi3y2kqvd1pjqgfbjdmj";
   };
 
   patches = [ ./const.patch ./install_prefix.patch ];
diff --git a/pkgs/os-specific/linux/spl/git.nix b/pkgs/os-specific/linux/spl/git.nix
index 9faba199a5d..ed7b37adcd8 100644
--- a/pkgs/os-specific/linux/spl/git.nix
+++ b/pkgs/os-specific/linux/spl/git.nix
@@ -1,13 +1,13 @@
 { callPackage, fetchFromGitHub, ... } @ args:
 
 callPackage ./generic.nix (args // rec {
-  version = "2015-07-21";
+  version = "2015-09-11";
 
   src = fetchFromGitHub {
     owner = "zfsonlinux";
     repo = "spl";
-    rev = "9eb361aaa537724c9a90ab6a9f33521bfd80bad9";
-    sha256 = "18sv4mw85fbm8i1s8k4y5dc43l6ll2f6hgfrawvzgvwni5i4h7n8";
+    rev = "f17d005bcc9b7edeb15b10bf947379a504b2d9f7";
+    sha256 = "0ryw2vh3px0q38skm53g83p46011ndrdxi3y2kqvd1pjqgfbjdmj";
   };
 
   patches = [ ./const.patch ./install_prefix.patch ];
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index b98f6e69282..4c9e0475b94 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -20,7 +20,7 @@ stdenv.mkDerivation rec {
 
   patches =
     [ # These are all changes between upstream and
-      # https://github.com/edolstra/systemd/tree/nixos-v217.
+      # https://github.com/NixOS/systemd/tree/nixos-v217.
       ./fixes.patch
     ];
 
diff --git a/pkgs/os-specific/linux/systemd/fixes.patch b/pkgs/os-specific/linux/systemd/fixes.patch
index c1c768dbacb..2997c02d26d 100644
--- a/pkgs/os-specific/linux/systemd/fixes.patch
+++ b/pkgs/os-specific/linux/systemd/fixes.patch
@@ -220,7 +220,7 @@ index 25c4a0b..e1f2d6d 100644
                          flags |= SHOW_MASKED;
                  else if (strneq ("equivalent", word, l))
 diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
-index 70a5918..1926e52 100644
+index 70a5918..a5661e8 100644
 --- a/src/fsck/fsck.c
 +++ b/src/fsck/fsck.c
 @@ -315,8 +315,7 @@ int main(int argc, char *argv[]) {
@@ -272,11 +272,231 @@ index e487369..ff4e9c9 100644
 -        return r < 0 ? EXIT_FAILURE : r;
 +        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
  }
+diff --git a/src/journal-remote/journal-remote-parse.c b/src/journal-remote/journal-remote-parse.c
+index 7dd8878..70a9a13 100644
+--- a/src/journal-remote/journal-remote-parse.c
++++ b/src/journal-remote/journal-remote-parse.c
+@@ -344,22 +344,25 @@ int process_data(RemoteSource *source) {
+                    LLLLLLLL0011223344...\n
+                 */
+                 sep = memchr(line, '=', n);
+-                if (sep)
++                if (sep) {
+                         /* chomp newline */
+                         n--;
+-                else
++
++                        r = iovw_put(&source->iovw, line, n);
++                        if (r < 0)
++                                return r;
++                } else {
+                         /* replace \n with = */
+                         line[n-1] = '=';
+-                log_trace("Received: %.*s", (int) n, line);
+ 
+-                r = iovw_put(&source->iovw, line, n);
+-                if (r < 0) {
+-                        log_error("Failed to put line in iovect");
+-                        return r;
++                        source->field_len = n;
++                        source->state = STATE_DATA_START;
++
++                        /* we cannot put the field in iovec until we have all data */
+                 }
+ 
+-                if (!sep)
+-                        source->state = STATE_DATA_START;
++                log_trace("Received: %.*s (%s)", (int) n, line, sep ? "text" : "binary");
++
+                 return 0; /* continue */
+         }
+ 
+@@ -382,6 +385,7 @@ int process_data(RemoteSource *source) {
+ 
+         case STATE_DATA: {
+                 void *data;
++                char *field;
+ 
+                 assert(source->data_size > 0);
+ 
+@@ -396,11 +400,12 @@ int process_data(RemoteSource *source) {
+ 
+                 assert(data);
+ 
+-                r = iovw_put(&source->iovw, data, source->data_size);
+-                if (r < 0) {
+-                        log_error("failed to put binary buffer in iovect");
++                field = (char*) data - sizeof(uint64_t) - source->field_len;
++                memmove(field + sizeof(uint64_t), field, source->field_len);
++
++                r = iovw_put(&source->iovw, field + sizeof(uint64_t), source->field_len + source->data_size);
++                if (r < 0)
+                         return r;
+-                }
+ 
+                 source->state = STATE_DATA_FINISH;
+ 
+diff --git a/src/journal-remote/journal-remote-parse.h b/src/journal-remote/journal-remote-parse.h
+index 8499f4e..22db550 100644
+--- a/src/journal-remote/journal-remote-parse.h
++++ b/src/journal-remote/journal-remote-parse.h
+@@ -42,7 +42,9 @@ typedef struct RemoteSource {
+         size_t offset;     /* offset to the beginning of live data in the buffer */
+         size_t scanned;    /* number of bytes since the beginning of data without a newline */
+         size_t filled;     /* total number of bytes in the buffer */
+-        size_t data_size;  /* size of the binary data chunk being processed */
++
++        size_t field_len;  /* used for binary fields: the field name length */
++        size_t data_size;  /* and the size of the binary data chunk being processed */
+ 
+         struct iovec_wrapper iovw;
+ 
+diff --git a/src/journal/journal-authenticate.c b/src/journal/journal-authenticate.c
+index 5ab1982..1f980ee 100644
+--- a/src/journal/journal-authenticate.c
++++ b/src/journal/journal-authenticate.c
+@@ -229,7 +229,7 @@ int journal_file_maybe_append_tag(JournalFile *f, uint64_t realtime) {
+         return 0;
+ }
+ 
+-int journal_file_hmac_put_object(JournalFile *f, int type, Object *o, uint64_t p) {
++int journal_file_hmac_put_object(JournalFile *f, ObjectType type, Object *o, uint64_t p) {
+         int r;
+ 
+         assert(f);
+@@ -246,7 +246,7 @@ int journal_file_hmac_put_object(JournalFile *f, int type, Object *o, uint64_t p
+                 if (r < 0)
+                         return r;
+         } else {
+-                if (type >= 0 && o->object.type != type)
++                if (type > OBJECT_UNUSED && o->object.type != type)
+                         return -EBADMSG;
+         }
+ 
+diff --git a/src/journal/journal-authenticate.h b/src/journal/journal-authenticate.h
+index 0aaf836..565fe84 100644
+--- a/src/journal/journal-authenticate.h
++++ b/src/journal/journal-authenticate.h
+@@ -33,7 +33,7 @@ int journal_file_append_first_tag(JournalFile *f);
+ int journal_file_hmac_setup(JournalFile *f);
+ int journal_file_hmac_start(JournalFile *f);
+ int journal_file_hmac_put_header(JournalFile *f);
+-int journal_file_hmac_put_object(JournalFile *f, int type, Object *o, uint64_t p);
++int journal_file_hmac_put_object(JournalFile *f, ObjectType type, Object *o, uint64_t p);
+ 
+ int journal_file_fss_load(JournalFile *f);
+ int journal_file_parse_verification_key(JournalFile *f, const char *key);
+diff --git a/src/journal/journal-def.h b/src/journal/journal-def.h
+index e55fa19..ab089cb 100644
+--- a/src/journal/journal-def.h
++++ b/src/journal/journal-def.h
+@@ -52,8 +52,8 @@ typedef struct HashItem HashItem;
+ typedef struct FSSHeader FSSHeader;
+ 
+ /* Object types */
+-enum {
+-        OBJECT_UNUSED,
++typedef enum ObjectType {
++        OBJECT_UNUSED, /* also serves as "any type" or "additional context" */
+         OBJECT_DATA,
+         OBJECT_FIELD,
+         OBJECT_ENTRY,
+@@ -62,7 +62,7 @@ enum {
+         OBJECT_ENTRY_ARRAY,
+         OBJECT_TAG,
+         _OBJECT_TYPE_MAX
+-};
++} ObjectType;
+ 
+ /* Object flags */
+ enum {
 diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
-index 8a2c0fc..9de3ddd 100644
+index 8a2c0fc..c55a4dc 100644
 --- a/src/journal/journal-file.c
 +++ b/src/journal/journal-file.c
-@@ -1657,7 +1657,7 @@ static int generic_array_bisect(
+@@ -374,7 +374,13 @@ static int journal_file_allocate(JournalFile *f, uint64_t offset, uint64_t size)
+         return 0;
+ }
+ 
+-static int journal_file_move_to(JournalFile *f, int context, bool keep_always, uint64_t offset, uint64_t size, void **ret) {
++static unsigned type_to_context(ObjectType type) {
++        /* One context for each type, plus one catch-all for the rest */
++        assert_cc(_OBJECT_TYPE_MAX <= MMAP_CACHE_MAX_CONTEXTS);
++        return type > OBJECT_UNUSED && type < _OBJECT_TYPE_MAX ? type : 0;
++}
++
++static int journal_file_move_to(JournalFile *f, ObjectType type, bool keep_always, uint64_t offset, uint64_t size, void **ret) {
+         assert(f);
+         assert(ret);
+ 
+@@ -391,7 +397,7 @@ static int journal_file_move_to(JournalFile *f, int context, bool keep_always, u
+                         return -EADDRNOTAVAIL;
+         }
+ 
+-        return mmap_cache_get(f->mmap, f->fd, f->prot, context, keep_always, offset, size, &f->last_stat, ret, NULL);
++        return mmap_cache_get(f->mmap, f->fd, f->prot, type_to_context(type), keep_always, offset, size, &f->last_stat, ret);
+ }
+ 
+ static uint64_t minimum_header_size(Object *o) {
+@@ -412,7 +418,7 @@ static uint64_t minimum_header_size(Object *o) {
+         return table[o->object.type];
+ }
+ 
+-int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Object **ret) {
++int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset, Object **ret) {
+         int r;
+         void *t;
+         Object *o;
+@@ -425,7 +431,7 @@ int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec
+         if (!VALID64(offset))
+                 return -EFAULT;
+ 
+-        r = journal_file_move_to(f, type_to_context(type), false, offset, sizeof(ObjectHeader), &t);
++        r = journal_file_move_to(f, type, false, offset, sizeof(ObjectHeader), &t);
+         if (r < 0)
+                 return r;
+ 
+@@ -441,11 +447,11 @@ int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Objec
+         if (s < minimum_header_size(o))
+                 return -EBADMSG;
+ 
+-        if (type > 0 && o->object.type != type)
++        if (type > OBJECT_UNUSED && o->object.type != type)
+                 return -EBADMSG;
+ 
+         if (s > sizeof(ObjectHeader)) {
+-                r = journal_file_move_to(f, o->object.type, false, offset, s, &t);
++                r = journal_file_move_to(f, type, false, offset, s, &t);
+                 if (r < 0)
+                         return r;
+ 
+@@ -482,14 +488,14 @@ static uint64_t journal_file_entry_seqnum(JournalFile *f, uint64_t *seqnum) {
+         return r;
+ }
+ 
+-int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object **ret, uint64_t *offset) {
++int journal_file_append_object(JournalFile *f, ObjectType type, uint64_t size, Object **ret, uint64_t *offset) {
+         int r;
+         uint64_t p;
+         Object *tail, *o;
+         void *t;
+ 
+         assert(f);
+-        assert(type > 0 && type < _OBJECT_TYPE_MAX);
++        assert(type > OBJECT_UNUSED && type < _OBJECT_TYPE_MAX);
+         assert(size >= sizeof(ObjectHeader));
+         assert(offset);
+         assert(ret);
+@@ -502,7 +508,7 @@ int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object *
+         if (p == 0)
+                 p = le64toh(f->header->header_size);
+         else {
+-                r = journal_file_move_to_object(f, -1, p, &tail);
++                r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &tail);
+                 if (r < 0)
+                         return r;
+ 
+@@ -1657,7 +1663,7 @@ static int generic_array_bisect(
                          }
                  }
  
@@ -285,6 +505,369 @@ index 8a2c0fc..9de3ddd 100644
                          if (direction == DIRECTION_UP) {
                                  i = n;
                                  subtract_one = true;
+@@ -1793,23 +1799,6 @@ _pure_ static int test_object_offset(JournalFile *f, uint64_t p, uint64_t needle
+                 return TEST_RIGHT;
+ }
+ 
+-int journal_file_move_to_entry_by_offset(
+-                JournalFile *f,
+-                uint64_t p,
+-                direction_t direction,
+-                Object **ret,
+-                uint64_t *offset) {
+-
+-        return generic_array_bisect(f,
+-                                    le64toh(f->header->entry_array_offset),
+-                                    le64toh(f->header->n_entries),
+-                                    p,
+-                                    test_object_offset,
+-                                    direction,
+-                                    ret, offset, NULL);
+-}
+-
+-
+ static int test_object_seqnum(JournalFile *f, uint64_t p, uint64_t needle) {
+         Object *o;
+         int r;
+@@ -1939,9 +1928,81 @@ int journal_file_move_to_entry_by_monotonic(
+                                              ret, offset, NULL);
+ }
+ 
++void journal_file_reset_location(JournalFile *f) {
++        f->location_type = LOCATION_HEAD;
++        f->current_offset = 0;
++        f->current_seqnum = 0;
++        f->current_realtime = 0;
++        f->current_monotonic = 0;
++        zero(f->current_boot_id);
++        f->current_xor_hash = 0;
++}
++
++void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset) {
++        f->location_type = LOCATION_SEEK;
++        f->current_offset = offset;
++        f->current_seqnum = le64toh(o->entry.seqnum);
++        f->current_realtime = le64toh(o->entry.realtime);
++        f->current_monotonic = le64toh(o->entry.monotonic);
++        f->current_boot_id = o->entry.boot_id;
++        f->current_xor_hash = le64toh(o->entry.xor_hash);
++}
++
++int journal_file_compare_locations(JournalFile *af, JournalFile *bf) {
++        assert(af);
++        assert(bf);
++        assert(af->location_type == LOCATION_SEEK);
++        assert(bf->location_type == LOCATION_SEEK);
++
++        /* If contents and timestamps match, these entries are
++         * identical, even if the seqnum does not match */
++        if (sd_id128_equal(af->current_boot_id, bf->current_boot_id) &&
++            af->current_monotonic == bf->current_monotonic &&
++            af->current_realtime == bf->current_realtime &&
++            af->current_xor_hash == bf->current_xor_hash)
++                return 0;
++
++        if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) {
++
++                /* If this is from the same seqnum source, compare
++                 * seqnums */
++                if (af->current_seqnum < bf->current_seqnum)
++                        return -1;
++                if (af->current_seqnum > bf->current_seqnum)
++                        return 1;
++
++                /* Wow! This is weird, different data but the same
++                 * seqnums? Something is borked, but let's make the
++                 * best of it and compare by time. */
++        }
++
++        if (sd_id128_equal(af->current_boot_id, bf->current_boot_id)) {
++
++                /* If the boot id matches, compare monotonic time */
++                if (af->current_monotonic < bf->current_monotonic)
++                        return -1;
++                if (af->current_monotonic > bf->current_monotonic)
++                        return 1;
++        }
++
++        /* Otherwise, compare UTC time */
++        if (af->current_realtime < bf->current_realtime)
++                return -1;
++        if (af->current_realtime > bf->current_realtime)
++                return 1;
++
++        /* Finally, compare by contents */
++        if (af->current_xor_hash < bf->current_xor_hash)
++                return -1;
++        if (af->current_xor_hash > bf->current_xor_hash)
++                return 1;
++
++        return 0;
++}
++
+ int journal_file_next_entry(
+                 JournalFile *f,
+-                Object *o, uint64_t p,
++                uint64_t p,
+                 direction_t direction,
+                 Object **ret, uint64_t *offset) {
+ 
+@@ -1949,18 +2010,14 @@ int journal_file_next_entry(
+         int r;
+ 
+         assert(f);
+-        assert(p > 0 || !o);
+ 
+         n = le64toh(f->header->n_entries);
+         if (n <= 0)
+                 return 0;
+ 
+-        if (!o)
++        if (p == 0)
+                 i = direction == DIRECTION_DOWN ? 0 : n - 1;
+         else {
+-                if (o->object.type != OBJECT_ENTRY)
+-                        return -EINVAL;
+-
+                 r = generic_array_bisect(f,
+                                          le64toh(f->header->entry_array_offset),
+                                          le64toh(f->header->n_entries),
+@@ -2006,55 +2063,6 @@ int journal_file_next_entry(
+         return 1;
+ }
+ 
+-int journal_file_skip_entry(
+-                JournalFile *f,
+-                Object *o, uint64_t p,
+-                int64_t skip,
+-                Object **ret, uint64_t *offset) {
+-
+-        uint64_t i, n;
+-        int r;
+-
+-        assert(f);
+-        assert(o);
+-        assert(p > 0);
+-
+-        if (o->object.type != OBJECT_ENTRY)
+-                return -EINVAL;
+-
+-        r = generic_array_bisect(f,
+-                                 le64toh(f->header->entry_array_offset),
+-                                 le64toh(f->header->n_entries),
+-                                 p,
+-                                 test_object_offset,
+-                                 DIRECTION_DOWN,
+-                                 NULL, NULL,
+-                                 &i);
+-        if (r <= 0)
+-                return r;
+-
+-        /* Calculate new index */
+-        if (skip < 0) {
+-                if ((uint64_t) -skip >= i)
+-                        i = 0;
+-                else
+-                        i = i - (uint64_t) -skip;
+-        } else
+-                i  += (uint64_t) skip;
+-
+-        n = le64toh(f->header->n_entries);
+-        if (n <= 0)
+-                return -EBADMSG;
+-
+-        if (i >= n)
+-                i = n-1;
+-
+-        return generic_array_get(f,
+-                                 le64toh(f->header->entry_array_offset),
+-                                 i,
+-                                 ret, offset);
+-}
+-
+ int journal_file_next_entry_for_data(
+                 JournalFile *f,
+                 Object *o, uint64_t p,
+@@ -2289,7 +2297,7 @@ void journal_file_dump(JournalFile *f) {
+ 
+         p = le64toh(f->header->header_size);
+         while (p != 0) {
+-                r = journal_file_move_to_object(f, -1, p, &o);
++                r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o);
+                 if (r < 0)
+                         goto fail;
+ 
+diff --git a/src/journal/journal-file.h b/src/journal/journal-file.h
+index 211e121..ca17c97 100644
+--- a/src/journal/journal-file.h
++++ b/src/journal/journal-file.h
+@@ -48,6 +48,20 @@ typedef enum direction {
+         DIRECTION_DOWN
+ } direction_t;
+ 
++typedef enum LocationType {
++        /* The first and last entries, resp. */
++        LOCATION_HEAD,
++        LOCATION_TAIL,
++
++        /* We already read the entry we currently point to, and the
++         * next one to read should probably not be this one again. */
++        LOCATION_DISCRETE,
++
++        /* We should seek to the precise location specified, and
++         * return it, as we haven't read it yet. */
++        LOCATION_SEEK
++} LocationType;
++
+ typedef struct JournalFile {
+         int fd;
+ 
+@@ -63,6 +77,8 @@ typedef struct JournalFile {
+         bool tail_entry_monotonic_valid:1;
+ 
+         direction_t last_direction;
++        LocationType location_type;
++        uint64_t last_n_entries;
+ 
+         char *path;
+         struct stat last_stat;
+@@ -72,6 +88,11 @@ typedef struct JournalFile {
+         HashItem *field_hash_table;
+ 
+         uint64_t current_offset;
++        uint64_t current_seqnum;
++        uint64_t current_realtime;
++        uint64_t current_monotonic;
++        sd_id128_t current_boot_id;
++        uint64_t current_xor_hash;
+ 
+         JournalMetrics metrics;
+         MMapCache *mmap;
+@@ -160,13 +181,13 @@ static inline bool VALID_EPOCH(uint64_t u) {
+ #define JOURNAL_HEADER_COMPRESSED_LZ4(h) \
+         (!!(le32toh((h)->incompatible_flags) & HEADER_INCOMPATIBLE_COMPRESSED_LZ4))
+ 
+-int journal_file_move_to_object(JournalFile *f, int type, uint64_t offset, Object **ret);
++int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset, Object **ret);
+ 
+ uint64_t journal_file_entry_n_items(Object *o) _pure_;
+ uint64_t journal_file_entry_array_n_items(Object *o) _pure_;
+ uint64_t journal_file_hash_table_n_items(Object *o) _pure_;
+ 
+-int journal_file_append_object(JournalFile *f, int type, uint64_t size, Object **ret, uint64_t *offset);
++int journal_file_append_object(JournalFile *f, ObjectType type, uint64_t size, Object **ret, uint64_t *offset);
+ int journal_file_append_entry(JournalFile *f, const dual_timestamp *ts, const struct iovec iovec[], unsigned n_iovec, uint64_t *seqno, Object **ret, uint64_t *offset);
+ 
+ int journal_file_find_data_object(JournalFile *f, const void *data, uint64_t size, Object **ret, uint64_t *offset);
+@@ -175,12 +196,13 @@ int journal_file_find_data_object_with_hash(JournalFile *f, const void *data, ui
+ int journal_file_find_field_object(JournalFile *f, const void *field, uint64_t size, Object **ret, uint64_t *offset);
+ int journal_file_find_field_object_with_hash(JournalFile *f, const void *field, uint64_t size, uint64_t hash, Object **ret, uint64_t *offset);
+ 
+-int journal_file_next_entry(JournalFile *f, Object *o, uint64_t p, direction_t direction, Object **ret, uint64_t *offset);
+-int journal_file_skip_entry(JournalFile *f, Object *o, uint64_t p, int64_t skip, Object **ret, uint64_t *offset);
++void journal_file_reset_location(JournalFile *f);
++void journal_file_save_location(JournalFile *f, Object *o, uint64_t offset);
++int journal_file_compare_locations(JournalFile *af, JournalFile *bf);
++int journal_file_next_entry(JournalFile *f, uint64_t p, direction_t direction, Object **ret, uint64_t *offset);
+ 
+ int journal_file_next_entry_for_data(JournalFile *f, Object *o, uint64_t p, uint64_t data_offset, direction_t direction, Object **ret, uint64_t *offset);
+ 
+-int journal_file_move_to_entry_by_offset(JournalFile *f, uint64_t seqnum, direction_t direction, Object **ret, uint64_t *offset);
+ int journal_file_move_to_entry_by_seqnum(JournalFile *f, uint64_t seqnum, direction_t direction, Object **ret, uint64_t *offset);
+ int journal_file_move_to_entry_by_realtime(JournalFile *f, uint64_t realtime, direction_t direction, Object **ret, uint64_t *offset);
+ int journal_file_move_to_entry_by_monotonic(JournalFile *f, sd_id128_t boot_id, uint64_t monotonic, direction_t direction, Object **ret, uint64_t *offset);
+@@ -205,21 +227,3 @@ int journal_file_get_cutoff_realtime_usec(JournalFile *f, usec_t *from, usec_t *
+ int journal_file_get_cutoff_monotonic_usec(JournalFile *f, sd_id128_t boot, usec_t *from, usec_t *to);
+ 
+ bool journal_file_rotate_suggested(JournalFile *f, usec_t max_file_usec);
+-
+-
+-static unsigned type_to_context(int type) {
+-        /* One context for each type, plus one catch-all for the rest */
+-        return type > 0 && type < _OBJECT_TYPE_MAX ? type : 0;
+-}
+-
+-static inline int journal_file_object_keep(JournalFile *f, Object *o, uint64_t offset, void **release_cookie) {
+-        unsigned context = type_to_context(o->object.type);
+-        uint64_t s = le64toh(o->object.size);
+-
+-        return mmap_cache_get(f->mmap, f->fd, f->prot, context, true,
+-                              offset, s, &f->last_stat, NULL, release_cookie);
+-}
+-
+-static inline int journal_file_object_release(JournalFile *f, void *release_cookie) {
+-        return mmap_cache_release(f->mmap, f->fd, release_cookie);
+-}
+diff --git a/src/journal/journal-internal.h b/src/journal/journal-internal.h
+index 70847db..e99050c 100644
+--- a/src/journal/journal-internal.h
++++ b/src/journal/journal-internal.h
+@@ -57,20 +57,6 @@ struct Match {
+         LIST_HEAD(Match, matches);
+ };
+ 
+-typedef enum LocationType {
+-        /* The first and last entries, resp. */
+-        LOCATION_HEAD,
+-        LOCATION_TAIL,
+-
+-        /* We already read the entry we currently point to, and the
+-         * next one to read should probably not be this one again. */
+-        LOCATION_DISCRETE,
+-
+-        /* We should seek to the precise location specified, and
+-         * return it, as we haven't read it yet. */
+-        LOCATION_SEEK
+-} LocationType;
+-
+ struct Location {
+         LocationType type;
+ 
+diff --git a/src/journal/journal-verify.c b/src/journal/journal-verify.c
+index f74adcb..5baa22d 100644
+--- a/src/journal/journal-verify.c
++++ b/src/journal/journal-verify.c
+@@ -368,7 +368,7 @@ static int contains_uint64(MMapCache *m, int fd, uint64_t n, uint64_t p) {
+ 
+                 c = (a + b) / 2;
+ 
+-                r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) &z, NULL);
++                r = mmap_cache_get(m, fd, PROT_READ|PROT_WRITE, 0, false, c * sizeof(uint64_t), sizeof(uint64_t), NULL, (void **) &z);
+                 if (r < 0)
+                         return r;
+ 
+@@ -865,7 +865,7 @@ int journal_file_verify(
+                 if (show_progress)
+                         draw_progress(0x7FFF * p / le64toh(f->header->tail_object_offset), &last_usec);
+ 
+-                r = journal_file_move_to_object(f, -1, p, &o);
++                r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o);
+                 if (r < 0) {
+                         error(p, "invalid object");
+                         goto fail;
+@@ -1085,11 +1085,11 @@ int journal_file_verify(
+                                         q = last_tag;
+ 
+                                 while (q <= p) {
+-                                        r = journal_file_move_to_object(f, -1, q, &o);
++                                        r = journal_file_move_to_object(f, OBJECT_UNUSED, q, &o);
+                                         if (r < 0)
+                                                 goto fail;
+ 
+-                                        r = journal_file_hmac_put_object(f, -1, o, q);
++                                        r = journal_file_hmac_put_object(f, OBJECT_UNUSED, o, q);
+                                         if (r < 0)
+                                                 goto fail;
+ 
+@@ -1097,7 +1097,7 @@ int journal_file_verify(
+                                 }
+ 
+                                 /* Position might have changed, let's reposition things */
+-                                r = journal_file_move_to_object(f, -1, p, &o);
++                                r = journal_file_move_to_object(f, OBJECT_UNUSED, p, &o);
+                                 if (r < 0)
+                                         goto fail;
+ 
 diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c
 index f50faf4..03579fd 100644
 --- a/src/journal/journalctl.c
@@ -298,6 +881,21 @@ index f50faf4..03579fd 100644
                  arg_lines = 10;
  
          if (!!arg_directory + !!arg_file + !!arg_machine > 1) {
+diff --git a/src/journal/journald-native.c b/src/journal/journald-native.c
+index a635202..655e2dd 100644
+--- a/src/journal/journald-native.c
++++ b/src/journal/journald-native.c
+@@ -132,8 +132,8 @@ void server_process_native_message(
+ 
+                 /* A property follows */
+ 
+-                /* n received properties, +1 for _TRANSPORT */
+-                if (!GREEDY_REALLOC(iovec, m, n + 1 + N_IOVEC_META_FIELDS + !!object_pid * N_IOVEC_OBJECT_FIELDS)) {
++                /* n existing properties, 1 new, +1 for _TRANSPORT */
++                if (!GREEDY_REALLOC(iovec, m, n + 2 + N_IOVEC_META_FIELDS + N_IOVEC_OBJECT_FIELDS)) {
+                         log_oom();
+                         break;
+                 }
 diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
 index 12735c4..08b143b 100644
 --- a/src/journal/journald-server.c
@@ -310,6 +908,739 @@ index 12735c4..08b143b 100644
  
          if (s->mmap)
                  mmap_cache_unref(s->mmap);
+diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
+index b7db6f1..f6f669d 100644
+--- a/src/journal/mmap-cache.c
++++ b/src/journal/mmap-cache.c
+@@ -38,7 +38,7 @@ typedef struct FileDescriptor FileDescriptor;
+ struct Window {
+         MMapCache *cache;
+ 
+-        unsigned keep_always;
++        bool keep_always;
+         bool in_unused;
+ 
+         int prot;
+@@ -76,7 +76,7 @@ struct MMapCache {
+ 
+ 
+         Hashmap *fds;
+-        Hashmap *contexts;
++        Context *contexts[MMAP_CACHE_MAX_CONTEXTS];
+ 
+         LIST_HEAD(Window, unused);
+         Window *last_unused;
+@@ -185,7 +185,7 @@ static void context_detach_window(Context *c) {
+         c->window = NULL;
+         LIST_REMOVE(by_window, w->contexts, c);
+ 
+-        if (!w->contexts && w->keep_always == 0) {
++        if (!w->contexts && !w->keep_always) {
+                 /* Not used anymore? */
+                 LIST_PREPEND(unused, c->cache->unused, w);
+                 if (!c->cache->last_unused)
+@@ -219,18 +219,13 @@ static void context_attach_window(Context *c, Window *w) {
+ 
+ static Context *context_add(MMapCache *m, unsigned id) {
+         Context *c;
+-        int r;
+ 
+         assert(m);
+ 
+-        c = hashmap_get(m->contexts, UINT_TO_PTR(id + 1));
++        c = m->contexts[id];
+         if (c)
+                 return c;
+ 
+-        r = hashmap_ensure_allocated(&m->contexts, NULL);
+-        if (r < 0)
+-                return NULL;
+-
+         c = new0(Context, 1);
+         if (!c)
+                 return NULL;
+@@ -238,11 +233,8 @@ static Context *context_add(MMapCache *m, unsigned id) {
+         c->cache = m;
+         c->id = id;
+ 
+-        r = hashmap_put(m->contexts, UINT_TO_PTR(id + 1), c);
+-        if (r < 0) {
+-                free(c);
+-                return NULL;
+-        }
++        assert(!m->contexts[id]);
++        m->contexts[id] = c;
+ 
+         return c;
+ }
+@@ -252,8 +244,10 @@ static void context_free(Context *c) {
+ 
+         context_detach_window(c);
+ 
+-        if (c->cache)
+-                assert_se(hashmap_remove(c->cache->contexts, UINT_TO_PTR(c->id + 1)));
++        if (c->cache) {
++                assert(c->cache->contexts[c->id] == c);
++                c->cache->contexts[c->id] = NULL;
++        }
+ 
+         free(c);
+ }
+@@ -302,15 +296,14 @@ static FileDescriptor* fd_add(MMapCache *m, int fd) {
+ }
+ 
+ static void mmap_cache_free(MMapCache *m) {
+-        Context *c;
+         FileDescriptor *f;
++        int i;
+ 
+         assert(m);
+ 
+-        while ((c = hashmap_first(m->contexts)))
+-                context_free(c);
+-
+-        hashmap_free(m->contexts);
++        for (i = 0; i < MMAP_CACHE_MAX_CONTEXTS; i++)
++                if (m->contexts[i])
++                        context_free(m->contexts[i]);
+ 
+         while ((f = hashmap_first(m->fds)))
+                 fd_free(f);
+@@ -352,8 +345,7 @@ static int try_context(
+                 bool keep_always,
+                 uint64_t offset,
+                 size_t size,
+-                void **ret,
+-                void **release_cookie) {
++                void **ret) {
+ 
+         Context *c;
+ 
+@@ -361,8 +353,9 @@ static int try_context(
+         assert(m->n_ref > 0);
+         assert(fd >= 0);
+         assert(size > 0);
++        assert(ret);
+ 
+-        c = hashmap_get(m->contexts, UINT_TO_PTR(context+1));
++        c = m->contexts[context];
+         if (!c)
+                 return 0;
+ 
+@@ -378,12 +371,9 @@ static int try_context(
+                 return 0;
+         }
+ 
+-        c->window->keep_always += keep_always;
++        c->window->keep_always |= keep_always;
+ 
+-        if (ret)
+-                *ret = (uint8_t*) c->window->ptr + (offset - c->window->offset);
+-        if (keep_always && release_cookie)
+-                *release_cookie = c->window;
++        *ret = (uint8_t*) c->window->ptr + (offset - c->window->offset);
+         return 1;
+ }
+ 
+@@ -395,8 +385,7 @@ static int find_mmap(
+                 bool keep_always,
+                 uint64_t offset,
+                 size_t size,
+-                void **ret,
+-                void **release_cookie) {
++                void **ret) {
+ 
+         FileDescriptor *f;
+         Window *w;
+@@ -427,10 +416,7 @@ static int find_mmap(
+         context_attach_window(c, w);
+         w->keep_always += keep_always;
+ 
+-        if (ret)
+-                *ret = (uint8_t*) w->ptr + (offset - w->offset);
+-        if (keep_always && release_cookie)
+-                *release_cookie = c->window;
++        *ret = (uint8_t*) w->ptr + (offset - w->offset);
+         return 1;
+ }
+ 
+@@ -443,8 +429,7 @@ static int add_mmap(
+                 uint64_t offset,
+                 size_t size,
+                 struct stat *st,
+-                void **ret,
+-                void **release_cookie) {
++                void **ret) {
+ 
+         uint64_t woffset, wsize;
+         Context *c;
+@@ -457,6 +442,7 @@ static int add_mmap(
+         assert(m->n_ref > 0);
+         assert(fd >= 0);
+         assert(size > 0);
++        assert(ret);
+ 
+         woffset = offset & ~((uint64_t) page_size() - 1ULL);
+         wsize = size + (offset - woffset);
+@@ -526,10 +512,7 @@ static int add_mmap(
+         c->window = w;
+         LIST_PREPEND(by_window, w->contexts, c);
+ 
+-        if (ret)
+-                *ret = (uint8_t*) w->ptr + (offset - w->offset);
+-        if (keep_always && release_cookie)
+-                *release_cookie = c->window;
++        *ret = (uint8_t*) w->ptr + (offset - w->offset);
+         return 1;
+ 
+ outofmem:
+@@ -546,8 +529,7 @@ int mmap_cache_get(
+                 uint64_t offset,
+                 size_t size,
+                 struct stat *st,
+-                void **ret,
+-                void **release_cookie) {
++                void **ret) {
+ 
+         int r;
+ 
+@@ -555,16 +537,18 @@ int mmap_cache_get(
+         assert(m->n_ref > 0);
+         assert(fd >= 0);
+         assert(size > 0);
++        assert(ret);
++        assert(context < MMAP_CACHE_MAX_CONTEXTS);
+ 
+         /* Check whether the current context is the right one already */
+-        r = try_context(m, fd, prot, context, keep_always, offset, size, ret, release_cookie);
++        r = try_context(m, fd, prot, context, keep_always, offset, size, ret);
+         if (r != 0) {
+                 m->n_hit ++;
+                 return r;
+         }
+ 
+         /* Search for a matching mmap */
+-        r = find_mmap(m, fd, prot, context, keep_always, offset, size, ret, release_cookie);
++        r = find_mmap(m, fd, prot, context, keep_always, offset, size, ret);
+         if (r != 0) {
+                 m->n_hit ++;
+                 return r;
+@@ -573,39 +557,7 @@ int mmap_cache_get(
+         m->n_missed++;
+ 
+         /* Create a new mmap */
+-        return add_mmap(m, fd, prot, context, keep_always, offset, size, st, ret, release_cookie);
+-}
+-
+-int mmap_cache_release(
+-                MMapCache *m,
+-                int fd,
+-                void *release_cookie) {
+-
+-        FileDescriptor *f;
+-        Window *w;
+-
+-        assert(m);
+-        assert(m->n_ref > 0);
+-        assert(fd >= 0);
+-
+-        f = hashmap_get(m->fds, INT_TO_PTR(fd + 1));
+-        if (!f)
+-                return -EBADF;
+-
+-        assert(f->fd == fd);
+-
+-        LIST_FOREACH(by_fd, w, f->windows)
+-                if (w == release_cookie)
+-                        break;
+-
+-        if (!w)
+-                return -ENOENT;
+-
+-        if (w->keep_always == 0)
+-                return -ENOLCK;
+-
+-        w->keep_always -= 1;
+-        return 0;
++        return add_mmap(m, fd, prot, context, keep_always, offset, size, st, ret);
+ }
+ 
+ void mmap_cache_close_fd(MMapCache *m, int fd) {
+@@ -621,18 +573,6 @@ void mmap_cache_close_fd(MMapCache *m, int fd) {
+         fd_free(f);
+ }
+ 
+-void mmap_cache_close_context(MMapCache *m, unsigned context) {
+-        Context *c;
+-
+-        assert(m);
+-
+-        c = hashmap_get(m->contexts, UINT_TO_PTR(context + 1));
+-        if (!c)
+-                return;
+-
+-        context_free(c);
+-}
+-
+ unsigned mmap_cache_get_hit(MMapCache *m) {
+         assert(m);
+ 
+diff --git a/src/journal/mmap-cache.h b/src/journal/mmap-cache.h
+index 76e5316..fe2c83d 100644
+--- a/src/journal/mmap-cache.h
++++ b/src/journal/mmap-cache.h
+@@ -25,6 +25,8 @@
+ #include <stdbool.h>
+ #include <sys/stat.h>
+ 
++#define MMAP_CACHE_MAX_CONTEXTS 8
++
+ typedef struct MMapCache MMapCache;
+ 
+ MMapCache* mmap_cache_new(void);
+@@ -40,14 +42,8 @@ int mmap_cache_get(
+         uint64_t offset,
+         size_t size,
+         struct stat *st,
+-        void **ret,
+-        void **release_cookie);
+-int mmap_cache_release(
+-        MMapCache *m,
+-        int fd,
+-        void *release_cookie);
++        void **ret);
+ void mmap_cache_close_fd(MMapCache *m, int fd);
+-void mmap_cache_close_context(MMapCache *m, unsigned context);
+ 
+ unsigned mmap_cache_get_hit(MMapCache *m);
+ unsigned mmap_cache_get_missed(MMapCache *m);
+diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
+index cf21c4d..cb7fc32 100644
+--- a/src/journal/sd-journal.c
++++ b/src/journal/sd-journal.c
+@@ -87,7 +87,7 @@ static void detach_location(sd_journal *j) {
+         j->current_field = 0;
+ 
+         ORDERED_HASHMAP_FOREACH(f, j->files, i)
+-                f->current_offset = 0;
++                journal_file_reset_location(f);
+ }
+ 
+ static void reset_location(sd_journal *j) {
+@@ -114,20 +114,19 @@ static void init_location(Location *l, LocationType type, JournalFile *f, Object
+         l->seqnum_set = l->realtime_set = l->monotonic_set = l->xor_hash_set = true;
+ }
+ 
+-static void set_location(sd_journal *j, LocationType type, JournalFile *f, Object *o,
+-                         direction_t direction, uint64_t offset) {
++static void set_location(sd_journal *j, JournalFile *f, Object *o) {
+         assert(j);
+-        assert(type == LOCATION_DISCRETE || type == LOCATION_SEEK);
+         assert(f);
+         assert(o);
+ 
+-        init_location(&j->current_location, type, f, o);
++        init_location(&j->current_location, LOCATION_DISCRETE, f, o);
+ 
+         j->current_file = f;
+         j->current_field = 0;
+ 
+-        f->last_direction = direction;
+-        f->current_offset = offset;
++        /* Let f know its candidate entry was picked. */
++        assert(f->location_type == LOCATION_SEEK);
++        f->location_type = LOCATION_DISCRETE;
+ }
+ 
+ static int match_is_valid(const void *data, size_t size) {
+@@ -413,144 +412,51 @@ _public_ void sd_journal_flush_matches(sd_journal *j) {
+         detach_location(j);
+ }
+ 
+-static int compare_entry_order(JournalFile *af, Object *_ao,
+-                               JournalFile *bf, uint64_t bp) {
+-
+-        uint64_t a, b;
+-        Object *ao, *bo;
+-        int r;
+-
+-        assert(af);
+-        assert(bf);
+-        assert(_ao);
+-
+-        /* The mmap cache might invalidate the object from the first
+-         * file if we look at the one from the second file. Hence
+-         * temporarily copy the header of the first one, and look at
+-         * that only. */
+-        ao = alloca(offsetof(EntryObject, items));
+-        memcpy(ao, _ao, offsetof(EntryObject, items));
+-
+-        r = journal_file_move_to_object(bf, OBJECT_ENTRY, bp, &bo);
+-        if (r < 0)
+-                return strcmp(af->path, bf->path);
+-
+-        /* We operate on two different files here, hence we can access
+-         * two objects at the same time, which we normally can't.
+-         *
+-         * If contents and timestamps match, these entries are
+-         * identical, even if the seqnum does not match */
+-
+-        if (sd_id128_equal(ao->entry.boot_id, bo->entry.boot_id) &&
+-            ao->entry.monotonic == bo->entry.monotonic &&
+-            ao->entry.realtime == bo->entry.realtime &&
+-            ao->entry.xor_hash == bo->entry.xor_hash)
+-                return 0;
+-
+-        if (sd_id128_equal(af->header->seqnum_id, bf->header->seqnum_id)) {
+-
+-                /* If this is from the same seqnum source, compare
+-                 * seqnums */
+-                a = le64toh(ao->entry.seqnum);
+-                b = le64toh(bo->entry.seqnum);
+-
+-                if (a < b)
+-                        return -1;
+-                if (a > b)
+-                        return 1;
+-
+-                /* Wow! This is weird, different data but the same
+-                 * seqnums? Something is borked, but let's make the
+-                 * best of it and compare by time. */
+-        }
+-
+-        if (sd_id128_equal(ao->entry.boot_id, bo->entry.boot_id)) {
+-
+-                /* If the boot id matches, compare monotonic time */
+-                a = le64toh(ao->entry.monotonic);
+-                b = le64toh(bo->entry.monotonic);
+-
+-                if (a < b)
+-                        return -1;
+-                if (a > b)
+-                        return 1;
+-        }
+-
+-        /* Otherwise, compare UTC time */
+-        a = le64toh(ao->entry.realtime);
+-        b = le64toh(bo->entry.realtime);
+-
+-        if (a < b)
+-                return -1;
+-        if (a > b)
+-                return 1;
+-
+-        /* Finally, compare by contents */
+-        a = le64toh(ao->entry.xor_hash);
+-        b = le64toh(bo->entry.xor_hash);
+-
+-        if (a < b)
+-                return -1;
+-        if (a > b)
+-                return 1;
+-
+-        return 0;
+-}
+-
+-_pure_ static int compare_with_location(JournalFile *af, Object *ao, Location *l) {
+-        uint64_t a;
+-
+-        assert(af);
+-        assert(ao);
++_pure_ static int compare_with_location(JournalFile *f, Location *l) {
++        assert(f);
+         assert(l);
++        assert(f->location_type == LOCATION_SEEK);
+         assert(l->type == LOCATION_DISCRETE || l->type == LOCATION_SEEK);
+ 
+         if (l->monotonic_set &&
+-            sd_id128_equal(ao->entry.boot_id, l->boot_id) &&
++            sd_id128_equal(f->current_boot_id, l->boot_id) &&
+             l->realtime_set &&
+-            le64toh(ao->entry.realtime) == l->realtime &&
++            f->current_realtime == l->realtime &&
+             l->xor_hash_set &&
+-            le64toh(ao->entry.xor_hash) == l->xor_hash)
++            f->current_xor_hash == l->xor_hash)
+                 return 0;
+ 
+         if (l->seqnum_set &&
+-            sd_id128_equal(af->header->seqnum_id, l->seqnum_id)) {
+-
+-                a = le64toh(ao->entry.seqnum);
++            sd_id128_equal(f->header->seqnum_id, l->seqnum_id)) {
+ 
+-                if (a < l->seqnum)
++                if (f->current_seqnum < l->seqnum)
+                         return -1;
+-                if (a > l->seqnum)
++                if (f->current_seqnum > l->seqnum)
+                         return 1;
+         }
+ 
+         if (l->monotonic_set &&
+-            sd_id128_equal(ao->entry.boot_id, l->boot_id)) {
++            sd_id128_equal(f->current_boot_id, l->boot_id)) {
+ 
+-                a = le64toh(ao->entry.monotonic);
+-
+-                if (a < l->monotonic)
++                if (f->current_monotonic < l->monotonic)
+                         return -1;
+-                if (a > l->monotonic)
++                if (f->current_monotonic > l->monotonic)
+                         return 1;
+         }
+ 
+         if (l->realtime_set) {
+ 
+-                a = le64toh(ao->entry.realtime);
+-
+-                if (a < l->realtime)
++                if (f->current_realtime < l->realtime)
+                         return -1;
+-                if (a > l->realtime)
++                if (f->current_realtime > l->realtime)
+                         return 1;
+         }
+ 
+         if (l->xor_hash_set) {
+-                a = le64toh(ao->entry.xor_hash);
+ 
+-                if (a < l->xor_hash)
++                if (f->current_xor_hash < l->xor_hash)
+                         return -1;
+-                if (a > l->xor_hash)
++                if (f->current_xor_hash > l->xor_hash)
+                         return 1;
+         }
+ 
+@@ -766,9 +672,9 @@ static int find_location_with_matches(
+                 /* No matches is simple */
+ 
+                 if (j->current_location.type == LOCATION_HEAD)
+-                        return journal_file_next_entry(f, NULL, 0, DIRECTION_DOWN, ret, offset);
++                        return journal_file_next_entry(f, 0, DIRECTION_DOWN, ret, offset);
+                 if (j->current_location.type == LOCATION_TAIL)
+-                        return journal_file_next_entry(f, NULL, 0, DIRECTION_UP, ret, offset);
++                        return journal_file_next_entry(f, 0, DIRECTION_UP, ret, offset);
+                 if (j->current_location.seqnum_set && sd_id128_equal(j->current_location.seqnum_id, f->header->seqnum_id))
+                         return journal_file_move_to_entry_by_seqnum(f, j->current_location.seqnum, direction, ret, offset);
+                 if (j->current_location.monotonic_set) {
+@@ -779,7 +685,7 @@ static int find_location_with_matches(
+                 if (j->current_location.realtime_set)
+                         return journal_file_move_to_entry_by_realtime(f, j->current_location.realtime, direction, ret, offset);
+ 
+-                return journal_file_next_entry(f, NULL, 0, direction, ret, offset);
++                return journal_file_next_entry(f, 0, direction, ret, offset);
+         } else
+                 return find_location_for_match(j, j->level0, f, direction, ret, offset);
+ }
+@@ -791,49 +697,61 @@ static int next_with_matches(
+                 Object **ret,
+                 uint64_t *offset) {
+ 
+-        Object *c;
+-        uint64_t cp;
+-
+         assert(j);
+         assert(f);
+         assert(ret);
+         assert(offset);
+ 
+-        c = *ret;
+-        cp = *offset;
+-
+         /* No matches is easy. We simple advance the file
+          * pointer by one. */
+         if (!j->level0)
+-                return journal_file_next_entry(f, c, cp, direction, ret, offset);
++                return journal_file_next_entry(f, f->current_offset, direction, ret, offset);
+ 
+         /* If we have a match then we look for the next matching entry
+          * with an offset at least one step larger */
+-        return next_for_match(j, j->level0, f, direction == DIRECTION_DOWN ? cp+1 : cp-1, direction, ret, offset);
++        return next_for_match(j, j->level0, f,
++                              direction == DIRECTION_DOWN ? f->current_offset + 1
++                                                          : f->current_offset - 1,
++                              direction, ret, offset);
+ }
+ 
+-static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direction, Object **ret, uint64_t *offset) {
++static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direction) {
+         Object *c;
+-        uint64_t cp;
++        uint64_t cp, n_entries;
+         int r;
+ 
+         assert(j);
+         assert(f);
+ 
+-        if (f->last_direction == direction && f->current_offset > 0) {
+-                cp = f->current_offset;
++        n_entries = le64toh(f->header->n_entries);
+ 
+-                r = journal_file_move_to_object(f, OBJECT_ENTRY, cp, &c);
+-                if (r < 0)
+-                        return r;
++        /* If we hit EOF before, we don't need to look into this file again
++         * unless direction changed or new entries appeared. */
++        if (f->last_direction == direction && f->location_type == LOCATION_TAIL &&
++            n_entries == f->last_n_entries)
++                return 0;
+ 
+-                r = next_with_matches(j, f, direction, &c, &cp);
+-                if (r <= 0)
+-                        return r;
++        f->last_n_entries = n_entries;
++
++        if (f->last_direction == direction && f->current_offset > 0) {
++                /* LOCATION_SEEK here means we did the work in a previous
++                 * iteration and the current location already points to a
++                 * candidate entry. */
++                if (f->location_type != LOCATION_SEEK) {
++                        r = next_with_matches(j, f, direction, &c, &cp);
++                        if (r <= 0)
++                                return r;
++
++                        journal_file_save_location(f, c, cp);
++                }
+         } else {
++                f->last_direction = direction;
++
+                 r = find_location_with_matches(j, f, direction, &c, &cp);
+                 if (r <= 0)
+                         return r;
++
++                journal_file_save_location(f, c, cp);
+         }
+ 
+         /* OK, we found the spot, now let's advance until an entry
+@@ -848,30 +766,25 @@ static int next_beyond_location(sd_journal *j, JournalFile *f, direction_t direc
+                 if (j->current_location.type == LOCATION_DISCRETE) {
+                         int k;
+ 
+-                        k = compare_with_location(f, c, &j->current_location);
++                        k = compare_with_location(f, &j->current_location);
+ 
+                         found = direction == DIRECTION_DOWN ? k > 0 : k < 0;
+                 } else
+                         found = true;
+ 
+-                if (found) {
+-                        if (ret)
+-                                *ret = c;
+-                        if (offset)
+-                                *offset = cp;
++                if (found)
+                         return 1;
+-                }
+ 
+                 r = next_with_matches(j, f, direction, &c, &cp);
+                 if (r <= 0)
+                         return r;
++
++                journal_file_save_location(f, c, cp);
+         }
+ }
+ 
+ static int real_journal_next(sd_journal *j, direction_t direction) {
+         JournalFile *f, *new_file = NULL;
+-        uint64_t new_offset = 0;
+-        uint64_t p = 0;
+         Iterator i;
+         Object *o;
+         int r;
+@@ -882,38 +795,38 @@ static int real_journal_next(sd_journal *j, direction_t direction) {
+         ORDERED_HASHMAP_FOREACH(f, j->files, i) {
+                 bool found;
+ 
+-                r = next_beyond_location(j, f, direction, &o, &p);
++                r = next_beyond_location(j, f, direction);
+                 if (r < 0) {
+                         log_debug("Can't iterate through %s, ignoring: %s", f->path, strerror(-r));
+                         remove_file_real(j, f);
+                         continue;
+-                } else if (r == 0)
++                } else if (r == 0) {
++                        f->location_type = LOCATION_TAIL;
+                         continue;
++                }
+ 
+                 if (!new_file)
+                         found = true;
+                 else {
+                         int k;
+ 
+-                        k = compare_entry_order(f, o, new_file, new_offset);
++                        k = journal_file_compare_locations(f, new_file);
+ 
+                         found = direction == DIRECTION_DOWN ? k < 0 : k > 0;
+                 }
+ 
+-                if (found) {
++                if (found)
+                         new_file = f;
+-                        new_offset = p;
+-                }
+         }
+ 
+         if (!new_file)
+                 return 0;
+ 
+-        r = journal_file_move_to_object(new_file, OBJECT_ENTRY, new_offset, &o);
++        r = journal_file_move_to_object(new_file, OBJECT_ENTRY, new_file->current_offset, &o);
+         if (r < 0)
+                 return r;
+ 
+-        set_location(j, LOCATION_DISCRETE, new_file, o, direction, new_offset);
++        set_location(j, new_file, o);
+ 
+         return 1;
+ }
+@@ -2526,7 +2439,6 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
+                 size_t ol;
+                 bool found;
+                 int r;
+-                void *release_cookie;
+ 
+                 /* Proceed to next data object in the field's linked list */
+                 if (j->unique_offset == 0) {
+@@ -2552,10 +2464,10 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
+                         continue;
+                 }
+ 
+-                /* We do not use the type context here, but 0 instead,
+-                 * so that we can look at this data object at the same
++                /* We do not use OBJECT_DATA context here, but OBJECT_UNUSED
++                 * instead, so that we can look at this data object at the same
+                  * time as one on another file */
+-                r = journal_file_move_to_object(j->unique_file, 0, j->unique_offset, &o);
++                r = journal_file_move_to_object(j->unique_file, OBJECT_UNUSED, j->unique_offset, &o);
+                 if (r < 0)
+                         return r;
+ 
+@@ -2567,10 +2479,6 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
+                         return -EBADMSG;
+                 }
+ 
+-                r = journal_file_object_keep(j->unique_file, o, j->unique_offset, &release_cookie);
+-                if (r < 0)
+-                        return r;
+-
+                 r = return_data(j, j->unique_file, o, &odata, &ol);
+                 if (r < 0)
+                         return r;
+@@ -2615,10 +2523,6 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
+                                 found = true;
+                 }
+ 
+-                r = journal_file_object_release(j->unique_file, release_cookie);
+-                if (r < 0)
+-                        return r;
+-
+                 if (found)
+                         continue;
+ 
 diff --git a/src/libsystemd-network/network-internal.c b/src/libsystemd-network/network-internal.c
 index 372f3ed..d56ee51 100644
 --- a/src/libsystemd-network/network-internal.c
@@ -814,10 +2145,47 @@ index 8d171a5..bd0d324 100644
  bool paths_check_timestamp(const char* const* paths, usec_t *paths_ts_usec, bool update);
  
 diff --git a/src/shared/virt.c b/src/shared/virt.c
-index f9c4e67..f10baab 100644
+index f9c4e67..f3104d5 100644
 --- a/src/shared/virt.c
 +++ b/src/shared/virt.c
-@@ -293,8 +293,26 @@ int detect_container(const char **id) {
+@@ -151,7 +151,7 @@ int detect_vm(const char **id) {
+         _cleanup_free_ char *domcap = NULL, *cpuinfo_contents = NULL;
+         static thread_local int cached_found = -1;
+         static thread_local const char *cached_id = NULL;
+-        const char *_id = NULL;
++        const char *_id = NULL, *_id_cpuid = NULL;
+         int r;
+ 
+         if (_likely_(cached_found >= 0)) {
+@@ -197,10 +197,26 @@ int detect_vm(const char **id) {
+ 
+         /* this will set _id to "other" and return 0 for unknown hypervisors */
+         r = detect_vm_cpuid(&_id);
+-        if (r != 0)
++
++        /* finish when found a known hypervisor other than kvm */
++        if (r < 0 || (r > 0 && !streq(_id, "kvm")))
+                 goto finish;
+ 
++        _id_cpuid = _id;
++
+         r = detect_vm_dmi(&_id);
++
++        /* kvm with and without Virtualbox */
++        if (streq_ptr(_id_cpuid, "kvm")) {
++                if (r > 0 && streq(_id, "oracle"))
++                        goto finish;
++
++                _id = _id_cpuid;
++                r = 1;
++                goto finish;
++        }
++
++        /* information from dmi */
+         if (r != 0)
+                 goto finish;
+ 
+@@ -293,8 +309,26 @@ int detect_container(const char **id) {
  
                  r = read_one_line_file("/run/systemd/container", &m);
                  if (r == -ENOENT) {
@@ -875,6 +2243,30 @@ index 28eaa6a..3866308 100644
          reboot(RB_ENABLE_CAD);
  
          switch (a) {
+diff --git a/src/systemd/sd-journal.h b/src/systemd/sd-journal.h
+index eb24372..00237a2 100644
+--- a/src/systemd/sd-journal.h
++++ b/src/systemd/sd-journal.h
+@@ -138,13 +138,15 @@ int sd_journal_reliable_fd(sd_journal *j);
+ int sd_journal_get_catalog(sd_journal *j, char **text);
+ int sd_journal_get_catalog_for_message_id(sd_id128_t id, char **text);
+ 
++/* the inverse condition avoids ambiguity of danling 'else' after the macro */
+ #define SD_JOURNAL_FOREACH(j)                                           \
+-        if (sd_journal_seek_head(j) >= 0)                               \
+-                while (sd_journal_next(j) > 0)
++        if (sd_journal_seek_head(j) < 0) { }                            \
++        else while (sd_journal_next(j) > 0)
+ 
++/* the inverse condition avoids ambiguity of danling 'else' after the macro */
+ #define SD_JOURNAL_FOREACH_BACKWARDS(j)                                 \
+-        if (sd_journal_seek_tail(j) >= 0)                               \
+-                while (sd_journal_previous(j) > 0)
++        if (sd_journal_seek_tail(j) < 0) { }                            \
++        else while (sd_journal_previous(j) > 0)
+ 
+ #define SD_JOURNAL_FOREACH_DATA(j, data, l)                             \
+         for (sd_journal_restart_data(j); sd_journal_enumerate_data((j), &(data), &(l)) > 0; )
 diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c
 index 63d64b2..57264de 100644
 --- a/src/test/test-path-util.c
diff --git a/pkgs/os-specific/linux/trace-cmd/default.nix b/pkgs/os-specific/linux/trace-cmd/default.nix
index 1a22d094867..aeb2c371c2a 100644
--- a/pkgs/os-specific/linux/trace-cmd/default.nix
+++ b/pkgs/os-specific/linux/trace-cmd/default.nix
@@ -2,12 +2,12 @@
 
 stdenv.mkDerivation rec {
   name    = "trace-cmd-${version}";
-  version = "2.5.3";
+  version = "2.6";
 
   src = fetchgit {
     url    = "git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git";
     rev    = "refs/tags/trace-cmd-v${version}";
-    sha256 = "32db3df07d0371c2b072029c6c86c4204be8cbbcb53840fa8c42dbf2e35c047b";
+    sha256 = "42286440a45d1b24552a1d3cdb656dc648ad346fc426b5798bacdbffd3c4b226";
   };
 
   buildInputs = [ asciidoc libxslt ];
diff --git a/pkgs/os-specific/linux/udisks/2-default.nix b/pkgs/os-specific/linux/udisks/2-default.nix
index 9b7a7501629..76d6caa767c 100644
--- a/pkgs/os-specific/linux/udisks/2-default.nix
+++ b/pkgs/os-specific/linux/udisks/2-default.nix
@@ -11,6 +11,8 @@ stdenv.mkDerivation rec {
     sha256 = "0spl155k0g2l2hvqf8xyjv08i68gfyhzpjva6cwlzxx0bz4gbify";
   };
 
+  outputs = [ "out" "doc" ];
+
   patches = [ ./force-path.patch ];
 
   # FIXME remove /var/run/current-system/sw/* references
diff --git a/pkgs/os-specific/linux/upower/0.99.nix b/pkgs/os-specific/linux/upower/0.99.nix
deleted file mode 100644
index 58133db9023..00000000000
--- a/pkgs/os-specific/linux/upower/0.99.nix
+++ /dev/null
@@ -1,51 +0,0 @@
-{ stdenv, fetchurl, pkgconfig, glib, dbus, dbus_glib, dbus_tools
-, intltool, libxslt, docbook_xsl, udev, libusb1, pmutils
-, useSystemd ? true, systemd, gobjectIntrospection
-}:
-
-assert stdenv.isLinux;
-
-stdenv.mkDerivation rec {
-  name = "upower-0.99.2";
-
-  src = fetchurl {
-    url = "http://upower.freedesktop.org/releases/${name}.tar.xz";
-    sha256 = "0vwlh20jmaf01m38kfn8yx2869a3clmkzlycrj99rf4nvwx4bp79";
-  };
-
-  buildInputs =
-    [ dbus_glib intltool libxslt docbook_xsl udev libusb1 gobjectIntrospection ]
-    ++ stdenv.lib.optional useSystemd systemd;
-
-  nativeBuildInputs = [ pkgconfig ];
-
-  preConfigure =
-    ''
-      substituteInPlace src/linux/up-backend.c \
-        --replace /usr/bin/pm- ${pmutils}/bin/pm- \
-        --replace /usr/sbin/pm- ${pmutils}/sbin/pm-
-      substituteInPlace src/notify-upower.sh \
-        --replace /usr/bin/dbus-send ${dbus_tools}/bin/dbus-send
-    '';
-
-  configureFlags =
-    [ "--with-backend=linux" "--localstatedir=/var"
-      "--enable-deprecated" # needed for Xfce (Nov 2013)
-    ]
-    ++ stdenv.lib.optional useSystemd
-    [ "--enable-systemd"
-      "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
-      "--with-systemdutildir=$(out)/lib/systemd"
-      "--with-udevrulesdir=$(out)/lib/udev/rules.d"
-    ];
-
-  NIX_CFLAGS_LINK = "-lgcc_s";
-
-  installFlags = "historydir=$(TMPDIR)/foo";
-
-  meta = {
-    homepage = http://upower.freedesktop.org/;
-    description = "A D-Bus service for power management";
-    platforms = stdenv.lib.platforms.linux;
-  };
-}
diff --git a/pkgs/os-specific/linux/upower/default.nix b/pkgs/os-specific/linux/upower/default.nix
index 90914284773..66b9c34ab51 100644
--- a/pkgs/os-specific/linux/upower/default.nix
+++ b/pkgs/os-specific/linux/upower/default.nix
@@ -1,54 +1,29 @@
-{ stdenv, fetchurl, fetchpatch, pkgconfig, glib, dbus, dbus_glib, dbus_tools, polkit
-, intltool, libxslt, docbook_xsl, udev, libusb1, pmutils
+{ stdenv, fetchurl, pkgconfig, glib, dbus_glib
+, intltool, libxslt, docbook_xsl, udev, libusb1
 , useSystemd ? true, systemd, gobjectIntrospection
 }:
 
 assert stdenv.isLinux;
 
 stdenv.mkDerivation rec {
-  name = "upower-0.9.23";
+  name = "upower-0.99.3";
 
   src = fetchurl {
     url = "http://upower.freedesktop.org/releases/${name}.tar.xz";
-    sha256 = "06wqhab2mn0j4biiwh7mn4kxbxnfnzjkxvhpgvnlpaz9m2q54cj3";
+    sha256 = "0f6x9mi1jzgqdpycaikyhjljnw3aacsl3gxndyg0dfqkq6y9jwb9";
   };
 
-  patches = [
-    (fetchpatch rec {
-      url = "http://anonscm.debian.org/gitweb/?p=pkg-utopia/upower.git;"
-        + "a=blob_plain;f=debian/patches/${name};hb=b424b2763fbbba95df8c6ab3feeb57d072a9ddf7";
-      sha256 = "0iq991abrn745icyz6x0wyixrjli01vbmbd9lnwwgyil58h3z8sp";
-      name = "no_deprecation_define.patch";
-    })
-    (fetchpatch {
-      url = "http://cgit.freedesktop.org/upower/patch/?id=22da1a0bc5943b683189418d8b0f766e91b2bdbe";
-      sha256 = "0yfgg6pw4bwskannvdwjxr75lgdrjpxhsskwlzm0frp8v5jy4k4z";
-      name = "clamp-battery-percentages.patch";
-    })
-  ];
-
   buildInputs =
-    [ dbus_glib polkit intltool libxslt docbook_xsl udev libusb1 gobjectIntrospection ]
+    [ dbus_glib intltool libxslt docbook_xsl udev libusb1 gobjectIntrospection ]
     ++ stdenv.lib.optional useSystemd systemd;
 
   nativeBuildInputs = [ pkgconfig ];
 
-  preConfigure =
-    ''
-      substituteInPlace src/linux/up-backend.c \
-        --replace /usr/bin/pm- ${pmutils}/bin/pm- \
-        --replace /usr/sbin/pm- ${pmutils}/sbin/pm-
-      substituteInPlace src/notify-upower.sh \
-        --replace /usr/bin/dbus-send ${dbus_tools}/bin/dbus-send
-    '';
-
   configureFlags =
     [ "--with-backend=linux" "--localstatedir=/var"
-      "--enable-deprecated" # needed for Xfce (Nov 2013)
     ]
     ++ stdenv.lib.optional useSystemd
-    [ "--enable-systemd"
-      "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
+    [ "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
       "--with-systemdutildir=$(out)/lib/systemd"
       "--with-udevrulesdir=$(out)/lib/udev/rules.d"
     ];
diff --git a/pkgs/os-specific/linux/util-linux/default.nix b/pkgs/os-specific/linux/util-linux/default.nix
index 7f2aeca255c..7768875ca57 100644
--- a/pkgs/os-specific/linux/util-linux/default.nix
+++ b/pkgs/os-specific/linux/util-linux/default.nix
@@ -53,5 +53,6 @@ stdenv.mkDerivation rec {
     homepage = http://www.kernel.org/pub/linux/utils/util-linux/;
     description = "A set of system utilities for Linux";
     platforms = stdenv.lib.platforms.linux;
+    priority = 6; # lower priority than coreutils ("kill") and shadow ("login" etc.) packages
   };
 }
diff --git a/pkgs/os-specific/linux/wis-go7007/default.nix b/pkgs/os-specific/linux/wis-go7007/default.nix
index 53868672025..4dae68d4871 100644
--- a/pkgs/os-specific/linux/wis-go7007/default.nix
+++ b/pkgs/os-specific/linux/wis-go7007/default.nix
@@ -56,7 +56,7 @@ stdenv.mkDerivation {
     mkdir -p $out/etc/udev/rules.d
  
     makeFlagsArray=(KERNELSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source \
-        FIRMWARE_DIR=$out/firmware FXLOAD=${fxload}/sbin/fxload \
+        FIRMWARE_DIR=$out/lib/firmware FXLOAD=${fxload}/sbin/fxload \
         DESTDIR=$out SKIP_DEPMOD=1 \
         USE_UDEV=y)
   ''; # */
diff --git a/pkgs/os-specific/linux/xf86-input-wacom/default.nix b/pkgs/os-specific/linux/xf86-input-wacom/default.nix
index 9e475f7aed9..fca9dab2261 100644
--- a/pkgs/os-specific/linux/xf86-input-wacom/default.nix
+++ b/pkgs/os-specific/linux/xf86-input-wacom/default.nix
@@ -3,11 +3,11 @@
 , ncurses, pkgconfig, randrproto, xorgserver, xproto, udev, libXinerama, pixman }:
 
 stdenv.mkDerivation rec {
-  name = "xf86-input-wacom-0.30.0";
+  name = "xf86-input-wacom-0.31.0";
 
   src = fetchurl {
     url = "mirror://sourceforge/linuxwacom/${name}.tar.bz2";
-    sha256 = "1xa1i2ks00fa20c5dlpqzlapzj638a7qm5c0wqc3qvgwliwy9m4a";
+    sha256 = "0xiz5vpkp8zm5m2k909sbvm9v8rf6hwn3gvqr2msswc00hzp5sg7";
   };
 
   buildInputs = [ inputproto libX11 libXext libXi libXrandr libXrender
diff --git a/pkgs/os-specific/linux/zfs/default.nix b/pkgs/os-specific/linux/zfs/default.nix
index 399169b364e..1432fa3e79b 100644
--- a/pkgs/os-specific/linux/zfs/default.nix
+++ b/pkgs/os-specific/linux/zfs/default.nix
@@ -1,13 +1,13 @@
 { callPackage, fetchFromGitHub, ... } @ args:
 
 callPackage ./generic.nix (args // rec {
-  version = "0.6.4.2";
+  version = "0.6.5.1";
 
   src = fetchFromGitHub {
     owner = "zfsonlinux";
     repo = "zfs";
     rev = "zfs-${version}";
-    sha256 = "192x4z5am5wgrr4hb5skshyr5a6af52xpnk6pni4hs4pxvlpcs37";
+    sha256 = "0lbii5kc3b68zj8mvvznl05czwdkr0ld3a2javbkngfvrcn09rz2";
   };
 
   patches = [ ./nix-build.patch ];
diff --git a/pkgs/os-specific/linux/zfs/git.nix b/pkgs/os-specific/linux/zfs/git.nix
index 26c48076c4e..0423d139c83 100644
--- a/pkgs/os-specific/linux/zfs/git.nix
+++ b/pkgs/os-specific/linux/zfs/git.nix
@@ -1,13 +1,13 @@
 { callPackage, stdenv, fetchFromGitHub, spl_git, ... } @ args:
 
 callPackage ./generic.nix (args // rec {
-  version = "2015-07-21";
+  version = "2015-09-19";
 
   src = fetchFromGitHub {
     owner = "zfsonlinux";
     repo = "zfs";
-    rev = "3b79cef21294f3ec46c4f71cc5a68a75a4d0ebc7";
-    sha256 = "01l4cg62wgn3wzasskx2nh3a4c74vq8qcwz090x8x1r4c2r4v943";
+    rev = "3af56fd95fbe8b417d7ed7c9c25ef59d6f1ee161";
+    sha256 = "08sx1jzwrsdyvvlcf5as7rkglgbx5x6zvfn8ps8gk4miqfckq4z0";
   };
 
   patches = [ ./nix-build.patch ];
diff --git a/pkgs/os-specific/linux/zfs/kernel-4.1-compat.patch b/pkgs/os-specific/linux/zfs/kernel-4.1-compat.patch
deleted file mode 100644
index 7e75e843af3..00000000000
--- a/pkgs/os-specific/linux/zfs/kernel-4.1-compat.patch
+++ /dev/null
@@ -1,149 +0,0 @@
-diff --git a/config/kernel-vfs-rw-iterate.m4 b/config/kernel-vfs-rw-iterate.m4
-new file mode 100644
-index 0000000..f8dc422
---- /dev/null
-+++ b/config/kernel-vfs-rw-iterate.m4
-@@ -0,0 +1,27 @@
-+dnl #
-+dnl # Linux 4.1.x API
-+dnl #
-+AC_DEFUN([ZFS_AC_KERNEL_VFS_RW_ITERATE],
-+	[AC_MSG_CHECKING([whether fops->read/write_iter() are available])
-+	ZFS_LINUX_TRY_COMPILE([
-+		#include <linux/fs.h>
-+
-+		ssize_t test_read(struct kiocb *kiocb, struct iov_iter *to)
-+		    { return 0; }
-+		ssize_t test_write(struct kiocb *kiocb, struct iov_iter *from)
-+		    { return 0; }
-+
-+		static const struct file_operations
-+		    fops __attribute__ ((unused)) = {
-+		    .read_iter = test_read,
-+		    .write_iter = test_write,
-+		};
-+	],[
-+	],[
-+		AC_MSG_RESULT(yes)
-+		AC_DEFINE(HAVE_VFS_RW_ITERATE, 1,
-+			[fops->read/write_iter() are available])
-+	],[
-+		AC_MSG_RESULT(no)
-+	])
-+])
-diff --git a/config/kernel.m4 b/config/kernel.m4
-index a9f2f58..fe42e17 100644
---- a/config/kernel.m4
-+++ b/config/kernel.m4
-@@ -96,6 +96,7 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [
- 	ZFS_AC_KERNEL_5ARG_SGET
- 	ZFS_AC_KERNEL_LSEEK_EXECUTE
- 	ZFS_AC_KERNEL_VFS_ITERATE
-+	ZFS_AC_KERNEL_VFS_RW_ITERATE
- 
- 	AS_IF([test "$LINUX_OBJ" != "$LINUX"], [
- 		KERNELMAKE_PARAMS="$KERNELMAKE_PARAMS O=$LINUX_OBJ"
-diff --git a/module/zfs/zpl_file.c b/module/zfs/zpl_file.c
-index 66db113..5471140 100644
---- a/module/zfs/zpl_file.c
-+++ b/module/zfs/zpl_file.c
-@@ -196,8 +196,7 @@ zpl_fsync(struct file *filp, loff_t start, loff_t end, int datasync)
- static int
- zpl_aio_fsync(struct kiocb *kiocb, int datasync)
- {
--	return (zpl_fsync(kiocb->ki_filp, kiocb->ki_pos,
--	    kiocb->ki_pos + kiocb->ki_nbytes, datasync));
-+	return (zpl_fsync(kiocb->ki_filp, kiocb->ki_pos, -1, datasync));
- }
- #else
- #error "Unsupported fops->fsync() implementation"
-@@ -261,12 +260,11 @@ zpl_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos)
- }
- 
- static ssize_t
--zpl_aio_read(struct kiocb *kiocb, const struct iovec *iovp,
--	unsigned long nr_segs, loff_t pos)
-+zpl_iter_read_common(struct kiocb *kiocb, const struct iovec *iovp,
-+    unsigned long nr_segs, size_t count)
- {
- 	cred_t *cr = CRED();
- 	struct file *filp = kiocb->ki_filp;
--	size_t count = kiocb->ki_nbytes;
- 	ssize_t read;
- 	size_t alloc_size = sizeof (struct iovec) * nr_segs;
- 	struct iovec *iov_tmp = kmem_alloc(alloc_size, KM_SLEEP);
-@@ -284,6 +282,22 @@ zpl_aio_read(struct kiocb *kiocb, const struct iovec *iovp,
- 	return (read);
- }
- 
-+#if defined(HAVE_VFS_RW_ITERATE)
-+static ssize_t
-+zpl_iter_read(struct kiocb *kiocb, struct iov_iter *to)
-+{
-+	return (zpl_iter_read_common(kiocb, to->iov, to->nr_segs,
-+	    iov_iter_count(to)));
-+}
-+#else
-+static ssize_t
-+zpl_aio_read(struct kiocb *kiocb, const struct iovec *iovp,
-+    unsigned long nr_segs, loff_t pos)
-+{
-+	return (zpl_iter_read_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes));
-+}
-+#endif /* HAVE_VFS_RW_ITERATE */
-+
- static inline ssize_t
- zpl_write_common_iovec(struct inode *ip, const struct iovec *iovp, size_t count,
-     unsigned long nr_segs, loff_t *ppos, uio_seg_t segment,
-@@ -344,12 +358,11 @@ zpl_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos)
- }
- 
- static ssize_t
--zpl_aio_write(struct kiocb *kiocb, const struct iovec *iovp,
--	unsigned long nr_segs, loff_t pos)
-+zpl_iter_write_common(struct kiocb *kiocb, const struct iovec *iovp,
-+    unsigned long nr_segs, size_t count)
- {
- 	cred_t *cr = CRED();
- 	struct file *filp = kiocb->ki_filp;
--	size_t count = kiocb->ki_nbytes;
- 	ssize_t wrote;
- 	size_t alloc_size = sizeof (struct iovec) * nr_segs;
- 	struct iovec *iov_tmp = kmem_alloc(alloc_size, KM_SLEEP);
-@@ -367,6 +380,22 @@ zpl_aio_write(struct kiocb *kiocb, const struct iovec *iovp,
- 	return (wrote);
- }
- 
-+#if defined(HAVE_VFS_RW_ITERATE)
-+static ssize_t
-+zpl_iter_write(struct kiocb *kiocb, struct iov_iter *from)
-+{
-+	return (zpl_iter_write_common(kiocb, from->iov, from->nr_segs,
-+	    iov_iter_count(from)));
-+}
-+#else
-+static ssize_t
-+zpl_aio_write(struct kiocb *kiocb, const struct iovec *iovp,
-+    unsigned long nr_segs, loff_t pos)
-+{
-+	return (zpl_iter_write_common(kiocb, iovp, nr_segs, kiocb->ki_nbytes));
-+}
-+#endif /* HAVE_VFS_RW_ITERATE */
-+
- static loff_t
- zpl_llseek(struct file *filp, loff_t offset, int whence)
- {
-@@ -778,8 +807,13 @@ const struct file_operations zpl_file_operations = {
- 	.llseek		= zpl_llseek,
- 	.read		= zpl_read,
- 	.write		= zpl_write,
-+#ifdef HAVE_VFS_RW_ITERATE
-+	.read_iter	= zpl_iter_read,
-+	.write_iter	= zpl_iter_write,
-+#else
- 	.aio_read	= zpl_aio_read,
- 	.aio_write	= zpl_aio_write,
-+#endif
- 	.mmap		= zpl_mmap,
- 	.fsync		= zpl_fsync,
- 	.aio_fsync	= zpl_aio_fsync,