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/bsd/netbsd/default.nix299
-rw-r--r--pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix10
-rw-r--r--pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix2
-rw-r--r--pkgs/os-specific/darwin/native-x11-and-opengl/default.nix2
-rw-r--r--pkgs/os-specific/darwin/osx-private-sdk/default.nix2
-rw-r--r--pkgs/os-specific/darwin/skhd/default.nix4
-rw-r--r--pkgs/os-specific/gnu/hurd/default.nix29
-rw-r--r--pkgs/os-specific/gnu/libpthread/default.nix2
-rw-r--r--pkgs/os-specific/gnu/mig/default.nix2
-rw-r--r--pkgs/os-specific/linux/acpid/default.nix12
-rw-r--r--pkgs/os-specific/linux/alsa-utils/default.nix4
-rw-r--r--pkgs/os-specific/linux/batman-adv/alfred.nix4
-rw-r--r--pkgs/os-specific/linux/blcr/default.nix1
-rw-r--r--pkgs/os-specific/linux/bluez/default.nix37
-rw-r--r--pkgs/os-specific/linux/compsize/default.nix30
-rw-r--r--pkgs/os-specific/linux/cpufrequtils/default.nix2
-rw-r--r--pkgs/os-specific/linux/drbd/default.nix2
-rw-r--r--pkgs/os-specific/linux/firejail/default.nix8
-rw-r--r--pkgs/os-specific/linux/fuse/common.nix13
-rw-r--r--pkgs/os-specific/linux/fuse/default.nix7
-rw-r--r--pkgs/os-specific/linux/fuse/fuse3-fix-version.patch8
-rw-r--r--pkgs/os-specific/linux/hwdata/default.nix6
-rw-r--r--pkgs/os-specific/linux/i7z/default.nix44
-rw-r--r--pkgs/os-specific/linux/input-utils/default.nix30
-rw-r--r--pkgs/os-specific/linux/iproute/default.nix5
-rw-r--r--pkgs/os-specific/linux/iwd/default.nix8
-rw-r--r--pkgs/os-specific/linux/kernel/common-config.nix16
-rw-r--r--pkgs/os-specific/linux/kernel/linux-4.14.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/linux-4.16.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/linux-4.4.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/linux-4.9.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/linux-copperhead-lts.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/linux-copperhead-stable.nix4
-rw-r--r--pkgs/os-specific/linux/kernel/linux-mptcp.nix3
-rw-r--r--pkgs/os-specific/linux/kernel/linux-testing.nix6
-rw-r--r--pkgs/os-specific/linux/kernel/mips-ext3-n32.patch17
-rw-r--r--pkgs/os-specific/linux/kernel/mips-fpu-sigill.patch507
-rw-r--r--pkgs/os-specific/linux/kernel/mips-fpureg-emulation.patch144
-rw-r--r--pkgs/os-specific/linux/kernel/patches.nix35
-rw-r--r--pkgs/os-specific/linux/libcap/default.nix8
-rw-r--r--pkgs/os-specific/linux/libsmbios/default.nix6
-rw-r--r--pkgs/os-specific/linux/lsscsi/default.nix8
-rw-r--r--pkgs/os-specific/linux/mdadm/default.nix2
-rw-r--r--pkgs/os-specific/linux/mwprocapture/default.nix3
-rw-r--r--pkgs/os-specific/linux/pam/default.nix15
-rw-r--r--pkgs/os-specific/linux/pam_u2f/default.nix4
-rw-r--r--pkgs/os-specific/linux/phc-intel/default.nix1
-rw-r--r--pkgs/os-specific/linux/psmisc/default.nix2
-rw-r--r--pkgs/os-specific/linux/systemd/cryptsetup-generator.nix13
-rw-r--r--pkgs/os-specific/linux/systemd/default.nix14
-rw-r--r--pkgs/os-specific/linux/tbs/default.nix63
-rw-r--r--pkgs/os-specific/linux/uclibc/default.nix52
-rw-r--r--pkgs/os-specific/linux/upower/default.nix2
-rw-r--r--pkgs/os-specific/linux/usbutils/default.nix4
-rw-r--r--pkgs/os-specific/linux/wireguard/default.nix4
-rw-r--r--pkgs/os-specific/linux/xf86-input-multitouch/default.nix2
-rw-r--r--pkgs/os-specific/windows/mingwrt/common.nix12
-rw-r--r--pkgs/os-specific/windows/mingwrt/default.nix32
-rw-r--r--pkgs/os-specific/windows/mingwrt/headers.nix17
-rw-r--r--pkgs/os-specific/windows/pthread-w32/default.nix2
-rw-r--r--pkgs/os-specific/windows/w32api/common.nix14
-rw-r--r--pkgs/os-specific/windows/w32api/default.nix34
-rw-r--r--pkgs/os-specific/windows/w32api/headers.nix17
63 files changed, 573 insertions, 1083 deletions
diff --git a/pkgs/os-specific/bsd/netbsd/default.nix b/pkgs/os-specific/bsd/netbsd/default.nix
index ecd09eaff807..b4fb99504ef2 100644
--- a/pkgs/os-specific/bsd/netbsd/default.nix
+++ b/pkgs/os-specific/bsd/netbsd/default.nix
@@ -1,5 +1,5 @@
 { stdenv, hostPlatform, fetchcvs, lib, groff, mandoc, zlib, coreutils
-, yacc, flex, libressl, bash }:
+, yacc, flex, libressl, bash, less, writeText }:
 
 let
   fetchNetBSD = path: version: sha256: fetchcvs {
@@ -10,10 +10,11 @@ let
   };
 
   netBSDDerivation = attrs: stdenv.mkDerivation ((rec {
-    name = "${attrs.pname or (baseNameOf attrs.path)}-netbsd-${attrs.version}";
+    name = "bsd-${attrs.pname or (baseNameOf attrs.path)}-netbsd-${attrs.version}";
     src = attrs.src or fetchNetBSD attrs.path attrs.version attrs.sha256;
 
     extraPaths = [ ];
+    setOutputFlags = false;
 
     nativeBuildInputs = [ makeMinimal mandoc groff install stat
                           yacc flex tsort lorder ];
@@ -25,25 +26,34 @@ let
     DESTDIR = "$(out)";
     TOOLDIR = "$(out)";
     USETOOLS = "never";
-    NOCLANGERROR="yes";
-    NOGCCERROR="yes";
+    NOCLANGERROR = "yes";
+    NOGCCERROR = "yes";
     LEX = "flex";
+    MKUNPRIVED = "yes";
+    HOST_SH = "${bash}/bin/sh";
+    OBJCOPY = if stdenv.isDarwin then "true" else "objcopy";
+    MACHINE_ARCH = hostPlatform.parsed.cpu.name;
+    MACHINE_CPU = hostPlatform.parsed.cpu.name;
+
+    INSTALL_FILE = "install -U -c";
+    INSTALL_DIR = "xinstall -U -d";
+    INSTALL_LINK = "install -U -l h";
+    INSTALL_SYMLINK = "install -U -l s";
 
     # libs will be provided by cc-wrapper
-    LIBCRT0="";
-    LIBCRTI="";
-    LIBCRTEND="";
-    LIBCRTBEGIN="";
-    LIBC="";
-    LIBUTIL="";
+    LIBCRT0 = "";
+    LIBCRTI = "";
+    LIBCRTEND = "";
+    LIBCRTBEGIN = "";
+    LIBC = "";
+    LIBUTIL = "";
     LIBSSL = "";
     LIBCRYPTO = "";
     LIBCRYPT = "";
     LIBCURSES = "";
     LIBTERMINFO = "";
     LIBM = "";
-    "LIBDO.terminfo" = "_external";
-    "LIBDO.curses" = "_external";
+    LIBL = "";
     _GCC_CRTBEGIN = "";
     _GCC_CRTBEGINS = "";
     _GCC_CRTEND = "";
@@ -53,10 +63,14 @@ let
     _GCC_CRTDIR = "";
     _GCC_CRTN = "";
 
+    "LIBDO.terminfo" = "_external";
+    "LIBDO.curses" = "_external";
+
     # all dirs will be prefixed with DESTDIR
     BINDIR = "/bin";
     LIBDIR = "/lib";
     SHLIBDIR = "/lib";
+    INCSDIR = "/include";
     MANDIR = "/share/man";
     INFODIR = "/share/info";
     DOCDIR = "/share/doc";
@@ -64,22 +78,12 @@ let
     X11BINDIR = "/bin";
     X11USRLIBDIR = "/lib";
     X11MANDIR = "/share/man";
-    SHLINKDIR = "/usr/libexec";
-
-    HOST_SH = "${bash}/bin/sh";
-
-    SHLIB_WARNTEXTREL = "no";
-    SHLIB_MKMAP = "no";
-    PRESERVE = "-p";
-    OBJCOPY = if stdenv.isDarwin then "true" else "objcopy";
-
-    MACHINE_ARCH = hostPlatform.parsed.cpu.name;
-    MACHINE_CPU = hostPlatform.parsed.cpu.name;
 
     # NetBSD makefiles should be able to detect this
     # but without they end up using gcc on Darwin stdenv
     preConfigure = ''
       export HAVE_${if stdenv.cc.isGNU then "GCC" else "LLVM"}=${lib.head (lib.splitString "." (lib.getVersion stdenv.cc.cc))}
+
       # Parallel building. Needs the space.
       export makeFlags+=" -j $NIX_BUILD_CORES"
     '';
@@ -90,6 +94,7 @@ let
       sourceRoot=$PWD/$sourceRoot
       export NETBSDSRCDIR=$sourceRoot
       export BSDSRCDIR=$NETBSDSRCDIR
+      export _SRC_TOP_=$NETBSDSRCDIR
       chmod -R u+w $sourceRoot
       for path in $extraPaths; do
         cd $path
@@ -104,19 +109,7 @@ let
       fi
     '';
 
-    # Need to create directories for xinstall to work. Unused ones
-    # will be removed in the postInstall.
-    preInstall = ''
-      mkdir -p $out$BINDIR $out$LIBDIR $out$INFODIR \
-               $out$DOCDIR $out$LOCALEDIR
-      for i in 1 2 3 4 5 6 7 8 9; do
-        mkdir -p $out$MANDIR/man$i $out$MANDIR/html$i \
-                 $out$DOCDIR/reference/ref$i
-      done
-      mkdir -p $out/usr/include
-    '';
-
-    postInstall = ''
+    preFixup = ''
       # Remove lingering /usr references
       if [ -d $out/usr ]; then
         cd $out/usr
@@ -134,7 +127,9 @@ let
     };
   }) // attrs);
 
-  # BOOTSTRAPPING
+  ##
+  ## BOOTSTRAPPING
+  ##
   makeMinimal = netBSDDerivation rec {
     path = "tools/make";
     sha256 = "0l4794zwj2haark3azf9xwcwqlkbrifhb2glaa9iba4dkg2mklsb";
@@ -143,16 +138,26 @@ let
     buildInputs = [];
     nativeBuildInputs = [];
 
-    patchPhase = ''
+    postPatch = ''
       patchShebangs configure
-      ${make.patchPhase}
+      ${make.postPatch}
+    '';
+    buildPhase = ''
+      runHook preBuild
+
+      sh ./buildmake.sh
+
+      runHook postBuild
     '';
-    buildPhase = "sh ./buildmake.sh";
     installPhase = ''
+      runHook preInstall
+
       install -D nbmake $out/bin/nbmake
       ln -s $out/bin/nbmake $out/bin/make
       mkdir -p $out/share
-      cp -r ../../share/mk $out/share/mk
+      cp -r $NETBSDSRCDIR/share/mk $out/share/mk
+
+      runHook postInstall
     '';
     extraPaths = [ make.src ] ++ make.extraPaths;
   };
@@ -170,7 +175,8 @@ let
 
     # temporarily use gnuinstall for bootstrapping
     # bsdinstall will be built later
-    makeFlags = "INSTALL=${coreutils}/bin/install";
+    makeFlags = [ "INSTALL=${coreutils}/bin/install" ];
+    installFlags = [];
     RENAME = "-D";
 
     postInstall = ''
@@ -211,14 +217,30 @@ let
     ] ++ libutil.extraPaths ++ libc.extraPaths;
   };
 
-  install = netBSDDerivation {
+  # HACK to ensure parent directories exist. This emulates GNU
+  # install’s -D option. No alternative seems to exist in BSD install.
+  install = let binstall = writeText "binstall" ''
+    #!/usr/bin/env sh
+    for last in $@; do true; done
+    mkdir -p $(dirname $last)
+    xinstall "$@"
+  ''; in netBSDDerivation {
     path = "usr.bin/xinstall";
     version = "7.1.2";
     sha256 = "0nzhyh714m19h61m45gzc5dszkbafp5iaphbp5mza6w020fzf2y8";
     extraPaths = [ mtree.src make.src ];
     nativeBuildInputs = [ makeMinimal mandoc groff ];
     buildInputs = [ compat fts ];
-    RENAME = "-D";
+    installPhase = ''
+      runHook preInstall
+
+      install -D install.1 $out/share/man/man1/install.1
+      install -D xinstall $out/bin/xinstall
+      install -D -m 0550 ${binstall} $out/bin/binstall
+      ln -s $out/bin/binstall $out/bin/install
+
+      runHook postInstall
+    '';
   };
 
   fts = netBSDDerivation {
@@ -239,10 +261,14 @@ let
       ar -rsc libfts.a lib/libc/gen/fts.o
     '';
     installPhase = ''
+      runHook preInstall
+
       install -D lib/libc/gen/fts.3 $out/share/man/man3/fts.3
       install -D include/fts.h $out/include/fts.h
       install -D lib/libc/include/namespace.h $out/include/namespace.h
       install -D libfts.a $out/lib/libfts.a
+
+      runHook postInstall
     '';
     setupHook = ./fts-setup-hook.sh;
   };
@@ -267,7 +293,9 @@ let
     sha256 = "0rjf9blihhm0n699vr2bg88m4yjhkbxh6fxliaay3wxkgnydjwn2";
     nativeBuildInputs = [ makeMinimal mandoc groff install ];
   };
-  # END BOOTSTRAPPING
+  ##
+  ## END BOOTSTRAPPING
+  ##
 
   libutil = netBSDDerivation {
     path = "lib/libutil";
@@ -291,44 +319,29 @@ let
     path = "usr.bin/make";
     sha256 = "0srkkg6qdzqlccfi4xh19gl766ks6hpss76bnfvwmd0zg4q4zdar";
     version = "7.1.2";
-    patchPhase = ''
+    postPatch = ''
       # make needs this to pick up our sys make files
       export NIX_CFLAGS_COMPILE+=" -D_PATH_DEFSYSPATH=\"$out/share/mk\""
 
-      # can't set owner or group in Nix build
-      # maybe there is a better way to trick it?
       substituteInPlace $NETBSDSRCDIR/share/mk/bsd.prog.mk \
-        --replace '-o ''${SCRIPTSOWN_''${.ALLSRC:T}:U''${SCRIPTSOWN}}' "" \
-        --replace '-g ''${SCRIPTSGRP_''${.ALLSRC:T}:U''${SCRIPTSGRP}}' "" \
-        --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \
-        --replace '-o ''${BINOWN} -g ''${BINGRP}' "" \
-        --replace '-o ''${RUMPBINOWN} -g ''${RUMPBINGRP}' "" \
-        --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.doc.mk \
-        --replace '-o ''${DOCOWN} -g ''${DOCGRP}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.links.mk \
-        --replace '-o ''${LINKSOWN_''${.ALLSRC:T}:U''${LINKSOWN}}' "" \
-        --replace '-g ''${LINKSGRP_''${.ALLSRC:T}:U''${LINKSGRP}}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.man.mk \
-        --replace '-o ''${MANOWN} -g ''${MANGRP}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.files.mk \
-        --replace '-o ''${FILESOWN_''${.ALLSRC:T}:U''${FILESOWN}}' "" \
-        --replace '-g ''${FILESGRP_''${.ALLSRC:T}:U''${FILESGRP}}' ""
-      substituteInPlace $NETBSDSRCDIR/share/mk/bsd.inc.mk \
-        --replace '-o ''${BINOWN} -g ''${BINGRP}' ""
+        --replace '-Wl,-dynamic-linker=''${_SHLINKER}' "" \
+        --replace '-Wl,-rpath,''${SHLIBDIR}' ""
       substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \
-        --replace '-o ''${DEBUGOWN} -g ''${DEBUGGRP}' "" \
-        --replace '-o ''${LIBOWN} -g ''${LIBGRP}' ""
+        --replace '_INSTRANLIB=''${empty(PRESERVE):?-a "''${RANLIB} -t":}' '_INSTRANLIB='
     '' + lib.optionalString stdenv.isDarwin ''
       substituteInPlace $NETBSDSRCDIR/share/mk/bsd.sys.mk \
-        --replace '-Wl,--fatal-warnings' ""
+        --replace '-Wl,--fatal-warnings' "" \
+        --replace '-Wl,--warn-shared-textrel' ""
       substituteInPlace $NETBSDSRCDIR/share/mk/bsd.lib.mk \
         --replace '-Wl,-soname,''${_LIB}.so.''${SHLIB_SOVERSION}' "" \
         --replace '-Wl,--whole-archive' "" \
-        --replace '-Wl,--no-whole-archive' ""
+        --replace '-Wl,--no-whole-archive' "" \
+        --replace '-Wl,--warn-shared-textrel' "" \
+        --replace '-Wl,-Map=''${_LIB}.so.''${SHLIB_SOVERSION}.map' "" \
+        --replace '-Wl,-rpath,''${SHLIBDIR}' ""
     '';
     postInstall = ''
-      (cd $NETBSDSRCDIR/share/mk && make install)
+      (cd $NETBSDSRCDIR/share/mk && make FILESDIR=/share/mk install)
     '';
     extraPaths = [
       (fetchNetBSD "share/mk" "7.1.2" "0570v0siv0wygn8ygs1yy9pgk9xjw9x1axr5qg4xrddv3lskf9xa")
@@ -345,12 +358,18 @@ let
     path = "usr.bin/who";
     version = "7.1.2";
     sha256 = "17ffwww957m3qw0b6fkgjpp12pd5ydg2hs9dxkkw0qpv11j00d88";
-    patchPhase = ''
+    postPatch = lib.optionalString stdenv.isLinux ''
       substituteInPlace $NETBSDSRCDIR/usr.bin/who/utmpentry.c \
-        --replace "strncpy(e->name, up->ut_name, sizeof(up->ut_name))" "strncpy(e->name, up->ut_user, sizeof(up->ut_user))" \
         --replace "utmptime = st.st_mtimespec" "utmptime = st.st_mtim" \
-        --replace "timespeccmp(&st.st_mtimespec, &utmptime, >)" "st.st_mtim.tv_sec == utmptime.tv_sec ? st.st_mtim.tv_nsec > utmptime.tv_nsec : st.st_mtim.tv_sec > utmptime.tv_sec" \
-        --replace "timespecclear(&utmptime)" "utmptime.tv_sec = utmptime.tv_nsec = 0"
+        --replace "timespeccmp(&st.st_mtimespec, &utmptime, >)" "st.st_mtim.tv_sec == utmptime.tv_sec ? st.st_mtim.tv_nsec > utmptime.tv_nsec : st.st_mtim.tv_sec > utmptime.tv_sec"
+   '' + lib.optionalString stdenv.isDarwin ''
+      substituteInPlace $NETBSDSRCDIR/usr.bin/who/utmpentry.c \
+        --replace "timespeccmp(&st.st_mtimespec, &utmpxtime, >)" "st.st_mtimespec.tv_sec == utmpxtime.tv_sec ? st.st_mtimespec.tv_nsec > utmpxtime.tv_nsec : st.st_mtimespec.tv_sec > utmpxtime.tv_sec"
+   '' + ''
+      substituteInPlace $NETBSDSRCDIR/usr.bin/who/utmpentry.c \
+        --replace "strncpy(e->name, up->ut_name, sizeof(up->ut_name))" "strncpy(e->name, up->ut_user, sizeof(up->ut_user))" \
+        --replace "timespecclear(&utmptime)" "utmptime.tv_sec = utmptime.tv_nsec = 0" \
+        --replace "timespecclear(&utmpxtime)" "utmpxtime.tv_sec = utmpxtime.tv_nsec = 0"
     '';
   };
 
@@ -370,13 +389,38 @@ in rec {
     version = "7.1.2";
   };
 
+  dict = netBSDDerivation {
+    path = "share/dict";
+    version = "7.1.2";
+    sha256 = "0nickhsjwgnr2h9nvwflvgfz93kqms5hzdnpyq02crpj35w98bh4";
+    makeFlags = [ "BINDIR=/share" ];
+  };
+
   games = netBSDDerivation {
     path = "games";
     sha256 = "04wjsang8f8kxsifiayklbxaaxmm3vx9rfr91hfbxj4hk8gkqzy1";
     version = "7.1.2";
-    patchPhase = ''
+    makeFlags = [ "BINDIR=/bin"
+                  "SCRIPTSDIR=/bin" ];
+    postPatch = ''
       sed -i '1i #include <time.h>' adventure/save.c
 
+      for f in $(find . -name pathnames.h); do
+        substituteInPlace $f \
+          --replace /usr/share/games $out/share/games \
+          --replace /usr/games $out/bin \
+          --replace /usr/libexec $out/libexec \
+          --replace /usr/bin/more ${less}/bin/less \
+          --replace /usr/share/dict ${dict}/share/dict
+      done
+      substituteInPlace boggle/boggle/bog.h \
+        --replace /usr/share/games $out/share/games
+      substituteInPlace ching/ching/ching.sh \
+        --replace /usr/share $out/share \
+        --replace /usr/libexec $out/libexec
+      substituteInPlace hunt/huntd/driver.c \
+        --replace "(void) setpgrp(getpid(), getpid());" ""
+
       # Disable some games that don't build. They should be possible
       # to build but need to look at how to implement stuff in
       # Linux. macOS is missing gettime. TODO try to get these
@@ -386,25 +430,33 @@ in rec {
       }
 
       disableGame atc
-      disableGame boggle
       disableGame dm
-      disableGame fortune
-      disableGame hunt
-      disableGame larn
-      disableGame phantasia
-      disableGame rogue
+      disableGame dab
       disableGame sail
       disableGame trek
-      disableGame dab
+      ${lib.optionalString stdenv.isLinux "disableGame boggle"}
+      ${lib.optionalString stdenv.isLinux "disableGame hunt"}
+      ${lib.optionalString stdenv.isLinux "disableGame larn"}
+      ${lib.optionalString stdenv.isLinux "disableGame phantasia"}
+      ${lib.optionalString stdenv.isLinux "disableGame rogue"}
       ${lib.optionalString stdenv.isDarwin "disableGame adventure"}
       ${lib.optionalString stdenv.isDarwin "disableGame factor"}
       ${lib.optionalString stdenv.isDarwin "disableGame gomoku"}
       ${lib.optionalString stdenv.isDarwin "disableGame mille"}
+    '';
 
-      substituteInPlace Makefile.inc \
-        --replace 2555 555 \
-        --replace 2550 550
+    # HACK strfile needs to be installed first & in the path. The
+    # Makefile should do this for us but haven't gotten it to work
+    preBuild = ''
+      (cd fortune/strfile && make && make BINDIR=/bin install)
+      export PATH=$out/bin:$PATH
     '';
+
+    postInstall = ''
+      substituteInPlace $out/usr/share/games/quiz.db/index \
+        --replace /usr $out
+    '';
+
     NIX_CFLAGS_COMPILE = [
       "-D__noinline="
       "-D__scanflike(a,b)="
@@ -412,39 +464,35 @@ in rec {
       "-DOXTABS=XTABS"
       "-DRANDOM_MAX=RAND_MAX"
       "-DINFTIM=-1"
-      (if hostPlatform.isMusl then "-include sys/ttydefaults.h -include sys/file.h" else "")
+      (lib.optionalString hostPlatform.isMusl "-include sys/ttydefaults.h -include sys/file.h")
+      "-DBE32TOH(x)=((void)0)"
+      "-DBE64TOH(x)=((void)0)"
+      "-D__c99inline=__inline"
     ];
-    postBuild = ''
-      mkdir -p $out/usr/games $out/usr/share/games/ching \
-               $out/usr/share/games/quiz.db \
-               $out/usr/libexec/ching $out/var/games/hackdir
-      touch $out/var/games/hackdir/perm
-    '';
-    preFixup = ''
-      mkdir -p $out/bin
-      mv $out/games/* $out/bin
-      rmdir $out/games
-    '';
+
     buildInputs = [ compat libcurses libterminfo libressl ];
-    extraPaths = [
-      (fetchNetBSD "share/dict" "7.1.2" "0nickhsjwgnr2h9nvwflvgfz93kqms5hzdnpyq02crpj35w98bh4")
-      who.src
-    ];
+    extraPaths = [ dict.src who.src ];
   };
 
-  # finger = netBSDDerivation {
-  #   path = "usr.bin/finger";
-  #   sha256 = "0jl672z50f2yf7ikp682b3xrarm6bnrrx9vi94xnp2fav8m8zfyi";
-  #   version = "7.1.2";
-  #   extraPaths = [ who.src ];
-  #   NIX_CFLAGS_COMPILE = [
-  #     "-DSUPPORT_UTMP"
-  #     "-USUPPORT_UTMPX"
-  #   ];
-  #   patchPhase = ''
-  #     ${who.patchPhase}
-  #   '';
-  # };
+  finger = netBSDDerivation {
+    path = "usr.bin/finger";
+    sha256 = "0jl672z50f2yf7ikp682b3xrarm6bnrrx9vi94xnp2fav8m8zfyi";
+    version = "7.1.2";
+    NIX_CFLAGS_COMPILE = [
+      (if stdenv.isLinux then "-DSUPPORT_UTMP" else "-USUPPORT_UTMP")
+      (if stdenv.isDarwin then "-DSUPPORT_UTMPX" else "-USUPPORT_UTMPX")
+    ];
+    postPatch = ''
+      NIX_CFLAGS_COMPILE+=" -I$NETBSDSRCDIR/include"
+
+      substituteInPlace extern.h \
+        --replace psort _psort
+
+      ${who.postPatch}
+    '';
+    extraPaths = [ who.src ]
+              ++ lib.optional stdenv.isDarwin (fetchNetBSD "include/utmp.h" "7.1.2" "05690fzz0825p2bq0sfyb00mxwd0wa06qryqgqkwpqk9y2xzc7px");
+  };
 
   fingerd = netBSDDerivation {
     path = "libexec/fingerd";
@@ -456,8 +504,8 @@ in rec {
     path = "lib/libedit";
     buildInputs = [ libterminfo libcurses ];
     propagatedBuildInputs = [ compat ];
-    postBuild = "mkdir -p $out/usr/include/readline";
-    patchPhase = ''
+    makeFlags = [ "INCSDIR=/include" ];
+    postPatch = ''
       sed -i '1i #undef bool_t' el.h
       substituteInPlace config.h \
         --replace "#define HAVE_STRUCT_DIRENT_D_NAMLEN 1" ""
@@ -477,6 +525,13 @@ in rec {
     sha256 = "06plg0bjqgbb0aghpb9qlk8wkp1l2izdlr64vbr5laqyw8jg84zq";
     buildInputs = [ compat tic nbperf ];
     MKPIC = if stdenv.isDarwin then "no" else "yes";
+    makeFlags = [ "INCSDIR=/include" ];
+    postPatch = ''
+      substituteInPlace term.c --replace /usr/share $out/share
+    '';
+    postInstall = ''
+      (cd $NETBSDSRCDIR/share/terminfo && make && make BINDIR=/share install)
+    '';
     extraPaths = [
       (fetchNetBSD "share/terminfo" "7.1.2" "1z5vzq8cw24j05r6df4vd6r57cvdbv7vbm4h962kplp14xrbg2h3")
     ];
@@ -487,6 +542,7 @@ in rec {
     version = "7.1.2";
     sha256 = "04djah9dadzw74nswn0xydkxn900kav8xdvxlxdl50nbrynxg9yf";
     buildInputs = [ libterminfo ];
+    makeFlags = [ "INCSDIR=/include" ];
     NIX_CFLAGS_COMPILE = [
       "-D__scanflike(a,b)="
       "-D__va_list=va_list"
@@ -495,7 +551,7 @@ in rec {
     propagatedBuildInputs = [ compat ];
     MKDOC = "no"; # missing vfontedpr
     MKPIC = if stdenv.isDarwin then "no" else "yes";
-    patchPhase = lib.optionalString (!stdenv.isDarwin) ''
+    postPatch = lib.optionalString (!stdenv.isDarwin) ''
       substituteInPlace printw.c \
         --replace "funopen(win, NULL, __winwrite, NULL, NULL)" NULL \
         --replace "__strong_alias(vwprintw, vw_printw)" 'extern int vwprintw(WINDOW*, const char*, va_list) __attribute__ ((alias ("vw_printw")));'
@@ -523,4 +579,11 @@ in rec {
     ];
   };
 
+  misc = netBSDDerivation {
+    path = "share/misc";
+    version = "7.1.2";
+    sha256 = "1vyn30js14nnadlls55mg7g1gz8h14l75rbrrh8lgn49qg289665";
+    makeFlags = [ "BINDIR=/share" ];
+  };
+
 }
diff --git a/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix b/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix
index d9b3dfb74049..3cee697366bb 100644
--- a/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/libiconv/default.nix
@@ -1,14 +1,18 @@
 { stdenv, appleDerivation }:
 
 appleDerivation {
-  preConfigure = "cd libiconv";
+  preConfigure = "cd libiconv"
+    + stdenv.lib.optionalString stdenv.hostPlatform.isiOS ''
+
+      sed -i 's/darwin\*/ios\*/g' configure libcharset/configure
+    '';
 
   postInstall = ''
     mv $out/lib/libiconv.dylib $out/lib/libiconv-nocharset.dylib
-    install_name_tool -id $out/lib/libiconv-nocharset.dylib $out/lib/libiconv-nocharset.dylib
+    ${stdenv.cc.bintools.targetPrefix}install_name_tool -id $out/lib/libiconv-nocharset.dylib $out/lib/libiconv-nocharset.dylib
 
     # re-export one useless symbol; ld will reject a dylib that only reexports other dylibs
-    echo 'void dont_use_this(){}' | clang -dynamiclib -x c - -current_version 2.4.0 \
+    echo 'void dont_use_this(){}' | ${stdenv.cc.bintools.targetPrefix}clang -dynamiclib -x c - -current_version 2.4.0 \
       -compatibility_version 7.0.0 -current_version 7.0.0 -o $out/lib/libiconv.dylib \
       -Wl,-reexport_library -Wl,$out/lib/libiconv-nocharset.dylib \
       -Wl,-reexport_library -Wl,$out/lib/libcharset.dylib
diff --git a/pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix b/pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix
index 5b9f30b62c39..f336b14ee37b 100644
--- a/pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix
+++ b/pkgs/os-specific/darwin/ios-sdk-pkgs/default.nix
@@ -13,7 +13,7 @@ let
 minSdkVersion = "9.0";
 
 iosPlatformArch = { parsed, ... }: {
-  "arm"     = "armv7";
+  "armv7a"  = "armv7";
   "aarch64" = "arm64";
   "x86_64"  = "x86_64";
 }.${parsed.cpu.name};
diff --git a/pkgs/os-specific/darwin/native-x11-and-opengl/default.nix b/pkgs/os-specific/darwin/native-x11-and-opengl/default.nix
index 3844912f6ba3..fa3d4284e597 100644
--- a/pkgs/os-specific/darwin/native-x11-and-opengl/default.nix
+++ b/pkgs/os-specific/darwin/native-x11-and-opengl/default.nix
@@ -1,7 +1,5 @@
 { stdenv, writeScript }:
 
-assert stdenv.isDarwin;
-
 stdenv.mkDerivation rec {
   name = "darwin-native-x11-and-opengl";
 
diff --git a/pkgs/os-specific/darwin/osx-private-sdk/default.nix b/pkgs/os-specific/darwin/osx-private-sdk/default.nix
index 1eecdbc5618d..115512a6febd 100644
--- a/pkgs/os-specific/darwin/osx-private-sdk/default.nix
+++ b/pkgs/os-specific/darwin/osx-private-sdk/default.nix
@@ -10,7 +10,7 @@ stdenv.mkDerivation {
     sha256 = "0bv0884yxpvk2ishxj8gdy1w6wb0gwfq55q5qjp0s8z0z7f63zqh";
   };
 
-  # NOTE: we install only headers that are really needed to keep closure sie
+  # NOTE: we install only headers that are really needed to keep closure size
   # reasonable.
   installPhase = ''
     mkdir -p $out/include
diff --git a/pkgs/os-specific/darwin/skhd/default.nix b/pkgs/os-specific/darwin/skhd/default.nix
index 24eb644e96fb..c51ada10d688 100644
--- a/pkgs/os-specific/darwin/skhd/default.nix
+++ b/pkgs/os-specific/darwin/skhd/default.nix
@@ -2,13 +2,13 @@
 
 stdenv.mkDerivation rec {
   name = "skhd-${version}";
-  version = "0.0.12";
+  version = "0.1.1";
 
   src = fetchFromGitHub {
     owner = "koekeishiya";
     repo = "skhd";
     rev = "v${version}";
-    sha256 = "09ihfd7cfqnfv095skn6rbrmjji61skwgg36b6s055fycrlbyp0h";
+    sha256 = "1wh7v90ydh27gbaiwn2r6ncx6yiic4mph3w9vi1282nz2q02zxss";
   };
 
   buildInputs = [ Carbon ];
diff --git a/pkgs/os-specific/gnu/hurd/default.nix b/pkgs/os-specific/gnu/hurd/default.nix
index 5eccee62468d..ae1c504fd19e 100644
--- a/pkgs/os-specific/gnu/hurd/default.nix
+++ b/pkgs/os-specific/gnu/hurd/default.nix
@@ -75,25 +75,16 @@ stdenv.mkDerivation ({
 
 //
 
-(if !headersOnly && buildTarget != null
- then assert installTarget != null; {
-   # Use the default `buildPhase' and `installPhase' so that the usual hooks
-   # can still be used.
-   buildFlags = buildTarget;
-   installTargets = installTarget;
- }
- else {})
+stdenv.lib.optionalAttrs (!headersOnly && buildTarget != null) {
+  # Use the default `buildPhase' and `installPhase' so that the usual hooks
+  # can still be used.
+  buildFlags = buildTarget;
+  installTargets = assert installTarget != null; installTarget;
+}
 
 //
 
-(if headersOnly
- then { dontBuild = true; installPhase = "make install-headers"; }
- else (if (cross != null)
-       then {
-         crossConfig = cross.config;
-
-         # The `configure' script wants to build executables so tell it where
-         # to find `crt1.o' et al.
-         LDFLAGS = "-B${glibcCross}/lib";
-       }
-       else { })))
+stdenv.lib.optionalAttrs headersOnly {
+  dontBuild = true;
+  installPhase = "make install-headers";
+})
diff --git a/pkgs/os-specific/gnu/libpthread/default.nix b/pkgs/os-specific/gnu/libpthread/default.nix
index 294a1548582b..a2e1081a1e8d 100644
--- a/pkgs/os-specific/gnu/libpthread/default.nix
+++ b/pkgs/os-specific/gnu/libpthread/default.nix
@@ -55,8 +55,6 @@ stdenv.mkDerivation ({
 
 (if cross != null
  then {
-   crossConfig = cross.config;
-
    # Tell gcc where to find `crt1.o' et al.  This is specified in two
    # different ways: one for gcc as run from `configure', and one for linking
    # libpthread.so (by default `libtool --mode=link' swallows `-B', hence
diff --git a/pkgs/os-specific/gnu/mig/default.nix b/pkgs/os-specific/gnu/mig/default.nix
index 34426b45d55e..2855f5b4240f 100644
--- a/pkgs/os-specific/gnu/mig/default.nix
+++ b/pkgs/os-specific/gnu/mig/default.nix
@@ -46,7 +46,7 @@ stdenv.mkDerivation {
 
     homepage = http://www.gnu.org/software/hurd/microkernel/mach/mig/gnu_mig.html;
 
-    # platforms = stdenv.lib.platforms.gnu;  # really GNU/Hurd
+    # platforms = stdenv.lib.platforms.gnu ++ stdenv.lib.platforms.linux;  # really GNU/Hurd
     maintainers = [ stdenv.lib.maintainers.ludo ];
   };
 }
diff --git a/pkgs/os-specific/linux/acpid/default.nix b/pkgs/os-specific/linux/acpid/default.nix
index 7a234b16c913..ad763d2ee298 100644
--- a/pkgs/os-specific/linux/acpid/default.nix
+++ b/pkgs/os-specific/linux/acpid/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl }:
+{ stdenv, fetchurl, autoreconfHook }:
 
 stdenv.mkDerivation rec {
   name = "acpid-2.0.29";
@@ -8,6 +8,16 @@ stdenv.mkDerivation rec {
     sha256 = "1zq38al07z92r2md18zivrzgjqnn7m2wahdpgri6wijwjwkknl2q";
   };
 
+  nativeBuildInputs = [ autoreconfHook ];
+
+  # remove when https://sourceforge.net/p/acpid2/code/merge-requests/1/ is merged
+  postPatch = ''
+    substituteInPlace configure.ac \
+      --replace "AC_FUNC_MALLOC" "" \
+      --replace "AC_FUNC_REALLOC" "" \
+      --replace "strrchr strtol" "strrchr strtol malloc realloc"
+  '';
+
   meta = with stdenv.lib; {
     homepage = http://tedfelix.com/linux/acpid-netlink.html;
     description = "A daemon for delivering ACPI events to userspace programs";
diff --git a/pkgs/os-specific/linux/alsa-utils/default.nix b/pkgs/os-specific/linux/alsa-utils/default.nix
index e2340939fce7..b8498c096d33 100644
--- a/pkgs/os-specific/linux/alsa-utils/default.nix
+++ b/pkgs/os-specific/linux/alsa-utils/default.nix
@@ -2,14 +2,14 @@
 
 stdenv.mkDerivation rec {
   name = "alsa-utils-${version}";
-  version = "1.1.5";
+  version = "1.1.6";
 
   src = fetchurl {
     urls = [
       "ftp://ftp.alsa-project.org/pub/utils/${name}.tar.bz2"
       "http://alsa.cybermirror.org/utils/${name}.tar.bz2"
     ];
-    sha256 = "1s727md6mb408y2cfwzjkx23abxhampyrjdkgpyygdhxx62x42rj";
+    sha256 = "0vnkyymgwj9rfdb11nvab30dnfrylmakdfildxl0y8mj836awp0m";
   };
 
   patchPhase = ''
diff --git a/pkgs/os-specific/linux/batman-adv/alfred.nix b/pkgs/os-specific/linux/batman-adv/alfred.nix
index 9b7484932ebd..90489e12d690 100644
--- a/pkgs/os-specific/linux/batman-adv/alfred.nix
+++ b/pkgs/os-specific/linux/batman-adv/alfred.nix
@@ -1,14 +1,14 @@
 { stdenv, fetchurl, pkgconfig, gpsd, libcap, libnl }:
 
 let
-  ver = "2018.0";
+  ver = "2018.1";
 in
 stdenv.mkDerivation rec {
   name = "alfred-${ver}";
 
   src = fetchurl {
     url = "http://downloads.open-mesh.org/batman/releases/batman-adv-${ver}/${name}.tar.gz";
-    sha256 = "0mzjgjkmgdrrqa6fbpii9q1xqvg3kvwgq2k2kpdf0vy4xxnypky7";
+    sha256 = "0xkd842yp227jzfybjq8c5s7y5c7amm1f5ai80k8wyjwysnad3w0";
   };
 
   nativeBuildInputs = [ pkgconfig ];
diff --git a/pkgs/os-specific/linux/blcr/default.nix b/pkgs/os-specific/linux/blcr/default.nix
index ab1a93b3a703..275600d42785 100644
--- a/pkgs/os-specific/linux/blcr/default.nix
+++ b/pkgs/os-specific/linux/blcr/default.nix
@@ -2,7 +2,6 @@
 
 # BLCR version 0.8.6 should works with linux kernel up to version 3.17.x
 
-assert stdenv.isLinux;
 assert builtins.compareVersions "3.18" kernel.version == 1;
 
 stdenv.mkDerivation {
diff --git a/pkgs/os-specific/linux/bluez/default.nix b/pkgs/os-specific/linux/bluez/default.nix
index d4595d73d942..a67133c32367 100644
--- a/pkgs/os-specific/linux/bluez/default.nix
+++ b/pkgs/os-specific/linux/bluez/default.nix
@@ -2,8 +2,6 @@
   pythonPackages, readline, udev, libical,
   systemd, enableWiimote ? false, enableMidi ? false }:
 
-assert stdenv.isLinux;
-
 stdenv.mkDerivation rec {
   name = "bluez-5.49";
 
@@ -12,24 +10,28 @@ stdenv.mkDerivation rec {
     sha256 = "15ffsaz7l3fgdg03l7g1xx9jw7xgs6pc548zxqsxawsca5x1sc1k";
   };
 
-  pythonPath = with pythonPackages;
-    [ dbus-python pygobject2 pygobject3 recursivePthLoader ];
+  pythonPath = with pythonPackages; [
+    dbus-python pygobject2 pygobject3 recursivePthLoader
+  ];
 
   buildInputs = [
-    pkgconfig dbus glib alsaLib pythonPackages.python pythonPackages.wrapPython
+    dbus glib alsaLib pythonPackages.python pythonPackages.wrapPython
     readline udev libical
   ];
 
+  nativeBuildInputs = [ pkgconfig ];
+
   outputs = [ "out" "dev" "test" ];
 
   patches = [ ./bluez-5.37-obexd_without_systemd-1.patch ];
 
-  preConfigure = ''
-      substituteInPlace tools/hid2hci.rules --replace /sbin/udevadm ${systemd}/bin/udevadm
-      substituteInPlace tools/hid2hci.rules --replace "hid2hci " "$out/lib/udev/hid2hci "
-    '';
+  postConfigure = ''
+    substituteInPlace tools/hid2hci.rules \
+      --replace /sbin/udevadm ${systemd}/bin/udevadm \
+      --replace "hid2hci " "$out/lib/udev/hid2hci "
+  '';
 
-  configureFlags = [
+  configureFlags = (with stdenv.lib; [
     "--localstatedir=/var"
     "--enable-library"
     "--enable-cups"
@@ -40,8 +42,8 @@ stdenv.mkDerivation rec {
     "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
     "--with-systemduserunitdir=$(out)/etc/systemd/user"
     "--with-udevdir=$(out)/lib/udev"
-    ] ++ stdenv.lib.optional enableWiimote [ "--enable-wiimote" ]
-    ++ stdenv.lib.optional enableMidi [ "--enable-midi" ];
+    ] ++ optional enableWiimote [ "--enable-wiimote" ]
+      ++ optional enableMidi    [ "--enable-midi" ]);
 
   # Work around `make install' trying to create /var/lib/bluetooth.
   installFlags = "statedir=$(TMPDIR)/var/lib/bluetooth";
@@ -73,14 +75,21 @@ stdenv.mkDerivation rec {
     # Add extra configuration
     mkdir $out/etc/bluetooth
     ln -s /etc/bluetooth/main.conf $out/etc/bluetooth/main.conf
+
+    # Add missing tools, ref https://git.archlinux.org/svntogit/packages.git/tree/trunk/PKGBUILD?h=packages/bluez
+    for files in `find tools/ -type f -perm -755`; do
+      filename=$(basename $files)
+      install -Dm755 tools/$filename $out/bin/$filename
+    done
   '';
 
   enableParallelBuilding = true;
 
   meta = with stdenv.lib; {
-    homepage = http://www.bluez.org/;
-    repositories.git = https://git.kernel.org/pub/scm/bluetooth/bluez.git;
     description = "Bluetooth support for Linux";
+    homepage = http://www.bluez.org/;
+    license = with licenses; [ gpl2 lgpl21 ];
     platforms = platforms.linux;
+    repositories.git = https://git.kernel.org/pub/scm/bluetooth/bluez.git;
   };
 }
diff --git a/pkgs/os-specific/linux/compsize/default.nix b/pkgs/os-specific/linux/compsize/default.nix
new file mode 100644
index 000000000000..a18011836f97
--- /dev/null
+++ b/pkgs/os-specific/linux/compsize/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchFromGitHub, btrfs-progs }:
+
+stdenv.mkDerivation rec {
+  name = "compsize-${version}";
+  version = "2018-04-07";
+
+  src = fetchFromGitHub {
+    owner = "kilobyte";
+    repo = "compsize";
+    rev = "903f772e37fc0ac6d6cf94ddbc98c691763c1e62";
+    sha256 = "0jps8n0xsdh4mcww5q29rzysbv50iq6rmihxrf99lzgrw0sw5m7k";
+  };
+
+  buildInputs = [ btrfs-progs ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    mkdir -p $out/share/man/man8
+    install -m 0755 compsize $out/bin
+    install -m 0444 compsize.8 $out/share/man/man8
+  '';
+
+  meta = with stdenv.lib; {
+    description = "btrfs: Find compression type/ratio on a file or set of files";
+    homepage    = https://github.com/kilobyte/compsize;
+    license     = licenses.gpl2;
+    maintainers = with maintainers; [ CrazedProgrammer ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/pkgs/os-specific/linux/cpufrequtils/default.nix b/pkgs/os-specific/linux/cpufrequtils/default.nix
index 65be409a75e3..e36aaa5e38d0 100644
--- a/pkgs/os-specific/linux/cpufrequtils/default.nix
+++ b/pkgs/os-specific/linux/cpufrequtils/default.nix
@@ -1,7 +1,5 @@
 { stdenv, fetchurl, libtool, gettext }:
 
-assert stdenv.system == "i686-linux" || stdenv.system == "x86_64-linux";
-
 stdenv.mkDerivation rec {
   name = "cpufrequtils-008";
 
diff --git a/pkgs/os-specific/linux/drbd/default.nix b/pkgs/os-specific/linux/drbd/default.nix
index 971eef6a8b52..8d18d5980207 100644
--- a/pkgs/os-specific/linux/drbd/default.nix
+++ b/pkgs/os-specific/linux/drbd/default.nix
@@ -1,7 +1,5 @@
 { stdenv, fetchurl, flex, systemd, perl }:
 
-assert stdenv.isLinux;
-
 stdenv.mkDerivation rec {
   name = "drbd-8.4.4";
 
diff --git a/pkgs/os-specific/linux/firejail/default.nix b/pkgs/os-specific/linux/firejail/default.nix
index 1c7ebce9f877..9f2374e75a88 100644
--- a/pkgs/os-specific/linux/firejail/default.nix
+++ b/pkgs/os-specific/linux/firejail/default.nix
@@ -3,11 +3,11 @@ let
   s = # Generated upstream information
   rec {
     baseName="firejail";
-    version="0.9.52";
+    version="0.9.54";
     name="${baseName}-${version}";
-    hash="0w8l8z4j7iph8fp7rchhnfsrik3f00f9v5xr191fp38fphzcj56s";
-    url="https://vorboss.dl.sourceforge.net/project/firejail/firejail/firejail-0.9.52.tar.xz";
-    sha256="0w8l8z4j7iph8fp7rchhnfsrik3f00f9v5xr191fp38fphzcj56s";
+    hash="0mkpqlhi1vxiwd1pmlsk02vpydy1gj61k1gi3zlz6qw84xa6i6ff";
+    url="https://vorboss.dl.sourceforge.net/project/firejail/firejail/firejail-0.9.54.tar.xz";
+    sha256="0mkpqlhi1vxiwd1pmlsk02vpydy1gj61k1gi3zlz6qw84xa6i6ff";
   };
   buildInputs = [
     which
diff --git a/pkgs/os-specific/linux/fuse/common.nix b/pkgs/os-specific/linux/fuse/common.nix
index 95011653ad01..04a4a1a0e1f1 100644
--- a/pkgs/os-specific/linux/fuse/common.nix
+++ b/pkgs/os-specific/linux/fuse/common.nix
@@ -1,4 +1,4 @@
-{ version, sha256Hash, maintainers }:
+{ version, sha256Hash }:
 
 { stdenv, fetchFromGitHub, fetchpatch
 , fusePackages, utillinux, gettext
@@ -28,10 +28,7 @@ in stdenv.mkDerivation rec {
         url = "https://github.com/libfuse/libfuse/commit/914871b20a901e3e1e981c92bc42b1c93b7ab81b.patch";
         sha256 = "1w4j6f1awjrycycpvmlv0x5v9gprllh4dnbjxl4dyl2jgbkaw6pa";
       })
-    ++ stdenv.lib.optional isFuse3 ./fuse3-install.patch
-    # TODO: Only relevant for 3.2.2 (opened an upstream issue)
-    ++ stdenv.lib.optional isFuse3 ./fuse3-fix-version.patch;
-
+    ++ stdenv.lib.optional isFuse3 ./fuse3-install.patch;
 
   nativeBuildInputs = if isFuse3
     then [ meson ninja pkgconfig ]
@@ -76,10 +73,10 @@ in stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
-  meta = {
+  meta = with stdenv.lib; {
     inherit (src.meta) homepage;
     description = "Kernel module and library that allows filesystems to be implemented in user space";
-    platforms = stdenv.lib.platforms.linux;
-    inherit maintainers;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.primeos ];
   };
 }
diff --git a/pkgs/os-specific/linux/fuse/default.nix b/pkgs/os-specific/linux/fuse/default.nix
index ddf280bbe2f7..f308930f0dc5 100644
--- a/pkgs/os-specific/linux/fuse/default.nix
+++ b/pkgs/os-specific/linux/fuse/default.nix
@@ -4,17 +4,14 @@ let
   mkFuse = args: callPackage (import ./common.nix args) {
     inherit utillinux;
   };
-  maintainers = stdenv.lib.maintainers;
 in {
   fuse_2 = mkFuse {
     version = "2.9.7";
     sha256Hash = "1wyjjfb7p4jrkk15zryzv33096a5fmsdyr2p4b00dd819wnly2n2";
-    maintainers = [ ];
   };
 
   fuse_3 = mkFuse {
-    version = "3.2.2";
-    sha256Hash = "1a0x4vpyg9lc6clwvx995mk0v6jqd37xabzp9rpdir37x814g3wh";
-    maintainers = [ maintainers.primeos ];
+    version = "3.2.3";
+    sha256Hash = "185p1vjcsyzpcdkrcyw06zpapv4jc43qw9i8a4amzpgk1rsgg19d";
   };
 }
diff --git a/pkgs/os-specific/linux/fuse/fuse3-fix-version.patch b/pkgs/os-specific/linux/fuse/fuse3-fix-version.patch
deleted file mode 100644
index b6351aab3c01..000000000000
--- a/pkgs/os-specific/linux/fuse/fuse3-fix-version.patch
+++ /dev/null
@@ -1,8 +0,0 @@
---- a/meson.build	2018-04-01 01:05:19.612723597 +0200
-+++ b/meson.build	2018-04-01 01:40:58.171109615 +0200
-@@ -1,4 +1,4 @@
--project('libfuse3', 'c', version: '3.2.1',
-+project('libfuse3', 'c', version: '3.2.2',
-         meson_version: '>= 0.38',
-         default_options: [ 'buildtype=debugoptimized' ])
-
diff --git a/pkgs/os-specific/linux/hwdata/default.nix b/pkgs/os-specific/linux/hwdata/default.nix
index 15b3903ddd1a..070ddfd77789 100644
--- a/pkgs/os-specific/linux/hwdata/default.nix
+++ b/pkgs/os-specific/linux/hwdata/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   name = "hwdata-${version}";
-  version = "0.311";
+  version = "0.312";
 
   src = fetchurl {
-    url = "https://github.com/vcrhonek/hwdata/archive/v0.311.tar.gz";
-    sha256 = "159av9wvl3biryxd5pgqcwz6wkdaa0ydmcysmzznx939mfv7w18z";
+    url = "https://github.com/vcrhonek/hwdata/archive/v0.312.tar.gz";
+    sha256 = "04dbxfn40b8vyw49qpkslv20akbqm5hwl3cndmqacp6cik1l0gai";
   };
 
   preConfigure = "patchShebangs ./configure";
diff --git a/pkgs/os-specific/linux/i7z/default.nix b/pkgs/os-specific/linux/i7z/default.nix
index 6d0c5ae82bcc..48d28036aa4f 100644
--- a/pkgs/os-specific/linux/i7z/default.nix
+++ b/pkgs/os-specific/linux/i7z/default.nix
@@ -1,4 +1,5 @@
-{ stdenv, fetchurl, qt4, ncurses }:
+{ stdenv, lib, fetchurl, ncurses
+, withGui ? false, qt4 ? null }:
 
 stdenv.mkDerivation rec {
   name = "i7z-0.27.2";
@@ -8,29 +9,46 @@ stdenv.mkDerivation rec {
     sha256 = "1wa7ix6m75wl3k2n88sz0x8cckvlzqklja2gvzqfw5rcfdjjvxx7";
   };
 
-  buildInputs = [ qt4 ncurses ];
+  buildInputs = [ ncurses ] ++ lib.optional withGui qt4;
+
+  enableParallelBuilding = true;
 
   buildPhase = ''
+    runHook preBuild
+
     make
-    cd GUI
-    qmake
-    make clean
-    make
-    cd ..
+    ${lib.optionalString withGui ''
+      cd GUI
+      qmake
+      make clean
+      make
+      cd ..
+    ''}
+
+    runHook postBuild
   '';
 
   installPhase = ''
-    mkdir -p $out/sbin
+    runHook preInstall
+
+    mkdir -p $out/{bin,sbin}
     make install prefix=$out
-    install -Dm755 GUI/i7z_GUI $out/sbin/i7z-gui
+    ${lib.optionalString withGui ''
+      install -Dm755 GUI/i7z_GUI $out/bin/i7z-gui
+    ''}
+    mv $out/sbin/* $out/bin/
+    rmdir $out/sbin
+
+    runHook postInstall
   '';
 
-  meta = {
+  meta = with lib; {
     description = "A better i7 (and now i3, i5) reporting tool for Linux";
     homepage = https://github.com/ajaiantilal/i7z;
     repositories.git = https://github.com/ajaiantilal/i7z.git;
-    license = stdenv.lib.licenses.gpl2;
-    maintainers = [ stdenv.lib.maintainers.bluescreen303 ];
-    platforms = stdenv.lib.platforms.linux;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ bluescreen303 ];
+    # broken on ARM
+    platforms = [ "x86_64-linux" ];
   };
 }
diff --git a/pkgs/os-specific/linux/input-utils/default.nix b/pkgs/os-specific/linux/input-utils/default.nix
new file mode 100644
index 000000000000..cd0fc01384bc
--- /dev/null
+++ b/pkgs/os-specific/linux/input-utils/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchurl, linuxHeaders }:
+
+stdenv.mkDerivation rec {
+  name = "input-utils-${version}";
+  version = "1.3";
+  
+  src = fetchurl {
+    url = "https://www.kraxel.org/releases/input/input-${version}.tar.gz";
+    sha256 = "11w0pp20knx6qpgzmawdbk1nj2z3fzp8yd6nag6s8bcga16w6hli";
+  };
+
+  prePatch = ''
+    # Use proper include path for kernel include files.
+    substituteInPlace ./name.sh --replace "/usr/include/linux/" "${linuxHeaders}/include/linux/"
+    substituteInPlace ./lirc.sh --replace "/usr/include/linux/" "${linuxHeaders}/include/linux/"
+  '';
+
+  makeFlags = [
+    "prefix=$(out)"
+    "STRIP=-s"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Input layer utilities, includes lsinput";
+    homepage    = https://www.kraxel.org/blog/linux/input/;
+    license     = licenses.gpl2;
+    maintainers = with maintainers; [ samueldr ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/pkgs/os-specific/linux/iproute/default.nix b/pkgs/os-specific/linux/iproute/default.nix
index 7d412d7e15d0..8ccb0c203803 100644
--- a/pkgs/os-specific/linux/iproute/default.nix
+++ b/pkgs/os-specific/linux/iproute/default.nix
@@ -1,4 +1,4 @@
-{ fetchurl, stdenv, lib, flex, bash, bison, db, iptables, pkgconfig }:
+{ fetchurl, stdenv, config, lib, flex, bash, bison, db, iptables, pkgconfig }:
 
 stdenv.mkDerivation rec {
   name = "iproute2-${version}";
@@ -26,8 +26,9 @@ stdenv.mkDerivation rec {
     "HDRDIR=$(TMPDIR)/include/iproute2" # Don't install headers
   ];
 
+  # enable iproute2 module if you want this folder to be created
   buildFlags = [
-    "CONFDIR=/etc/iproute2"
+    "CONFDIR=${config.iproute2.confDir or "/run/iproute2"}"
   ];
 
   installFlags = [
diff --git a/pkgs/os-specific/linux/iwd/default.nix b/pkgs/os-specific/linux/iwd/default.nix
index a1c577d2bb57..792c7bcb0849 100644
--- a/pkgs/os-specific/linux/iwd/default.nix
+++ b/pkgs/os-specific/linux/iwd/default.nix
@@ -3,17 +3,17 @@
 let
   ell = fetchgit {
      url = https://git.kernel.org/pub/scm/libs/ell/ell.git;
-     rev = "0.4";
-     sha256 = "0l203n1jnqa2mcifir8ydxhcvbiwlvk89ailm0lida83l9vdlwpv";
+     rev = "0.5";
+     sha256 = "0xw53bigh99nhacjb67qs1g145fwls7065l8vsrziwzpkyd5s6a8";
   };
 in stdenv.mkDerivation rec {
   name = "iwd-${version}";
-  version = "0.1";
+  version = "0.2";
 
   src = fetchgit {
     url = https://git.kernel.org/pub/scm/network/wireless/iwd.git;
     rev = version;
-    sha256 = "1f8c6xvcvqw8z78mskynd2fkghggcl7vfz8vxzvpx0fkqcprn5n0";
+    sha256 = "0khc017s27n6y6c6wbqhmcghzggnagxbi8j36hl5g73y6s44vx42";
   };
 
   nativeBuildInputs = [
diff --git a/pkgs/os-specific/linux/kernel/common-config.nix b/pkgs/os-specific/linux/kernel/common-config.nix
index 4af5889fd1cd..cee2197f3c7a 100644
--- a/pkgs/os-specific/linux/kernel/common-config.nix
+++ b/pkgs/os-specific/linux/kernel/common-config.nix
@@ -37,7 +37,12 @@ with stdenv.lib;
   DEBUG_STACKOVERFLOW n
   SCHEDSTATS n
   DETECT_HUNG_TASK y
-  DEBUG_INFO n # Not until we implement a separate debug output
+
+  ${if (features.debug or false) then ''
+    DEBUG_INFO y
+  '' else ''
+    DEBUG_INFO n
+  ''}
 
   ${optionalString (versionOlder version "4.4") ''
     CPU_NOTIFIER_ERROR_INJECT? n
@@ -636,6 +641,11 @@ with stdenv.lib;
     X86_X2APIC y
     IRQ_REMAP y
   ''}
+  
+  # needed for iwd WPS support (wpa_supplicant replacement)
+  ${optionalString (versionAtLeast version "4.7") ''
+    KEY_DH_OPERATIONS y
+  ''}
 
   # Disable the firmware helper fallback, udev doesn't implement it any more
   FW_LOADER_USER_HELPER_FALLBACK? n
@@ -704,9 +714,5 @@ with stdenv.lib;
     DEBUG_MEMORY_INIT? y
   ''}
 
-  ${optionalString (features.debug or false)  ''
-    DEBUG_INFO y
-  ''}
-
   ${extraConfig}
 ''
diff --git a/pkgs/os-specific/linux/kernel/linux-4.14.nix b/pkgs/os-specific/linux/kernel/linux-4.14.nix
index d9aef3a21930..f44adb6bc946 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.14.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.14.nix
@@ -3,13 +3,13 @@
 with stdenv.lib;
 
 buildLinux (args // rec {
-  version = "4.14.37";
+  version = "4.14.41";
 
   # branchVersion needs to be x.y
   extraMeta.branch = concatStrings (intersperse "." (take 2 (splitString "." version)));
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
-    sha256 = "14lfj2vfxw36k8cbmzs280w4h81yz5xhlhq5550kww906vnyg5w1";
+    sha256 = "0vffv1iqcvrzvhs534czdjhj7702gr01pyn9idr8dj85kdx19wfc";
   };
 } // (args.argsOverride or {}))
diff --git a/pkgs/os-specific/linux/kernel/linux-4.16.nix b/pkgs/os-specific/linux/kernel/linux-4.16.nix
index 3da2cda30e22..c1df425280e0 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.16.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.16.nix
@@ -3,7 +3,7 @@
 with stdenv.lib;
 
 buildLinux (args // rec {
-  version = "4.16.5";
+  version = "4.16.9";
 
   # modDirVersion needs to be x.y.z, will automatically add .0 if needed
   modDirVersion = concatStrings (intersperse "." (take 3 (splitString "." "${version}.0")));
@@ -13,6 +13,6 @@ buildLinux (args // rec {
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
-    sha256 = "0f1a8ggjb2jxc8n3hvypc81xbwylwkqi0mnynd9q316ay152zb1r";
+    sha256 = "12lvdnfz06r7pj5f15x39c4glhbp3sv7bdbwj4yimbp6iqwvndv0";
   };
 } // (args.argsOverride or {}))
diff --git a/pkgs/os-specific/linux/kernel/linux-4.4.nix b/pkgs/os-specific/linux/kernel/linux-4.4.nix
index fe8633ed0da7..dd946c281316 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.4.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.4.nix
@@ -1,11 +1,11 @@
 { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 buildLinux (args // rec {
-  version = "4.4.129";
+  version = "4.4.132";
   extraMeta.branch = "4.4";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
-    sha256 = "0aviyky8f73l6jpi1d4by947rj78d5vckxkyf9aj73bavaxc8rd1";
+    sha256 = "0d06dv7maspgv33dlc6r8cb8pkpg4q2vxbpzz6285n0ah4fb05f4";
   };
 } // (args.argsOverride or {}))
diff --git a/pkgs/os-specific/linux/kernel/linux-4.9.nix b/pkgs/os-specific/linux/kernel/linux-4.9.nix
index 63fe3db3b577..3a7dc9353f8b 100644
--- a/pkgs/os-specific/linux/kernel/linux-4.9.nix
+++ b/pkgs/os-specific/linux/kernel/linux-4.9.nix
@@ -1,11 +1,11 @@
 { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
 
 buildLinux (args // rec {
-  version = "4.9.96";
+  version = "4.9.100";
   extraMeta.branch = "4.9";
 
   src = fetchurl {
     url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
-    sha256 = "0zw7x86c8qa2kzkwlxlhqzsnddyp1ncw4ja660bqnzqrnmp5jvw2";
+    sha256 = "0z572csacfwn3kl3yaz4wpd7wkzabm42p2z4ysx5rq0kf4x6zfy5";
   };
 } // (args.argsOverride or {}))
diff --git a/pkgs/os-specific/linux/kernel/linux-copperhead-lts.nix b/pkgs/os-specific/linux/kernel/linux-copperhead-lts.nix
index 76b59ee75fb1..8054ba0be6ac 100644
--- a/pkgs/os-specific/linux/kernel/linux-copperhead-lts.nix
+++ b/pkgs/os-specific/linux/kernel/linux-copperhead-lts.nix
@@ -3,9 +3,9 @@
 with stdenv.lib;
 
 let
-  version = "4.14.37";
+  version = "4.14.41";
   revision = "a";
-  sha256 = "0dwi17hx13kkccqc2315dnb8sfdc0jgv9v4b1xd10v2pnq7qb0x8";
+  sha256 = "16jwv1drs6xlwghzn8ps7v8x5xja61b5y6747c86g17idfaac1k3";
 
   # modVersion needs to be x.y.z, will automatically add .0 if needed
   modVersion = concatStrings (intersperse "." (take 3 (splitString "." "${version}.0")));
diff --git a/pkgs/os-specific/linux/kernel/linux-copperhead-stable.nix b/pkgs/os-specific/linux/kernel/linux-copperhead-stable.nix
index 86b7eaa8823e..5c65f2064b42 100644
--- a/pkgs/os-specific/linux/kernel/linux-copperhead-stable.nix
+++ b/pkgs/os-specific/linux/kernel/linux-copperhead-stable.nix
@@ -3,9 +3,9 @@
 with stdenv.lib;
 
 let
-  version = "4.16.5";
+  version = "4.16.9";
   revision = "a";
-  sha256 = "150cwq51x3cnnvnd7izizi93jmiqs0na15p8ip4vkm5frspmnks7";
+  sha256 = "1g1924whb79cflh4wcqpyq9d7nfxdsvsjh2mv5ps85fsg2109kpl";
 
   # modVersion needs to be x.y.z, will automatically add .0 if needed
   modVersion = concatStrings (intersperse "." (take 3 (splitString "." "${version}.0")));
diff --git a/pkgs/os-specific/linux/kernel/linux-mptcp.nix b/pkgs/os-specific/linux/kernel/linux-mptcp.nix
index c4bade2abeda..d486bd1d6d24 100644
--- a/pkgs/os-specific/linux/kernel/linux-mptcp.nix
+++ b/pkgs/os-specific/linux/kernel/linux-mptcp.nix
@@ -33,8 +33,7 @@ buildLinux (rec {
     DEFAULT_MPTCP_PM default
 
     # MPTCP scheduler selection.
-    # Disabled as the only non-default is the useless round-robin.
-    MPTCP_SCHED_ADVANCED n
+    MPTCP_SCHED_ADVANCED y
     DEFAULT_MPTCP_SCHED default
 
     # Smarter TCP congestion controllers
diff --git a/pkgs/os-specific/linux/kernel/linux-testing.nix b/pkgs/os-specific/linux/kernel/linux-testing.nix
index d02ab4157191..691c0d7a0a97 100644
--- a/pkgs/os-specific/linux/kernel/linux-testing.nix
+++ b/pkgs/os-specific/linux/kernel/linux-testing.nix
@@ -1,13 +1,13 @@
 { stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, libelf, utillinux, ... } @ args:
 
 buildLinux (args // rec {
-  version = "4.17-rc3";
-  modDirVersion = "4.17.0-rc3";
+  version = "4.17-rc5";
+  modDirVersion = "4.17.0-rc5";
   extraMeta.branch = "4.17";
 
   src = fetchurl {
     url = "https://git.kernel.org/torvalds/t/linux-${version}.tar.gz";
-    sha256 = "1divgjzmpl98b5j416vhkq53li0y9v5vvdwbgwpr2xznspzbkygq";
+    sha256 = "1khx3s8nb604h23hasamshcvcwll0j4vi5v6v274ls01ja9mg1xk";
   };
 
   # Should the testing kernels ever be built on Hydra?
diff --git a/pkgs/os-specific/linux/kernel/mips-ext3-n32.patch b/pkgs/os-specific/linux/kernel/mips-ext3-n32.patch
deleted file mode 100644
index fcb6f9177c7d..000000000000
--- a/pkgs/os-specific/linux/kernel/mips-ext3-n32.patch
+++ /dev/null
@@ -1,17 +0,0 @@
-Dirty patch that makes ext3 work again on 3.5 and 3.6 kernels,
-on mips n32.
-
-http://www.linux-mips.org/archives/linux-mips/2012-11/msg00030.html
-
-diff --git a/fs/ext3/dir.c b/fs/ext3/dir.c
-index 92490e9..bf63d7b 100644
---- a/fs/ext3/dir.c
-+++ b/fs/ext3/dir.c
-@@ -228,6 +228,7 @@ out:
- 
- static inline int is_32bit_api(void)
- {
-+	return 1;
- #ifdef CONFIG_COMPAT
- 	return is_compat_task();
- #else
diff --git a/pkgs/os-specific/linux/kernel/mips-fpu-sigill.patch b/pkgs/os-specific/linux/kernel/mips-fpu-sigill.patch
deleted file mode 100644
index 248aba2b2c20..000000000000
--- a/pkgs/os-specific/linux/kernel/mips-fpu-sigill.patch
+++ /dev/null
@@ -1,507 +0,0 @@
-From bf55ef4e3c2f622ac013f196affbd11b67b59223 Mon Sep 17 00:00:00 2001
-From: Mark H Weaver <mhw@netris.org>
-Date: Fri, 28 Oct 2011 13:24:37 -0400
-Subject: [PATCH 2/4] Fix handling of prefx instruction in mips/math-emu
-
-* The instruction is named prefx, not pfetch, and its function
-  field is 0x17, not 0x07.
-
-* Recognize the prefx instruction regardless of what bits happen to be
-  in bits 21-25, which is the format field of the floating-point ops,
-  but holds the base register of the prefx instruction.
----
- arch/mips/include/asm/inst.h |    4 ++--
- arch/mips/math-emu/cp1emu.c  |   16 +++++++---------
- 2 files changed, 9 insertions(+), 11 deletions(-)
-
-diff --git a/arch/mips/include/asm/inst.h b/arch/mips/include/asm/inst.h
-index ab84064..3048edc 100644
---- a/arch/mips/include/asm/inst.h
-+++ b/arch/mips/include/asm/inst.h
-@@ -161,8 +161,8 @@ enum cop1_sdw_func {
-  */
- enum cop1x_func {
- 	lwxc1_op     =  0x00, ldxc1_op     =  0x01,
--	pfetch_op    =  0x07, swxc1_op     =  0x08,
--	sdxc1_op     =  0x09, madd_s_op    =  0x20,
-+	swxc1_op     =  0x08, sdxc1_op     =  0x09,
-+	prefx_op     =  0x17, madd_s_op    =  0x20,
- 	madd_d_op    =  0x21, madd_e_op    =  0x22,
- 	msub_s_op    =  0x28, msub_d_op    =  0x29,
- 	msub_e_op    =  0x2a, nmadd_s_op   =  0x30,
-diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
-index dbf2f93..87ddba1 100644
---- a/arch/mips/math-emu/cp1emu.c
-+++ b/arch/mips/math-emu/cp1emu.c
-@@ -739,7 +739,7 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 			break;
- 
- 		default:
--			return SIGILL;
-+			goto SIGILL_unless_prefx_op;
- 		}
- 		break;
- 	}
-@@ -809,19 +809,17 @@ static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 			goto copcsr;
- 
- 		default:
--			return SIGILL;
-+			goto SIGILL_unless_prefx_op;
- 		}
- 		break;
- 	}
- 
--	case 0x7:		/* 7 */
--		if (MIPSInst_FUNC(ir) != pfetch_op) {
--			return SIGILL;
--		}
--		/* ignore prefx operation */
--		break;
--
- 	default:
-+	      SIGILL_unless_prefx_op:
-+		if (MIPSInst_FUNC(ir) == prefx_op) {
-+			/* ignore prefx operation */
-+			break;
-+		}
- 		return SIGILL;
- 	}
- 
--- 
-1.7.5.4
-
-From 97a564e3eddbfb84844b8eccb3bd751c71dfb3eb Mon Sep 17 00:00:00 2001
-From: Mark H Weaver <mhw@netris.org>
-Date: Fri, 28 Oct 2011 13:35:27 -0400
-Subject: [PATCH 3/4] Don't process empty cause flags after simple fp move on
- mips
-
----
- arch/mips/math-emu/cp1emu.c |    4 ++--
- 1 files changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
-index 87ddba1..fefcba2 100644
---- a/arch/mips/math-emu/cp1emu.c
-+++ b/arch/mips/math-emu/cp1emu.c
-@@ -912,7 +912,7 @@ static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 		case fmov_op:
- 			/* an easy one */
- 			SPFROMREG(rv.s, MIPSInst_FS(ir));
--			goto copcsr;
-+			break;
- 
- 			/* binary op on handler */
- 		      scopbop:
-@@ -1099,7 +1099,7 @@ static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 		case fmov_op:
- 			/* an easy one */
- 			DPFROMREG(rv.d, MIPSInst_FS(ir));
--			goto copcsr;
-+			break;
- 
- 			/* binary op on handler */
- 		      dcopbop:{
--- 
-1.7.5.4
-
-From 4051727b3007ef3675e7258ed86fa8517f86d929 Mon Sep 17 00:00:00 2001
-From: Mark H Weaver <mhw@netris.org>
-Date: Fri, 28 Oct 2011 13:39:10 -0400
-Subject: [PATCH 4/4] Support Loongson2f floating-point instructions in
- mips/math-emu
-
-* (arch/mips/include/asm/inst.h): Add Loongson2f function field values
-  for madd/msub/nmadd/nmsub that use the spec2 opcode, and the
-  Loongson2f/MIPS-5 format field value for paired-single
-  floating-point operations.
-
-* (arch/mips/math-emu/cp1emu.c): Add support for the Loongson2f
-  instructions for madd/msub/nmadd/nmsub, which use the spec2 opcode.
-  Also add support for the Loongson2f instructions that use the
-  paired-single floating-point format.
----
- arch/mips/include/asm/inst.h |    4 +-
- arch/mips/math-emu/cp1emu.c  |  287 +++++++++++++++++++++++++++++++++++++++++-
- 2 files changed, 289 insertions(+), 2 deletions(-)
-
-diff --git a/arch/mips/include/asm/inst.h b/arch/mips/include/asm/inst.h
-index 3048edc..0e8ba7c 100644
---- a/arch/mips/include/asm/inst.h
-+++ b/arch/mips/include/asm/inst.h
-@@ -61,6 +61,8 @@ enum spec_op {
- enum spec2_op {
- 	madd_op, maddu_op, mul_op, spec2_3_unused_op,
- 	msub_op, msubu_op, /* more unused ops */
-+	loongson_madd_op = 0x18, loongson_msub_op,
-+	loongson_nmadd_op, loongson_nmsub_op,
- 	clz_op = 0x20, clo_op,
- 	dclz_op = 0x24, dclo_op,
- 	sdbpp_op = 0x3f
-@@ -133,7 +135,7 @@ enum cop0_com_func {
-  */
- enum cop1_fmt {
- 	s_fmt, d_fmt, e_fmt, q_fmt,
--	w_fmt, l_fmt
-+	w_fmt, l_fmt, ps_fmt
- };
- 
- /*
-diff --git a/arch/mips/math-emu/cp1emu.c b/arch/mips/math-emu/cp1emu.c
-index fefcba2..166b2a4 100644
---- a/arch/mips/math-emu/cp1emu.c
-+++ b/arch/mips/math-emu/cp1emu.c
-@@ -7,6 +7,9 @@
-  * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
-  * Copyright (C) 2000  MIPS Technologies, Inc.
-  *
-+ * Loongson instruction support
-+ * Copyright (C) 2011  Mark H Weaver <mhw@netris.org>
-+ *
-  *  This program is free software; you can distribute it and/or modify it
-  *  under the terms of the GNU General Public License (Version 2) as
-  *  published by the Free Software Foundation.
-@@ -57,6 +60,14 @@
- #endif
- #define __mips 4
- 
-+#ifdef __loongson_fp
-+#undef __loongson_fp
-+#endif
-+#if __mips >= 4 && __mips != 32
-+/* Include support for Loongson floating point instructions */
-+#define __loongson_fp 1
-+#endif
-+
- /* Function which emulates a floating point instruction. */
- 
- static int fpu_emu(struct pt_regs *, struct mips_fpu_struct *,
-@@ -66,6 +77,10 @@ static int fpu_emu(struct pt_regs *, struct mips_fpu_struct *,
- static int fpux_emu(struct pt_regs *,
- 	struct mips_fpu_struct *, mips_instruction, void *__user *);
- #endif
-+#ifdef __loongson_fp
-+static int loongson_spec2_emu(struct pt_regs *,
-+	struct mips_fpu_struct *, mips_instruction, void *__user *);
-+#endif
- 
- /* Further private data for which no space exists in mips_fpu_struct */
- 
-@@ -203,6 +218,14 @@ static inline int cop1_64bit(struct pt_regs *xcp)
- #define DPFROMREG(dp, x)	DIFROMREG((dp).bits, x)
- #define DPTOREG(dp, x)	DITOREG((dp).bits, x)
- 
-+/* Support for Loongson paired single floating-point format */
-+#define PSIFROMREG(si1, si2, x) ({ u64 di; DIFROMREG(di, x);		\
-+			(si1) = (u32)di; (si2) = (u32)(di >> 32); })
-+#define PSITOREG(si1, si2, x) DITOREG((si1) | ((u64)(si2) << 32), x)
-+
-+#define PSPFROMREG(sp1, sp2, x) PSIFROMREG((sp1).bits, (sp2).bits, x)
-+#define PSPTOREG(sp1, sp2, x)	PSITOREG((sp1).bits, (sp2).bits, x)
-+
- /*
-  * Emulate the single floating point instruction pointed at by EPC.
-  * Two instructions if the instruction is in a branch delay slot.
-@@ -568,6 +591,15 @@ static int cop1Emulate(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 		break;
- #endif
- 
-+#ifdef __loongson_fp
-+	case spec2_op:{
-+		int sig = loongson_spec2_emu(xcp, ctx, ir, fault_addr);
-+		if (sig)
-+			return sig;
-+		break;
-+	}
-+#endif
-+
- 	default:
- 		return SIGILL;
- 	}
-@@ -646,6 +678,172 @@ DEF3OP(msub, dp, ieee754dp_mul, ieee754dp_sub, );
- DEF3OP(nmadd, dp, ieee754dp_mul, ieee754dp_add, ieee754dp_neg);
- DEF3OP(nmsub, dp, ieee754dp_mul, ieee754dp_sub, ieee754dp_neg);
- 
-+#ifdef __loongson_fp
-+static int loongson_spec2_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
-+	mips_instruction ir, void *__user *fault_addr)
-+{
-+	int rfmt;		/* resulting format */
-+	unsigned rcsr = 0;	/* resulting csr */
-+	union {
-+		ieee754dp d;
-+		struct {
-+			ieee754sp s;
-+			ieee754sp s2;
-+		};
-+	} rv;			/* resulting value */
-+
-+	/* XXX maybe add a counter for loongson spec2 fp instructions? */
-+	/* MIPS_FPU_EMU_INC_STATS(cp1xops); */
-+
-+	switch (rfmt = (MIPSInst_FFMT(ir) & 0xf)) {
-+	case s_fmt:{
-+		ieee754sp(*handler) (ieee754sp, ieee754sp, ieee754sp);
-+		ieee754sp fd, fs, ft;
-+
-+		switch (MIPSInst_FUNC(ir)) {
-+		case loongson_madd_op:
-+			handler = fpemu_sp_madd;
-+			goto scoptop;
-+		case loongson_msub_op:
-+			handler = fpemu_sp_msub;
-+			goto scoptop;
-+		case loongson_nmadd_op:
-+			handler = fpemu_sp_nmadd;
-+			goto scoptop;
-+		case loongson_nmsub_op:
-+			handler = fpemu_sp_nmsub;
-+			goto scoptop;
-+
-+		      scoptop:
-+			SPFROMREG(fd, MIPSInst_FD(ir));
-+			SPFROMREG(fs, MIPSInst_FS(ir));
-+			SPFROMREG(ft, MIPSInst_FT(ir));
-+			rv.s = (*handler) (fd, fs, ft);
-+
-+		      copcsr:
-+			if (ieee754_cxtest(IEEE754_INEXACT))
-+				rcsr |= FPU_CSR_INE_X | FPU_CSR_INE_S;
-+			if (ieee754_cxtest(IEEE754_UNDERFLOW))
-+				rcsr |= FPU_CSR_UDF_X | FPU_CSR_UDF_S;
-+			if (ieee754_cxtest(IEEE754_OVERFLOW))
-+				rcsr |= FPU_CSR_OVF_X | FPU_CSR_OVF_S;
-+			if (ieee754_cxtest(IEEE754_INVALID_OPERATION))
-+				rcsr |= FPU_CSR_INV_X | FPU_CSR_INV_S;
-+
-+			break;
-+
-+		default:
-+			return SIGILL;
-+		}
-+		break;
-+	}
-+
-+	case d_fmt:{
-+		ieee754dp(*handler) (ieee754dp, ieee754dp, ieee754dp);
-+		ieee754dp fd, fs, ft;
-+
-+		switch (MIPSInst_FUNC(ir)) {
-+		case loongson_madd_op:
-+			handler = fpemu_dp_madd;
-+			goto dcoptop;
-+		case loongson_msub_op:
-+			handler = fpemu_dp_msub;
-+			goto dcoptop;
-+		case loongson_nmadd_op:
-+			handler = fpemu_dp_nmadd;
-+			goto dcoptop;
-+		case loongson_nmsub_op:
-+			handler = fpemu_dp_nmsub;
-+			goto dcoptop;
-+
-+		      dcoptop:
-+			DPFROMREG(fd, MIPSInst_FD(ir));
-+			DPFROMREG(fs, MIPSInst_FS(ir));
-+			DPFROMREG(ft, MIPSInst_FT(ir));
-+			rv.d = (*handler) (fd, fs, ft);
-+			goto copcsr;
-+
-+		default:
-+			return SIGILL;
-+		}
-+		break;
-+	}
-+
-+	case ps_fmt:{
-+		ieee754sp(*handler) (ieee754sp, ieee754sp, ieee754sp);
-+		struct _ieee754_csr ieee754_csr_save;
-+		ieee754sp fd1, fs1, ft1;
-+		ieee754sp fd2, fs2, ft2;
-+
-+		switch (MIPSInst_FUNC(ir)) {
-+		case loongson_madd_op:
-+			handler = fpemu_sp_madd;
-+			goto pscoptop;
-+		case loongson_msub_op:
-+			handler = fpemu_sp_msub;
-+			goto pscoptop;
-+		case loongson_nmadd_op:
-+			handler = fpemu_sp_nmadd;
-+			goto pscoptop;
-+		case loongson_nmsub_op:
-+			handler = fpemu_sp_nmsub;
-+			goto pscoptop;
-+
-+		      pscoptop:
-+			PSPFROMREG(fd1, fd2, MIPSInst_FD(ir));
-+			PSPFROMREG(fs1, fs2, MIPSInst_FS(ir));
-+			PSPFROMREG(ft1, ft2, MIPSInst_FT(ir));
-+			rv.s = (*handler) (fd1, fs1, ft1);
-+			ieee754_csr_save = ieee754_csr;
-+			rv.s2 = (*handler) (fd2, fs2, ft2);
-+			ieee754_csr.cx |= ieee754_csr_save.cx;
-+			ieee754_csr.sx |= ieee754_csr_save.sx;
-+			goto copcsr;
-+
-+		default:
-+			return SIGILL;
-+		}
-+		break;
-+	}
-+
-+	default:
-+		return SIGILL;
-+	}
-+
-+	/*
-+	 * Update the fpu CSR register for this operation.
-+	 * If an exception is required, generate a tidy SIGFPE exception,
-+	 * without updating the result register.
-+	 * Note: cause exception bits do not accumulate, they are rewritten
-+	 * for each op; only the flag/sticky bits accumulate.
-+	 */
-+	ctx->fcr31 = (ctx->fcr31 & ~FPU_CSR_ALL_X) | rcsr;
-+	if ((ctx->fcr31 >> 5) & ctx->fcr31 & FPU_CSR_ALL_E) {
-+		/*printk ("SIGFPE: fpu csr = %08x\n",ctx->fcr31); */
-+		return SIGFPE;
-+	}
-+
-+	/*
-+	 * Now we can safely write the result back to the register file.
-+	 */
-+	switch (rfmt) {
-+	case d_fmt:
-+		DPTOREG(rv.d, MIPSInst_FD(ir));
-+		break;
-+	case s_fmt:
-+		SPTOREG(rv.s, MIPSInst_FD(ir));
-+		break;
-+	case ps_fmt:
-+		PSPTOREG(rv.s, rv.s2, MIPSInst_FD(ir));
-+		break;
-+	default:
-+		return SIGILL;
-+	}
-+
-+	return 0;
-+}
-+#endif
-+
- static int fpux_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 	mips_instruction ir, void *__user *fault_addr)
- {
-@@ -840,7 +1038,12 @@ static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 	unsigned cond;
- 	union {
- 		ieee754dp d;
--		ieee754sp s;
-+		struct {
-+			ieee754sp s;
-+#ifdef __loongson_fp
-+			ieee754sp s2; /* for Loongson paired singles */
-+#endif
-+		};
- 		int w;
- #ifdef __mips64
- 		s64 l;
-@@ -1210,6 +1413,83 @@ static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 		break;
- 	}
- 
-+#ifdef __loongson_fp
-+	case ps_fmt:{		/* 6 */
-+		/* Support for Loongson paired single fp instructions */
-+		union {
-+			ieee754sp(*b) (ieee754sp, ieee754sp);
-+			ieee754sp(*u) (ieee754sp);
-+		} handler;
-+
-+		switch (MIPSInst_FUNC(ir)) {
-+			/* binary ops */
-+		case fadd_op:
-+			handler.b = ieee754sp_add;
-+			goto pscopbop;
-+		case fsub_op:
-+			handler.b = ieee754sp_sub;
-+			goto pscopbop;
-+		case fmul_op:
-+			handler.b = ieee754sp_mul;
-+			goto pscopbop;
-+
-+			/* unary  ops */
-+		case fabs_op:
-+			handler.u = ieee754sp_abs;
-+			goto pscopuop;
-+		case fneg_op:
-+			handler.u = ieee754sp_neg;
-+			goto pscopuop;
-+		case fmov_op:
-+			/* an easy one */
-+			PSPFROMREG(rv.s, rv.s2, MIPSInst_FS(ir));
-+			break;
-+
-+		      pscopbop: /* paired binary op handler */
-+			{
-+				struct _ieee754_csr ieee754_csr_save;
-+				ieee754sp fs1, ft1;
-+				ieee754sp fs2, ft2;
-+
-+				PSPFROMREG(fs1, fs2, MIPSInst_FS(ir));
-+				PSPFROMREG(ft1, ft2, MIPSInst_FT(ir));
-+				rv.s  = (*handler.b) (fs1, ft1);
-+				ieee754_csr_save = ieee754_csr;
-+				rv.s2 = (*handler.b) (fs2, ft2);
-+				ieee754_csr.cx |= ieee754_csr_save.cx;
-+				ieee754_csr.sx |= ieee754_csr_save.sx;
-+				goto copcsr;
-+			}
-+		      pscopuop: /* paired unary op handler */
-+			{
-+				struct _ieee754_csr ieee754_csr_save;
-+				ieee754sp fs1;
-+				ieee754sp fs2;
-+
-+				PSPFROMREG(fs1, fs2, MIPSInst_FS(ir));
-+				rv.s  = (*handler.u) (fs1);
-+				ieee754_csr_save = ieee754_csr;
-+				rv.s2 = (*handler.u) (fs2);
-+				ieee754_csr.cx |= ieee754_csr_save.cx;
-+				ieee754_csr.sx |= ieee754_csr_save.sx;
-+				goto copcsr;
-+			}
-+			break;
-+
-+		default:
-+			if (MIPSInst_FUNC(ir) >= fcmp_op) {
-+				/* Loongson fp hardware handles all
-+				   cases of fp compare insns, so we
-+				   shouldn't have to */
-+				printk ("Loongson paired-single fp compare"
-+					" unimplemented in cp1emu.c\n");
-+			}
-+			return SIGILL;
-+		}
-+		break;
-+	}
-+#endif
-+
- 	case w_fmt:{
- 		ieee754sp fs;
- 
-@@ -1299,6 +1579,11 @@ static int fpu_emu(struct pt_regs *xcp, struct mips_fpu_struct *ctx,
- 		DITOREG(rv.l, MIPSInst_FD(ir));
- 		break;
- #endif
-+#ifdef __loongson_fp
-+	case ps_fmt:
-+		PSPTOREG(rv.s, rv.s2, MIPSInst_FD(ir));
-+		break;
-+#endif
- 	default:
- 		return SIGILL;
- 	}
--- 
-1.7.5.4
-
diff --git a/pkgs/os-specific/linux/kernel/mips-fpureg-emulation.patch b/pkgs/os-specific/linux/kernel/mips-fpureg-emulation.patch
deleted file mode 100644
index 452c4f26f6fd..000000000000
--- a/pkgs/os-specific/linux/kernel/mips-fpureg-emulation.patch
+++ /dev/null
@@ -1,144 +0,0 @@
-From ab1ce0a6cd51ca83194a865837f3b90f366a733d Mon Sep 17 00:00:00 2001
-From: Lluis Batlle i Rossell <viric@viric.name>
-Date: Sat, 16 Jun 2012 00:22:53 +0200
-Subject: [PATCH] MIPS: Add emulation for fpureg-mem unaligned access
-To: linux-mips@linux-mips.org
-Cc: loongson-dev@googlegroups.com
-
-Reusing most of the code from lw,ld,sw,sd emulation,
-I add the emulation for lwc1,ldc1,swc1,sdc1.
-
-This avoids the direct SIGBUS sent to userspace processes that have
-misaligned memory accesses.
-
-I've tested the change in Loongson2F, with an own test program, and
-WebKit 1.4.0, as both were killed by sigbus without this patch.
-
-Signed-off: Lluis Batlle i Rossell <viric@viric.name>
----
- arch/mips/kernel/unaligned.c |   43 +++++++++++++++++++++++++++++-------------
- 1 file changed, 30 insertions(+), 13 deletions(-)
-
-diff --git a/arch/mips/kernel/unaligned.c b/arch/mips/kernel/unaligned.c
-index 9c58bdf..4531e6c 100644
---- a/arch/mips/kernel/unaligned.c
-+++ b/arch/mips/kernel/unaligned.c
-@@ -85,6 +85,7 @@
- #include <asm/cop2.h>
- #include <asm/inst.h>
- #include <asm/uaccess.h>
-+#include <asm/fpu.h>
- 
- #define STR(x)  __STR(x)
- #define __STR(x)  #x
-@@ -108,6 +109,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 	union mips_instruction insn;
- 	unsigned long value;
- 	unsigned int res;
-+	fpureg_t *fpuregs;
- 
- 	perf_sw_event(PERF_COUNT_SW_EMULATION_FAULTS, 1, regs, 0);
- 
-@@ -183,6 +185,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		break;
- 
- 	case lw_op:
-+	case lwc1_op:
- 		if (!access_ok(VERIFY_READ, addr, 4))
- 			goto sigbus;
- 
-@@ -209,7 +212,12 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		if (res)
- 			goto fault;
- 		compute_return_epc(regs);
--		regs->regs[insn.i_format.rt] = value;
-+		if (insn.i_format.opcode == lw_op) {
-+			regs->regs[insn.i_format.rt] = value;
-+		} else {
-+			fpuregs = get_fpu_regs(current);
-+			fpuregs[insn.i_format.rt] = value;
-+		}
- 		break;
- 
- 	case lhu_op:
-@@ -291,6 +299,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		goto sigill;
- 
- 	case ld_op:
-+	case ldc1_op:
- #ifdef CONFIG_64BIT
- 		/*
- 		 * A 32-bit kernel might be running on a 64-bit processor.  But
-@@ -325,7 +334,12 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		if (res)
- 			goto fault;
- 		compute_return_epc(regs);
--		regs->regs[insn.i_format.rt] = value;
-+		if (insn.i_format.opcode == ld_op) {
-+			regs->regs[insn.i_format.rt] = value;
-+		} else {
-+			fpuregs = get_fpu_regs(current);
-+			fpuregs[insn.i_format.rt] = value;
-+		}
- 		break;
- #endif /* CONFIG_64BIT */
- 
-@@ -370,10 +384,16 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		break;
- 
- 	case sw_op:
-+	case swc1_op:
- 		if (!access_ok(VERIFY_WRITE, addr, 4))
- 			goto sigbus;
- 
--		value = regs->regs[insn.i_format.rt];
-+		if (insn.i_format.opcode == sw_op) {
-+			value = regs->regs[insn.i_format.rt];
-+		} else {
-+			fpuregs = get_fpu_regs(current);
-+			value = fpuregs[insn.i_format.rt];
-+		}
- 		__asm__ __volatile__ (
- #ifdef __BIG_ENDIAN
- 			"1:\tswl\t%1,(%2)\n"
-@@ -401,6 +421,7 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		break;
- 
- 	case sd_op:
-+	case sdc1_op:
- #ifdef CONFIG_64BIT
- 		/*
- 		 * A 32-bit kernel might be running on a 64-bit processor.  But
-@@ -412,7 +433,12 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		if (!access_ok(VERIFY_WRITE, addr, 8))
- 			goto sigbus;
- 
--		value = regs->regs[insn.i_format.rt];
-+		if (insn.i_format.opcode == sd_op) {
-+			value = regs->regs[insn.i_format.rt];
-+		} else {
-+			fpuregs = get_fpu_regs(current);
-+			value = fpuregs[insn.i_format.rt];
-+		}
- 		__asm__ __volatile__ (
- #ifdef __BIG_ENDIAN
- 			"1:\tsdl\t%1,(%2)\n"
-@@ -443,15 +469,6 @@ static void emulate_load_store_insn(struct pt_regs *regs,
- 		/* Cannot handle 64-bit instructions in 32-bit kernel */
- 		goto sigill;
- 
--	case lwc1_op:
--	case ldc1_op:
--	case swc1_op:
--	case sdc1_op:
--		/*
--		 * I herewith declare: this does not happen.  So send SIGBUS.
--		 */
--		goto sigbus;
--
- 	/*
- 	 * COP2 is available to implementor for application specific use.
- 	 * It's up to applications to register a notifier chain and do
--- 
-1.7.9.5
-
diff --git a/pkgs/os-specific/linux/kernel/patches.nix b/pkgs/os-specific/linux/kernel/patches.nix
index cedb2dfc2230..fb28bba1c32f 100644
--- a/pkgs/os-specific/linux/kernel/patches.nix
+++ b/pkgs/os-specific/linux/kernel/patches.nix
@@ -1,26 +1,6 @@
 { stdenv, fetchurl, fetchpatch, pkgs }:
 
-let
-
-  makeTuxonicePatch = { version, kernelVersion, sha256,
-    url ? "http://tuxonice.nigelcunningham.com.au/downloads/all/tuxonice-for-linux-${kernelVersion}-${version}.patch.bz2" }:
-    { name = "tuxonice-${kernelVersion}";
-      patch = stdenv.mkDerivation {
-        name = "tuxonice-${version}-for-${kernelVersion}.patch";
-        src = fetchurl {
-          inherit url sha256;
-        };
-        phases = [ "installPhase" ];
-        installPhase = ''
-          source $stdenv/setup
-          bunzip2 -c $src > $out
-        '';
-      };
-    };
-in
-
 rec {
-
   bridge_stp_helper =
     { name = "bridge-stp-helper";
       patch = ./bridge-stp-helper.patch;
@@ -31,21 +11,6 @@ rec {
       patch = ./p9-fixes.patch;
     };
 
-  mips_fpureg_emu =
-    { name = "mips-fpureg-emulation";
-      patch = ./mips-fpureg-emulation.patch;
-    };
-
-  mips_fpu_sigill =
-    { name = "mips-fpu-sigill";
-      patch = ./mips-fpu-sigill.patch;
-    };
-
-  mips_ext3_n32 =
-    { name = "mips-ext3-n32";
-      patch = ./mips-ext3-n32.patch;
-    };
-
   modinst_arg_list_too_long =
     { name = "modinst-arglist-too-long";
       patch = ./modinst-arg-list-too-long.patch;
diff --git a/pkgs/os-specific/linux/libcap/default.nix b/pkgs/os-specific/linux/libcap/default.nix
index f00d6272902d..8248a628f0ac 100644
--- a/pkgs/os-specific/linux/libcap/default.nix
+++ b/pkgs/os-specific/linux/libcap/default.nix
@@ -1,5 +1,4 @@
-{ stdenv, buildPackages, fetchurl, attr, perl, pam ? null }:
-assert pam != null -> stdenv.isLinux;
+{ stdenv, buildPackages, fetchurl, attr, perl, pam }:
 
 stdenv.mkDerivation rec {
   name = "libcap-${version}";
@@ -10,8 +9,7 @@ stdenv.mkDerivation rec {
     sha256 = "0qjiqc5pknaal57453nxcbz3mn1r4hkyywam41wfcglq3v2qlg39";
   };
 
-  outputs = [ "out" "dev" "lib" "man" "doc" ]
-    ++ stdenv.lib.optional (pam != null) "pam";
+  outputs = [ "out" "dev" "lib" "man" "doc" "pam" ];
 
   depsBuildBuild = [ buildPackages.stdenv.cc ];
   nativeBuildInputs = [ perl ];
@@ -22,7 +20,7 @@ stdenv.mkDerivation rec {
 
   makeFlags = [
     "lib=lib"
-    (stdenv.lib.optional (pam != null) "PAM_CAP=yes")
+    "PAM_CAP=yes"
     "BUILD_CC=$(CC_FOR_BUILD)"
     "CC:=$(CC)"
   ];
diff --git a/pkgs/os-specific/linux/libsmbios/default.nix b/pkgs/os-specific/linux/libsmbios/default.nix
index 62898675f2be..c61fa683c758 100644
--- a/pkgs/os-specific/linux/libsmbios/default.nix
+++ b/pkgs/os-specific/linux/libsmbios/default.nix
@@ -1,5 +1,5 @@
 { stdenv, fetchFromGitHub, pkgconfig, autoreconfHook, help2man, gettext
-, libxml2, perl, doxygen }:
+, libxml2, perl, python3, doxygen }:
 
 
 stdenv.mkDerivation rec {
@@ -15,7 +15,9 @@ stdenv.mkDerivation rec {
 
   nativeBuildInputs = [ autoreconfHook doxygen gettext libxml2 help2man perl pkgconfig ];
 
-  configureFlags = [ "--disable-python" "--disable-graphviz" ];
+  buildInputs = [ python3 ];
+
+  configureFlags = [ "--disable-graphviz" ];
 
   enableParallelBuilding = true;
 
diff --git a/pkgs/os-specific/linux/lsscsi/default.nix b/pkgs/os-specific/linux/lsscsi/default.nix
index 833c032ccd2c..d250d658282f 100644
--- a/pkgs/os-specific/linux/lsscsi/default.nix
+++ b/pkgs/os-specific/linux/lsscsi/default.nix
@@ -1,13 +1,11 @@
 { stdenv, fetchurl }:
 
-assert stdenv.isLinux;
-
 stdenv.mkDerivation {
-  name = "lsscsi-0.28";
+  name = "lsscsi-0.29";
 
   src = fetchurl {
-    url = "http://sg.danny.cz/scsi/lsscsi-0.28.tgz";
-    sha256 = "0l6xz8545lnfd9f4z974ar1pbzfdkr6c8r56zjrcaazl3ad00p82";
+    url = "http://sg.danny.cz/scsi/lsscsi-0.29.tgz";
+    sha256 = "0538fjgxky03yn7mzyslkyi2af3yy5llsnjjcgjx73x08wd6hv5n";
   };
 
   preConfigure = ''
diff --git a/pkgs/os-specific/linux/mdadm/default.nix b/pkgs/os-specific/linux/mdadm/default.nix
index 7a59c2ea7573..b6fdae75bac2 100644
--- a/pkgs/os-specific/linux/mdadm/default.nix
+++ b/pkgs/os-specific/linux/mdadm/default.nix
@@ -3,8 +3,6 @@
 , buildPlatform, hostPlatform
 }:
 
-assert stdenv.isLinux;
-
 let
   sendmail-script = writeScript "sendmail-script" ''
     #!/bin/sh
diff --git a/pkgs/os-specific/linux/mwprocapture/default.nix b/pkgs/os-specific/linux/mwprocapture/default.nix
index e2abbd7335ee..72095bc8cdab 100644
--- a/pkgs/os-specific/linux/mwprocapture/default.nix
+++ b/pkgs/os-specific/linux/mwprocapture/default.nix
@@ -5,9 +5,6 @@ with stdenv.lib;
 # The Magewell Pro Capture drivers are not supported for kernels older than 3.2
 assert versionAtLeast kernel.version "3.2.0";
 
-# this package currently only supports x86 and x86_64, as I have no ARM device to test on
-assert (stdenv.system == "x86_64-linux") || (stdenv.system == "i686-linux");
-
 let
   bits =
   if stdenv.is64bit then "64"
diff --git a/pkgs/os-specific/linux/pam/default.nix b/pkgs/os-specific/linux/pam/default.nix
index 5f92dfcc8390..e2d34abb70cc 100644
--- a/pkgs/os-specific/linux/pam/default.nix
+++ b/pkgs/os-specific/linux/pam/default.nix
@@ -33,21 +33,6 @@ stdenv.mkDerivation rec {
 
   enableParallelBuilding = true;
 
-  crossAttrs = {
-    propagatedBuildInputs = [ flex.crossDrv cracklib.crossDrv ];
-    preConfigure = preConfigure + ''
-      $crossConfig-ar x ${flex.crossDrv}/lib/libfl.a
-      mv libyywrap.o libyywrap-target.o
-      ar x ${flex}/lib/libfl.a
-      mv libyywrap.o libyywrap-host.o
-      export LDFLAGS="$LDFLAGS $PWD/libyywrap-target.o"
-      sed -e 's/@CC@/gcc/' -i doc/specs/Makefile.in
-    '';
-    postConfigure = ''
-      sed -e "s@ $PWD/libyywrap-target.o@ $PWD/libyywrap-host.o@" -i doc/specs/Makefile
-    '';
-  };
-
   postInstall = ''
     mv -v $out/sbin/unix_chkpwd{,.orig}
     ln -sv /run/wrappers/bin/unix_chkpwd $out/sbin/unix_chkpwd
diff --git a/pkgs/os-specific/linux/pam_u2f/default.nix b/pkgs/os-specific/linux/pam_u2f/default.nix
index 0f0b6ebb37a6..58e3f79d42b2 100644
--- a/pkgs/os-specific/linux/pam_u2f/default.nix
+++ b/pkgs/os-specific/linux/pam_u2f/default.nix
@@ -2,11 +2,11 @@
 
 stdenv.mkDerivation rec {
   name    = "pam_u2f-${version}";
-  version = "1.0.5";
+  version = "1.0.7";
 
   src     = fetchurl {
     url = "https://developers.yubico.com/pam-u2f/Releases/${name}.tar.gz";
-    sha256 = "0bbwy9k3002anhkv67zwck3dry7blqnnp291dc4qsjrca0blw217";
+    sha256 = "1kz7d3vr5dag1d5zq14kcp887p5d0q079dy1sqyl8ndi567asjh3";
   };
 
   nativeBuildInputs = [ pkgconfig ];
diff --git a/pkgs/os-specific/linux/phc-intel/default.nix b/pkgs/os-specific/linux/phc-intel/default.nix
index cc6ac64d58ad..68acbb83531e 100644
--- a/pkgs/os-specific/linux/phc-intel/default.nix
+++ b/pkgs/os-specific/linux/phc-intel/default.nix
@@ -1,6 +1,5 @@
 { stdenv, fetchurl, kernel, which }:
 
-assert stdenv.isLinux;
 # Don't bother with older versions, though some might even work:
 assert stdenv.lib.versionAtLeast kernel.version "4.10";
 
diff --git a/pkgs/os-specific/linux/psmisc/default.nix b/pkgs/os-specific/linux/psmisc/default.nix
index edc7220d6586..358fa700382f 100644
--- a/pkgs/os-specific/linux/psmisc/default.nix
+++ b/pkgs/os-specific/linux/psmisc/default.nix
@@ -1,7 +1,5 @@
 {stdenv, fetchurl, ncurses}:
 
-assert stdenv.isLinux;
-
 stdenv.mkDerivation rec {
   name = "psmisc-23.1";
 
diff --git a/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix b/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix
index f69269347e37..c89a8ff91479 100644
--- a/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix
+++ b/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix
@@ -1,7 +1,5 @@
 { stdenv, systemd, cryptsetup }:
 
-assert stdenv.isLinux;
-
 stdenv.lib.overrideDerivation systemd (p: {
   version = p.version;
   name = "systemd-cryptsetup-generator";
@@ -13,6 +11,17 @@ stdenv.lib.overrideDerivation systemd (p: {
     ninja systemd-cryptsetup systemd-cryptsetup-generator
   '';
 
+  # As ninja install is not used here, the rpath needs to be manually fixed.
+  # Otherwise the resulting binary doesn't properly link against systemd-shared.so
+  postFixup = ''
+    sharedLib=libsystemd-shared-${p.version}.so
+    for prog in `find $out -type f -executable`; do
+      (patchelf --print-needed $prog | grep $sharedLib > /dev/null) && (
+        patchelf --set-rpath `patchelf --print-rpath $prog`:"$out/lib/systemd" $prog
+      ) || true
+    done
+  '';
+
   installPhase = ''
     mkdir -p $out/lib/systemd/
     cp systemd-cryptsetup $out/lib/systemd/systemd-cryptsetup
diff --git a/pkgs/os-specific/linux/systemd/default.nix b/pkgs/os-specific/linux/systemd/default.nix
index 615e4f867c4d..c1f139d42a64 100644
--- a/pkgs/os-specific/linux/systemd/default.nix
+++ b/pkgs/os-specific/linux/systemd/default.nix
@@ -1,9 +1,9 @@
 { stdenv, fetchFromGitHub, fetchpatch, pkgconfig, intltool, gperf, libcap, kmod
 , zlib, xz, pam, acl, cryptsetup, libuuid, m4, utillinux, libffi
 , glib, kbd, libxslt, coreutils, libgcrypt, libgpgerror, libidn2, libapparmor
-, audit, lz4, bzip2, kexectools, libmicrohttpd
+, audit, lz4, bzip2, libmicrohttpd
 , linuxHeaders ? stdenv.cc.libc.linuxHeaders
-, libseccomp, iptables, gnu-efi
+, iptables, gnu-efi
 , autoreconfHook, gettext, docbook_xsl, docbook_xml_dtd_42, docbook_xml_dtd_45
 , ninja, meson, python3Packages, glibcLocales
 , patchelf
@@ -11,10 +11,10 @@
 , hostPlatform
 , buildPackages
 , withSelinux ? false, libselinux
+, withLibseccomp ? libseccomp.meta.available, libseccomp
+, withKexectools ? kexectools.meta.available, kexectools
 }:
 
-assert stdenv.isLinux;
-
 let
   pythonLxmlEnv = buildPackages.python3Packages.python.withPackages ( ps: with ps; [ python3Packages.lxml ]);
 
@@ -44,13 +44,13 @@ in stdenv.mkDerivation rec {
     [ linuxHeaders libcap kmod xz pam acl
       /* cryptsetup */ libuuid glib libgcrypt libgpgerror libidn2
       libmicrohttpd ] ++
-      stdenv.lib.meta.enableIfAvailable kexectools ++
-      stdenv.lib.meta.enableIfAvailable libseccomp ++
+      stdenv.lib.optional withKexectools kexectools ++
+      stdenv.lib.optional withLibseccomp libseccomp ++
     [ libffi audit lz4 bzip2 libapparmor
       iptables gnu-efi
       # This is actually native, but we already pull it from buildPackages
       pythonLxmlEnv
-    ] ++ stdenv.lib.optionals withSelinux [ libselinux ];
+    ] ++ stdenv.lib.optional withSelinux libselinux;
 
   #dontAddPrefix = true;
 
diff --git a/pkgs/os-specific/linux/tbs/default.nix b/pkgs/os-specific/linux/tbs/default.nix
new file mode 100644
index 000000000000..291666c0b450
--- /dev/null
+++ b/pkgs/os-specific/linux/tbs/default.nix
@@ -0,0 +1,63 @@
+{ stdenv, lib, fetchFromGitHub, kernel, kmod, perl, patchutils, perlPackages, libelf }:
+let
+
+  media = fetchFromGitHub rec {
+    name = repo;
+    owner = "tbsdtv";
+    repo = "linux_media";
+    rev = "efe31531b77efd3a4c94516504a5823d31cdc776";
+    sha256 = "1533qi3sb91v00289hl5zaj4l35r2sf9fqc6z5ky1vbb7byxgnlr";
+  };
+
+  build = fetchFromGitHub rec {
+    name = repo;
+    owner = "tbsdtv";
+    repo = "media_build";
+    rev = "a0d62eba4d429e0e9d2c2f910fb203e817cac84b";
+    sha256 = "1329s7w9xlqjqwkpaqsd6b5dmzhm97jw0c7c7zzmmbdkl289i4i4";
+  };
+
+in stdenv.mkDerivation {
+  name = "tbs-2018.04.18-${kernel.version}";
+
+  srcs = [ media build ];
+  sourceRoot = "${build.name}";
+
+  preConfigure = ''
+    make dir DIR=../${media.name}
+  '';
+
+  postPatch = ''
+    patchShebangs .
+
+    sed -i v4l/Makefile \
+      -i v4l/scripts/make_makefile.pl \
+      -e 's,/sbin/depmod,${kmod}/bin/depmod,g' \
+      -e 's,/sbin/lsmod,${kmod}/bin/lsmod,g'
+
+    sed -i v4l/Makefile \
+      -e 's,^OUTDIR ?= /lib/modules,OUTDIR ?= ${kernel.dev}/lib/modules,' \
+      -e 's,^SRCDIR ?= /lib/modules,SRCDIR ?= ${kernel.dev}/lib/modules,'
+  '';
+
+  buildFlags = [ "VER=${kernel.modDirVersion}" ];
+  installFlags = [ "DESTDIR=$(out)" ];
+
+  hardeningDisable = [ "all" ];
+
+  nativeBuildInputs = [ patchutils kmod perl perlPackages.ProcProcessTable ]
+  ++ kernel.moduleBuildDependencies;
+
+   postInstall = ''
+    xz $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/media/dvb-core/dvb-core.ko
+    xz $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/media/v4l2-core/videodev.ko
+  '';
+
+  meta = with lib; {
+    homepage = https://www.tbsdtv.com/;
+    description = "Linux driver for TBSDTV cards";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ ck3d ];
+    priority = -1;
+  };
+}
diff --git a/pkgs/os-specific/linux/uclibc/default.nix b/pkgs/os-specific/linux/uclibc/default.nix
index 180aabc94cc6..3da12c41dc12 100644
--- a/pkgs/os-specific/linux/uclibc/default.nix
+++ b/pkgs/os-specific/linux/uclibc/default.nix
@@ -1,8 +1,8 @@
-{stdenv, fetchzip, linuxHeaders, libiconvReal, cross ? null, gccCross ? null,
-extraConfig ? ""}:
-
-assert stdenv.isLinux;
-assert cross != null -> gccCross != null;
+{ stdenv, buildPackages
+, fetchurl, linuxHeaders, libiconvReal
+, buildPlatform, hostPlatform
+, extraConfig ? ""
+}:
 
 let
   configParser = ''
@@ -28,9 +28,6 @@ let
     }
   '';
 
-  archMakeFlag = if cross != null then "ARCH=${cross.arch}" else "";
-  crossMakeFlag = if cross != null then "CROSS=${cross.config}-" else "";
-
   # UCLIBC_SUSV4_LEGACY defines 'tmpnam', needed for gcc libstdc++ builds.
   nixConfig = ''
     RUNTIME_PREFIX "/"
@@ -43,7 +40,7 @@ let
     UCLIBC_SUSV4_LEGACY y
     UCLIBC_HAS_THREADS_NATIVE y
     KERNEL_HEADERS "${linuxHeaders}/include"
-  '' + stdenv.lib.optionalString (stdenv.isAarch32 && cross == null) ''
+  '' + stdenv.lib.optionalString (stdenv.isAarch32 && buildPlatform != hostPlatform) ''
     CONFIG_ARM_EABI y
     ARCH_WANTS_BIG_ENDIAN n
     ARCH_BIG_ENDIAN n
@@ -52,29 +49,27 @@ let
     UCLIBC_HAS_FPU n
   '';
 
-  name = "uclibc-0.9.34-pre-20150131";
-  rev = "343f6b8f1f754e397632b0552e4afe586c8b392b";
-
+  version = "1.0.30";
 in
 
 stdenv.mkDerivation {
-  name = name + stdenv.lib.optionalString (cross != null) ("-" + cross.config);
+  name = "uclibc-ng-${version}";
+  inherit version;
 
-  src = fetchzip {
-    name = name + "-source";
-    url = "http://git.uclibc.org/uClibc/snapshot/uClibc-${rev}.tar.bz2";
-    sha256 = "1kgylzpid7da5i7wz7slh5q9rnq1m8bv5h9ilm76g0xwc2iwlhbw";
+  src = fetchurl {
+    url = "https://downloads.uclibc-ng.org/releases/${version}/uClibc-ng-${version}.tar.bz2";
+    # from "${url}.sha256";
+    sha256 = "3e0f057f24882823d697126015aa4d7d48fa2542be3939985cb3c26dcbcab5a8";
   };
 
   # 'ftw' needed to build acl, a coreutils dependency
   configurePhase = ''
-    make defconfig ${archMakeFlag}
+    make defconfig
     ${configParser}
     cat << EOF | parseconfig
     ${nixConfig}
     ${extraConfig}
-    ${if cross != null then stdenv.lib.attrByPath [ "uclibc" "extraConfig" ] "" cross else ""}
-    $extraCrossConfig
+    ${hostPlatform.platform.uclibc.extraConfig or ""}
     EOF
     ( set +o pipefail; yes "" | make oldconfig )
   '';
@@ -82,11 +77,16 @@ stdenv.mkDerivation {
   hardeningDisable = [ "stackprotector" ];
 
   # Cross stripping hurts.
-  dontStrip = cross != null;
+  dontStrip = stdenv.hostPlatform != stdenv.buildPlatform;
 
-  makeFlags = [ crossMakeFlag "VERBOSE=1" ];
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
 
-  buildInputs = stdenv.lib.optional (gccCross != null) gccCross;
+  makeFlags = [
+    "ARCH=${hostPlatform.parsed.cpu.name}"
+    "VERBOSE=1"
+  ] ++ stdenv.lib.optionals (stdenv.buildPlatform != stdenv.hostPlatform) [
+    "CROSS=${stdenv.cc.targetPrefix}"
+  ];
 
   # `make libpthread/nptl/sysdeps/unix/sysv/linux/lowlevelrwlock.h`:
   # error: bits/sysnum.h: No such file or directory
@@ -94,7 +94,7 @@ stdenv.mkDerivation {
 
   installPhase = ''
     mkdir -p $out
-    make PREFIX=$out VERBOSE=1 install ${crossMakeFlag}
+    make PREFIX=$out VERBOSE=1 install
     (cd $out/include && ln -s $(ls -d ${linuxHeaders}/include/* | grep -v "scsi$") .)
     # libpthread.so may not exist, so I do || true
     sed -i s@/lib/@$out/lib/@g $out/lib/libc.so $out/lib/libpthread.so || true
@@ -106,10 +106,10 @@ stdenv.mkDerivation {
   };
 
   meta = with stdenv.lib; {
-    homepage = http://www.uclibc.org/;
+    homepage = "https://uclibc-ng.org";
     description = "A small implementation of the C library";
     maintainers = with maintainers; [ rasendubi ];
     license = licenses.lgpl2;
-    platforms = subtractLists ["aarch64-linux"] platforms.linux;
+    platforms = platforms.linux;
   };
 }
diff --git a/pkgs/os-specific/linux/upower/default.nix b/pkgs/os-specific/linux/upower/default.nix
index 713ef974f9fb..8c1d117bc8b8 100644
--- a/pkgs/os-specific/linux/upower/default.nix
+++ b/pkgs/os-specific/linux/upower/default.nix
@@ -3,8 +3,6 @@
 , useSystemd ? true, systemd, gobjectIntrospection
 }:
 
-assert stdenv.isLinux;
-
 stdenv.mkDerivation rec {
   name = "upower-0.99.7";
 
diff --git a/pkgs/os-specific/linux/usbutils/default.nix b/pkgs/os-specific/linux/usbutils/default.nix
index 31e4a3dd26f6..adb2a0ee2fb1 100644
--- a/pkgs/os-specific/linux/usbutils/default.nix
+++ b/pkgs/os-specific/linux/usbutils/default.nix
@@ -1,11 +1,11 @@
 { stdenv, fetchurl, pkgconfig, libusb1, hwdata }:
 
 stdenv.mkDerivation rec {
-  name = "usbutils-009";
+  name = "usbutils-010";
 
   src = fetchurl {
     url = "mirror://kernel/linux/utils/usb/usbutils/${name}.tar.xz";
-    sha256 = "0q3iavmak2bs9xw486w4xfbjl0hbzii93ssgpr95mxmm9kjz1gwb";
+    sha256 = "06aag4jfgsfjxk563xsp9ik9nadihmasrr37a1gb0vwqni5kdiv1";
   };
 
   nativeBuildInputs = [ pkgconfig ];
diff --git a/pkgs/os-specific/linux/wireguard/default.nix b/pkgs/os-specific/linux/wireguard/default.nix
index b88646424be5..c5daaabd5be8 100644
--- a/pkgs/os-specific/linux/wireguard/default.nix
+++ b/pkgs/os-specific/linux/wireguard/default.nix
@@ -6,11 +6,11 @@ assert kernel != null -> stdenv.lib.versionAtLeast kernel.version "3.10";
 let
   name = "wireguard-${version}";
 
-  version = "0.0.20180413";
+  version = "0.0.20180514";
 
   src = fetchurl {
     url    = "https://git.zx2c4.com/WireGuard/snapshot/WireGuard-${version}.tar.xz";
-    sha256 = "0lbjx62ihc8prqfhvmi0v1xq1q3ayzj5rfy2p5149nr9qx3z37j1";
+    sha256 = "1nk6yj1gdmpar99zzw39n1v795m6fxsrilg37d02jm780rgbd5g8";
   };
 
   meta = with stdenv.lib; {
diff --git a/pkgs/os-specific/linux/xf86-input-multitouch/default.nix b/pkgs/os-specific/linux/xf86-input-multitouch/default.nix
index e1bafa93ea6f..527471bad328 100644
--- a/pkgs/os-specific/linux/xf86-input-multitouch/default.nix
+++ b/pkgs/os-specific/linux/xf86-input-multitouch/default.nix
@@ -11,8 +11,6 @@
 , libpciaccess
 }:
 
-assert stdenv.isLinux;
-
 stdenv.mkDerivation {
   name = "xf86-input-multitouch-20110312";
 
diff --git a/pkgs/os-specific/windows/mingwrt/common.nix b/pkgs/os-specific/windows/mingwrt/common.nix
new file mode 100644
index 000000000000..7dc2ae56aa84
--- /dev/null
+++ b/pkgs/os-specific/windows/mingwrt/common.nix
@@ -0,0 +1,12 @@
+{ lib, fetchurl }:
+
+rec {
+  name = "mingwrt-3.20";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/mingw/MinGW/Base/mingw-rt/${name}-mingw32-src.tar.gz";
+    sha256 = "02pydg1m8y35nxb4k34nlb5c341y2waq76z42mgdzlcf661r91pi";
+  };
+
+  meta.platforms = [ lib.systems.inspect.isMinGW ];
+}
diff --git a/pkgs/os-specific/windows/mingwrt/default.nix b/pkgs/os-specific/windows/mingwrt/default.nix
index 98461d690d92..3429f7564ade 100644
--- a/pkgs/os-specific/windows/mingwrt/default.nix
+++ b/pkgs/os-specific/windows/mingwrt/default.nix
@@ -1,29 +1,7 @@
-{stdenv, fetchurl, binutils ? null, gccCross ? null, onlyHeaders ? false}:
-
-let
-  name = "mingwrt-3.20";
-in
-stdenv.mkDerivation (rec {
-  inherit name;
-
-  src = fetchurl {
-    url = "mirror://sourceforge/mingw/MinGW/Base/mingw-rt/${name}-mingw32-src.tar.gz";
-    sha256 = "02pydg1m8y35nxb4k34nlb5c341y2waq76z42mgdzlcf661r91pi";
-  };
-
-} //
-(if onlyHeaders then {
-  name = name + "-headers";
-  phases = [ "unpackPhase" "installPhase" ];
-  installPhase = ''
-    mkdir -p $out
-    cp -R include $out
-  '';
-} else {
-  buildInputs = [ gccCross binutils ];
-
-  crossConfig = gccCross.crossConfig;
+{ stdenv, callPackage }:
 
+stdenv.mkDerivation {
+  inherit (callPackage ./common.nix {}) name src meta;
   dontStrip = true;
-})
-)
+  hardeningDisable = [ "stackprotector" "fortify" ];
+}
diff --git a/pkgs/os-specific/windows/mingwrt/headers.nix b/pkgs/os-specific/windows/mingwrt/headers.nix
new file mode 100644
index 000000000000..51180af0fc73
--- /dev/null
+++ b/pkgs/os-specific/windows/mingwrt/headers.nix
@@ -0,0 +1,17 @@
+{ stdenvNoCC, callPackage }:
+
+let
+  inherit (callPackage ./common.nix {}) name src meta;
+
+in stdenvNoCC.mkDerivation {
+  name = name + "-headers";
+
+  inherit src meta;
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  installPhase = ''
+    mkdir -p $out
+    cp -R include $out
+  '';
+}
diff --git a/pkgs/os-specific/windows/pthread-w32/default.nix b/pkgs/os-specific/windows/pthread-w32/default.nix
index f0b6852d5bf9..ef42dadc2973 100644
--- a/pkgs/os-specific/windows/pthread-w32/default.nix
+++ b/pkgs/os-specific/windows/pthread-w32/default.nix
@@ -1,4 +1,4 @@
-{ fetchurl, stdenv, mingw_headers }:
+{ fetchurl, stdenv, mingw_header, hostPlatform, buildPlatform }:
 
 # This file is tweaked for cross-compilation only.
 assert hostPlatform != buildPlatform;
diff --git a/pkgs/os-specific/windows/w32api/common.nix b/pkgs/os-specific/windows/w32api/common.nix
new file mode 100644
index 000000000000..273ae2c8df4b
--- /dev/null
+++ b/pkgs/os-specific/windows/w32api/common.nix
@@ -0,0 +1,14 @@
+{ fetchurl, xz }:
+
+rec {
+  name = "w32api-3.17-2";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/mingw/MinGW/Base/w32api/w32api-3.17/${name}-mingw32-src.tar.lzma";
+    sha256 = "09rhnl6zikmdyb960im55jck0rdy5z9nlg3akx68ixn7khf3j8wb";
+  };
+
+  nativeBuildInputs = [ xz ];
+
+  meta.platforms = [ lib.systems.inspect.isMinGW ];
+}
diff --git a/pkgs/os-specific/windows/w32api/default.nix b/pkgs/os-specific/windows/w32api/default.nix
index 3443fff9668d..51b88201998c 100644
--- a/pkgs/os-specific/windows/w32api/default.nix
+++ b/pkgs/os-specific/windows/w32api/default.nix
@@ -1,32 +1,6 @@
-{ stdenv, fetchurl, xz, binutils ? null
-, gccCross ? null, onlyHeaders ? false }:
-
-let
-  name = "w32api-3.17-2";
-in
-stdenv.mkDerivation ({
-  inherit name;
-
-  src = fetchurl {
-    url = "mirror://sourceforge/mingw/MinGW/Base/w32api/w32api-3.17/${name}-mingw32-src.tar.lzma";
-    sha256 = "09rhnl6zikmdyb960im55jck0rdy5z9nlg3akx68ixn7khf3j8wb";
-  };
-
-  nativeBuildInputs = [ xz ];
-
-} //
-(if onlyHeaders then {
-  name = name + "-headers";
-  phases = [ "unpackPhase" "installPhase" ];
-  installPhase = ''
-    mkdir -p $out
-    cp -R include $out
-  '';
-} else {
-  buildInputs = [ gccCross binutils ];
-
-  crossConfig = gccCross.crossConfig;
+{ stdenv, callPackage }:
 
+stdenv.mkDerivation {
+  inherit (callPackage ./common.nix {}) name src nativeBuildInputs meta;
   dontStrip = true;
-})
-)
+}
diff --git a/pkgs/os-specific/windows/w32api/headers.nix b/pkgs/os-specific/windows/w32api/headers.nix
new file mode 100644
index 000000000000..3083118bb366
--- /dev/null
+++ b/pkgs/os-specific/windows/w32api/headers.nix
@@ -0,0 +1,17 @@
+{ stdenvNoCC, callPackage }:
+
+let
+  inherit (callPackage ./common.nix {}) name src meta;
+
+in stdenvNoCC.mkDerivation {
+  name = name + "-headers";
+
+  inherit src nativeBuildInputs meta;
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  installPhase = ''
+    mkdir -p $out
+    cp -R include $out
+  '';
+}