about summary refs log tree commit diff
path: root/nixpkgs/pkgs/os-specific/linux
diff options
context:
space:
mode:
Diffstat (limited to 'nixpkgs/pkgs/os-specific/linux')
-rw-r--r--nixpkgs/pkgs/os-specific/linux/915resolution/default.nix20
-rw-r--r--nixpkgs/pkgs/os-specific/linux/acpi-call/default.nix43
-rw-r--r--nixpkgs/pkgs/os-specific/linux/acpi/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/acpid/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/acpitool/default.nix51
-rw-r--r--nixpkgs/pkgs/os-specific/linux/afuse/default.nix21
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alienfx/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alienfx/unistd.patch12
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-firmware/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-lib/alsa-plugin-conf-multilib.patch232
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-lib/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-oss/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-plugins/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-plugins/wrapper.nix5
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-tools/default.nix54
-rw-r--r--nixpkgs/pkgs/os-specific/linux/alsa-utils/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/amdgpu-pro/default.nix183
-rw-r--r--nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0001-fix-warnings-for-Werror.patch71
-rw-r--r--nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0002-fix-sketchy-int-ptr-warning.patch25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0003-disable-firmware-copy.patch25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/amdgpu-pro/xreallocarray.c5
-rw-r--r--nixpkgs/pkgs/os-specific/linux/anbox/default.nix138
-rw-r--r--nixpkgs/pkgs/os-specific/linux/anbox/kmod.nix43
-rw-r--r--nixpkgs/pkgs/os-specific/linux/android-udev-rules/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/apparmor/default.nix254
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/builder.sh302
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/default.nix140
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.12-xstate-fp.patch26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-kcl_str.patch14
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-mtrr.patch27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-preempt.patch103
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-sep_printf.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.7-arch-cpu_has_pge-v2.patch70
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.9-get_user_pages.patch28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-get_user_pages.patch25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-page_cache_release-put_page.patch16
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/patch-samples.patch26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/atop/default.nix48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/atop/default.upstream4
-rw-r--r--nixpkgs/pkgs/os-specific/linux/audit/default.nix53
-rw-r--r--nixpkgs/pkgs/os-specific/linux/autofs/default.nix48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/batman-adv/alfred.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/batman-adv/batctl.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/batman-adv/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bbswitch/default.nix57
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bcc/default.nix78
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bcc/fix-deadlock-detector-import.patch14
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bcc/libbcc-path.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/beegfs/default.nix163
-rw-r--r--nixpkgs/pkgs/os-specific/linux/beegfs/kernel-module.nix46
-rw-r--r--nixpkgs/pkgs/os-specific/linux/blcr/default.nix43
-rw-r--r--nixpkgs/pkgs/os-specific/linux/blktrace/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bluez/bluez-5.37-obexd_without_systemd-1.patch61
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bluez/default.nix96
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bolt/0001-skip-mkdir.patch12
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bolt/default.nix61
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bpftrace/bcc-source.patch32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bpftrace/default.nix57
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bpftrace/disable-gtests.patch73
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bridge-utils/add-ip6-header.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/bridge-utils/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/default.nix64
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/gcc.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/i686-build-failure.patch18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/license.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.11.patch52
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.12.patch68
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.15.patch47
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.7.patch109
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.8.patch64
-rw-r--r--nixpkgs/pkgs/os-specific/linux/broadcom-sta/null-pointer-fix.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/btfs/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/busybox/busybox-in-store.patch23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/busybox/default.nix111
-rw-r--r--nixpkgs/pkgs/os-specific/linux/busybox/sandbox-shell.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cachefilesd/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/can-isotp/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/can-utils/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cgmanager/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/checkpolicy/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/checksec/0001-attempt-to-modprobe-config-before-checking-kernel.patch27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/checksec/default.nix43
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cifs-utils/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/compsize/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/conky/default.nix143
-rw-r--r--nixpkgs/pkgs/os-specific/linux/conntrack-tools/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/consoletools/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/conspy/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/conspy/default.upstream5
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cpufrequtils/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cpufrequtils/remove-pot-creation-date.patch24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cpupower/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cpuset/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cramfsswap/builder.sh6
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cramfsswap/default.nix19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/crda/default.nix57
-rw-r--r--nixpkgs/pkgs/os-specific/linux/criu/default.nix46
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cryptodev/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cryptsetup/default.nix53
-rw-r--r--nixpkgs/pkgs/os-specific/linux/cryptsetup/disable-failing-tests.patch19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dbus-broker/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/devmem2/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/directvnc/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/disk-indicator/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/displaylink/default.nix74
-rw-r--r--nixpkgs/pkgs/os-specific/linux/displaylink/udev-installer.patch18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dmidecode/default.nix19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dmraid/default.nix49
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dmraid/hardening-format.patch18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dmtcp/default.nix47
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dmtcp/ld-linux-so-buffer-size.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dpdk/default.nix64
-rw-r--r--nixpkgs/pkgs/os-specific/linux/drbd/default.nix43
-rw-r--r--nixpkgs/pkgs/os-specific/linux/drbd/pass-force.patch15
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dropwatch/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/dstat/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/e1000e/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/earlyoom/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ebtables/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/edac-utils/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ena/default.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/eudev/default.nix60
-rw-r--r--nixpkgs/pkgs/os-specific/linux/evdi/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/eventstat/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/exfat/default.nix46
-rw-r--r--nixpkgs/pkgs/os-specific/linux/facetimehd/default.nix61
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fatrace/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fbterm/default.nix60
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ffado/default.nix67
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firejail/default.nix59
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firejail/default.upstream3
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/default.nix21
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/no-root-install.patch18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/6.30.163.46.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/broadcom-bt-firmware/default.nix46
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/bt-fw-converter/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/facetimehd-firmware/default.nix64
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/fwupd/add-option-for-installation-sysconfdir.patch171
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/fwupd/default.nix137
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/fwupd/fix-paths.patch15
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/fwupd/installed-tests-path.patch25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/default.nix60
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/do-not-create-sharedstatedir.patch10
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/intel2200BGFirmware/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/openelec-dvb-firmware/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi-wireless/default.nix53
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools-dont-install-sysv-init-scripts.patch20
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools.nix31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/rt5677/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/rtl8192su-firmware/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/rtl8723bs-firmware/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/rtlwifi_new-firmware/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/firmware/zd1211/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/flashbench/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fnotifystat/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/forkstat/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/forktty/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/forktty/default.upstream2
-rw-r--r--nixpkgs/pkgs/os-specific/linux/freefall/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fscrypt/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fscryptctl/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fswebcam/default.nix20
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ftop/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_buffer_overflow.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_printf_format.patch20
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fuse/common.nix87
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fuse/default.nix17
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fuse/fuse3-install.patch34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fwts/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/fxload/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/gfxtablet/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/gogoclient/config-paths.patch39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/gogoclient/default.nix44
-rw-r--r--nixpkgs/pkgs/os-specific/linux/gogoclient/gcc46-include-fix.patch22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/google-authenticator/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/gpu-switch/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/gradm/default.nix51
-rw-r--r--nixpkgs/pkgs/os-specific/linux/guvcview/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hal-flash/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hd-idle/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hdapsd/default.nix21
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hdapsd/postInstall.sh7
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hdparm/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hibernate/default.nix45
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hibernate/gen-manpages.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hibernate/hibernate.patch37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hibernate/install.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hostapd/default.nix72
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hwdata/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/hyperv-daemons/default.nix109
-rw-r--r--nixpkgs/pkgs/os-specific/linux/i2c-tools/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/i7z/default.nix58
-rw-r--r--nixpkgs/pkgs/os-specific/linux/i7z/qt5.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/i810switch/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ifenslave/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iio-sensor-proxy/default.nix51
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ima-evm-utils/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ima-evm-utils/xattr.patch73
-rw-r--r--nixpkgs/pkgs/os-specific/linux/input-utils/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/intel-ocl/default.nix73
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iomelt/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ioport/default.nix17
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iotop/default.nix20
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iproute/default.nix55
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ipsec-tools/CVE-2015-4047.patch16
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ipsec-tools/default.nix51
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ipsec-tools/dont-create-localstatedir-during-install.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ipset/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iptables/default.nix67
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iptstate/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iputils/build-ninfod-with-openssl.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iputils/default.nix62
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ipvsadm/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/irqbalance/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/it87/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iw/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/iwd/default.nix73
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ixgbevf/default.nix31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/jfbview/default.nix68
-rw-r--r--nixpkgs/pkgs/os-specific/linux/jool/cli.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/jool/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/jool/source.nix11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/jujuutils/default.nix19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kbd/default.nix72
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kbd/keymaps.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kbd/search-paths.patch71
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kbdlight/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix85
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/bridge-stp-helper.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/common-config.nix702
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.11.patch784
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.4.patch407
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.9.patch784
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/README.md21
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/default.nix11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/generate-config.pl145
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/generic.nix176
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/genksyms-fix-segfault.patch19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/hardened-config.nix120
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-4.14.nix18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-4.19.nix18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-4.4.nix11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-4.9.nix11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-5.0.nix18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-hardkernel-4.14.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-libre.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp-93.nix47
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp.nix49
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-rpi.nix60
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-testing-bcachefs.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/linux-testing.nix16
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/manual-config.nix298
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/modinst-arg-list-too-long.patch14
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/p9-fixes.patch85
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/patches.nix60
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/perf.nix75
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/randstruct-provide-seed.patch12
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kernel/tag-hardened.patch7
-rwxr-xr-xnixpkgs/pkgs/os-specific/linux/kernel/update.sh62
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kexectools/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/keyutils/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/klibc/default.nix48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/klibc/no-reinstall-kernel-headers.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/klibc/shrunk.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmod-blacklist-ubuntu/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmod-debian-aliases/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmod/aggregator.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmod/darwin.patch123
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmod/default.nix44
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmod/module-dir.patch157
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmscon/default.nix58
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmscon/kmscon-8-glibc-2.26.patch25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/kmscube/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/latencytop/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ldm/default.nix43
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ledger-udev-rules/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libaio/default.nix38
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libatasmart/default.nix21
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libcap-ng/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libcap/default.nix60
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libcgroup/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libnl/default.nix50
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libratbag/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libselinux/default.nix50
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libsemanage/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libsepol/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libsmbios/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libudev0-shim/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libvolume_id/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libwebcam/default.nix55
-rw-r--r--nixpkgs/pkgs/os-specific/linux/libwebcam/uvcdynctrl_symlink_support_and_take_data_dir_from_env.patch65
-rw-r--r--nixpkgs/pkgs/os-specific/linux/light/default.nix31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lightum/default.nix38
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lksctp-tools/default.nix17
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lm-sensors/default.nix31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lockdep/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/logitech-udev-rules/default.nix19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lsiutil/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lsscsi/default.nix19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lttng-modules/default.nix38
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lvm2/default.nix93
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lvm2/default.upstream4
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lvm2/purity.patch44
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lxc/default.nix88
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lxc/support-db2x.patch16
-rw-r--r--nixpkgs/pkgs/os-specific/linux/lxcfs/default.nix42
-rw-r--r--nixpkgs/pkgs/os-specific/linux/macchanger/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mba6x_bl/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mbpfan/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mcelog/default.nix51
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mdadm/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mdadm/no-self-references.patch130
-rw-r--r--nixpkgs/pkgs/os-specific/linux/microcode/amd.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/microcode/intel.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/microcode/iucode-tool.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mingetty/default.nix21
-rw-r--r--nixpkgs/pkgs/os-specific/linux/miraclecast/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mkinitcpio-nfs-utils/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mmc-utils/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/molly-guard/default.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/msr-tools/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mstpd/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/multipath-tools/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/musl/default.nix120
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mwprocapture/default.nix67
-rw-r--r--nixpkgs/pkgs/os-specific/linux/mxu11x0/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ndiswrapper/default.nix49
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ndiswrapper/no-sbin.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/net-tools/config.h79
-rw-r--r--nixpkgs/pkgs/os-specific/linux/net-tools/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/netatop/default.nix42
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nfs-utils/default.nix121
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nftables/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nmon/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nss_ldap/crashes.patch104
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nss_ldap/default.nix38
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nss_ldap/nss_ldap-265-glibc-2.16.patch139
-rw-r--r--nixpkgs/pkgs/os-specific/linux/numactl/default.nix31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/numad/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/numad/numad-linker-flags.patch33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidia-x11/atomic64_t.patch12
-rwxr-xr-xnixpkgs/pkgs/os-specific/linux/nvidia-x11/builder.sh146
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidia-x11/default.nix80
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidia-x11/drm_mode_connector.patch24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidia-x11/generic.nix99
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidia-x11/persistenced.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidia-x11/settings.nix89
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidia-x11/vm_operations_struct-fault.patch31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvidiabl/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/nvme-cli/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/odp-dpdk/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ofp/default.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/open-iscsi/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/open-isns/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/builder.sh16
-rw-r--r--nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/default.nix20
-rw-r--r--nixpkgs/pkgs/os-specific/linux/openvswitch/default.nix77
-rw-r--r--nixpkgs/pkgs/os-specific/linux/otpw/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pagemon/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam/default.nix66
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_ccreds/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_krb5/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_ldap/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_mount/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_mount/insert_utillinux_path_hooks.patch30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_pgsql/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/multiple-key-files.patch365
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_u2f/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pam_usb/default.nix76
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pax-utils/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/paxctl/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/paxctl/setup-hook.sh8
-rw-r--r--nixpkgs/pkgs/os-specific/linux/paxtest/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pcm/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pcmciautils/default.nix55
-rw-r--r--nixpkgs/pkgs/os-specific/linux/perf-tools/default.nix44
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pflask/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/phc-intel/default.nix53
-rw-r--r--nixpkgs/pkgs/os-specific/linux/piper/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pipework/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pktgen/default.nix64
-rw-r--r--nixpkgs/pkgs/os-specific/linux/ply/default.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/plymouth/default.nix65
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pm-utils/default.nix55
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pmount/default.nix45
-rw-r--r--nixpkgs/pkgs/os-specific/linux/policycoreutils/default.nix36
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pommed-light/default.nix65
-rw-r--r--nixpkgs/pkgs/os-specific/linux/powerstat/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/powertop/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/powertop/fix-vertical-scrolling.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pps-tools/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/prl-tools/autostart.desktop8
-rw-r--r--nixpkgs/pkgs/os-specific/linux/prl-tools/default.nix170
-rw-r--r--nixpkgs/pkgs/os-specific/linux/procdump/default.nix48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/procps-ng/default.nix54
-rw-r--r--nixpkgs/pkgs/os-specific/linux/pscircle/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/psmisc/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/r8168/default.nix56
-rw-r--r--nixpkgs/pkgs/os-specific/linux/radeontools/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/radeontop/default.nix45
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rdma-core/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/read-edid/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/regionset/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/reptyr/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rewritefs/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rfkill/default.nix20
-rwxr-xr-xnixpkgs/pkgs/os-specific/linux/rfkill/rfkill-hook.sh19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rfkill/udev.nix55
-rw-r--r--nixpkgs/pkgs/os-specific/linux/roccat-tools/default.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtkit/default.nix45
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtl8192eu/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtl8723bs/default.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtl8812au/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtl8814au/default.nix39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtl8821au/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtl8821ce/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/rtlwifi_new/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/s6-linux-utils/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sch_cake/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/schedtool/default.nix20
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/sdnotify-wrapper.c172
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sdparm/default.nix18
-rw-r--r--nixpkgs/pkgs/os-specific/linux/selinux-python/default.nix49
-rw-r--r--nixpkgs/pkgs/os-specific/linux/selinux-sandbox/default.nix61
-rw-r--r--nixpkgs/pkgs/os-specific/linux/semodule-utils/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sepolgen/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/service-wrapper/default.nix26
-rwxr-xr-xnixpkgs/pkgs/os-specific/linux/service-wrapper/service-wrapper.sh247
-rw-r--r--nixpkgs/pkgs/os-specific/linux/setools/default.nix42
-rw-r--r--nixpkgs/pkgs/os-specific/linux/seturgent/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/shadow/default.nix93
-rw-r--r--nixpkgs/pkgs/os-specific/linux/shadow/keep-path.patch19
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sinit/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/smem/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/smemstat/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/speedometer/default.nix26
-rw-r--r--nixpkgs/pkgs/os-specific/linux/spl/default.nix56
-rw-r--r--nixpkgs/pkgs/os-specific/linux/spl/install_prefix.patch168
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sssd/default.nix91
-rw-r--r--nixpkgs/pkgs/os-specific/linux/statifier/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/syscall_limiter/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysdig/default.nix64
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysdig/default.upstream8
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysfsutils/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysklogd/default.nix28
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysklogd/systemd.patch845
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysklogd/union-wait.patch11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/syslinux/default.nix85
-rw-r--r--nixpkgs/pkgs/os-specific/linux/syslinux/perl-deps.patch81
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysstat/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysstat/install.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/systemd-wait/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/systemd/default.nix225
-rw-r--r--nixpkgs/pkgs/os-specific/linux/sysvinit/default.nix45
-rw-r--r--nixpkgs/pkgs/os-specific/linux/targetcli/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tbs/default.nix63
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tcp-wrappers/cdecls.patch31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tcp-wrappers/default.nix75
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tcp-wrappers/tcp-wrappers-7.6-headers.patch295
-rw-r--r--nixpkgs/pkgs/os-specific/linux/thunderbolt/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tiptop/default.nix35
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tiscamera/allow-pipeline-stop-in-trigger-mode.patch48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tiscamera/default.nix98
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tmon/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tomb/default.nix44
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tp_smapi/default.nix48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tp_smapi/update.nix11
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tpacpi-bat/default.nix34
-rw-r--r--nixpkgs/pkgs/os-specific/linux/trace-cmd/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/trinity/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/tunctl/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/uclibc/default.nix114
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks-glue/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks/1-default.nix44
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks/2-default.nix78
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks/fix-paths.patch131
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks/force-path.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks/glibc.patch25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks/no-pci-db.patch13
-rw-r--r--nixpkgs/pkgs/os-specific/linux/udisks/purity.patch57
-rw-r--r--nixpkgs/pkgs/os-specific/linux/undervolt/default.nix27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/untie/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/upower/default.nix41
-rw-r--r--nixpkgs/pkgs/os-specific/linux/usbguard/default.nix66
-rw-r--r--nixpkgs/pkgs/os-specific/linux/usbip/default.nix22
-rw-r--r--nixpkgs/pkgs/os-specific/linux/usbutils/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/usbutils/fix-paths.patch16
-rw-r--r--nixpkgs/pkgs/os-specific/linux/usermount/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/util-linux/default.nix76
-rw-r--r--nixpkgs/pkgs/os-specific/linux/util-linux/rtcwake-search-PATH-for-shutdown.patch27
-rw-r--r--nixpkgs/pkgs/os-specific/linux/uvcdynctrl/default.nix30
-rw-r--r--nixpkgs/pkgs/os-specific/linux/v4l-utils/default.nix51
-rw-r--r--nixpkgs/pkgs/os-specific/linux/v4l2loopback/default.nix37
-rw-r--r--nixpkgs/pkgs/os-specific/linux/v86d/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/virtualbox/default.nix33
-rw-r--r--nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kbuild.patch85
-rw-r--r--nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kerndir.patch48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/wireguard/default.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/wireless-tools/default.nix24
-rw-r--r--nixpkgs/pkgs/os-specific/linux/wpa_supplicant/default.nix112
-rw-r--r--nixpkgs/pkgs/os-specific/linux/wpa_supplicant/gui.nix32
-rw-r--r--nixpkgs/pkgs/os-specific/linux/x86_energy_perf_policy/default.nix25
-rw-r--r--nixpkgs/pkgs/os-specific/linux/x86info/default.nix40
-rw-r--r--nixpkgs/pkgs/os-specific/linux/xf86-input-mtrack/default.nix42
-rw-r--r--nixpkgs/pkgs/os-specific/linux/xf86-input-multitouch/default.nix48
-rw-r--r--nixpkgs/pkgs/os-specific/linux/xf86-input-wacom/default.nix31
-rw-r--r--nixpkgs/pkgs/os-specific/linux/xf86-video-nested/default.nix29
-rw-r--r--nixpkgs/pkgs/os-specific/linux/xsensors/default.nix23
-rw-r--r--nixpkgs/pkgs/os-specific/linux/xsensors/remove-unused-variables.patch39
-rw-r--r--nixpkgs/pkgs/os-specific/linux/xsensors/replace-deprecated-gtk.patch168
-rw-r--r--nixpkgs/pkgs/os-specific/linux/zfs/default.nix200
520 files changed, 26966 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/os-specific/linux/915resolution/default.nix b/nixpkgs/pkgs/os-specific/linux/915resolution/default.nix
new file mode 100644
index 000000000000..ce21887f19f8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/915resolution/default.nix
@@ -0,0 +1,20 @@
+{stdenv, fetchurl}:
+
+stdenv.mkDerivation rec {
+  name = "915resolution-0.5.3";
+
+  src = fetchurl {
+    url = "http://915resolution.mango-lang.org/${name}.tar.gz";
+    sha256 = "0hmmy4kkz3x6yigz6hk99416ybznd67dpjaxap50nhay9f1snk5n";
+  };
+
+  patchPhase = "rm *.o";
+  installPhase = "mkdir -p $out/sbin; cp 915resolution $out/sbin/";
+
+  meta = with stdenv.lib; {
+    homepage = http://915resolution.mango-lang.org/;
+    description = "A tool to modify Intel 800/900 video BIOS";
+    platforms = [ "i686-linux" "x86_64-linux" ];
+    license = licenses.publicDomain;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/acpi-call/default.nix b/nixpkgs/pkgs/os-specific/linux/acpi-call/default.nix
new file mode 100644
index 000000000000..bd12373da884
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/acpi-call/default.nix
@@ -0,0 +1,43 @@
+{ stdenv, fetchgit, fetchpatch, kernel }:
+
+stdenv.mkDerivation {
+  name = "acpi-call-${kernel.version}";
+
+  src = fetchgit {
+    url = "git://github.com/mkottman/acpi_call.git";
+    rev = "ac67445bc75ec4fcf46ceb195fb84d74ad350d51";
+    sha256 = "0jl19irz9x9pxab2qp4z8c3jijv2m30zhmnzi6ygbrisqqlg4c75";
+  };
+
+  patches = [
+    (fetchpatch {
+      url = "https://github.com/mkottman/acpi_call/pull/67.patch";
+      sha256 = "0z07apvdl8nvl8iwfk1sl1iidfjyx12fc0345bmp2nq1537kpbri";
+    })
+  ];
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  preBuild = ''
+    sed -e 's/break/true/' -i examples/turn_off_gpu.sh
+    sed -e 's@/bin/bash@.bin/sh@' -i examples/turn_off_gpu.sh
+    sed -e "s@/lib/modules/\$(.*)@${kernel.dev}/lib/modules/${kernel.modDirVersion}@" -i Makefile
+    sed -e 's@acpi/acpi[.]h@linux/acpi.h@g' -i acpi_call.c
+  '';
+
+  installPhase = ''
+    mkdir -p $out/lib/modules/${kernel.modDirVersion}/misc
+    cp acpi_call.ko $out/lib/modules/${kernel.modDirVersion}/misc
+    mkdir -p $out/bin
+    cp examples/turn_off_gpu.sh $out/bin/test_discrete_video_off.sh
+    chmod a+x $out/bin/test_discrete_video_off.sh
+  '';
+
+  meta = {
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+    description = "A module allowing arbitrary ACPI calls; use case: hybrid video";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/acpi/default.nix b/nixpkgs/pkgs/os-specific/linux/acpi/default.nix
new file mode 100644
index 000000000000..37de98780b69
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/acpi/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "acpi-${version}";
+  version = "1.7";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/acpiclient/${version}/${name}.tar.gz";
+    sha256 = "01ahldvf0gc29dmbd5zi4rrnrw2i1ajnf30sx2vyaski3jv099fp";
+  };
+
+  meta = with stdenv.lib; {
+    description = "Show battery status and other ACPI information";
+    longDescription = ''
+      Linux ACPI client is a small command-line
+      program that attempts to replicate the functionality of
+      the "old" `apm' command on ACPI systems.  It includes
+      battery and thermal information.
+    '';
+    homepage = https://sourceforge.net/projects/acpiclient/;
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/acpid/default.nix b/nixpkgs/pkgs/os-specific/linux/acpid/default.nix
new file mode 100644
index 000000000000..99d1cf38f0ac
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/acpid/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl, autoreconfHook }:
+
+stdenv.mkDerivation rec {
+  name = "acpid-2.0.31";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/acpid2/${name}.tar.xz";
+    sha256 = "1hrc0xm6q12knbgzhq0i8g2rfrkwcvh1asd7k9rs3nc5xmlwd7gw";
+  };
+
+  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 = https://sourceforge.net/projects/acpid2/;
+    description = "A daemon for delivering ACPI events to userspace programs";
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/acpitool/default.nix b/nixpkgs/pkgs/os-specific/linux/acpitool/default.nix
new file mode 100644
index 000000000000..ce47932587cf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/acpitool/default.nix
@@ -0,0 +1,51 @@
+{stdenv, fetchurl, fetchpatch}:
+
+let
+   acpitool-patch-051-4 = params: fetchpatch rec {
+     inherit (params) name sha256;
+     url = "https://anonscm.debian.org/cgit/pkg-acpi/acpitool.git/plain/debian/patches/${name}?h=debian/0.5.1-4&id=3fd9f396f12ec9c1cae3337a2a25026b7faad2ae";
+   };
+
+in stdenv.mkDerivation rec {
+  name = "acpitool-0.5.1";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/acpitool/${name}.tar.bz2";
+    sha256 = "004fb6cd43102918b6302cf537a2db7ceadda04aef2e0906ddf230f820dad34f";
+  };
+
+  patches = [
+    (acpitool-patch-051-4 {
+      name = "ac_adapter.patch";
+      sha256 = "0rn14vfv9x5gmwyvi6bha5m0n0pm4wbpg6h8kagmy3i1f8lkcfi8";
+    })
+    (acpitool-patch-051-4 {
+      name = "battery.patch";
+      sha256 = "190msm5cgqgammxp1j4dycfz206mggajm5904r7ifngkcwizh9m7";
+    })
+    (acpitool-patch-051-4 {
+      name = "kernel3.patch";
+      sha256 = "1qb47iqnv09i7kgqkyk9prr0pvlx0yaip8idz6wc03wci4y4bffg";
+    })
+    (acpitool-patch-051-4 {
+      name = "wakeup.patch";
+      sha256 = "1mmzf8n4zsvc7ngn51map2v42axm9vaf8yknbd5amq148sjf027z";
+    })
+    (acpitool-patch-051-4 {
+      name = "0001-Do-not-assume-fixed-line-lengths-for-proc-acpi-wakeu.patch";
+      sha256 = "10wwh7l3jbmlpa80fzdr18nscahrg5krl18pqwy77f7683mg937m";
+    })
+    (acpitool-patch-051-4 {
+      name = "typos.patch";
+      sha256 = "1178fqpk6sbqp1cyb1zf9qv7ahpd3pidgpid3bbpms7gyhqvvdpa";
+    })
+  ];
+
+  meta = {
+    description = "A small, convenient command-line ACPI client with a lot of features";
+    homepage = https://sourceforge.net/projects/acpitool/;
+    license = stdenv.lib.licenses.gpl2Plus;
+    maintainers = [ stdenv.lib.maintainers.guibert ];
+    platforms = stdenv.lib.platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/afuse/default.nix b/nixpkgs/pkgs/os-specific/linux/afuse/default.nix
new file mode 100644
index 000000000000..67c5ff140874
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/afuse/default.nix
@@ -0,0 +1,21 @@
+{ stdenv, fetchurl, pkgconfig, autoreconfHook, fuse }:
+
+stdenv.mkDerivation {
+  name = "afuse-0.4.1";
+
+  src = fetchurl {
+    url = https://github.com/pcarrier/afuse/archive/v0.4.1.tar.gz;
+    sha256 = "1sfhicmxppkvdd4z9klfn63snb71gr9hff6xij1gzk94xg6m0ycc";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ fuse ];
+
+  meta = {
+    description = "Automounter in userspace";
+    homepage = https://github.com/pcarrier/afuse;
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = [ stdenv.lib.maintainers.marcweber ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/alienfx/default.nix b/nixpkgs/pkgs/os-specific/linux/alienfx/default.nix
new file mode 100644
index 000000000000..d04e7b8fbeb0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alienfx/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, libusb1, fetchgit}:
+
+
+let
+  rev = "85ee5eeaca59a1c92659c3f49b148b0447d78f16";
+in
+
+stdenv.mkDerivation {
+  name = "alienfx-1.0.0";
+  src = fetchgit {
+    inherit rev;
+    url = https://github.com/tibz/alienfx.git;
+
+    sha256 = "47501a3b4e08d39edee4cd829ae24259a7e740b9798db76b846fa872989f8fb1";
+  };
+
+  prePatch = ''
+    substituteInPlace Makefile --replace /usr/ $out/
+    substituteInPlace Makefile --replace "install -o root -g root -m 4755" "install -m 555"
+  '';
+
+  patches = [./unistd.patch];
+  buildInputs = [ libusb1 ];
+  makeFlags = "build";
+  preInstall = ''
+    mkdir -p $out/bin
+    mkdir -p $out/man/man1
+  '';
+  installTargets = "install";
+  postInstall = ''cp alienfx.1 $out/man/man1'';
+
+  meta = {
+    description = "Controls AlienFX lighting";
+    homepage = https://github.com/tibz/alienfx;
+    maintainers = [stdenv.lib.maintainers.tomberek];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
+
diff --git a/nixpkgs/pkgs/os-specific/linux/alienfx/unistd.patch b/nixpkgs/pkgs/os-specific/linux/alienfx/unistd.patch
new file mode 100644
index 000000000000..546a27892f0d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alienfx/unistd.patch
@@ -0,0 +1,12 @@
+diff --git a/alienfx.cpp b/alienfx.cpp
+index 5981039..aea8992 100644
+--- a/alienfx.cpp
++++ b/alienfx.cpp
+@@ -13,6 +13,7 @@
+ #include <string.h>
+ #include <iostream>
+ #include <libusb-1.0/libusb.h>
++#include <unistd.h>
+ 
+ using namespace std;
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-firmware/default.nix b/nixpkgs/pkgs/os-specific/linux/alsa-firmware/default.nix
new file mode 100644
index 000000000000..53fcf7d68433
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-firmware/default.nix
@@ -0,0 +1,33 @@
+{stdenv, fetchurl}:
+
+stdenv.mkDerivation rec {
+  name = "alsa-firmware-1.0.29";
+
+  src = fetchurl {
+    url = "mirror://alsa/firmware/${name}.tar.bz2";
+    sha256 = "0gfcyj5anckjn030wcxx5v2xk2s219nyf99s9m833275b5wz2piw";
+  };
+
+  configureFlags = [
+    "--with-hotplug-dir=$(out)/lib/firmware"
+  ];
+
+  dontStrip = true;
+
+  postInstall = ''
+    # These are lifted from the Arch PKGBUILD
+    # remove files which conflicts with linux-firmware
+    rm -rf $out/lib/firmware/{ct{efx,speq}.bin,ess,korg,sb16,yamaha}
+    # remove broken symlinks (broken upstream)
+    rm -rf $out/lib/firmware/turtlebeach
+    # remove empty dir
+    rm -rf $out/bin
+  '';
+
+  meta = {
+    homepage = http://www.alsa-project.org/;
+    description = "Soundcard firmwares from the alsa project";
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-lib/alsa-plugin-conf-multilib.patch b/nixpkgs/pkgs/os-specific/linux/alsa-lib/alsa-plugin-conf-multilib.patch
new file mode 100644
index 000000000000..b17df9a492e5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-lib/alsa-plugin-conf-multilib.patch
@@ -0,0 +1,232 @@
+diff --git a/src/control/control.c b/src/control/control.c
+index d66ed75..42cecad 100644
+--- a/src/control/control.c
++++ b/src/control/control.c
+@@ -838,6 +838,10 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
+ #ifndef PIC
+ 	extern void *snd_control_open_symbols(void);
+ #endif
++
++	snd_config_t *libs = NULL;
++	const char *libs_lib = NULL;
++
+ 	if (snd_config_get_type(ctl_conf) != SND_CONFIG_TYPE_COMPOUND) {
+ 		if (name)
+ 			SNDERR("Invalid type for CTL %s definition", name);
+@@ -879,6 +883,19 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
+ 					SNDERR("Invalid type for %s", id);
+ 					goto _err;
+ 				}
++
++				continue;
++			}
++			// Handle an array of extra libs.
++			if (strcmp(id, "libs") == 0) {
++				if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
++					SNDERR("Invalid type for libs definition in CTL %s definition",
++						str);
++					goto _err;
++				}
++
++				libs = n;
++
+ 				continue;
+ 			}
+ 			if (strcmp(id, "open") == 0) {
+@@ -903,7 +920,62 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
+ 		open_name = buf;
+ 		sprintf(buf, "_snd_ctl_%s_open", str);
+ 	}
+-	if (!lib) {
++
++#ifndef PIC
++	snd_control_open_symbols();
++#endif
++
++	// Normal alsa behaviour when there is no libs array.
++	if (!libs) {
++		if (lib) {
++			open_func = snd_dlobj_cache_get(lib, open_name,
++				SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 1);
++		}
++	}
++	// Handle libs array.
++	// Suppresses error messages if any function is loaded successfully.
++	else {
++		if (lib) {
++			open_func = snd_dlobj_cache_get(lib, open_name,
++				SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 0);
++		}
++
++		if (!open_func) {
++			snd_config_for_each(i, next, libs) {
++				snd_config_t *n = snd_config_iterator_entry(i);
++
++				err = snd_config_get_string(n, &libs_lib);
++				if (err < 0) {
++					SNDERR("Invalid entry in CTL %s libs definition", str);
++					goto _err;
++				}
++
++				if (!open_func) {
++					open_func = snd_dlobj_cache_get(libs_lib, open_name,
++						SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 0);
++				}
++			}
++		}
++
++		// Print error messages.
++		if (!open_func) {
++			if (lib) {
++				SNDERR("Either %s cannot be opened or %s was not defined inside",
++					lib, open_name);
++			}
++
++			snd_config_for_each(i, next, libs) {
++				snd_config_t *n = snd_config_iterator_entry(i);
++
++				snd_config_get_string(n, &libs_lib);
++				SNDERR("Either %s cannot be opened or %s was not defined inside",
++					libs_lib, open_name);
++			}
++		}
++	}
++
++	// Look in ALSA_PLUGIN_DIR iff we found nowhere else to look.
++	if (!lib && (!libs || !libs_lib)) {
+ 		const char *const *build_in = build_in_ctls;
+ 		while (*build_in) {
+ 			if (!strcmp(*build_in, str))
+@@ -919,12 +991,11 @@ static int snd_ctl_open_conf(snd_ctl_t **ctlp, const char *name,
+ 			lib = buf1;
+ 			sprintf(buf1, "%s/libasound_module_ctl_%s.so", ALSA_PLUGIN_DIR, str);
+ 		}
+-	}
+-#ifndef PIC
+-	snd_control_open_symbols();
+-#endif
+-	open_func = snd_dlobj_cache_get(lib, open_name,
++
++		open_func = snd_dlobj_cache_get(lib, open_name,
+ 			SND_DLSYM_VERSION(SND_CONTROL_DLSYM_VERSION), 1);
++	}
++
+ 	if (open_func) {
+ 		err = open_func(ctlp, name, ctl_root, ctl_conf, mode);
+ 		if (err >= 0) {
+diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c
+index 2e24338..7f489f4 100644
+--- a/src/pcm/pcm.c
++++ b/src/pcm/pcm.c
+@@ -2116,6 +2116,10 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
+ #ifndef PIC
+ 	extern void *snd_pcm_open_symbols(void);
+ #endif
++
++	snd_config_t *libs = NULL;
++	const char *libs_lib = NULL;
++
+ 	if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
+ 		char *val;
+ 		id = NULL;
+@@ -2160,6 +2164,19 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
+ 					SNDERR("Invalid type for %s", id);
+ 					goto _err;
+ 				}
++
++				continue;
++			}
++			// Handle an array of extra libs.
++			if (strcmp(id, "libs") == 0) {
++				if (snd_config_get_type(n) != SND_CONFIG_TYPE_COMPOUND) {
++					SNDERR("Invalid type for libs definition in PCM %s definition",
++						str);
++					goto _err;
++				}
++
++				libs = n;
++
+ 				continue;
+ 			}
+ 			if (strcmp(id, "open") == 0) {
+@@ -2184,7 +2201,62 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
+ 		open_name = buf;
+ 		sprintf(buf, "_snd_pcm_%s_open", str);
+ 	}
+-	if (!lib) {
++
++#ifndef PIC
++	snd_pcm_open_symbols();	/* this call is for static linking only */
++#endif
++
++	// Normal alsa behaviour when there is no libs array.
++	if (!libs) {
++		if (lib) {
++			open_func = snd_dlobj_cache_get(lib, open_name,
++				SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
++		}
++	}
++	// Handle libs array.
++	// Suppresses error messages if any function is loaded successfully.
++	else {
++		if (lib) {
++			open_func = snd_dlobj_cache_get(lib, open_name,
++				SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 0);
++		}
++
++		if (!open_func) {
++			snd_config_for_each(i, next, libs) {
++				snd_config_t *n = snd_config_iterator_entry(i);
++
++				err = snd_config_get_string(n, &libs_lib);
++				if (err < 0) {
++					SNDERR("Invalid entry in PCM %s libs definition", str);
++					goto _err;
++				}
++
++				if (!open_func) {
++					open_func = snd_dlobj_cache_get(libs_lib, open_name,
++						SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 0);
++				}
++			}
++		}
++
++		// Print error messages.
++		if (!open_func) {
++			if (lib) {
++				SNDERR("Either %s cannot be opened or %s was not defined inside",
++					lib, open_name);
++			}
++
++			snd_config_for_each(i, next, libs) {
++				snd_config_t *n = snd_config_iterator_entry(i);
++
++				snd_config_get_string(n, &libs_lib);
++				SNDERR("Either %s cannot be opened or %s was not defined inside",
++					libs_lib, open_name);
++			}
++		}
++	}
++
++	// Look in ALSA_PLUGIN_DIR iff we found nowhere else to look.
++	if (!lib && (!libs || !libs_lib)) {
+ 		const char *const *build_in = build_in_pcms;
+ 		while (*build_in) {
+ 			if (!strcmp(*build_in, str))
+@@ -2200,12 +2272,11 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
+ 			lib = buf1;
+ 			sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str);
+ 		}
+-	}
+-#ifndef PIC
+-	snd_pcm_open_symbols();	/* this call is for static linking only */
+-#endif
+-	open_func = snd_dlobj_cache_get(lib, open_name,
++
++		open_func = snd_dlobj_cache_get(lib, open_name,
+ 			SND_DLSYM_VERSION(SND_PCM_DLSYM_VERSION), 1);
++	}
++
+ 	if (open_func) {
+ 		err = open_func(pcmp, name, pcm_root, pcm_conf, stream, mode);
+ 		if (err >= 0) {
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-lib/default.nix b/nixpkgs/pkgs/os-specific/linux/alsa-lib/default.nix
new file mode 100644
index 000000000000..3c3fbc6e7972
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-lib/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "alsa-lib-1.1.8";
+
+  src = fetchurl {
+    url = "mirror://alsa/lib/${name}.tar.bz2";
+    sha256 = "1pxf0zkmps03l3zzd0fr828xhkg6a8hxljmbxzc2cyj2ls9kmp1w";
+  };
+
+  patches = [
+    ./alsa-plugin-conf-multilib.patch
+  ];
+
+  # Fix pcm.h file in order to prevent some compilation bugs
+  # 2: see http://stackoverflow.com/questions/3103400/how-to-overcome-u-int8-t-vs-uint8-t-issue-efficiently
+  postPatch = ''
+    sed -i -e 's|//int snd_pcm_mixer_element(snd_pcm_t \*pcm, snd_mixer_t \*mixer, snd_mixer_elem_t \*\*elem);|/\*int snd_pcm_mixer_element(snd_pcm_t \*pcm, snd_mixer_t \*mixer, snd_mixer_elem_t \*\*elem);\*/|' include/pcm.h
+
+
+    sed -i -e '1i#include <stdint.h>' include/pcm.h
+    sed -i -e 's/u_int\([0-9]*\)_t/uint\1_t/g' include/pcm.h
+  '';
+
+  outputs = [ "out" "dev" ];
+
+  meta = with stdenv.lib; {
+    homepage = http://www.alsa-project.org/;
+    description = "ALSA, the Advanced Linux Sound Architecture libraries";
+
+    longDescription = ''
+      The Advanced Linux Sound Architecture (ALSA) provides audio and
+      MIDI functionality to the Linux-based operating system.
+    '';
+
+    license = licenses.gpl3Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-oss/default.nix b/nixpkgs/pkgs/os-specific/linux/alsa-oss/default.nix
new file mode 100644
index 000000000000..2b8ef40461d0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-oss/default.nix
@@ -0,0 +1,30 @@
+{stdenv, fetchurl, alsaLib, gettext, ncurses, libsamplerate}:
+
+stdenv.mkDerivation rec {
+  name = "alsa-oss-1.1.6";
+
+  src = fetchurl {
+    url = "mirror://alsa/oss-lib/${name}.tar.bz2";
+    sha256 = "1sj512wyci5qv8cisps96xngh7y9r5mv18ybqnazy18zwr1zgly3";
+  };
+
+  buildInputs = [ alsaLib ncurses libsamplerate ];
+  nativeBuildInputs = [ gettext ];
+
+  configureFlags = [ "--disable-xmlto" ];
+
+  installFlags = "ASOUND_STATE_DIR=$(TMPDIR)/dummy";
+
+  meta = with stdenv.lib; {
+    homepage = http://www.alsa-project.org/;
+    description = "ALSA, the Advanced Linux Sound Architecture alsa-oss emulation";
+
+    longDescription = ''
+      The Advanced Linux Sound Architecture (ALSA) provides audio and
+      MIDI functionality to the Linux-based operating system.
+    '';
+
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-plugins/default.nix b/nixpkgs/pkgs/os-specific/linux/alsa-plugins/default.nix
new file mode 100644
index 000000000000..9012f32f31df
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-plugins/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, lib, pkgconfig, alsaLib, libogg, libpulseaudio ? null, libjack2 ? null }:
+
+stdenv.mkDerivation rec {
+  name = "alsa-plugins-1.1.6";
+
+  src = fetchurl {
+    url = "mirror://alsa/plugins/${name}.tar.bz2";
+    sha256 = "04qcwkisbh0d6lnh0rw1k6n869fbs6zbfq6yvb41rymiwgmk27bg";
+  };
+
+  # ToDo: a52, etc.?
+  buildInputs =
+    [ pkgconfig alsaLib libogg ]
+    ++ lib.optional (libpulseaudio != null) libpulseaudio
+    ++ lib.optional (libjack2 != null) libjack2;
+
+  meta = with lib; {
+    description = "Various plugins for ALSA";
+    homepage = http://alsa-project.org/;
+    license = licenses.lgpl21;
+    maintainers = [maintainers.marcweber];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-plugins/wrapper.nix b/nixpkgs/pkgs/os-specific/linux/alsa-plugins/wrapper.nix
new file mode 100644
index 000000000000..769b6ecd9bf2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-plugins/wrapper.nix
@@ -0,0 +1,5 @@
+{ writeScriptBin, stdenv, alsaPlugins }:
+writeScriptBin "ap${if stdenv.hostPlatform.system == "i686-linux" then "32" else "64"}" ''
+  #${stdenv.shell}
+  ALSA_PLUGIN_DIRS=${alsaPlugins}/lib/alsa-lib "$@"
+''
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/alsa-tools/default.nix
new file mode 100644
index 000000000000..14b10e6752bb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-tools/default.nix
@@ -0,0 +1,54 @@
+{ stdenv, fetchurl, alsaLib, pkgconfig, gtk2, gtk3, fltk13 }:
+# Comes from upstream as as bundle of several tools,
+# some use gtk2, some gtk3 (and some even fltk13).
+
+stdenv.mkDerivation rec {
+  name = "alsa-tools-${version}";
+  version = "1.1.7";
+
+  src = fetchurl {
+    url = "mirror://alsa/tools/${name}.tar.bz2";
+    sha256 = "1xjfghr9s0j6n91kgs95cc4r6qrjsgc4yj2w0nir3xpnm0l36950";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ alsaLib gtk2 gtk3 fltk13 ];
+
+  patchPhase = ''
+    export tools="as10k1 hda-verb hdspmixer echomixer hdajackretask hdspconf hwmixvolume mixartloader rmedigicontrol sscape_ctl vxloader envy24control hdajacksensetest hdsploader ld10k1 pcxhrloader sb16_csp us428control"
+    # export tools="as10k1 hda-verb hdspmixer qlo10k1 seq usx2yloader echomixer hdajackretask hdspconf hwmixvolume mixartloader rmedigicontrol sscape_ctl vxloader envy24control hdajacksensetest hdsploader ld10k1 pcxhrloader sb16_csp us428control"
+  '';
+
+  configurePhase = ''
+    for tool in $tools; do
+      echo "Tool: $tool:"
+      cd "$tool"; ./configure --prefix="$out"; cd -
+    done
+  '';
+
+  buildPhase = ''
+    for tool in $tools; do
+      cd "$tool"; make; cd -
+    done
+  '';
+
+  installPhase = ''
+    for tool in $tools; do
+      cd "$tool"; make install; cd -
+    done
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://www.alsa-project.org/;
+    description = "ALSA, the Advanced Linux Sound Architecture tools";
+
+    longDescription = ''
+      The Advanced Linux Sound Architecture (ALSA) provides audio and
+      MIDI functionality to the Linux-based operating system.
+    '';
+
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.fps ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/alsa-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/alsa-utils/default.nix
new file mode 100644
index 000000000000..2ced9c6094ec
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/alsa-utils/default.nix
@@ -0,0 +1,36 @@
+{stdenv, fetchurl, alsaLib, gettext, ncurses, libsamplerate, pciutils, fftw}:
+
+stdenv.mkDerivation rec {
+  name = "alsa-utils-${version}";
+  version = "1.1.8";
+
+  src = fetchurl {
+    url = "mirror://alsa/utils/${name}.tar.bz2";
+    sha256 = "1kx45yhrxai3k595yyqs4wj0p2n5b0c9mf0k36ljjf1bj8lgb6zx";
+  };
+
+  patchPhase = ''
+    substituteInPlace alsa-info/alsa-info.sh \
+      --replace "which" "type -p" \
+      --replace "lspci" "${pciutils}/bin/lspci"
+  '';
+  nativeBuildInputs = [ gettext ];
+  buildInputs = [ alsaLib ncurses libsamplerate fftw ];
+
+  configureFlags = [ "--disable-xmlto" "--with-udev-rules-dir=$(out)/lib/udev/rules.d" ];
+
+  installFlags = "ASOUND_STATE_DIR=$(TMPDIR)/dummy";
+
+  meta = with stdenv.lib; {
+    homepage = http://www.alsa-project.org/;
+    description = "ALSA, the Advanced Linux Sound Architecture utils";
+    longDescription = ''
+      The Advanced Linux Sound Architecture (ALSA) provides audio and
+      MIDI functionality to the Linux-based operating system.
+    '';
+
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.AndersonTorres ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/default.nix b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/default.nix
new file mode 100644
index 000000000000..b72944a49eb1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/default.nix
@@ -0,0 +1,183 @@
+{ stdenv, fetchurl, elfutils
+, xorg, patchelf, openssl, libdrm, udev
+, libxcb, libxshmfence, epoxy, perl, zlib
+, ncurses
+, libsOnly ? false, kernel ? null
+}:
+
+assert (!libsOnly) -> kernel != null;
+
+with stdenv.lib;
+
+let
+
+  kernelDir = if libsOnly then null else kernel.dev;
+
+  bitness = if stdenv.is64bit then "64" else "32";
+
+  libArch =
+    if stdenv.hostPlatform.system == "i686-linux" then
+      "i386-linux-gnu"
+    else if stdenv.hostPlatform.system == "x86_64-linux" then
+      "x86_64-linux-gnu"
+    else throw "amdgpu-pro is Linux only. Sorry. The build was stopped.";
+
+  libReplaceDir = "/usr/lib/${libArch}";
+
+  ncurses5 = ncurses.override { abiVersion = "5"; };
+
+in stdenv.mkDerivation rec {
+
+  version = "17.40";
+  pname = "amdgpu-pro";
+  build = "${version}-492261";
+
+  libCompatDir = "/run/lib/${libArch}";
+
+  name = pname + "-" + version + (optionalString (!libsOnly) "-${kernelDir.version}");
+
+  src = fetchurl {
+    url =
+    "https://www2.ati.com/drivers/linux/ubuntu/amdgpu-pro-${build}.tar.xz";
+    sha256 = "1c073lp9cq1rc2mddky2r0j2dv9dd167qj02visz37vwaxbm2r5h";
+    curlOpts = "--referer http://support.amd.com/en-us/kb-articles/Pages/AMD-Radeon-GPU-PRO-Linux-Beta-Driver%e2%80%93Release-Notes.aspx";
+  };
+
+  hardeningDisable = [ "pic" "format" ];
+
+  inherit libsOnly;
+
+  postUnpack = ''
+    cd $sourceRoot
+    mkdir root
+    cd root
+    for deb in ../*_all.deb ../*_i386.deb '' + optionalString stdenv.is64bit "../*_amd64.deb" + ''; do echo $deb; ar p $deb data.tar.xz | tar -xJ; done
+    sourceRoot=.
+  '';
+
+  modulePatches = optionals (!libsOnly) ([
+    ./patches/0001-fix-warnings-for-Werror.patch
+    ./patches/0002-fix-sketchy-int-ptr-warning.patch
+    ./patches/0003-disable-firmware-copy.patch
+  ]);
+
+  patchPhase = optionalString (!libsOnly) ''
+    pushd usr/src/amdgpu-${build}
+    for patch in $modulePatches
+    do
+      echo $patch
+      patch -f -p1 < $patch || true
+    done
+    popd
+  '';
+
+  xreallocarray = ./xreallocarray.c;
+
+  preBuild = optionalString (!libsOnly) ''
+    pushd usr/src/amdgpu-${build}
+    makeFlags="$makeFlags M=$(pwd)"
+    patchShebangs pre-build.sh
+    ./pre-build.sh ${kernel.version}
+    popd
+    pushd lib
+    $CC -fPIC -shared -o libhack-xreallocarray.so $xreallocarray
+    strip libhack-xreallocarray.so
+    popd
+  '';
+
+  modules = [
+    "amd/amdgpu/amdgpu.ko"
+    "amd/amdkcl/amdkcl.ko"
+    "ttm/amdttm.ko"
+  ];
+
+  postBuild = optionalString (!libsOnly)
+    (concatMapStrings (m: "xz usr/src/amdgpu-${build}/${m}\n") modules);
+
+  NIX_CFLAGS_COMPILE = "-Werror";
+
+  makeFlags = optionalString (!libsOnly)
+    "-C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build modules";
+
+  depLibPath = makeLibraryPath [
+    stdenv.cc.cc.lib xorg.libXext xorg.libX11 xorg.libXdamage xorg.libXfixes zlib
+    xorg.libXxf86vm libxcb libxshmfence epoxy openssl libdrm elfutils udev ncurses5
+  ];
+
+  installPhase = ''
+    mkdir -p $out
+
+    cp -r etc $out/etc
+    cp -r lib $out/lib
+
+    pushd usr
+    cp -r lib/${libArch}/* $out/lib
+  '' + optionalString (!libsOnly) ''
+    cp -r src/amdgpu-${build}/firmware $out/lib/firmware
+  '' + ''
+    cp -r share $out/share
+    popd
+
+    pushd opt/amdgpu-pro
+  '' + optionalString (!libsOnly && stdenv.is64bit) ''
+    cp -r bin $out/bin
+  '' + ''
+    cp -r include $out/include
+    cp -r share/* $out/share
+    cp -r lib/${libArch}/* $out/lib
+  '' + optionalString (!libsOnly) ''
+    mv lib/xorg $out/lib/xorg
+  '' + ''
+    popd
+
+  '' + optionalString (!libsOnly)
+    (concatMapStrings (m:
+      "install -Dm444 usr/src/amdgpu-${build}/${m}.xz $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/gpu/drm/${m}.xz\n") modules)
+  + ''
+    mv $out/etc/vulkan $out/share
+    interpreter="$(cat $NIX_CC/nix-support/dynamic-linker)"
+    libPath="$out/lib:$out/lib/gbm:$depLibPath"
+  '' + optionalString (!libsOnly && stdenv.is64bit) ''
+    for prog in clinfo modetest vbltest kms-universal-planes kms-steal-crtc modeprint amdgpu_test kmstest proptest; do
+      patchelf --interpreter "$interpreter" --set-rpath "$libPath" "$out/bin/$prog"
+    done
+  '' + ''
+    ln -s ${makeLibraryPath [ncurses5]}/libncursesw.so.5 $out/lib/libtinfo.so.5
+  '';
+
+  # we'll just set the full rpath on everything to avoid having to track down dlopen problems
+  postFixup = assert (stringLength libReplaceDir == stringLength libCompatDir); ''
+    libPath="$out/lib:$out/lib/gbm:$depLibPath"
+    for lib in `find "$out/lib/" -name '*.so*' -type f`; do
+      patchelf --set-rpath "$libPath" "$lib"
+    done
+    for lib in libEGL.so.1 libGL.so.1.2 ${optionalString (!libsOnly) "xorg/modules/extensions/libglx.so"} dri/amdgpu_dri.so libamdocl${bitness}.so; do
+      perl -pi -e 's:${libReplaceDir}:${libCompatDir}:g' "$out/lib/$lib"
+    done
+    for lib in dri/amdgpu_dri.so libdrm_amdgpu.so.1.0.0 libgbm_amdgpu.so.1.0.0 libkms_amdgpu.so.1.0.0 libamdocl${bitness}.so; do
+      perl -pi -e 's:/opt/amdgpu-pro/:/run/amdgpu-pro/:g' "$out/lib/$lib"
+    done
+    substituteInPlace "$out/share/vulkan/icd.d/amd_icd${bitness}.json" --replace "/opt/amdgpu-pro/lib/${libArch}" "$out/lib"
+  '' + optionalString (!libsOnly) ''
+    for lib in drivers/modesetting_drv.so libglamoregl.so; do
+      patchelf --add-needed $out/lib/libhack-xreallocarray.so $out/lib/xorg/modules/$lib
+    done
+  '';
+
+  buildInputs = [
+    patchelf
+    perl
+  ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "AMDGPU-PRO drivers";
+    homepage =  http://support.amd.com/en-us/kb-articles/Pages/AMDGPU-PRO-Beta-Driver-for-Vulkan-Release-Notes.aspx ;
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ corngood ];
+    # Copied from the nvidia default.nix to prevent a store collision.
+    priority = 4;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0001-fix-warnings-for-Werror.patch b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0001-fix-warnings-for-Werror.patch
new file mode 100644
index 000000000000..ecde6401ac18
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0001-fix-warnings-for-Werror.patch
@@ -0,0 +1,71 @@
+From 9167d76c435a7c1df7954f0fbe5cc6d083f8ed2f Mon Sep 17 00:00:00 2001
+From: David McFarland <corngood@gmail.com>
+Date: Mon, 6 Feb 2017 22:13:49 -0400
+Subject: [PATCH 1/3] fix warnings for Werror
+
+---
+ amd/amdgpu/amdgpu_device.c         | 4 ++--
+ amd/amdgpu/amdgpu_sa.c             | 2 +-
+ amd/display/dc/bios/bios_parser2.c | 8 ++++----
+ 3 files changed, 7 insertions(+), 7 deletions(-)
+
+diff --git a/amd/amdgpu/amdgpu_device.c b/amd/amdgpu/amdgpu_device.c
+index fc1c543..186e06d 100644
+--- a/amd/amdgpu/amdgpu_device.c
++++ b/amd/amdgpu/amdgpu_device.c
+@@ -3164,7 +3164,7 @@ void amdgpu_debugfs_cleanup(struct drm_minor *minor)
+ 	struct drm_info_node *node, *tmp;
+ 
+ 	if (!&minor->debugfs_root)
+-		return 0;
++		return;
+ 
+ 	mutex_lock(&minor->debugfs_lock);
+ 	list_for_each_entry_safe(node, tmp,
+@@ -3175,7 +3175,7 @@ void amdgpu_debugfs_cleanup(struct drm_minor *minor)
+ 	}
+ 	mutex_unlock(&minor->debugfs_lock);
+ 
+-	return 0;
++	return;
+ }
+ #endif
+ 
+diff --git a/amd/amdgpu/amdgpu_sa.c b/amd/amdgpu/amdgpu_sa.c
+index 7206b34..8b7123c 100644
+--- a/amd/amdgpu/amdgpu_sa.c
++++ b/amd/amdgpu/amdgpu_sa.c
+@@ -430,7 +430,7 @@ void amdgpu_sa_bo_dump_debug_info(struct amdgpu_sa_manager *sa_manager,
+ 		if (i->fence)
+ #if defined(BUILD_AS_DKMS)
+ 			seq_printf(m, " protected by 0x%08x on context %d",
+-					i->fence->seqno, i->fence->context);
++					i->fence->seqno, (int)i->fence->context);
+ #else
+ 			seq_printf(m, " protected by 0x%08x on context %llu",
+ 				   i->fence->seqno, i->fence->context);
+diff --git a/amd/display/dc/bios/bios_parser2.c b/amd/display/dc/bios/bios_parser2.c
+index 86fce5a..99681c5 100644
+--- a/amd/display/dc/bios/bios_parser2.c
++++ b/amd/display/dc/bios/bios_parser2.c
+@@ -1326,13 +1326,13 @@ static enum bp_result get_embedded_panel_info_v2_1(
+ 	info->lcd_timing.misc_info.VERTICAL_CUT_OFF = 0;
+ 
+ 	info->lcd_timing.misc_info.H_REPLICATION_BY2 =
+-		lvds->lcd_timing.miscinfo & ATOM_H_REPLICATIONBY2;
++		(lvds->lcd_timing.miscinfo & ATOM_H_REPLICATIONBY2) != 0;
+ 	info->lcd_timing.misc_info.V_REPLICATION_BY2 =
+-		lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2;
++		(lvds->lcd_timing.miscinfo & ATOM_V_REPLICATIONBY2) != 0;
+ 	info->lcd_timing.misc_info.COMPOSITE_SYNC =
+-		lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC;
++		(lvds->lcd_timing.miscinfo & ATOM_COMPOSITESYNC) != 0;
+ 	info->lcd_timing.misc_info.INTERLACE =
+-		lvds->lcd_timing.miscinfo & ATOM_INTERLACE;
++		(lvds->lcd_timing.miscinfo & ATOM_INTERLACE) != 0;
+ 
+ 	/* not provided by VBIOS*/
+ 	info->lcd_timing.misc_info.DOUBLE_CLOCK = 0;
+-- 
+2.15.1
+
diff --git a/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0002-fix-sketchy-int-ptr-warning.patch b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0002-fix-sketchy-int-ptr-warning.patch
new file mode 100644
index 000000000000..20f429757a51
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0002-fix-sketchy-int-ptr-warning.patch
@@ -0,0 +1,25 @@
+From a07ee5dec35ca24a013a6638543ef5030b2bab40 Mon Sep 17 00:00:00 2001
+From: David McFarland <corngood@gmail.com>
+Date: Tue, 9 Jan 2018 21:45:33 -0400
+Subject: [PATCH 2/3] fix sketchy int->ptr warning
+
+---
+ amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+index d0f091b..707815a 100644
+--- a/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
++++ b/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+@@ -236,7 +236,7 @@ bool dm_helpers_dp_mst_write_payload_allocation_table(
+ 		pbn = drm_dp_calc_pbn_mode(clock, bpp);
+ 
+ 		slots = drm_dp_find_vcpi_slots(mst_mgr, pbn);
+-		ret = drm_dp_mst_allocate_vcpi(mst_mgr, mst_port, pbn, slots);
++		ret = drm_dp_mst_allocate_vcpi(mst_mgr, mst_port, pbn, &slots);
+ 
+ 		if (!ret)
+ 			return false;
+-- 
+2.15.1
+
diff --git a/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0003-disable-firmware-copy.patch b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0003-disable-firmware-copy.patch
new file mode 100644
index 000000000000..0091c471680c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/patches/0003-disable-firmware-copy.patch
@@ -0,0 +1,25 @@
+From 7a3062acbbabdb29239bbc8c984e62589a88576e Mon Sep 17 00:00:00 2001
+From: David McFarland <corngood@gmail.com>
+Date: Tue, 9 Jan 2018 21:49:55 -0400
+Subject: [PATCH 3/3] disable firmware copy
+
+---
+ pre-build.sh | 5 -----
+ 1 file changed, 5 deletions(-)
+
+diff --git a/pre-build.sh b/pre-build.sh
+index e7b8a32..bad8f25 100755
+--- a/pre-build.sh
++++ b/pre-build.sh
+@@ -38,8 +38,3 @@ find ttm -name '*.c' -exec grep EXPORT_SYMBOL {} + \
+     | sort -u \
+     | awk -F'[()]' '{print "#define "$2" amd"$2" //"$0}'\
+     >> include/rename_symbol.h
+-
+-FW_DIR="/lib/firmware/$KERNELVER"
+-mkdir -p $FW_DIR
+-cp -ar /usr/src/amdgpu-17.40-492261/firmware/radeon $FW_DIR
+-cp -ar /usr/src/amdgpu-17.40-492261/firmware/amdgpu $FW_DIR
+-- 
+2.15.1
+
diff --git a/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/xreallocarray.c b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/xreallocarray.c
new file mode 100644
index 000000000000..ab47bacb8228
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/amdgpu-pro/xreallocarray.c
@@ -0,0 +1,5 @@
+#include <malloc.h>
+
+void *xreallocarray(void *ptr, size_t nmemb, size_t size) {
+  return reallocarray(ptr, nmemb, size);
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/anbox/default.nix b/nixpkgs/pkgs/os-specific/linux/anbox/default.nix
new file mode 100644
index 000000000000..a21a0bb58bd8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/anbox/default.nix
@@ -0,0 +1,138 @@
+{ stdenv, lib, fetchFromGitHub, fetchurl
+, cmake, pkgconfig, dbus, makeWrapper
+, gtest
+, boost
+, libcap
+, systemd
+, mesa
+, libGL
+, libglvnd
+, glib
+, git
+, SDL2
+, SDL2_image
+, properties-cpp
+, protobuf
+, protobufc
+, python
+, lxc
+, writeText
+, writeScript
+, runtimeShell
+}:
+
+let
+
+  dbus-service = writeText "org.anbox.service" ''
+    [D-BUS Service]
+    Name=org.anbox
+    Exec=@out@/libexec/anbox-session-manager
+  '';
+
+  anbox-application-manager = writeScript "anbox-application-manager" ''
+    #!${runtimeShell}
+
+    ${systemd}/bin/busctl --user call \
+        org.freedesktop.DBus \
+        /org/freedesktop/DBus \
+        org.freedesktop.DBus \
+        StartServiceByName "su" org.anbox 0
+
+    @out@/bin/anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity
+  '';
+
+in
+
+stdenv.mkDerivation rec {
+  pname = "anbox";
+  version = "unstable-2019-03-07";
+
+  src = fetchFromGitHub {
+    owner = pname;
+    repo = pname;
+    rev = "d521e282965462e82465045ab95d4ae1c4619685";
+    sha256 = "1wfx4bsyxvrjl16dq5pqgial8rnnsnxzbak2ap0waddz847czxwz";
+  };
+
+  nativeBuildInputs = [
+    makeWrapper
+  ];
+
+  buildInputs = [
+    cmake pkgconfig dbus boost libcap gtest systemd mesa glib
+    SDL2 SDL2_image protobuf protobufc properties-cpp lxc python
+    libGL
+  ];
+
+  patchPhase = ''
+    patchShebangs scripts
+
+    cat >cmake/FindGMock.cmake <<'EOF'
+      add_library(gtest INTERFACE)
+      target_include_directories(gtest INTERFACE ${gtest.dev}/include)
+      target_link_libraries(gtest INTERFACE ${gtest}/lib/libgtest.so ''${CMAKE_THREAD_LIBS_INIT})
+      add_dependencies(gtest GMock)
+
+      add_library(gtest_main INTERFACE)
+      target_include_directories(gtest_main INTERFACE ${gtest.dev}/include)
+      target_link_libraries(gtest_main INTERFACE ${gtest}/lib/libgtest_main.so gtest)
+
+      add_library(gmock INTERFACE)
+      target_include_directories(gmock INTERFACE ${gtest.dev}/include)
+      target_link_libraries(gmock INTERFACE ${gtest}/lib/libgmock.so gtest)
+
+      add_library(gmock_main INTERFACE)
+      target_include_directories(gmock_main INTERFACE ${gtest.dev}/include)
+      target_link_libraries(gmock_main INTERFACE ${gtest}/lib/libgmock_main.so gmock gtest_main)
+
+      set(GTEST_LIBRARIES gtest)
+      set(GTEST_MAIN_LIBRARIES gtest_main)
+      set(GMOCK_LIBRARIES gmock gmock_main)
+      set(GTEST_BOTH_LIBRARIES ''${GTEST_LIBRARIES} ''${GTEST_MAIN_LIBRARIES})
+    EOF
+  '';
+
+  postInstall = ''
+    wrapProgram $out/bin/anbox \
+      --prefix LD_LIBRARY_PATH : ${stdenv.lib.makeLibraryPath [libGL libglvnd]} \
+      --prefix PATH : ${git}/bin
+
+    mkdir -p $out/share/dbus-1/services
+    substitute ${dbus-service} $out/share/dbus-1/services/org.anbox.service \
+      --subst-var out
+
+    mkdir $out/libexec
+    makeWrapper $out/bin/anbox $out/libexec/anbox-session-manager \
+      --add-flags session-manager
+
+    substitute ${anbox-application-manager} $out/bin/anbox-application-manager \
+      --subst-var out
+  '';
+
+  passthru.image = let
+    imgroot = "https://build.anbox.io/android-images";
+  in
+    {
+      armv7l-linux = fetchurl {
+        url = imgroot + "/2017/06/12/android_1_armhf.img";
+        sha256 = "1za4q6vnj8wgphcqpvyq1r8jg6khz7v6b7h6ws1qkd5ljangf1w5";
+      };
+      aarch64-linux = fetchurl {
+        url = imgroot + "/2017/08/04/android_1_arm64.img";
+        sha256 = "02yvgpx7n0w0ya64y5c7bdxilaiqj9z3s682l5s54vzfnm5a2bg5";
+      };
+      x86_64-linux = fetchurl {
+        url = imgroot + "/2018/07/19/android_amd64.img";
+        sha256 = "1jlcda4q20w30cm9ikm6bjq01p547nigik1dz7m4v0aps4rws13b";
+      };
+    }.${stdenv.system} or null;
+
+  meta = with stdenv.lib; {
+    homepage = https://anbox.io;
+    description = "Android in a box";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ edwtjo ];
+    platforms = [ "armv7l-linux" "aarch64-linux" "x86_64-linux" ];
+  };
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/anbox/kmod.nix b/nixpkgs/pkgs/os-specific/linux/anbox/kmod.nix
new file mode 100644
index 000000000000..8a102996cab6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/anbox/kmod.nix
@@ -0,0 +1,43 @@
+{ stdenv, lib, kernel, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "anbox-modules";
+  version = "2018-09-08-" + kernel.version;
+
+  src = fetchFromGitHub {
+    owner = "anbox";
+    repo = "anbox-modules";
+    rev = "27fd47e11ef6eef93738f8f3df3e42c88975544e";
+    sha256 = "1hnf5x5swjcws6mnxmd3byll8l7qsxxj9pgki2k31rbmqqf2sb0x";
+  };
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  KERNEL_SRC="${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
+
+  buildPhase = ''
+    for d in ashmem binder;do
+      cd $d
+      make
+      cd -
+    done
+  '';
+
+  installPhase = ''
+    modDir=$out/lib/modules/${kernel.modDirVersion}/kernel/updates/
+    mkdir -p $modDir
+    for d in ashmem binder;do
+      mv $d/$d*.ko $modDir/.
+    done
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Anbox ashmem and binder drivers.";
+    homepage = https://github.com/anbox/anbox-modules;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    broken = (versionOlder kernel.version "4.4") || (kernel.features.grsecurity);
+    maintainers = with maintainers; [ edwtjo ];
+  };
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/android-udev-rules/default.nix b/nixpkgs/pkgs/os-specific/linux/android-udev-rules/default.nix
new file mode 100644
index 000000000000..bfacdd4a2f42
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/android-udev-rules/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchFromGitHub }:
+
+## Usage
+# In NixOS, simply add this package to services.udev.packages:
+#   services.udev.packages = [ pkgs.android-udev-rules ];
+
+stdenv.mkDerivation rec {
+  name = "android-udev-rules-${version}";
+  version = "20190114";
+
+  src = fetchFromGitHub {
+    owner = "M0Rf30";
+    repo = "android-udev-rules";
+    rev = version;
+    sha256 = "1x3vaq8jpnfhxc2lzz5jnlz219w66sn151v5fkdgv68pya4nzhjj";
+  };
+
+  installPhase = ''
+    install -D 51-android.rules $out/lib/udev/rules.d/51-android.rules
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/M0Rf30/android-udev-rules;
+    description = "Android udev rules list aimed to be the most comprehensive on the net";
+    platforms = platforms.linux;
+    license = licenses.gpl3;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/apparmor/default.nix b/nixpkgs/pkgs/os-specific/linux/apparmor/default.nix
new file mode 100644
index 000000000000..6cb0c123406e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/apparmor/default.nix
@@ -0,0 +1,254 @@
+{ stdenv, lib, fetchurl, fetchpatch, makeWrapper, autoreconfHook
+, pkgconfig, which
+, flex, bison
+, linuxHeaders ? stdenv.cc.libc.linuxHeaders
+, gawk
+, withPerl ? stdenv.hostPlatform == stdenv.buildPlatform && lib.any (lib.meta.platformMatch stdenv.hostPlatform) perl.meta.platforms, perl
+, withPython ? stdenv.hostPlatform == stdenv.buildPlatform && lib.any (lib.meta.platformMatch stdenv.hostPlatform) python.meta.platforms, python
+, swig
+, ncurses
+, pam
+, libnotify
+, buildPackages
+}:
+
+let
+  apparmor-series = "2.13";
+  apparmor-patchver = "1";
+  apparmor-version = apparmor-series + "." + apparmor-patchver;
+
+  apparmor-meta = component: with stdenv.lib; {
+    homepage = http://apparmor.net/;
+    description = "A mandatory access control system - ${component}";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ phreedom thoughtpolice joachifm ];
+    platforms = platforms.linux;
+  };
+
+  apparmor-sources = fetchurl {
+    url = "https://launchpad.net/apparmor/${apparmor-series}/${apparmor-version}/+download/apparmor-${apparmor-version}.tar.gz";
+    sha256 = "7a060d94c275e59f96bacd1da150e6fee2c9152a85bf57800109d07d51ef8afb";
+  };
+
+  prePatchCommon = ''
+    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${buildPackages.perl}/bin/pod2man"
+    substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${buildPackages.perl}/bin/pod2html"
+    substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${linuxHeaders}/include/linux/capability.h"
+    substituteInPlace ./common/Make.rules --replace "/usr/share/man" "share/man"
+  '';
+
+  patches = stdenv.lib.optionals stdenv.hostPlatform.isMusl [
+    (fetchpatch {
+      url = "https://git.alpinelinux.org/cgit/aports/plain/testing/apparmor/0003-Added-missing-typedef-definitions-on-parser.patch?id=74b8427cc21f04e32030d047ae92caa618105b53";
+      name = "0003-Added-missing-typedef-definitions-on-parser.patch";
+      sha256 = "0yyaqz8jlmn1bm37arggprqz0njb4lhjni2d9c8qfqj0kll0bam0";
+    })
+    (fetchpatch {
+      url = "https://git.alpinelinux.org/cgit/aports/plain/testing/apparmor/0007-Do-not-build-install-vim-file-with-utils-package.patch?id=74b8427cc21f04e32030d047ae92caa618105b53";
+      name = "0007-Do-not-build-install-vim-file-with-utils-package.patch";
+      sha256 = "1m4dx901biqgnr4w4wz8a2z9r9dxyw7wv6m6mqglqwf2lxinqmp4";
+    })
+    # (alpine patches {1,4,5,6,8} are needed for apparmor 2.11, but not 2.12)
+  ];
+
+  # Set to `true` after the next FIXME gets fixed or this gets some
+  # common derivation infra. Too much copy-paste to fix one by one.
+  doCheck = false;
+
+  # FIXME: convert these to a single multiple-outputs package?
+
+  libapparmor = stdenv.mkDerivation {
+    name = "libapparmor-${apparmor-version}";
+    src = apparmor-sources;
+
+    nativeBuildInputs = [
+      autoreconfHook
+      bison
+      flex
+      pkgconfig
+      swig
+      ncurses
+      which
+      perl
+    ];
+
+    buildInputs = []
+      ++ stdenv.lib.optional withPerl perl
+      ++ stdenv.lib.optional withPython python;
+
+    # required to build apparmor-parser
+    dontDisableStatic = true;
+
+    prePatch = prePatchCommon + ''
+      substituteInPlace ./libraries/libapparmor/swig/perl/Makefile.am --replace install_vendor install_site
+      substituteInPlace ./libraries/libapparmor/swig/perl/Makefile.in --replace install_vendor install_site
+      substituteInPlace ./libraries/libapparmor/src/Makefile.am --replace "/usr/include/netinet/in.h" "${stdenv.cc.libc.dev}/include/netinet/in.h"
+      substituteInPlace ./libraries/libapparmor/src/Makefile.in --replace "/usr/include/netinet/in.h" "${stdenv.cc.libc.dev}/include/netinet/in.h"
+    '';
+    inherit patches;
+
+    postPatch = "cd ./libraries/libapparmor";
+    # https://gitlab.com/apparmor/apparmor/issues/1
+    configureFlags = [
+      (stdenv.lib.withFeature withPerl "perl")
+      (stdenv.lib.withFeature withPython "python")
+    ];
+
+    outputs = [ "out" ] ++ stdenv.lib.optional withPython "python";
+
+    postInstall = stdenv.lib.optionalString withPython ''
+      mkdir -p $python/lib
+      mv $out/lib/python* $python/lib/
+    '';
+
+    inherit doCheck;
+
+    meta = apparmor-meta "library";
+  };
+
+  apparmor-utils = stdenv.mkDerivation {
+    name = "apparmor-utils-${apparmor-version}";
+    src = apparmor-sources;
+
+    nativeBuildInputs = [ makeWrapper which ];
+
+    buildInputs = [
+      perl
+      python
+      libapparmor
+      libapparmor.python
+    ];
+
+    prePatch = prePatchCommon;
+    inherit patches;
+    postPatch = "cd ./utils";
+    makeFlags = ''LANGS='';
+    installFlags = ''DESTDIR=$(out) BINDIR=$(out)/bin VIM_INSTALL_PATH=$(out)/share PYPREFIX='';
+
+    postInstall = ''
+      for prog in aa-audit aa-autodep aa-cleanprof aa-complain aa-disable aa-enforce aa-genprof aa-logprof aa-mergeprof aa-status aa-unconfined ; do
+        wrapProgram $out/bin/$prog --prefix PYTHONPATH : "$out/lib/${python.libPrefix}/site-packages:$PYTHONPATH"
+      done
+
+      substituteInPlace $out/bin/aa-notify --replace /usr/bin/notify-send ${libnotify}/bin/notify-send
+      # aa-notify checks its name and does not work named ".aa-notify-wrapped"
+      mv $out/bin/aa-notify $out/bin/aa-notify-wrapped
+      makeWrapper ${perl}/bin/perl $out/bin/aa-notify --set PERL5LIB ${libapparmor}/${perl.libPrefix} --add-flags $out/bin/aa-notify-wrapped
+    '';
+
+    inherit doCheck;
+
+    meta = apparmor-meta "user-land utilities" // {
+      broken = !(withPython && withPerl);
+    };
+  };
+
+  apparmor-bin-utils = stdenv.mkDerivation {
+    name = "apparmor-bin-utils-${apparmor-version}";
+    src = apparmor-sources;
+
+    nativeBuildInputs = [
+      pkgconfig
+      libapparmor
+      gawk
+      which
+    ];
+
+    buildInputs = [
+      libapparmor
+    ];
+
+    prePatch = prePatchCommon;
+    postPatch = "cd ./binutils";
+    makeFlags = ''LANGS= USE_SYSTEM=1'';
+    installFlags = ''DESTDIR=$(out) BINDIR=$(out)/bin'';
+
+    inherit doCheck;
+
+    meta = apparmor-meta "binary user-land utilities";
+  };
+
+  apparmor-parser = stdenv.mkDerivation {
+    name = "apparmor-parser-${apparmor-version}";
+    src = apparmor-sources;
+
+    nativeBuildInputs = [ bison flex which ];
+
+    buildInputs = [ libapparmor ];
+
+    prePatch = prePatchCommon + ''
+      substituteInPlace ./parser/Makefile --replace "/usr/bin/bison" "${bison}/bin/bison"
+      substituteInPlace ./parser/Makefile --replace "/usr/bin/flex" "${flex}/bin/flex"
+      substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${linuxHeaders}/include/linux/capability.h"
+      ## techdoc.pdf still doesn't build ...
+      substituteInPlace ./parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages"
+    '';
+    inherit patches;
+    postPatch = "cd ./parser";
+    makeFlags = ''LANGS= USE_SYSTEM=1 INCLUDEDIR=${libapparmor}/include'';
+    installFlags = ''DESTDIR=$(out) DISTRO=unknown'';
+
+    inherit doCheck;
+
+    meta = apparmor-meta "rule parser";
+  };
+
+  apparmor-pam = stdenv.mkDerivation {
+    name = "apparmor-pam-${apparmor-version}";
+    src = apparmor-sources;
+
+    nativeBuildInputs = [ pkgconfig which ];
+
+    buildInputs = [ libapparmor pam ];
+
+    postPatch = "cd ./changehat/pam_apparmor";
+    makeFlags = ''USE_SYSTEM=1'';
+    installFlags = ''DESTDIR=$(out)'';
+
+    inherit doCheck;
+
+    meta = apparmor-meta "PAM service";
+  };
+
+  apparmor-profiles = stdenv.mkDerivation {
+    name = "apparmor-profiles-${apparmor-version}";
+    src = apparmor-sources;
+
+    nativeBuildInputs = [ which ];
+
+    postPatch = "cd ./profiles";
+    installFlags = ''DESTDIR=$(out) EXTRAS_DEST=$(out)/share/apparmor/extra-profiles'';
+
+    inherit doCheck;
+
+    meta = apparmor-meta "profiles";
+  };
+
+  apparmor-kernel-patches = stdenv.mkDerivation {
+    name = "apparmor-kernel-patches-${apparmor-version}";
+    src = apparmor-sources;
+
+    phases = ''unpackPhase installPhase'';
+
+    installPhase = ''
+      mkdir "$out"
+      cp -R ./kernel-patches/* "$out"
+    '';
+
+    inherit doCheck;
+
+    meta = apparmor-meta "kernel patches";
+  };
+
+in
+
+{
+  inherit
+    libapparmor
+    apparmor-utils
+    apparmor-bin-utils
+    apparmor-parser
+    apparmor-pam
+    apparmor-profiles
+    apparmor-kernel-patches;
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/builder.sh b/nixpkgs/pkgs/os-specific/linux/ati-drivers/builder.sh
new file mode 100644
index 000000000000..f6ad8e2c03b6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/builder.sh
@@ -0,0 +1,302 @@
+# TODO gentoo removes some tools because there are xorg sources (?)
+
+source $stdenv/setup
+set -x
+
+die(){ echo $@; exit 1; }
+
+unzip $src
+run_file=fglrx-$build/amd-driver-installer-$build-x86.x86_64.run
+sh $run_file --extract .
+
+for patch in $patches;do
+    patch -p1 < $patch
+done
+
+case "$system" in
+  x86_64-linux)
+    arch=x86_64
+    lib_arch=lib64
+    DIR_DEPENDING_ON_XORG_VERSION=xpic_64a
+  ;;
+  i686-linux)
+    arch=x86
+    lib_arch=lib
+    DIR_DEPENDING_ON_XORG_VERSION=xpic
+  ;;
+  *) exit 1;;
+esac
+
+# Handle/Build the kernel module.
+
+if test -z "$libsOnly"; then
+
+  kernelVersion=$(cd ${kernelDir}/lib/modules && ls)
+  kernelBuild=$(echo ${kernelDir}/lib/modules/$kernelVersion/build)
+  linuxsources=$(echo ${kernelDir}/lib/modules/$kernelVersion/source)
+
+  # note: maybe the .config file should be used to determine this ?
+  # current kbuild infrastructure allows using CONFIG_* defines
+  # but ati sources don't use them yet..
+  # copy paste from make.sh
+
+  setSMP(){
+
+    linuxincludes=$kernelBuild/include
+
+    # copied and stripped. source: make.sh:
+    # 3
+    # linux/autoconf.h may contain this: #define CONFIG_SMP 1
+
+    # Before 2.6.33 autoconf.h is under linux/.
+    # For 2.6.33 and later autoconf.h is under generated/.
+    if [ -f $linuxincludes/generated/autoconf.h ]; then
+        autoconf_h=$linuxincludes/generated/autoconf.h
+    else
+        autoconf_h=$linuxincludes/linux/autoconf.h
+    fi
+    src_file=$autoconf_h
+
+    [ -e $src_file ] || die "$src_file not found"
+
+    if [ `cat $src_file | grep "#undef" | grep "CONFIG_SMP" -c` = 0 ]; then
+      SMP=`cat $src_file | grep CONFIG_SMP | cut -d' ' -f3`
+      echo "file $src_file says: SMP=$SMP"
+    fi
+
+    if [ "$SMP" = 0 ]; then
+      echo "assuming default: SMP=$SMP"
+    fi
+    # act on final result
+    if [ ! "$SMP" = 0 ]; then
+      smp="-SMP"
+      def_smp=-D__SMP__
+    fi
+
+  }
+
+  setModVersions(){
+    ! grep CONFIG_MODVERSIONS=y $kernelBuild/.config ||
+    def_modversions="-DMODVERSIONS"
+    # make.sh contains much more code to determine this whether its enabled
+  }
+
+  # ==============================================================
+  # resolve if we are building for a kernel with a fix for CVE-2010-3081
+  # On kernels with the fix, use arch_compat_alloc_user_space instead
+  # of compat_alloc_user_space since the latter is GPL-only
+
+  COMPAT_ALLOC_USER_SPACE=arch_compat_alloc_user_space
+
+  for src_file in \
+    $kernelBuild/arch/x86/include/asm/compat.h \
+    $linuxsources/arch/x86/include/asm/compat.h \
+    $kernelBuild/include/asm-x86_64/compat.h \
+    $linuxsources/include/asm-x86_64/compat.h \
+    $kernelBuild/include/asm/compat.h;
+  do
+    if [ -e $src_file ];
+    then
+      break
+    fi
+  done
+  if [ ! -e $src_file ];
+    then
+    echo "Warning: x86 compat.h not found in kernel headers"
+    echo "neither arch/x86/include/asm/compat.h nor include/asm-x86_64/compat.h"
+    echo "could be found in $kernelBuild or $linuxsources"
+    echo ""
+  else
+    if [ `cat $src_file | grep -c arch_compat_alloc_user_space` -gt 0 ]
+    then
+      COMPAT_ALLOC_USER_SPACE=arch_compat_alloc_user_space
+    fi
+    echo "file $src_file says: COMPAT_ALLOC_USER_SPACE=$COMPAT_ALLOC_USER_SPACE"
+  fi
+
+  # make.sh contains some code figuring out whether to use these or not..
+  PAGE_ATTR_FIX=0
+  setSMP
+  setModVersions
+  CC=gcc
+  MODULE=fglrx
+  LIBIP_PREFIX=$TMP/arch/$arch/lib/modules/fglrx/build_mod
+  [ -d $LIBIP_PREFIX ]
+  GCC_MAJOR="`gcc --version | grep -o -e ") ." | head -1 | cut -d " " -f 2`"
+
+  { # build .ko module
+    cd ./common/lib/modules/fglrx/build_mod/2.6.x
+    echo .lib${MODULE}_ip.a.GCC${GCC_MAJOR}.cmd
+    echo 'This is a dummy file created to suppress this warning: could not find /lib/modules/fglrx/build_mod/2.6.x/.libfglrx_ip.a.GCC4.cmd for /lib/modules/fglrx/build_mod/2.6.x/libfglrx_ip.a.GCC4' > lib${MODULE}_ip.a.GCC${GCC_MAJOR}.cmd
+
+    sed -i -e "s@COMPAT_ALLOC_USER_SPACE@$COMPAT_ALLOC_USER_SPACE@" ../kcl_ioctl.c
+
+    make CC=${CC} \
+      LIBIP_PREFIX=$(echo "$LIBIP_PREFIX" | sed -e 's|^\([^/]\)|../\1|') \
+      MODFLAGS="-DMODULE -DATI -DFGL -DPAGE_ATTR_FIX=$PAGE_ATTR_FIX -DCOMPAT_ALLOC_USER_SPACE=$COMPAT_ALLOC_USER_SPACE $def_smp $def_modversions" \
+      KVER=$kernelVersion \
+      KDIR=$kernelBuild \
+      PAGE_ATTR_FIX=$PAGE_ATTR_FIX \
+      -j4
+
+    cd $TMP
+  }
+
+fi
+
+{ # install
+  mkdir -p $out/lib/xorg
+  cp -r common/usr/include $out
+  cp -r common/usr/sbin $out
+  cp -r common/usr/share $out
+  mkdir $out/bin/
+  cp -f common/usr/X11R6/bin/* $out/bin/
+  # cp -r arch/$arch/lib $out/lib
+  # what are those files used for?
+  cp -r common/etc $out
+  cp -r $DIR_DEPENDING_ON_XORG_VERSION/usr/X11R6/$lib_arch/* $out/lib/xorg
+
+  # install kernel module
+  if test -z "$libsOnly"; then
+    t=$out/lib/modules/${kernelVersion}/kernel/drivers/misc
+    mkdir -p $t
+
+    cp ./common/lib/modules/fglrx/build_mod/2.6.x/fglrx.ko $t
+  fi
+
+  # should this be installed at all?
+  # its used by the example fglrx_gamma only
+  # don't use $out/lib/modules/dri because this will cause the kernel module
+  # aggregator code to see both: kernel version and the dri direcotry. It'll
+  # fail saying different kernel versions
+  cp -r $TMP/arch/$arch/usr/X11R6/$lib_arch/modules/dri $out/lib
+  cp -r $TMP/arch/$arch/usr/X11R6/$lib_arch/modules/dri/* $out/lib
+  cp -r $TMP/arch/$arch/usr/X11R6/$lib_arch/*.so* $out/lib
+  cp -r $TMP/arch/$arch/usr/X11R6/$lib_arch/fglrx/fglrx-libGL.so.1.2 $out/lib/fglrx-libGL.so.1.2
+  cp -r $TMP/arch/$arch/usr/$lib_arch/* $out/lib
+  ln -s libatiuki.so.1.0 $out/lib/libatiuki.so.1
+  ln -s fglrx-libGL.so.1.2 $out/lib/libGL.so.1
+  ln -s fglrx-libGL.so.1.2 $out/lib/libGL.so
+  # FIXME : This file is missing or has changed versions
+  #ln -s libfglrx_gamma.so.1.0 $out/lib/libfglrx_gamma.so.1
+  # make xorg use the ati version
+  ln -s $out/lib/xorg/modules/extensions/{fglrx/fglrx-libglx.so,libglx.so}
+  # Correct some paths that are hardcoded into binary libs.
+  if [ "$arch" ==  "x86_64" ]; then
+    for lib in \
+      xorg/modules/extensions/fglrx/fglrx-libglx.so \
+      xorg/modules/glesx.so \
+      dri/fglrx_dri.so \
+      fglrx_dri.so \
+      fglrx-libGL.so.1.2
+    do
+      oldPaths="/usr/X11R6/lib/modules/dri"
+      newPaths="/run/opengl-driver/lib/dri"
+      sed -i -e "s|$oldPaths|$newPaths|" $out/lib/$lib
+    done
+  else
+    oldPaths="/usr/X11R6/lib32/modules/dri\x00/usr/lib32/dri"
+    newPaths="/run/opengl-driver-32/lib/dri\x00/dev/null/dri"
+    sed -i -e "s|$oldPaths|$newPaths|" \
+      $out/lib/xorg/modules/extensions/fglrx/fglrx-libglx.so
+
+    for lib in \
+      dri/fglrx_dri.so \
+      fglrx_dri.so \
+      xorg/modules/glesx.so
+    do
+      oldPaths="/usr/X11R6/lib32/modules/dri/"
+      newPaths="/run/opengl-driver-32/lib/dri"
+      sed -i -e "s|$oldPaths|$newPaths|" $out/lib/$lib
+    done
+
+    oldPaths="/usr/X11R6/lib32/modules/dri\x00"
+    newPaths="/run/opengl-driver-32/lib/dri"
+    sed -i -e "s|$oldPaths|$newPaths|" $out/lib/fglrx-libGL.so.1.2
+  fi
+  # libstdc++ and gcc are needed by some libs
+  for pelib1 in \
+    fglrx_dri.so \
+    dri/fglrx_dri.so
+  do
+    patchelf --remove-needed libX11.so.6 $out/lib/$pelib1
+  done
+
+  for pelib2 in \
+    libatiadlxx.so \
+    xorg/modules/glesx.so \
+    dri/fglrx_dri.so \
+    fglrx_dri.so \
+    libaticaldd.so
+  do
+    patchelf --set-rpath $glibcDir/lib/:$libStdCxx/lib/ $out/lib/$pelib2
+  done
+}
+
+if test -z "$libsOnly"; then
+
+{ # build samples
+  mkdir -p $out/bin
+  mkdir -p samples
+  cd samples
+  tar xfz ../common/usr/src/ati/fglrx_sample_source.tgz
+  eval "$patchPhaseSamples"
+
+
+  ( # build and install fgl_glxgears
+    cd fgl_glxgears;
+    gcc -DGL_ARB_texture_multisample=1 -g \
+    -I$libGLU_combined/include \
+    -I$out/include \
+    -L$libGLU_combined/lib -lGL -lGLU -lX11 -lm \
+    -o $out/bin/fgl_glxgears -Wall fgl_glxgears.c
+  )
+
+  true || ( # build and install
+
+    ###
+    ## FIXME ?
+    # doesn't build  undefined reference to `FGLRX_X11SetGamma'
+    # which should be contained in -lfglrx_gamma
+    # This should create $out/lib/libfglrx_gamma.so.1.0 ? because there is
+    # a symlink named libfglrx_gamma.so.1 linking to libfglrx_gamma.so.1.0 in $out/lib/
+
+    cd programs/fglrx_gamma
+    gcc -fPIC -I${libXxf86vm.dev}/include \
+      -I${xorgproto}/include \
+      -I$out/X11R6/include \
+      -L$out/lib \
+      -Wall -lm -lfglrx_gamma -lX11 -lXext -o $out/bin/fglrx_xgamma fglrx_xgamma.c
+  )
+
+  {
+    # patch and copy statically linked qt libs used by amdcccle
+    patchelf --set-interpreter $(echo $glibcDir/lib/ld-linux*.so.2) $TMP/arch/$arch/usr/share/ati/$lib_arch/libQtCore.so.4 &&
+    patchelf  --set-rpath $gcc/$lib_arch/ $TMP/arch/$arch/usr/share/ati/$lib_arch/libQtCore.so.4 &&
+    patchelf --set-rpath $gcc/$lib_arch/:$out/share/ati/:$libXrender/lib/:$libSM/lib/:$libICE/lib/:$libfontconfig/lib/:$libfreetype/lib/ $TMP/arch/$arch/usr/share/ati/$lib_arch/libQtGui.so.4 &&
+    mkdir -p $out/share/ati
+    cp -r $TMP/arch/$arch/usr/share/ati/$lib_arch/libQtCore.so.4 $out/share/ati/
+    cp -r $TMP/arch/$arch/usr/share/ati/$lib_arch/libQtGui.so.4 $out/share/ati/
+    # copy binaries and wrap them:
+    BIN=$TMP/arch/$arch/usr/X11R6/bin
+    patchelf --set-rpath $gcc/$lib_arch/:$out/share/ati/:$libXinerama/lib/:$libXrandr/lib/ $TMP/arch/$arch/usr/X11R6/bin/amdcccle
+    patchelf --set-rpath $libXrender/lib/:$libXrandr/lib/ $TMP/arch/$arch/usr/X11R6/bin/aticonfig
+    patchelf --shrink-rpath $BIN/amdcccle
+    for prog in $BIN/*; do
+      cp -f $prog $out/bin &&
+      patchelf --set-interpreter $(echo $glibcDir/lib/ld-linux*.so.2) $out/bin/$(basename $prog) &&
+      wrapProgram $out/bin/$(basename $prog) --prefix LD_LIBRARY_PATH : $out/lib/:$gcc/lib/:$out/share/ati/:$libXinerama/lib/:$libXrandr/lib/:$libfontconfig/lib/:$libfreetype/lib/:$LD_LIBRARY_PATH
+    done
+  }
+
+  rm -f $out/lib/fglrx/switchlibglx && rm -f $out/lib/fglrx/switchlibGL
+
+}
+
+fi
+
+for p in $extraDRIlibs; do
+  for lib in $p/lib/*.so*; do
+    ln -s $lib $out/lib/
+  done
+done
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/default.nix b/nixpkgs/pkgs/os-specific/linux/ati-drivers/default.nix
new file mode 100644
index 000000000000..b79054d44065
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/default.nix
@@ -0,0 +1,140 @@
+{ stdenv, lib, fetchurl, kernel ? null, which
+, xorg, makeWrapper, glibc, patchelf, unzip
+, fontconfig, freetype, libGLU_combined # for fgl_glxgears
+, # Whether to build the libraries only (i.e. not the kernel module or
+  # driver utils). Used to support 32-bit binaries on 64-bit
+  # Linux.
+  libsOnly ? false
+}:
+
+assert (!libsOnly) -> kernel != null;
+
+with stdenv.lib;
+
+# This derivation requires a maximum of gcc49, Linux kernel 4.1 and xorg.xserver 1.17
+# and will not build or run using versions newer
+
+# If you want to use a different Xorg version probably
+# DIR_DEPENDING_ON_XORG_VERSION in builder.sh has to be adopted (?)
+# make sure libglx.so of ati is used. xorg.xorgserver does provide it as well
+# which is a problem because it doesn't contain the xorgserver patch supporting
+# the XORG_DRI_DRIVER_PATH env var.
+# See https://marc.info/?l=nix-dev&m=139641585515351 for a
+# workaround (TODO)
+
+# The gentoo ebuild contains much more "magic" and is usually a great resource to
+# find patches XD
+
+# http://wiki.cchtml.com/index.php/Main_Page
+
+# /usr/lib/dri/fglrx_dri.so must point to /run/opengl-driver/lib/fglrx_dri.so
+# This is done in the builder script.
+
+stdenv.mkDerivation rec {
+
+  version = "15.12";
+  pname = "ati-drivers";
+  build = "15.302";
+
+  linuxonly =
+    if stdenv.hostPlatform.system == "i686-linux" then
+      true
+    else if stdenv.hostPlatform.system == "x86_64-linux" then
+      true
+    else throw "ati-drivers are Linux only. Sorry. The build was stopped.";
+
+  name = pname + "-" + version + (optionalString (!libsOnly) "-${kernelDir.version}");
+
+  builder = ./builder.sh;
+  gcc = stdenv.cc.cc;
+  libXinerama = xorg.libXinerama;
+  libXrandr = xorg.libXrandr;
+  libXrender = xorg.libXrender;
+  libXxf86vm = xorg.libXxf86vm;
+  xorgproto = xorg.xorgproto;
+  libSM = xorg.libSM;
+  libICE = xorg.libICE;
+  libfreetype = freetype;
+  libfontconfig = fontconfig;
+  libStdCxx = stdenv.cc.cc.lib;
+
+  src = fetchurl {
+    url =
+    "https://www2.ati.com/drivers/linux/radeon-crimson-15.12-15.302-151217a-297685e.zip";
+    sha256 = "704f2dfc14681f76dae3b4120c87b1ded33cf43d5a1d800b6de5ca292bb61e58";
+    curlOpts = "--referer https://www.amd.com/en/support";
+  };
+
+  hardeningDisable = [ "pic" "format" ];
+
+  patchPhaseSamples = "patch -p2 < ${./patches/patch-samples.patch}";
+  patches = [
+    ./patches/15.12-xstate-fp.patch
+    ./patches/15.9-kcl_str.patch
+    ./patches/15.9-mtrr.patch
+    ./patches/15.9-preempt.patch
+    ./patches/15.9-sep_printf.patch ]
+  ++ optionals ( kernel != null &&
+                 (lib.versionAtLeast kernel.version "4.6") )
+               [ ./patches/kernel-4.6-get_user_pages.patch
+                 ./patches/kernel-4.6-page_cache_release-put_page.patch ]
+  ++ optionals ( kernel != null &&
+                 (lib.versionAtLeast kernel.version "4.7") )
+               [ ./patches/4.7-arch-cpu_has_pge-v2.patch ]
+  ++ optionals ( kernel != null &&
+                 (lib.versionAtLeast kernel.version "4.9") )
+               [ ./patches/4.9-get_user_pages.patch ];
+
+  buildInputs =
+    [ xorg.libXrender xorg.libXext xorg.libX11 xorg.libXinerama xorg.libSM
+      xorg.libXrandr xorg.libXxf86vm xorg.xorgproto xorg.imake xorg.libICE
+      patchelf
+      unzip
+      libGLU_combined
+      fontconfig
+      freetype
+      makeWrapper
+      which
+    ];
+
+  inherit libsOnly;
+
+  kernelDir = if libsOnly then null else kernel.dev;
+
+  # glibc only used for setting the binaries interpreter
+  glibcDir = glibc.out;
+
+  # outputs TODO: probably many fixes are needed;
+  LD_LIBRARY_PATH = makeLibraryPath
+    [ xorg.libXrender xorg.libXext xorg.libX11 xorg.libXinerama xorg.libSM
+      xorg.libXrandr xorg.libXxf86vm xorg.xorgproto xorg.imake xorg.libICE
+      libGLU_combined
+      fontconfig
+      freetype
+      stdenv.cc.cc
+    ];
+
+  # without this some applications like blender don't start, but they start
+  # with nvidia. This causes them to be symlinked to $out/lib so that they
+  # appear in /run/opengl-driver/lib which get's added to LD_LIBRARY_PATH
+
+  extraDRIlibs = [ xorg.libXrandr.out xorg.libXrender.out xorg.libXext.out
+                   xorg.libX11.out xorg.libXinerama.out xorg.libSM.out
+                   xorg.libICE.out ];
+
+  inherit libGLU_combined; # only required to build the examples
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "ATI Catalyst display drivers";
+    homepage = http://support.amd.com/us/gpudownload/Pages/index.aspx;
+    license = licenses.unfree;
+    maintainers = with maintainers; [ marcweber offline jerith666 ];
+    platforms = platforms.linux;
+    hydraPlatforms = [];
+    # Copied from the nvidia default.nix to prevent a store collision.
+    priority = 4;
+  };
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.12-xstate-fp.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.12-xstate-fp.patch
new file mode 100644
index 000000000000..22e43fc0c7b6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.12-xstate-fp.patch
@@ -0,0 +1,26 @@
+From: Krzysztof Kolasa <kkolasa@winsoft.pl>
+Date: Thu, 26 Nov 2015 14:28:46 +0100
+Subject: [PATCH] Patch for kernel 4.4.0-rc2
+
+constant change of name XSTATE_XP to name XFEATURE_MASK_FP
+---
+ firegl_public.c | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/common/lib/modules/fglrx/build_mod/firegl_public.c b/common/lib/modules/fglrx/build_mod/firegl_public.c
+index 3626c7b..f071d42 100644
+--- a/common/lib/modules/fglrx/build_mod/firegl_public.c
++++ b/common/lib/modules/fglrx/build_mod//firegl_public.c
+@@ -6463,7 +6463,11 @@ static int KCL_fpu_save_init(struct task_struct *tsk)
+       if (!(fpu->state->xsave.xsave_hdr.xstate_bv & XSTATE_FP))
+ #else
+ 	  copy_xregs_to_kernel(&fpu->state.xsave);
+-      if (!(fpu->state.xsave.header.xfeatures & XSTATE_FP))
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,0)
++      if (!(fpu->state.xsave.header.xfeatures & XFEATURE_MASK_FP))
++#else
++      if (!(fpu->state.xsave.header.xfeatures & XSTATE_FP))
++#endif
+ #endif
+          return 1;
+    } else if (static_cpu_has(X86_FEATURE_FXSR)) {
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-kcl_str.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-kcl_str.patch
new file mode 100644
index 000000000000..20c3bc8a169b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-kcl_str.patch
@@ -0,0 +1,14 @@
+--- a/common/lib/modules/fglrx/build_mod/kcl_str.c	2015-09-13 13:47:30.000000000 -0400
++++ b/common/lib/modules/fglrx/build_mod/kcl_str.c	2015-09-13 13:49:42.000000000 -0400
+@@ -169,7 +169,11 @@ int ATI_API_CALL KCL_STR_Strnicmp(const
+                                   const char* s2,
+                                   KCL_TYPE_SizeSigned count)
+ {
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4,0,0)
+     return strnicmp(s1, s2, count);
++#else
++    return strncasecmp(s1, s2, count);
++#endif
+ }
+ 
+ /** \brief Locate character in string
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-mtrr.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-mtrr.patch
new file mode 100644
index 000000000000..bdf70b4ccdc4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-mtrr.patch
@@ -0,0 +1,27 @@
+--- a/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-09-19 23:43:22.000000000 -0400
++++ b/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-09-19 23:52:07.000000000 -0400
+@@ -3442,7 +3442,11 @@ int ATI_API_CALL KCL_MEM_MTRR_Support(vo
+ int ATI_API_CALL KCL_MEM_MTRR_AddRegionWc(unsigned long base, unsigned long size)
+ {
+ #ifdef CONFIG_MTRR
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
++    return arch_phys_wc_add(base, size);
++#else
+     return mtrr_add(base, size, MTRR_TYPE_WRCOMB, 1);
++#endif
+ #else /* !CONFIG_MTRR */
+     return -EPERM;
+ #endif /* !CONFIG_MTRR */
+@@ -3451,7 +3455,12 @@ int ATI_API_CALL KCL_MEM_MTRR_AddRegionW
+ int ATI_API_CALL KCL_MEM_MTRR_DeleteRegion(int reg, unsigned long base, unsigned long size)
+ {
+ #ifdef CONFIG_MTRR
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
++    arch_phys_wc_del(reg);
++    return reg;
++#else
+     return mtrr_del(reg, base, size);
++#endif
+ #else /* !CONFIG_MTRR */
+     return -EPERM;
+ #endif /* !CONFIG_MTRR */
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-preempt.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-preempt.patch
new file mode 100644
index 000000000000..c6598835133e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-preempt.patch
@@ -0,0 +1,103 @@
+--- a/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-08-30 17:36:02.000000000 -0400
++++ b/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-08-30 17:39:36.000000000 -0400
+@@ -21,6 +21,8 @@
+ !!! since it requires changes to linux/init/main.c.
+ #endif /* !MODULE */
+ 
++#include <linux/preempt.h>
++
+ // ============================================================
+ #include <linux/version.h>
+ 
+@@ -4997,7 +4999,9 @@ static unsigned int kas_spin_unlock(kas_
+ unsigned long ATI_API_CALL KAS_GetExecutionLevel(void)
+ {
+     unsigned long ret;
++    preempt_disable();
+     ret = kas_GetExecutionLevel();
++    preempt_enable();
+     return ret;
+ }
+ 
+@@ -5022,8 +5026,10 @@ unsigned int ATI_API_CALL KAS_Ih_Execute
+     KCL_DEBUG5(FN_FIREGL_KAS,"0x%08X, 0x%08X\n", ih_routine, ih_context);
+ 
+     //Prevent simultaneous entry on some SMP systems.
++    preempt_disable();
+     if (test_and_set_bit(0, (void *)&(kasContext.in_interrupts[smp_processor_id()])))
+     {
++    	preempt_enable();
+         KCL_DEBUG1(FN_FIREGL_KAS, "The processor is handling the interrupt\n");
+         return IRQ_NONE;
+     }
+@@ -5036,9 +5042,9 @@ unsigned int ATI_API_CALL KAS_Ih_Execute
+ 
+     kasSetExecutionLevel(orig_level);
+     spin_unlock(&kasContext.lock_ih); 
+-
+     clear_bit(0, (void *)&(kasContext.in_interrupts[smp_processor_id()]));
+     KCL_DEBUG5(FN_FIREGL_KAS,"%d\n", ret);
++    preempt_enable();
+ 
+     return ret;
+ }
+@@ -5256,6 +5262,7 @@ unsigned int ATI_API_CALL KAS_Spinlock_A
+ 
+     KCL_DEBUG5(FN_FIREGL_KAS,"0x%08X\n", hSpinLock);
+ 
++    preempt_disable();
+     spin_lock_info.routine_type = spinlock_obj->routine_type;
+     spin_lock_info.plock = &(spinlock_obj->lock);
+ 
+@@ -5263,6 +5270,7 @@ unsigned int ATI_API_CALL KAS_Spinlock_A
+ 
+     spinlock_obj->acquire_type = spin_lock_info.acquire_type;
+     spinlock_obj->flags = spin_lock_info.flags;
++    preempt_enable();
+ 
+     KCL_DEBUG5(FN_FIREGL_KAS,"%d\n", ret);
+     return ret;
+@@ -6034,6 +6042,8 @@ unsigned int ATI_API_CALL KAS_Interlocke
+ 
+     KCL_DEBUG5(FN_FIREGL_KAS,"0x%08X, 0x%08X, 0x%08X\n", hListHead, hListEntry, phPrevEntry);
+ 
++    preempt_disable();
++
+     /* Protect the operation with spinlock */
+     spin_lock_info.routine_type = listhead_obj->routine_type;
+     spin_lock_info.plock = &(listhead_obj->lock);
+@@ -6041,6 +6051,7 @@ unsigned int ATI_API_CALL KAS_Interlocke
+     if (!kas_spin_lock(&spin_lock_info))
+     {
+         KCL_DEBUG_ERROR("Unable to grab list spinlock\n");
++	preempt_enable();
+         return 0; /* No spinlock - no operation */
+     }
+ 
+@@ -6065,6 +6076,7 @@ unsigned int ATI_API_CALL KAS_Interlocke
+     spin_unlock_info.flags = spin_lock_info.flags;
+ 
+     ret = kas_spin_unlock(&spin_unlock_info);
++    preempt_enable();
+     KCL_DEBUG5(FN_FIREGL_KAS,"%d", ret);
+     return ret;
+ }
+@@ -6153,8 +6165,10 @@ unsigned int ATI_API_CALL KAS_Interlocke
+     spin_lock_info.routine_type = listhead_obj->routine_type;
+     spin_lock_info.plock = &(listhead_obj->lock);
+ 
++    preempt_disable();
+     if (!kas_spin_lock(&spin_lock_info))
+     {
++        preempt_enable();
+         KCL_DEBUG_ERROR("Unable to grab list spinlock");
+         return 0; /* No spinlock - no operation */
+     }
+@@ -6178,6 +6192,7 @@ unsigned int ATI_API_CALL KAS_Interlocke
+     spin_unlock_info.flags = spin_lock_info.flags;
+ 
+     ret = kas_spin_unlock(&spin_unlock_info);
++    preempt_enable();
+     KCL_DEBUG5(FN_FIREGL_KAS,"%d", ret);
+     return ret;
+ }
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-sep_printf.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-sep_printf.patch
new file mode 100644
index 000000000000..3e4e8d6499a0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/15.9-sep_printf.patch
@@ -0,0 +1,11 @@
+--- a/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-09-14 15:14:36.000000000 -0400
++++ b/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-09-14 16:18:58.000000000 -0400
+@@ -649,6 +649,8 @@ static int firegl_major_proc_read(struct
+     *eof = 1;
+ 
+     len = snprintf(buf, request, "%d\n", major);
++#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
++    seq_printf(m, "%d\n", major);
+ #else
+     len = seq_printf(m, "%d\n", major);
+ #endif
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.7-arch-cpu_has_pge-v2.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.7-arch-cpu_has_pge-v2.patch
new file mode 100644
index 000000000000..cb86f5aff276
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.7-arch-cpu_has_pge-v2.patch
@@ -0,0 +1,70 @@
+diff -uNr 16.8/common/lib/modules/fglrx/build_mod/firegl_public.c 16.8b/common/lib/modules/fglrx/build_mod/firegl_public.c
+--- 16.8/common/lib/modules/fglrx/build_mod/firegl_public.c	2015-12-18 19:47:41.000000000 +0100
++++ 16.8b/common/lib/modules/fglrx/build_mod/firegl_public.c	2016-08-15 15:09:37.228538907 +0200
+@@ -4518,7 +4518,11 @@
+     write_cr0(cr0);
+     wbinvd();
+ 
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
++    if (boot_cpu_has(X86_FEATURE_PGE))
++#else
+     if (cpu_has_pge)
++#endif
+     {
+         cr4 = READ_CR4();
+         WRITE_CR4(cr4 & ~X86_CR4_PGE);
+@@ -4532,7 +4536,11 @@
+     wbinvd();
+     __flush_tlb();
+     write_cr0(cr0 & 0xbfffffff);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
++    if (boot_cpu_has(X86_FEATURE_PGE))
++#else
+     if (cpu_has_pge)
++#endif
+     {
+         WRITE_CR4(cr4);
+     }
+@@ -4559,7 +4567,11 @@
+     write_cr0(cr0);
+     wbinvd();
+ 
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
++    if (boot_cpu_has(X86_FEATURE_PGE))
++#else
+     if (cpu_has_pge)
++#endif
+     {
+         cr4 = READ_CR4();
+         WRITE_CR4(cr4 & ~X86_CR4_PGE);
+@@ -4572,7 +4584,11 @@
+     wbinvd();
+     __flush_tlb();
+     write_cr0(cr0 & 0xbfffffff);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
++    if (boot_cpu_has(X86_FEATURE_PGE))
++#else
+     if (cpu_has_pge)
++#endif
+     {
+         WRITE_CR4(cr4);
+     }
+diff -uNr 16.8/common/lib/modules/fglrx/build_mod/firegl_public.h 16.8b/common/lib/modules/fglrx/build_mod/firegl_public.h
+--- 16.8/common/lib/modules/fglrx/build_mod/firegl_public.h	2015-12-18 19:47:41.000000000 +0100
++++ 16.8b/common/lib/modules/fglrx/build_mod/firegl_public.h	2016-08-15 15:09:05.815141238 +0200
+@@ -650,9 +650,15 @@
+ #define cpu_has_pat  test_bit(X86_FEATURE_PAT, (void *) &boot_cpu_data.x86_capability)
+ #endif
+ 
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,7,0)
++#ifndef boot_cpu_has(X86_FEATURE_PGE)
++#define boot_cpu_has(X86_FEATURE_PGE) test_bit(X86_FEATURE_PGE, &boot_cpu_data.x86_capability)
++#endif
++#else
+ #ifndef cpu_has_pge
+ #define cpu_has_pge test_bit(X86_FEATURE_PGE, &boot_cpu_data.x86_capability)
+ #endif
++#endif
+ 
+ /* 2.6.29 defines pgprot_writecombine as a macro which resolves to a
+  * GPL-only function with the same name. So we always use our own
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.9-get_user_pages.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.9-get_user_pages.patch
new file mode 100644
index 000000000000..8a6c42cdb1fc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/4.9-get_user_pages.patch
@@ -0,0 +1,28 @@
+commit b3e4353fc68a6a024dcb95e2d61aa0afd7370233
+Author: Matt McHenry <matt@mchenryfamily.org>
+Date:   Fri Feb 3 20:19:41 2017
+
+    patch for 4.9 only
+
+diff --git a/common/lib/modules/fglrx/build_mod/firegl_public.c b/common/lib/modules/fglrx/build_mod/firegl_public.c
+index 4ce095f..3b591e1 100755
+--- a/common/lib/modules/fglrx/build_mod/firegl_public.c
++++ b/common/lib/modules/fglrx/build_mod/firegl_public.c
+@@ -3224,7 +3224,7 @@ int ATI_API_CALL KCL_LockUserPages(unsigned long vaddr, unsigned long* page_list
+     int ret;
+ 
+     down_read(&current->mm->mmap_sem);
+-    ret = get_user_pages(vaddr, page_cnt, 1, 0, (struct page **)page_list, NULL);
++    ret = get_user_pages(vaddr, page_cnt, 1, (struct page **)page_list, NULL);
+     up_read(&current->mm->mmap_sem);
+ 
+     return ret;
+@@ -3242,7 +3242,7 @@ int ATI_API_CALL KCL_LockReadOnlyUserPages(unsigned long vaddr, unsigned long* p
+     int ret;
+ 
+     down_read(&current->mm->mmap_sem);
+-    ret = get_user_pages(vaddr, page_cnt, 0, 0, (struct page **)page_list, NULL);
++    ret = get_user_pages(vaddr, page_cnt, 0, (struct page **)page_list, NULL);
+     up_read(&current->mm->mmap_sem);
+ 
+     return ret;
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-get_user_pages.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-get_user_pages.patch
new file mode 100644
index 000000000000..1e7209ed5ed1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-get_user_pages.patch
@@ -0,0 +1,25 @@
+diff --git a/common/lib/modules/fglrx/build_mod/firegl_public.c b/common/lib/modules/fglrx/build_mod/firegl_public.c
+index 9c70211..b2242af 100755
+--- a/common/lib/modules/fglrx/build_mod/firegl_public.c
++++ b/common/lib/modules/fglrx/build_mod/firegl_public.c
+@@ -3220,7 +3220,7 @@ int ATI_API_CALL KCL_LockUserPages(unsigned long vaddr, unsigned long* page_list
+     int ret;
+ 
+     down_read(&current->mm->mmap_sem);
+-    ret = get_user_pages(current, current->mm, vaddr, page_cnt, 1, 0, (struct page **)page_list, NULL);
++    ret = get_user_pages(vaddr, page_cnt, 1, 0, (struct page **)page_list, NULL);
+     up_read(&current->mm->mmap_sem);
+ 
+     return ret;
+@@ -3238,7 +3238,7 @@ int ATI_API_CALL KCL_LockReadOnlyUserPages(unsigned long vaddr, unsigned long* p
+     int ret;
+ 
+     down_read(&current->mm->mmap_sem);
+-    ret = get_user_pages(current, current->mm, vaddr, page_cnt, 0, 0, (struct page **)page_list, NULL);
++    ret = get_user_pages(vaddr, page_cnt, 0, 0, (struct page **)page_list, NULL);
+     up_read(&current->mm->mmap_sem);
+ 
+     return ret;
+-- 
+2.9.2
+
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-page_cache_release-put_page.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-page_cache_release-put_page.patch
new file mode 100644
index 000000000000..28820790e492
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/kernel-4.6-page_cache_release-put_page.patch
@@ -0,0 +1,16 @@
+diff --git a/common/lib/modules/fglrx/build_mod/firegl_public.c b/common/lib/modules/fglrx/build_mod/firegl_public.c
+index b2242af..586129c 100755
+--- a/common/lib/modules/fglrx/build_mod/firegl_public.c
++++ b/common/lib/modules/fglrx/build_mod/firegl_public.c
+@@ -3249,7 +3249,7 @@ void ATI_API_CALL KCL_UnlockUserPages(unsigned long* page_list, unsigned int pag
+     unsigned int i;
+     for (i=0; i<page_cnt; i++)
+     {
+-        page_cache_release((struct page*)page_list[i]);
++        put_page((struct page*)page_list[i]);
+     }
+ }
+ 
+-- 
+2.9.2
+
diff --git a/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/patch-samples.patch b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/patch-samples.patch
new file mode 100644
index 000000000000..8bd24b1d022b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ati-drivers/patches/patch-samples.patch
@@ -0,0 +1,26 @@
+diff --git a/samples/fgl_glxgears/fgl_glxgears.c b/samples/fgl_glxgears/fgl_glxgears.c
+index 6c8e313..2b8d035 100644
+--- a/samples/fgl_glxgears/fgl_glxgears.c
++++ b/samples/fgl_glxgears/fgl_glxgears.c
+@@ -1096,8 +1096,6 @@ static void event_loop(void)
+                   view_rotx -= 5.0;
+                }
+                else {
+-                  r = XLookupString(&event.xkey, buffer, sizeof(buffer),
+-                                    NULL, NULL);
+                   if (buffer[0] == 27) {
+                      /* escape */
+                      return;
+
+
+diff -Nur a/samples/fgl_glxgears/fgl_glxgears.c b/samples/fgl_glxgears/fgl_glxgears.c
+--- a/samples/fgl_glxgears/fgl_glxgears.c	2012-08-29 09:59:03.000000000 +0300
++++ b/samples/fgl_glxgears/fgl_glxgears.c	2013-09-07 09:26:11.034723135 +0300
+@@ -78,7 +78,6 @@
+ #endif // _WIN32
+ 
+ #define INT_PTR ptrdiff_t
+-#include <GL/glATI.h>
+ 
+ #ifdef _WIN32
+ #include <GL/wglATI.h>
diff --git a/nixpkgs/pkgs/os-specific/linux/atop/default.nix b/nixpkgs/pkgs/os-specific/linux/atop/default.nix
new file mode 100644
index 000000000000..5d002bf72eac
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/atop/default.nix
@@ -0,0 +1,48 @@
+{stdenv, fetchurl, zlib, ncurses}:
+
+stdenv.mkDerivation rec {
+  version = "2.4.0";
+  name = "atop-${version}";
+
+  src = fetchurl {
+    url = "https://www.atoptool.nl/download/atop-${version}.tar.gz";
+    sha256 = "0s9xlxlzz688a80zxld840zkrmzw998rdkkg6yc7ssq8fw50275y";
+  };
+
+  buildInputs = [zlib ncurses];
+
+  makeFlags = [
+    ''SCRPATH=$out/etc/atop''
+    ''LOGPATH=/var/log/atop''
+    ''INIPATH=$out/etc/rc.d/init.d''
+    ''CRNPATH=$out/etc/cron.d''
+    ''ROTPATH=$out/etc/logrotate.d''
+  ];
+
+  preConfigure = ''
+    sed -e "s@/usr/@$out/@g" -i $(find . -type f )
+    sed -e "/mkdir.*LOGPATH/s@mkdir@echo missing dir @" -i Makefile
+    sed -e "/touch.*LOGPATH/s@touch@echo should have created @" -i Makefile
+    sed -e 's/chown/true/g' -i Makefile
+    sed -e '/chkconfig/d' -i Makefile
+    sed -e 's/chmod 04711/chmod 0711/g' -i Makefile
+  '';
+
+  preInstall = ''
+    mkdir -p "$out"/{bin,sbin}
+    make systemdinstall $makeFlags
+  '';
+
+  meta = with stdenv.lib; {
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ raskin ];
+    description = ''Console system performance monitor'';
+
+    longDescription = ''
+      Atop is an ASCII full-screen performance monitor that is capable of reporting the activity of all processes (even if processes have finished during the interval), daily logging of system and process activity for long-term analysis, highlighting overloaded system resources by using colors, etc. At regular intervals, it shows system-level activity related to the CPU, memory, swap, disks and network layers, and for every active process it shows the CPU utilization, memory growth, disk utilization, priority, username, state, and exit code.
+    '';
+    inherit version;
+    license = licenses.gpl2;
+    downloadPage = http://atoptool.nl/downloadatop.php;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/atop/default.upstream b/nixpkgs/pkgs/os-specific/linux/atop/default.upstream
new file mode 100644
index 000000000000..46099d9c9595
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/atop/default.upstream
@@ -0,0 +1,4 @@
+url http://atoptool.nl/downloadatop.php
+version_link '[.]tar[.]'
+version '[^0-9]*[-.]([0-9]([-0-9.]*[0-9])?)[.].*' '\1'
+minimize_overwrite
diff --git a/nixpkgs/pkgs/os-specific/linux/audit/default.nix b/nixpkgs/pkgs/os-specific/linux/audit/default.nix
new file mode 100644
index 000000000000..c8edd865479e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/audit/default.nix
@@ -0,0 +1,53 @@
+{
+  stdenv, buildPackages, fetchurl, fetchpatch,
+  enablePython ? false, python ? null,
+}:
+
+assert enablePython -> python != null;
+
+stdenv.mkDerivation rec {
+  name = "audit-2.8.4";
+
+  src = fetchurl {
+    url = "https://people.redhat.com/sgrubb/audit/${name}.tar.gz";
+    sha256 = "0f4ci6ffznnmgblwgv7ich9mjfk3p6y5l6m6h3chhmzw156nj454";
+  };
+
+  outputs = [ "bin" "dev" "out" "man" ];
+
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
+  buildInputs = stdenv.lib.optional enablePython python;
+
+  configureFlags = [
+    # z/OS plugin is not useful on Linux,
+    # and pulls in an extra openldap dependency otherwise
+    "--disable-zos-remote"
+    (if enablePython then "--with-python" else "--without-python")
+  ];
+
+  enableParallelBuilding = true;
+
+  patches = stdenv.lib.optional stdenv.hostPlatform.isMusl [
+    (fetchpatch {
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/audit/0002-auparse-remove-use-of-rawmemchr.patch?id=3e57180fdf3f90c30a25aea44f57846efc93a696";
+      name = "0002-auparse-remove-use-of-rawmemchr.patch";
+      sha256 = "1caaqbfgb2rq3ria5bz4n8x30ihgihln6w9w9a46k62ba0wh9rkz";
+    })
+    (fetchpatch {
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/audit/0003-all-get-rid-of-strndupa.patch?id=3e57180fdf3f90c30a25aea44f57846efc93a696";
+      name = "0003-all-get-rid-of-strndupa.patch";
+      sha256 = "1ddrm6a0ijrf7caw1wpw2kkbjp2lkxkmc16v51j5j7dvdalc6591";
+    })
+  ];
+
+  prePatch = ''
+    sed -i 's,#include <sys/poll.h>,#include <poll.h>\n#include <limits.h>,' audisp/audispd.c
+  '';
+  meta = {
+    description = "Audit Library";
+    homepage = https://people.redhat.com/sgrubb/audit/;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [ fuuzetsu ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/autofs/default.nix b/nixpkgs/pkgs/os-specific/linux/autofs/default.nix
new file mode 100644
index 000000000000..38e2fa9bd344
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/autofs/default.nix
@@ -0,0 +1,48 @@
+{ stdenv, fetchurl, flex, bison, linuxHeaders, libtirpc, mount, umount, nfs-utils, e2fsprogs
+, libxml2, kerberos, kmod, openldap, sssd, cyrus_sasl, openssl }:
+
+let
+  version = "5.1.5";
+  name = "autofs-${version}";
+in stdenv.mkDerivation {
+  inherit name;
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/daemons/autofs/v5/${name}.tar.xz";
+    sha256 = "1nn0z60f49zchpv8yw67fk8hmbjszpnczs0bj2ql2vgxwbcxmbr3";
+  };
+
+  preConfigure = ''
+    configureFlags="--enable-force-shutdown --enable-ignore-busy --with-path=$PATH"
+    export sssldir="${sssd}/lib/sssd/modules"
+    export HAVE_SSS_AUTOFS=1
+
+    export MOUNT=${mount}/bin/mount
+    export MOUNT_NFS=${nfs-utils}/bin/mount.nfs
+    export UMOUNT=${umount}/bin/umount
+    export MODPROBE=${kmod}/bin/modprobe
+    export E2FSCK=${e2fsprogs}/bin/fsck.ext2
+    export E3FSCK=${e2fsprogs}/bin/fsck.ext3
+    export E4FSCK=${e2fsprogs}/bin/fsck.ext4
+
+    unset STRIP # Makefile.rules defines a usable STRIP only without the env var.
+  '';
+
+  installPhase = ''
+    make install SUBDIRS="lib daemon modules man" # all but samples
+    #make install SUBDIRS="samples" # impure!
+  '';
+
+  buildInputs = [ linuxHeaders libtirpc libxml2 kerberos kmod openldap sssd
+                  openssl cyrus_sasl ];
+
+  nativeBuildInputs = [ flex bison ];
+
+  meta = {
+    description = "Kernel-based automounter";
+    homepage = https://www.kernel.org/pub/linux/daemons/autofs/;
+    license = stdenv.lib.licenses.gpl2Plus;
+    executables = [ "automount" ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/batman-adv/alfred.nix b/nixpkgs/pkgs/os-specific/linux/batman-adv/alfred.nix
new file mode 100644
index 000000000000..671b13c4d79c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/batman-adv/alfred.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchurl, pkgconfig, gpsd, libcap, libnl }:
+
+let
+  ver = "2019.1";
+in
+stdenv.mkDerivation rec {
+  name = "alfred-${ver}";
+
+  src = fetchurl {
+    url = "https://downloads.open-mesh.org/batman/releases/batman-adv-${ver}/${name}.tar.gz";
+    sha256 = "0nsi5g77zsl0s683r0hqz91xs2bz91ic9c1qdsa3ikd46z8s8lkj";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ gpsd libcap libnl ];
+
+  preBuild = ''
+    makeFlags="PREFIX=$out PKG_CONFIG=${pkgconfig}/bin/pkg-config"
+  '';
+
+  meta = {
+    homepage = https://www.open-mesh.org/projects/batman-adv/wiki/Wiki;
+    description = "B.A.T.M.A.N. routing protocol in a linux kernel module for layer 2, information distribution tool";
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = with stdenv.lib.maintainers; [ fpletz ];
+    platforms = with stdenv.lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/batman-adv/batctl.nix b/nixpkgs/pkgs/os-specific/linux/batman-adv/batctl.nix
new file mode 100644
index 000000000000..44c975b8dcc1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/batman-adv/batctl.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchurl, pkgconfig, libnl }:
+
+let
+  ver = "2019.1";
+in
+stdenv.mkDerivation rec {
+  name = "batctl-${ver}";
+
+  src = fetchurl {
+    url = "https://downloads.open-mesh.org/batman/releases/batman-adv-${ver}/${name}.tar.gz";
+    sha256 = "14wp8rvm2m1r5qz7p1m08bzg2gmqyldkw1p6gk8rkdyqb3q0abg8";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libnl ];
+
+  preBuild = ''
+    makeFlags="PREFIX=$out PKG_CONFIG=${pkgconfig}/bin/pkg-config"
+  '';
+
+  meta = {
+    homepage = https://www.open-mesh.org/projects/batman-adv/wiki/Wiki;
+    description = "B.A.T.M.A.N. routing protocol in a linux kernel module for layer 2, control tool";
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = with stdenv.lib.maintainers; [ fpletz ];
+    platforms = with stdenv.lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/batman-adv/default.nix b/nixpkgs/pkgs/os-specific/linux/batman-adv/default.nix
new file mode 100644
index 000000000000..c6e23be8b89d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/batman-adv/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchurl, kernel }:
+
+let base = "batman-adv-2019.1"; in
+
+stdenv.mkDerivation rec {
+  name = "${base}-${kernel.version}";
+
+  src = fetchurl {
+    url = "http://downloads.open-mesh.org/batman/releases/${base}/${base}.tar.gz";
+    sha256 = "1af5q4631b72q0gg0xmhxx2k3adky2ahk4dq97k0436a0rg617dr";
+  };
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  preBuild = ''
+    makeFlags="KERNELPATH=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+    sed -i -e "s,INSTALL_MOD_DIR=,INSTALL_MOD_PATH=$out INSTALL_MOD_DIR=," \
+      -e /depmod/d Makefile
+  '';
+
+  meta = {
+    homepage = https://www.open-mesh.org/projects/batman-adv/wiki/Wiki;
+    description = "B.A.T.M.A.N. routing protocol in a linux kernel module for layer 2";
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = with stdenv.lib.maintainers; [ fpletz ];
+    platforms = with stdenv.lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/bbswitch/default.nix b/nixpkgs/pkgs/os-specific/linux/bbswitch/default.nix
new file mode 100644
index 000000000000..4b9148600686
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bbswitch/default.nix
@@ -0,0 +1,57 @@
+{ stdenv, fetchurl, fetchpatch, kernel, runtimeShell }:
+
+let
+  baseName = "bbswitch";
+  version = "0.8";
+  name = "${baseName}-${version}-${kernel.version}";
+
+in
+
+stdenv.mkDerivation {
+  inherit name;
+
+  src = fetchurl {
+    url = "https://github.com/Bumblebee-Project/${baseName}/archive/v${version}.tar.gz";
+    sha256 = "0xql1nv8dafnrcg54f3jsi3ny3cd2ca9iv73pxpgxd2gfczvvjkn";
+  };
+
+  patches = [ (fetchpatch {
+    url = "https://github.com/Bumblebee-Project/bbswitch/pull/102.patch";
+    sha256 = "1lbr6pyyby4k9rn2ry5qc38kc738d0442jhhq57vmdjb6hxjya7m";
+  }) ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  preBuild = ''
+    substituteInPlace Makefile \
+      --replace "\$(shell uname -r)" "${kernel.modDirVersion}" \
+      --replace "/lib/modules" "${kernel.dev}/lib/modules"
+  '';
+
+  installPhase = ''
+    mkdir -p $out/lib/modules/${kernel.modDirVersion}/misc
+    cp bbswitch.ko $out/lib/modules/${kernel.modDirVersion}/misc
+
+    mkdir -p $out/bin
+    tee $out/bin/discrete_vga_poweroff << EOF
+    #!${runtimeShell}
+
+    echo -n OFF > /proc/acpi/bbswitch
+    EOF
+    tee $out/bin/discrete_vga_poweron << EOF
+    #!${runtimeShell}
+
+    echo -n ON > /proc/acpi/bbswitch
+    EOF
+    chmod +x $out/bin/discrete_vga_poweroff $out/bin/discrete_vga_poweron
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A module for powering off hybrid GPUs";
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    homepage = https://github.com/Bumblebee-Project/bbswitch;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/bcc/default.nix b/nixpkgs/pkgs/os-specific/linux/bcc/default.nix
new file mode 100644
index 000000000000..885de8163be3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bcc/default.nix
@@ -0,0 +1,78 @@
+{ stdenv, fetchFromGitHub, makeWrapper, cmake, llvmPackages, kernel
+, flex, bison, elfutils, python, luajit, netperf, iperf, libelf
+, systemtap
+}:
+
+python.pkgs.buildPythonApplication rec {
+  version = "0.8.0";
+  name = "bcc-${version}";
+
+  src = fetchFromGitHub {
+    owner  = "iovisor";
+    repo   = "bcc";
+    rev    = "v${version}";
+    sha256 = "15vvybllmh9hdj801v3psd671c0qq2a1xdv73kabb9r4fzgaknxk";
+  };
+
+  format = "other";
+
+  buildInputs = [
+    llvmPackages.llvm llvmPackages.clang-unwrapped kernel
+    elfutils luajit netperf iperf
+    systemtap.stapBuild flex
+  ];
+
+  patches = [
+    # This is needed until we fix
+    # https://github.com/NixOS/nixpkgs/issues/40427
+    ./fix-deadlock-detector-import.patch
+  ];
+
+  nativeBuildInputs = [ makeWrapper cmake flex bison ]
+    # libelf is incompatible with elfutils-libelf
+    ++ stdenv.lib.filter (x: x != libelf) kernel.moduleBuildDependencies;
+
+  cmakeFlags = [
+    "-DBCC_KERNEL_MODULES_DIR=${kernel.dev}/lib/modules"
+    "-DREVISION=${version}"
+    "-DENABLE_USDT=ON"
+    "-DENABLE_CPP_API=ON"
+  ];
+
+  postPatch = ''
+    substituteAll ${./libbcc-path.patch} ./libbcc-path.patch
+    patch -p1 < libbcc-path.patch
+  '';
+
+  propagatedBuildInputs = [
+    python.pkgs.netaddr
+  ];
+
+  postInstall = ''
+    mkdir -p $out/bin $out/share
+    rm -r $out/share/bcc/tools/old
+    mv $out/share/bcc/tools/doc $out/share
+    mv $out/share/bcc/man $out/share/
+
+    find $out/share/bcc/tools -type f -executable -print0 | \
+    while IFS= read -r -d ''$'\0' f; do
+      bin=$out/bin/$(basename $f)
+      if [ ! -e $bin ]; then
+        ln -s $f $bin
+      fi
+    done
+
+    sed -i -e "s!lib=.*!lib=$out/bin!" $out/bin/{java,ruby,node,python}gc
+  '';
+
+  postFixup = ''
+    wrapPythonProgramsIn "$out/share/bcc/tools" "$out $pythonPath"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Dynamic Tracing Tools for Linux";
+    homepage = https://iovisor.github.io/bcc/;
+    license = licenses.asl20;
+    maintainers = with maintainers; [ ragge mic92 ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/bcc/fix-deadlock-detector-import.patch b/nixpkgs/pkgs/os-specific/linux/bcc/fix-deadlock-detector-import.patch
new file mode 100644
index 000000000000..87ce618a0dd9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bcc/fix-deadlock-detector-import.patch
@@ -0,0 +1,14 @@
+--- source.org/tools/deadlock_detector.py	1980-01-02 00:00:00.000000000 +0000
++++ source/tools/deadlock_detector.py	2018-05-29 13:57:11.807126673 +0100
+@@ -44,9 +44,8 @@
+ #
+ # 01-Feb-2017   Kenny Yu   Created this.
+ 
+-from __future__ import (
+-    absolute_import, division, unicode_literals, print_function
+-)
++from __future__ import absolute_import, division, unicode_literals, print_function
++
+ from bcc import BPF
+ from collections import defaultdict
+ import argparse
diff --git a/nixpkgs/pkgs/os-specific/linux/bcc/libbcc-path.patch b/nixpkgs/pkgs/os-specific/linux/bcc/libbcc-path.patch
new file mode 100644
index 000000000000..187bb3aadd00
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bcc/libbcc-path.patch
@@ -0,0 +1,11 @@
+--- source.org/src/python/bcc/libbcc.py	2018-05-13 08:35:06.850522883 +0100
++++ source/src/python/bcc/libbcc.py	2018-05-13 08:36:24.602733151 +0100
+@@ -14,7 +14,7 @@
+ 
+ import ctypes as ct
+ 
+-lib = ct.CDLL("libbcc.so.0", use_errno=True)
++lib = ct.CDLL("@out@/lib/libbcc.so.0", use_errno=True)
+ 
+ # keep in sync with bpf_common.h
+ lib.bpf_module_create_b.restype = ct.c_void_p
diff --git a/nixpkgs/pkgs/os-specific/linux/beegfs/default.nix b/nixpkgs/pkgs/os-specific/linux/beegfs/default.nix
new file mode 100644
index 000000000000..076c19cf400d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/beegfs/default.nix
@@ -0,0 +1,163 @@
+{ stdenv, fetchurl, pkgconfig, unzip, which
+, libuuid, attr, xfsprogs, cppunit, rdma-core
+, zlib, openssl, sqlite, jre, openjdk, ant
+, openssh, perl, gfortran, influxdb, curl
+} :
+
+let
+  version = "7.0";
+
+  subdirs = [
+    "beeond_thirdparty/build"
+    "beeond_thirdparty_gpl/build"
+    "thirdparty/build"
+    "opentk_lib/build"
+    "common/build"
+    "admon/build"
+    "java_lib/build"
+    "ctl/build"
+    "fsck/build"
+    "helperd/build"
+    "meta/build"
+    "mgmtd/build"
+    "storage/build"
+    "utils/build"
+    "mon/build"
+    "upgrade/beegfs_mirror_md/build"
+  ];
+
+in stdenv.mkDerivation rec {
+  name = "beegfs-${version}";
+
+  src = fetchurl {
+    url = "https://git.beegfs.com/pub/v7/repository/archive.tar.bz2?ref=${version}";
+    sha256 = "1wsljd5ybyhl94aqrdfvcs8a0l8w4pr0bs1vhjrf4y7ldhw35m3k";
+  };
+
+  nativeBuildInputs = [ which unzip pkgconfig cppunit openjdk ant perl ];
+
+  buildInputs = [
+    libuuid
+    attr
+    xfsprogs
+    zlib
+    openssl
+    sqlite
+    jre
+    rdma-core
+    openssh
+    gfortran
+    influxdb
+    curl
+  ];
+
+  hardeningDisable = [ "format" ]; # required for building beeond
+
+  postPatch = ''
+    patchShebangs ./
+    find -type f -name Makefile -exec sed -i "s:/bin/bash:${stdenv.shell}:" \{} \;
+    find -type f -name Makefile -exec sed -i "s:/bin/true:true:" \{} \;
+    find -type f -name "*.mk" -exec sed -i "s:/bin/true:true:" \{} \;
+
+    # unpack manually and patch variable name
+    sed -i '/tar -C $(SOURCE_PATH) -xzf $(PCOPY_TAR)/d' beeond_thirdparty/build/Makefile
+    cd beeond_thirdparty/source
+    tar xf pcopy-0.96.tar.gz
+    sed -i 's/\([^_]\)rank/\1grank/' pcopy-0.96/src/pcp.cpp
+    cd ../..
+  '';
+
+  buildPhase = ''
+    for i in ${toString subdirs}; do
+      make -C $i BEEGFS_OPENTK_IBVERBS=1 ''${enableParallelBuilding:+-j''${NIX_BUILD_CORES} -l''${NIX_BUILD_CORES}}
+    done
+    make -C admon/build admon_gui BEEGFS_OPENTK_IBVERBS=1
+  '';
+
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    binDir=$out/bin
+    docDir=$out/share/doc/beegfs
+    includeDir=$out/include/beegfs
+    libDir=$out/lib
+    libDirPkg=$out/lib/beegfs
+
+    mkdir -p $binDir $libDir $libDirPkg $docDir $includeDir
+
+    cp admon/build/beegfs-admon $binDir
+    cp admon/build/dist/usr/bin/beegfs-admon-gui $binDir
+    cp admon_gui/dist/beegfs-admon-gui.jar $libDirPkg
+    cp admon/build/dist/etc/beegfs-admon.conf $docDir
+
+    cp java_lib/build/jbeegfs.jar $libDirPkg
+    cp java_lib/build/libjbeegfs.so $libDir
+
+    cp ctl/build/beegfs-ctl $binDir
+    cp fsck/build/beegfs-fsck $binDir
+
+    cp utils/scripts/beegfs-check-servers $binDir
+    cp utils/scripts/beegfs-df $binDir
+    cp utils/scripts/beegfs-net $binDir
+
+    cp helperd/build/beegfs-helperd $binDir
+    cp helperd/build/dist/etc/beegfs-helperd.conf $docDir
+
+    cp client_module/build/dist/sbin/beegfs-setup-client $binDir
+    cp client_module/build/dist/etc/beegfs-client.conf $docDir
+
+    cp meta/build/beegfs-meta $binDir
+    cp meta/build/dist/sbin/beegfs-setup-meta $binDir
+    cp meta/build/dist/etc/beegfs-meta.conf $docDir
+
+    cp mgmtd/build/beegfs-mgmtd $binDir
+    cp mgmtd/build/dist/sbin/beegfs-setup-mgmtd $binDir
+    cp mgmtd/build/dist/etc/beegfs-mgmtd.conf $docDir
+
+    cp storage/build/beegfs-storage $binDir
+    cp storage/build/dist/sbin/beegfs-setup-storage $binDir
+    cp storage/build/dist/etc/beegfs-storage.conf $docDir
+
+    cp opentk_lib/build/libbeegfs-opentk.so $libDir
+
+    cp upgrade/beegfs_mirror_md/build/beegfs-mirror-md $binDir
+
+    cp client_devel/build/dist/usr/share/doc/beegfs-client-devel/examples/* $docDir
+    cp -r client_devel/include/* $includeDir
+
+    cp beeond_thirdparty_gpl/build/parallel $out/bin
+    cp beeond_thirdparty/build/pcopy/p* $out/bin
+    cp beeond_thirdparty/build/pcopy/s* $out/bin
+    cp -r beeond/scripts/* $out
+    cp beeond/source/* $out/bin
+  '';
+
+  postFixup = ''
+    substituteInPlace $out/bin/beegfs-admon-gui \
+      --replace " java " " ${jre}/bin/java " \
+      --replace "/opt/beegfs/beegfs-admon-gui/beegfs-admon-gui.jar" \
+                "$libDirPkg/beegfs-admon-gui.jar"
+
+    substituteInPlace $out/bin/beeond \
+      --replace /opt/beegfs/sbin "$out/bin"
+  '';
+
+  doCheck = true;
+
+  checkPhase = ''
+    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/opentk_lib/build/ \
+      common/build/test-runner --text
+  '';
+
+  meta = with stdenv.lib; {
+    description = "High performance distributed filesystem with RDMA support";
+    homepage = "https://www.beegfs.io";
+    platforms = [ "i686-linux" "x86_64-linux" ];
+    license = {
+      fullName = "BeeGFS_EULA";
+      url = "https://www.beegfs.io/docs/BeeGFS_EULA.txt";
+      free = false;
+    };
+    maintainers = with maintainers; [ markuskowa ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/beegfs/kernel-module.nix b/nixpkgs/pkgs/os-specific/linux/beegfs/kernel-module.nix
new file mode 100644
index 000000000000..286252b927b1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/beegfs/kernel-module.nix
@@ -0,0 +1,46 @@
+{ stdenv, fetchurl, which
+, kmod, kernel
+} :
+
+let
+  version = "7.0";
+in stdenv.mkDerivation {
+  name = "beegfs-module-${version}-${kernel.version}";
+
+  src = fetchurl {
+    url = "https://git.beegfs.com/pub/v7/repository/archive.tar.bz2?ref=${version}";
+    sha256 = "1wsljd5ybyhl94aqrdfvcs8a0l8w4pr0bs1vhjrf4y7ldhw35m3k";
+  };
+
+  hardeningDisable = [ "fortify" "pic" "stackprotector" ];
+
+  nativeBuildInputs = [ which kmod ];
+
+  buildInputs = kernel.moduleBuildDependencies;
+
+  makeFlags = [ "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build/" ];
+
+  postPatch = ''
+    patchShebangs ./
+    find -type f -name Makefile -exec sed -i "s:/bin/bash:${stdenv.shell}:" \{} \;
+    find -type f -name Makefile -exec sed -i "s:/bin/true:true:" \{} \;
+    find -type f -name "*.mk" -exec sed -i "s:/bin/true:true:" \{} \;
+  '';
+
+  preBuild = "cd client_module/build";
+
+  installPhase = ''
+    instdir=$out/lib/modules/${kernel.modDirVersion}/extras/fs/beegfs
+    mkdir -p $instdir
+    cp beegfs.ko $instdir
+  '';
+
+  meta = with stdenv.lib; {
+    description = "High performance distributed filesystem with RDMA support";
+    homepage = "https://www.beegfs.io";
+    platforms = [ "i686-linux" "x86_64-linux" ];
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ markuskowa ];
+    broken = stdenv.lib.versionAtLeast kernel.version "4.18";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/blcr/default.nix b/nixpkgs/pkgs/os-specific/linux/blcr/default.nix
new file mode 100644
index 000000000000..626e978f1f16
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/blcr/default.nix
@@ -0,0 +1,43 @@
+{ stdenv, fetchurl, kernel, perl, makeWrapper }:
+
+# BLCR version 0.8.6 should works with linux kernel up to version 3.17.x
+
+assert builtins.compareVersions "3.18" kernel.version == 1;
+
+stdenv.mkDerivation {
+  name = "blcr_${kernel.version}-0.8.6pre4";
+
+  src = fetchurl {
+    url = https://upc-bugs.lbl.gov/blcr-dist/blcr-0.8.6_b4.tar.gz;
+    sha256 = "1a3gdhdnmk592jc652szxgfz8rjd8dax5jwxfsypiqx5lgkj3m21";
+  };
+
+  buildInputs = [ perl makeWrapper ];
+
+  hardeningDisable = [ "pic" ];
+
+  preConfigure = ''
+    configureFlagsArray=(
+      --with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build
+      --with-kmod-dir=$out/lib/modules/${kernel.modDirVersion}
+      --with-system-map=${kernel}/System.map
+    )
+  '';
+
+  postInstall = ''
+    for prog in "$out/bin/"*
+    do
+      wrapProgram "$prog" --prefix LD_LIBRARY_PATH ":" "$out/lib"
+    done
+  '';
+
+  meta = {
+    description = "Berkeley Lab Checkpoint/Restart for Linux (BLCR)";
+    homepage = https://ftg.lbl.gov/projects/CheckpointRestart/;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [
+      z77z
+    ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/blktrace/default.nix b/nixpkgs/pkgs/os-specific/linux/blktrace/default.nix
new file mode 100644
index 000000000000..4ae449c19aa8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/blktrace/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, libaio }:
+
+stdenv.mkDerivation {
+  name = "blktrace-1.2.0";
+
+  # Official source
+  # "git://git.kernel.org/pub/scm/linux/kernel/git/axboe/blktrace.git"
+  src = fetchurl {
+    url = "http://brick.kernel.dk/snaps/blktrace-1.2.0.tar.bz2";
+    sha256 = "0i9z7ayh9qx4wi0ihyz15bhr1c9aknjl8v5i8c9mx3rhyy41i5i6";
+  };
+
+  buildInputs = [ libaio ];
+
+  preConfigure = ''
+    sed s,/usr/local,$out, -i Makefile
+  '';
+
+  meta = {
+    description = "Block layer IO tracing mechanism";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/bluez/bluez-5.37-obexd_without_systemd-1.patch b/nixpkgs/pkgs/os-specific/linux/bluez/bluez-5.37-obexd_without_systemd-1.patch
new file mode 100644
index 000000000000..749787c5b3a7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bluez/bluez-5.37-obexd_without_systemd-1.patch
@@ -0,0 +1,61 @@
+Submitted By:            Armin K. <krejzi at email dot com>
+Date:                    2013-04-29
+Initial Package Version: 5.17
+Upstream Status:         unknown
+Origin:                  Arch Linux (Giovanni Campagna)
+Description:             Allow using obexd without systemd in the user session
+
+Not all sessions run systemd --user (actually, the majority
+doesn't), so the dbus daemon must be able to spawn obexd
+directly, and to do so it needs the full path of the daemon.
+---
+ Makefile.obexd                      | 4 ++--
+ obexd/src/org.bluez.obex.service    | 4 ----
+ obexd/src/org.bluez.obex.service.in | 4 ++++
+ 3 files changed, 6 insertions(+), 6 deletions(-)
+ delete mode 100644 obexd/src/org.bluez.obex.service
+ create mode 100644 obexd/src/org.bluez.obex.service.in
+
+diff --git a/Makefile.obexd b/Makefile.obexd
+index 3760867..142e7c3 100644
+--- a/Makefile.obexd
++++ b/Makefile.obexd
+@@ -2,12 +2,12 @@
+ if SYSTEMD
+ systemduserunitdir = @SYSTEMD_USERUNITDIR@
+ systemduserunit_DATA = obexd/src/obex.service
++endif
+ 
+ dbussessionbusdir = @DBUS_SESSIONBUSDIR@
+ dbussessionbus_DATA = obexd/src/org.bluez.obex.service
+-endif
+ 
+-EXTRA_DIST += obexd/src/obex.service.in obexd/src/org.bluez.obex.service
++EXTRA_DIST += obexd/src/obex.service.in obexd/src/org.bluez.obex.service.in
+ 
+ obex_plugindir = $(libdir)/obex/plugins
+ 
+diff --git a/obexd/src/org.bluez.obex.service b/obexd/src/org.bluez.obex.service
+deleted file mode 100644
+index a538088..0000000
+--- a/obexd/src/org.bluez.obex.service
++++ /dev/null
+@@ -1,4 +0,0 @@
+-[D-BUS Service]
+-Name=org.bluez.obex
+-Exec=/bin/false
+-SystemdService=dbus-org.bluez.obex.service
+diff --git a/obexd/src/org.bluez.obex.service.in b/obexd/src/org.bluez.obex.service.in
+new file mode 100644
+index 0000000..9c815f2
+--- /dev/null
++++ b/obexd/src/org.bluez.obex.service.in
+@@ -0,0 +1,4 @@
++[D-BUS Service]
++Name=org.bluez.obex
++Exec=@libexecdir@/obexd
++SystemdService=dbus-org.bluez.obex.service
+-- 
+1.8.3.1
+
+
diff --git a/nixpkgs/pkgs/os-specific/linux/bluez/default.nix b/nixpkgs/pkgs/os-specific/linux/bluez/default.nix
new file mode 100644
index 000000000000..a917175b90ce
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bluez/default.nix
@@ -0,0 +1,96 @@
+{ stdenv, fetchurl, pkgconfig, dbus, glib, alsaLib,
+  python3, readline, udev, libical, systemd,
+  enableWiimote ? false, enableMidi ? false, enableSixaxis ? false }:
+
+stdenv.mkDerivation rec {
+  name = "bluez-5.50";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/bluetooth/${name}.tar.xz";
+    sha256 = "048r91vx9gs5nwwbah2s0xig04nwk14c5s0vb7qmaqdvighsmz2z";
+  };
+
+  pythonPath = with python3.pkgs; [
+    dbus-python pygobject2 pygobject3 recursivePthLoader
+  ];
+
+  buildInputs = [
+    dbus glib alsaLib python3 python3.pkgs.wrapPython
+    readline udev libical
+  ];
+
+  nativeBuildInputs = [ pkgconfig ];
+
+  outputs = [ "out" "dev" "test" ];
+
+  patches = [ ./bluez-5.37-obexd_without_systemd-1.patch ];
+
+  postConfigure = ''
+    substituteInPlace tools/hid2hci.rules \
+      --replace /sbin/udevadm ${systemd}/bin/udevadm \
+      --replace "hid2hci " "$out/lib/udev/hid2hci "
+  '';
+
+  configureFlags = (with stdenv.lib; [
+    "--localstatedir=/var"
+    "--enable-library"
+    "--enable-cups"
+    "--enable-pie"
+    "--with-dbusconfdir=$(out)/etc"
+    "--with-dbussystembusdir=$(out)/share/dbus-1/system-services"
+    "--with-dbussessionbusdir=$(out)/share/dbus-1/services"
+    "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
+    "--with-systemduserunitdir=$(out)/etc/systemd/user"
+    "--with-udevdir=$(out)/lib/udev"
+    ] ++ optional enableWiimote [ "--enable-wiimote" ]
+      ++ optional enableMidi    [ "--enable-midi" ]
+      ++ optional enableSixaxis [ "--enable-sixaxis" ]);
+
+  # Work around `make install' trying to create /var/lib/bluetooth.
+  installFlags = "statedir=$(TMPDIR)/var/lib/bluetooth";
+
+  makeFlags = "rulesdir=$(out)/lib/udev/rules.d";
+
+  postInstall = ''
+    mkdir -p $test/{bin,test}
+    cp -a test $test
+    pushd $test/test
+    for a in \
+            simple-agent \
+            test-adapter \
+            test-device \
+            test-thermometer \
+            list-devices \
+            monitor-bluetooth \
+            ; do
+      ln -s ../test/$a $test/bin/bluez-$a
+    done
+    popd
+    wrapPythonProgramsIn $test/test "$test/test $pythonPath"
+
+    # for bluez4 compatibility for NixOS
+    mkdir $out/sbin
+    ln -s ../libexec/bluetooth/bluetoothd $out/sbin/bluetoothd
+    ln -s ../libexec/bluetooth/obexd $out/sbin/obexd
+
+    # 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; {
+    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/nixpkgs/pkgs/os-specific/linux/bolt/0001-skip-mkdir.patch b/nixpkgs/pkgs/os-specific/linux/bolt/0001-skip-mkdir.patch
new file mode 100644
index 000000000000..0853bcea9167
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bolt/0001-skip-mkdir.patch
@@ -0,0 +1,12 @@
+diff --git a/scripts/meson-install.sh b/scripts/meson-install.sh
+index 859ae81..05a1c58 100644
+--- a/scripts/meson-install.sh
++++ b/scripts/meson-install.sh
+@@ -7,5 +7,5 @@ fi
+ 
+ BOLT_DBDIR=$1
+ 
+-echo "Creating database dir: ${BOLT_DBDIR}"
+-mkdir -p "${DESTDIR}/${BOLT_DBDIR}"
++# echo "Creating database dir: ${BOLT_DBDIR}"
++# mkdir -p "${DESTDIR}/${BOLT_DBDIR}"
diff --git a/nixpkgs/pkgs/os-specific/linux/bolt/default.nix b/nixpkgs/pkgs/os-specific/linux/bolt/default.nix
new file mode 100644
index 000000000000..f57fb1310c67
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bolt/default.nix
@@ -0,0 +1,61 @@
+{ stdenv, meson, ninja, pkgconfig, fetchFromGitLab,
+  python3, umockdev, gobject-introspection, dbus,
+  asciidoc, libxml2, libxslt, docbook_xml_dtd_45, docbook_xsl,
+  glib, systemd, polkit
+}:
+
+stdenv.mkDerivation rec {
+  pname = "bolt";
+  version = "0.7";
+
+  src = fetchFromGitLab {
+    domain = "gitlab.freedesktop.org";
+    owner = "bolt";
+    repo = "bolt";
+    rev = "${version}";
+    sha256 = "0xn2c31kcjh1j76gq1qrcxwjyjyqnsxygkfrvh3xk07qc92f99xd";
+  };
+
+  nativeBuildInputs = [
+    meson ninja pkgconfig
+    asciidoc libxml2 libxslt docbook_xml_dtd_45 docbook_xsl
+  ] ++ stdenv.lib.optional (!doCheck) python3;
+
+  buildInputs = [
+    glib systemd polkit
+  ];
+
+  doCheck = true;
+
+  preCheck = ''
+    export LD_LIBRARY_PATH=${umockdev.out}/lib/
+  '';
+
+  checkInputs = [
+    dbus umockdev gobject-introspection
+    (python3.withPackages
+      (p: [ p.pygobject3 p.dbus-python p.python-dbusmock ]))
+  ];
+
+  # meson install tries to create /var/lib/boltd
+  patches = [ ./0001-skip-mkdir.patch ];
+
+  postPatch = ''
+    patchShebangs tests/test-integration
+  '';
+
+  mesonFlags = [
+    "-Dlocalstatedir=/var"
+  ];
+
+  PKG_CONFIG_SYSTEMD_SYSTEMDSYSTEMUNITDIR = "${placeholder "out"}/lib/systemd/system";
+  PKG_CONFIG_UDEV_UDEVDIR = "${placeholder "out"}/lib/udev";
+
+  meta = with stdenv.lib; {
+    description = "Thunderbolt 3 device management daemon";
+    homepage = https://gitlab.freedesktop.org/bolt/bolt;
+    license = licenses.lgpl21Plus;
+    maintainers = [ maintainers.callahad ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/bpftrace/bcc-source.patch b/nixpkgs/pkgs/os-specific/linux/bpftrace/bcc-source.patch
new file mode 100644
index 000000000000..a4c9947f0c34
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bpftrace/bcc-source.patch
@@ -0,0 +1,32 @@
+From fc0a5bd2ddb5827c5288ee284c1f2d834d79e432 Mon Sep 17 00:00:00 2001
+From: Rodney Lorrimar <dev@rodney.id.au>
+Date: Tue, 16 Oct 2018 09:55:59 +1000
+Subject: [PATCH 1/3] Don't use ExternalProject for bcc sources
+
+---
+ CMakeLists.txt | 9 +++++++++
+ 1 file changed, 9 insertions(+)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index eae850a..b20fb33 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -31,6 +31,15 @@ if (OFFLINE_BUILDS)
+     UPDATE_DISCONNECTED 1
+     BUILD_COMMAND ${CMAKE_COMMAND} --build . --target bcc-static
+     )
++elseif (NIX_BUILDS)
++  include(ExternalProject)
++  ExternalProject_Add(bcc
++    DOWNLOAD_COMMAND rmdir bcc && ln -sf $ENV{bccSrc} bcc
++    STEP_TARGETS build update
++    EXCLUDE_FROM_ALL 1
++    UPDATE_DISCONNECTED 1
++    BUILD_COMMAND ${CMAKE_COMMAND} --build . --target bcc-static
++    )
+ else()
+   include(ExternalProject)
+   ExternalProject_Add(bcc
+-- 
+2.17.1
+
diff --git a/nixpkgs/pkgs/os-specific/linux/bpftrace/default.nix b/nixpkgs/pkgs/os-specific/linux/bpftrace/default.nix
new file mode 100644
index 000000000000..12773a957165
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bpftrace/default.nix
@@ -0,0 +1,57 @@
+{ stdenv, fetchFromGitHub
+, cmake, pkgconfig, flex, bison
+, llvmPackages, kernel, linuxHeaders, elfutils, libelf, bcc
+}:
+
+stdenv.mkDerivation rec {
+  name = "bpftrace-unstable-${version}";
+  version = "2018-10-27";
+
+  src = fetchFromGitHub {
+    owner = "iovisor";
+    repo = "bpftrace";
+    rev = "c07b54f61fd7b7b49e0a254e746d6f442c5d780d";
+    sha256 = "1mpcjfyay9akmpqxag2ndwpz1qsdx8ii07jh9fky4w40wi9cipyg";
+  };
+
+  # bpftrace requires an unreleased version of bcc, added to the cmake
+  # build as an ExternalProject.
+  # https://github.com/iovisor/bpftrace/issues/184
+  bccSrc = fetchFromGitHub {
+    owner = "iovisor";
+    repo = "bcc";
+    rev = "afd00154865f3b2da6781cf92cecebaca4853950";
+    sha256 = "0ad78smrnipr1f377i5rv6ksns7v2vq54g5badbj5ldqs4x0hygd";
+  };
+
+  buildInputs = [
+    llvmPackages.llvm llvmPackages.clang-unwrapped kernel
+    elfutils libelf bccSrc
+  ];
+
+  nativeBuildInputs = [ cmake pkgconfig flex bison ]
+    # libelf is incompatible with elfutils-libelf
+    ++ stdenv.lib.filter (x: x != libelf) kernel.moduleBuildDependencies;
+
+  patches = [
+    ./bcc-source.patch
+    # https://github.com/iovisor/bpftrace/issues/184
+    ./disable-gtests.patch
+  ];
+
+  configurePhase = ''
+    mkdir build
+    cd build
+    cmake ../                                   \
+      -DKERNEL_HEADERS_DIR=${linuxHeaders}      \
+      -DNIX_BUILDS:BOOL=ON                      \
+      -DCMAKE_INSTALL_PREFIX=$out
+  '';
+
+  meta = with stdenv.lib; {
+    description = "High-level tracing language for Linux eBPF";
+    homepage = https://github.com/iovisor/bpftrace;
+    license = licenses.asl20;
+    maintainers = with maintainers; [ rvl ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/bpftrace/disable-gtests.patch b/nixpkgs/pkgs/os-specific/linux/bpftrace/disable-gtests.patch
new file mode 100644
index 000000000000..941d85a41126
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bpftrace/disable-gtests.patch
@@ -0,0 +1,73 @@
+From 221eea24674fffb3b657b2bd0c923071b69d48a7 Mon Sep 17 00:00:00 2001
+From: Rodney Lorrimar <dev@rodney.id.au>
+Date: Tue, 16 Oct 2018 09:56:47 +1000
+Subject: [PATCH 2/3] Disable tests
+
+Would prefer to use gtest library in the normal way rather through
+ExternalProject.
+---
+ CMakeLists.txt       |  4 ++--
+ tests/CMakeLists.txt | 18 +++++++++++-------
+ 2 files changed, 13 insertions(+), 9 deletions(-)
+
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index b20fb33..7025d17 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -20,7 +20,7 @@ add_compile_options("-Wno-format-security")
+ #add_compile_options("-Wstrict-overflow=5")
+ #add_compile_options("-Wdisabled-optimization")
+ 
+-enable_testing()
++# enable_testing()
+ 
+ if (OFFLINE_BUILDS)
+   include(ExternalProject)
+@@ -79,7 +79,7 @@ include_directories(${CLANG_INCLUDE_DIRS})
+ add_subdirectory(src/arch)
+ add_subdirectory(src/ast)
+ add_subdirectory(src)
+-add_subdirectory(tests)
++# add_subdirectory(tests)
+ add_subdirectory(resources)
+ add_subdirectory(tools)
+ add_subdirectory(man)
+diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
+index c283efa..6b5bff0 100644
+--- a/tests/CMakeLists.txt
++++ b/tests/CMakeLists.txt
+@@ -45,6 +45,8 @@ if (OFFLINE_BUILDS)
+     EXCLUDE_FROM_ALL 1
+     UPDATE_DISCONNECTED 1
+     )
++elseif (NIX_BUILDS)
++
+ else()
+   include(ExternalProject)
+   ExternalProject_Add(gtest-git
+@@ -54,13 +56,15 @@ else()
+     EXCLUDE_FROM_ALL 1
+     )
+ endif()
+-add_dependencies(bpftrace_test gtest-git-build)
+-ExternalProject_Get_Property(gtest-git source_dir binary_dir)
+-target_include_directories(bpftrace_test PUBLIC ${source_dir}/googletest/include)
+-target_include_directories(bpftrace_test PUBLIC ${source_dir}/googlemock/include)
+-target_link_libraries(bpftrace_test ${binary_dir}/googlemock/gtest/libgtest.a)
+-target_link_libraries(bpftrace_test ${binary_dir}/googlemock/gtest/libgtest_main.a)
+-target_link_libraries(bpftrace_test ${binary_dir}/googlemock/libgmock.a)
++
++find_library(LIBGTEST "gtest")
++if(LIBGTEST)
++    set(LIBRARY_DEPENDENCIES
++        ${LIBRARY_DEPENDENCIES}
++       ${LIBGTEST}
++    )
++endif()
++
+ target_link_libraries(bpftrace_test ${CMAKE_THREAD_LIBS_INIT})
+ 
+ add_test(NAME bpftrace_test COMMAND bpftrace_test)
+-- 
+2.17.1
+
diff --git a/nixpkgs/pkgs/os-specific/linux/bridge-utils/add-ip6-header.patch b/nixpkgs/pkgs/os-specific/linux/bridge-utils/add-ip6-header.patch
new file mode 100644
index 000000000000..c9149bfec386
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bridge-utils/add-ip6-header.patch
@@ -0,0 +1,11 @@
+diff --git a/libbridge/libbridge.h b/libbridge/libbridge.h
+index 39964f2..dd14bae 100644
+--- a/libbridge/libbridge.h
++++ b/libbridge/libbridge.h
+@@ -20,6 +20,7 @@
+ #define _LIBBRIDGE_H
+
+ #include <sys/socket.h>
++#include <netinet/in.h>
+ #include <linux/if.h>
+ #include <linux/if_bridge.h>
diff --git a/nixpkgs/pkgs/os-specific/linux/bridge-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/bridge-utils/default.nix
new file mode 100644
index 000000000000..2725a5909b7b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/bridge-utils/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchurl, autoreconfHook }:
+
+stdenv.mkDerivation rec {
+  name = "bridge-utils-1.5";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/bridge/${name}.tar.gz";
+    sha256 = "42f9e5fb8f6c52e63a98a43b81bd281c227c529f194913e1c51ec48a393b6688";
+  };
+
+  # Remove patch once the kernel headers are updated
+  patches = [ ./add-ip6-header.patch ];
+
+  nativeBuildInputs = [ autoreconfHook ];
+  buildInputs = [ ];
+
+  postInstall = ''
+    # The bridge utils build does not fail even if the brctl binary
+    # is not build. This test ensures that we fail if we don't produce a brctl
+    # binary.
+    test -f $out/sbin/brctl
+  '';
+
+  meta = {
+    description = "https://sourceforge.net/projects/bridge/";
+    homepage = https://wiki.linuxfoundation.org/networking/bridge;
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/default.nix b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/default.nix
new file mode 100644
index 000000000000..541539522f85
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/default.nix
@@ -0,0 +1,64 @@
+{ stdenv, fetchurl, kernel }:
+
+let
+  version = "6.30.223.271";
+  hashes = {
+    i686-linux   = "1kaqa2dw3nb8k23ffvx46g8jj3wdhz8xa6jp1v3wb35cjfr712sg";
+    x86_64-linux = "1gj485qqr190idilacpxwgqyw21il03zph2rddizgj7fbd6pfyaz";
+  };
+
+  arch = stdenv.lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") "_64";
+  tarballVersion = stdenv.lib.replaceStrings ["."] ["_"] version;
+  tarball = "hybrid-v35${arch}-nodebug-pcoem-${tarballVersion}.tar.gz";
+in
+stdenv.mkDerivation {
+  name = "broadcom-sta-${version}-${kernel.version}";
+
+  src = fetchurl {
+    url = "https://docs.broadcom.com/docs-and-downloads/docs/linux_sta/${tarball}";
+    sha256 = hashes.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}");
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  patches = [
+    ./i686-build-failure.patch
+    ./license.patch
+    ./linux-4.7.patch
+    # source: https://git.archlinux.org/svntogit/community.git/tree/trunk/004-linux48.patch?h=packages/broadcom-wl-dkms
+    ./linux-4.8.patch
+    # source: https://aur.archlinux.org/cgit/aur.git/tree/linux411.patch?h=broadcom-wl
+    ./linux-4.11.patch
+    # source: https://aur.archlinux.org/cgit/aur.git/tree/linux412.patch?h=broadcom-wl
+    ./linux-4.12.patch
+    ./linux-4.15.patch
+    ./null-pointer-fix.patch
+    ./gcc.patch
+  ];
+
+  makeFlags = "KBASE=${kernel.dev}/lib/modules/${kernel.modDirVersion}";
+
+  unpackPhase = ''
+    sourceRoot=broadcom-sta
+    mkdir "$sourceRoot"
+    tar xvf "$src" -C "$sourceRoot"
+  '';
+
+  installPhase = ''
+    binDir="$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+    docDir="$out/share/doc/broadcom-sta/"
+    mkdir -p "$binDir" "$docDir"
+    cp wl.ko "$binDir"
+    cp lib/LICENSE.txt "$docDir"
+  '';
+
+  meta = {
+    description = "Kernel module driver for some Broadcom's wireless cards";
+    homepage = http://www.broadcom.com/support/802.11/linux_sta.php;
+    license = stdenv.lib.licenses.unfreeRedistributable;
+    maintainers = with stdenv.lib.maintainers; [ phreedom ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/gcc.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/gcc.patch
new file mode 100644
index 000000000000..f93e3f1d3a3f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/gcc.patch
@@ -0,0 +1,11 @@
+--- a/Makefile	2014-06-26 10:42:08.000000000 +0000
++++ b/Makefile	2014-07-17 22:44:01.662297228 +0000
+@@ -126,6 +126,8 @@
+ EXTRA_CFLAGS       += -I$(src)/src/shared/bcmwifi/include
+ #EXTRA_CFLAGS       += -DBCMDBG_ASSERT -DBCMDBG_ERR
+ 
++EXTRA_CFLAGS       += -Wno-date-time
++
+ EXTRA_LDFLAGS      := $(src)/lib/wlc_hybrid.o_shipped
+ 
+ KBASE              ?= /lib/modules/`uname -r`
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/i686-build-failure.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/i686-build-failure.patch
new file mode 100644
index 000000000000..cfa16075409b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/i686-build-failure.patch
@@ -0,0 +1,18 @@
+https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit?id=fe47ae6e1a5005b2e82f7eab57b5c3820453293a
+https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit?id=4ea1636b04dbd66536fa387bae2eea463efc705b
+
+diff -ru a/src/shared/linux_osl.c b/src/shared/linux_osl.c
+--- a/src/shared/linux_osl.c	2015-09-19 01:47:15.000000000 +0300
++++ b/src/shared/linux_osl.c	2015-11-21 15:20:30.585902518 +0200
+@@ -932,7 +932,11 @@
+ 	uint cycles;
+ 
+ #if defined(__i386__)
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
++	cycles = (u32)rdtsc();
++#else
+ 	rdtscl(cycles);
++#endif
+ #else
+ 	cycles = 0;
+ #endif 
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/license.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/license.patch
new file mode 100644
index 000000000000..aebb46365195
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/license.patch
@@ -0,0 +1,13 @@
+diff -Naur hybrid-portsrc-x86_32-v5_10_91_9.orig/src/wl/sys/wl_linux.c hybrid-portsrc-x86_32-v5_10_91_9/src/wl/sys/wl_linux.c
+--- hybrid-portsrc-x86_32-v5_10_91_9.orig/src/wl/sys/wl_linux.c	2009-04-23 02:48:59.000000000 +0900
++++ hybrid-portsrc-x86_32-v5_10_91_9/src/wl/sys/wl_linux.c	2009-05-08 00:48:20.000000000 +0900
+@@ -171,6 +171,8 @@
+ static void wl_free_if(wl_info_t *wl, wl_if_t *wlif);
+ static void wl_get_driver_info(struct net_device *dev, struct ethtool_drvinfo *info);
+ 
++MODULE_LICENSE("MIXED/Proprietary");
++
+ #if defined(WL_CONFIG_RFKILL)
+ #include <linux/rfkill.h>
+ static int wl_init_rfkill(wl_info_t *wl);
+
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.11.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.11.patch
new file mode 100644
index 000000000000..a779f8c84cfd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.11.patch
@@ -0,0 +1,52 @@
+diff --git a/src/wl/sys/wl_cfg80211_hybrid.c b/src/wl/sys/wl_cfg80211_hybrid.c
+index a9671e2..da36405 100644
+--- a/src/wl/sys/wl_cfg80211_hybrid.c
++++ b/src/wl/sys/wl_cfg80211_hybrid.c
+@@ -30,6 +30,9 @@
+ #include <linux/kthread.h>
+ #include <linux/netdevice.h>
+ #include <linux/ieee80211.h>
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
++#include <linux/sched/signal.h>
++#endif
+ #include <net/cfg80211.h>
+ #include <linux/nl80211.h>
+ #include <net/rtnetlink.h>
+diff --git a/src/wl/sys/wl_linux.c b/src/wl/sys/wl_linux.c
+index 489c9f5..f8278ad 100644
+--- a/src/wl/sys/wl_linux.c
++++ b/src/wl/sys/wl_linux.c
+@@ -117,6 +117,9 @@ int wl_found = 0;
+ 
+ typedef struct priv_link {
+ 	wl_if_t *wlif;
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
++	unsigned long last_rx;
++#endif
+ } priv_link_t;
+ 
+ #define WL_DEV_IF(dev)          ((wl_if_t*)((priv_link_t*)DEV_PRIV(dev))->wlif)
+@@ -2450,6 +2453,9 @@ wl_monitor(wl_info_t *wl, wl_rxsts_t *rxsts, void *p)
+ {
+ 	struct sk_buff *oskb = (struct sk_buff *)p;
+ 	struct sk_buff *skb;
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
++	priv_link_t *priv_link;
++#endif
+ 	uchar *pdata;
+ 	uint len;
+ 
+@@ -2916,7 +2922,13 @@ wl_monitor(wl_info_t *wl, wl_rxsts_t *rxsts, void *p)
+ 	if (skb == NULL) return;
+ 
+ 	skb->dev = wl->monitor_dev;
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
++	priv_link = MALLOC(wl->osh, sizeof(priv_link_t));
++	priv_link = netdev_priv(skb->dev);
++	priv_link->last_rx = jiffies;
++#else
+ 	skb->dev->last_rx = jiffies;
++#endif
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
+ 	skb_reset_mac_header(skb);
+ #else
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.12.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.12.patch
new file mode 100644
index 000000000000..8abc73db4db1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.12.patch
@@ -0,0 +1,68 @@
+diff --git a/src/wl/sys/wl_cfg80211_hybrid.c b/src/wl/sys/wl_cfg80211_hybrid.c
+index da36405..d3741eb 100644
+--- a/src/wl/sys/wl_cfg80211_hybrid.c
++++ b/src/wl/sys/wl_cfg80211_hybrid.c
+@@ -53,7 +53,11 @@ u32 wl_dbg_level = WL_DBG_ERR;
+ #endif
+ 
+ static s32 wl_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
++           enum nl80211_iftype type, struct vif_params *params);
++#else
+            enum nl80211_iftype type, u32 *flags, struct vif_params *params);
++#endif
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0)
+ static s32
+ wl_cfg80211_scan(struct wiphy *wiphy,
+@@ -466,7 +470,11 @@ wl_dev_ioctl(struct net_device *dev, u32 cmd, void *arg, u32 len)
+ 
+ static s32
+ wl_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
++                         enum nl80211_iftype type,
++#else
+                          enum nl80211_iftype type, u32 *flags,
++#endif
+    struct vif_params *params)
+ {
+ 	struct wl_cfg80211_priv *wl = wiphy_to_wl(wiphy);
+@@ -2361,6 +2369,20 @@ wl_bss_roaming_done(struct wl_cfg80211_priv *wl, struct net_device *ndev,
+                     const wl_event_msg_t *e, void *data)
+ {
+ 	struct wl_cfg80211_connect_info *conn_info = wl_to_conn(wl);
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
++	struct cfg80211_bss *bss;
++	struct wlc_ssid *ssid;
++	ssid = &wl->profile->ssid;
++	bss = cfg80211_get_bss(wl_to_wiphy(wl), NULL, (s8 *)&wl->bssid,
++	ssid->SSID, ssid->SSID_len, WLAN_CAPABILITY_ESS, WLAN_CAPABILITY_ESS);
++	struct cfg80211_roam_info roam_info = {
++		.bss = bss,
++		.req_ie = conn_info->req_ie,
++		.req_ie_len = conn_info->req_ie_len,
++		.resp_ie = conn_info->resp_ie,
++		.resp_ie_len = conn_info->resp_ie_len,
++	};
++#endif
+ 	s32 err = 0;
+ 
+ 	wl_get_assoc_ies(wl);
+@@ -2368,12 +2390,17 @@ wl_bss_roaming_done(struct wl_cfg80211_priv *wl, struct net_device *ndev,
+ 	memcpy(&wl->bssid, &e->addr, ETHER_ADDR_LEN);
+ 	wl_update_bss_info(wl);
+ 	cfg80211_roamed(ndev,
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0)
++			&roam_info,
++#else
+ #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 39)
+ 			&wl->conf->channel,	 
+ #endif
+ 			(u8 *)&wl->bssid,
+ 			conn_info->req_ie, conn_info->req_ie_len,
+-			conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
++			conn_info->resp_ie, conn_info->resp_ie_len,
++#endif
++			GFP_KERNEL);
+ 	WL_DBG(("Report roaming result\n"));
+ 
+ 	set_bit(WL_STATUS_CONNECTED, &wl->status);
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.15.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.15.patch
new file mode 100644
index 000000000000..523fa291d525
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.15.patch
@@ -0,0 +1,47 @@
+See: https://lkml.org/lkml/2017/11/25/90
+
+diff -urNZ a/src/wl/sys/wl_linux.c b/src/wl/sys/wl_linux.c
+--- a/src/wl/sys/wl_linux.c	2015-09-18 22:47:30.000000000 +0000
++++ b/src/wl/sys/wl_linux.c	2018-01-31 22:52:10.859856221 +0000
+@@ -93,7 +93,11 @@
+
+ #include <wlc_wowl.h>
+
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
++static void wl_timer(struct timer_list *tl);
++#else
+ static void wl_timer(ulong data);
++#endif
+ static void _wl_timer(wl_timer_t *t);
+ static struct net_device *wl_alloc_linux_if(wl_if_t *wlif);
+
+@@ -2298,9 +2302,15 @@
+ }
+
+ static void
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
++wl_timer(struct timer_list *tl)
++{
++	wl_timer_t *t = from_timer(t, tl, timer);
++#else
+ wl_timer(ulong data)
+ {
+ 	wl_timer_t *t = (wl_timer_t *)data;
++#endif
+
+ 	if (!WL_ALL_PASSIVE_ENAB(t->wl))
+ 		_wl_timer(t);
+@@ -2352,9 +2362,13 @@
+
+ 	bzero(t, sizeof(wl_timer_t));
+
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
++	timer_setup(&t->timer, wl_timer, 0);
++#else
+ 	init_timer(&t->timer);
+ 	t->timer.data = (ulong) t;
+ 	t->timer.function = wl_timer;
++#endif
+ 	t->wl = wl;
+ 	t->fn = fn;
+ 	t->arg = arg;
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.7.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.7.patch
new file mode 100644
index 000000000000..566680a09140
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.7.patch
@@ -0,0 +1,109 @@
+Since Linux 4.7, the enum ieee80211_band is no longer used
+
+This shall cause no problem's since both enums ieee80211_band
+and nl80211_band were added in the same commit:
+https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit?id=13ae75b103e07304a34ab40c9136e9f53e06475c
+
+This patch refactors the references of IEEE80211_BAND_* to NL80211_BAND_*
+
+Reference:
+https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit?id=57fbcce37be7c1d2622b56587c10ade00e96afa3
+
+--- a/src/wl/sys/wl_cfg80211_hybrid.c	2016-06-13 11:57:36.159340297 -0500
++++ b/src/wl/sys/wl_cfg80211_hybrid.c	2016-06-13 11:58:18.442323435 -0500
+@@ -236,7 +236,7 @@
+ #endif				
+ 
+ #define CHAN2G(_channel, _freq, _flags) {			\
+-	.band			= IEEE80211_BAND_2GHZ,		\
++	.band			= NL80211_BAND_2GHZ,		\
+ 	.center_freq		= (_freq),			\
+ 	.hw_value		= (_channel),			\
+ 	.flags			= (_flags),			\
+@@ -245,7 +245,7 @@
+ }
+ 
+ #define CHAN5G(_channel, _flags) {				\
+-	.band			= IEEE80211_BAND_5GHZ,		\
++	.band			= NL80211_BAND_5GHZ,		\
+ 	.center_freq		= 5000 + (5 * (_channel)),	\
+ 	.hw_value		= (_channel),			\
+ 	.flags			= (_flags),			\
+@@ -379,7 +379,7 @@
+ };
+ 
+ static struct ieee80211_supported_band __wl_band_2ghz = {
+-	.band = IEEE80211_BAND_2GHZ,
++	.band = NL80211_BAND_2GHZ,
+ 	.channels = __wl_2ghz_channels,
+ 	.n_channels = ARRAY_SIZE(__wl_2ghz_channels),
+ 	.bitrates = wl_g_rates,
+@@ -387,7 +387,7 @@
+ };
+ 
+ static struct ieee80211_supported_band __wl_band_5ghz_a = {
+-	.band = IEEE80211_BAND_5GHZ,
++	.band = NL80211_BAND_5GHZ,
+ 	.channels = __wl_5ghz_a_channels,
+ 	.n_channels = ARRAY_SIZE(__wl_5ghz_a_channels),
+ 	.bitrates = wl_a_rates,
+@@ -395,7 +395,7 @@
+ };
+ 
+ static struct ieee80211_supported_band __wl_band_5ghz_n = {
+-	.band = IEEE80211_BAND_5GHZ,
++	.band = NL80211_BAND_5GHZ,
+ 	.channels = __wl_5ghz_n_channels,
+ 	.n_channels = ARRAY_SIZE(__wl_5ghz_n_channels),
+ 	.bitrates = wl_a_rates,
+@@ -1876,8 +1876,8 @@
+ 	wdev->wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
+ #endif
+ 	wdev->wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
+-	wdev->wiphy->bands[IEEE80211_BAND_2GHZ] = &__wl_band_2ghz;
+-	wdev->wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_a; 
++	wdev->wiphy->bands[NL80211_BAND_2GHZ] = &__wl_band_2ghz;
++	wdev->wiphy->bands[NL80211_BAND_5GHZ] = &__wl_band_5ghz_a; 
+ 	wdev->wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
+ 	wdev->wiphy->cipher_suites = __wl_cipher_suites;
+ 	wdev->wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
+@@ -2000,7 +2000,7 @@
+ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 39)
+ 	freq = ieee80211_channel_to_frequency(notif_bss_info->channel,
+ 		(notif_bss_info->channel <= CH_MAX_2G_CHANNEL) ?
+-		IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ);
++		NL80211_BAND_2GHZ : NL80211_BAND_5GHZ);
+ #else
+ 	freq = ieee80211_channel_to_frequency(notif_bss_info->channel);
+ #endif
+@@ -2116,7 +2116,7 @@
+ 				return err;
+ 			}
+ 			chan = wf_chspec_ctlchan(chanspec);
+-			band = (chan <= CH_MAX_2G_CHANNEL) ? IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
++			band = (chan <= CH_MAX_2G_CHANNEL) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ;
+ 			freq = ieee80211_channel_to_frequency(chan, band);
+ 			channel = ieee80211_get_channel(wiphy, freq);
+ 			cfg80211_ibss_joined(ndev, (u8 *)&wl->bssid, channel, GFP_KERNEL);
+@@ -2250,10 +2250,10 @@
+ 		join_params->params.chanspec_list[0] =
+ 		    ieee80211_frequency_to_channel(chan->center_freq);
+ 
+-		if (chan->band == IEEE80211_BAND_2GHZ) {
++		if (chan->band == NL80211_BAND_2GHZ) {
+ 			chanspec |= WL_CHANSPEC_BAND_2G;
+ 		}
+-		else if (chan->band == IEEE80211_BAND_5GHZ) {
++		else if (chan->band == NL80211_BAND_5GHZ) {
+ 			chanspec |= WL_CHANSPEC_BAND_5G;
+ 		}
+ 		else {
+@@ -2885,7 +2885,7 @@
+ 
+ 	if (phy == 'n' || phy == 'a' || phy == 'v') {
+ 		wiphy = wl_to_wiphy(wl);
+-		wiphy->bands[IEEE80211_BAND_5GHZ] = &__wl_band_5ghz_n;
++		wiphy->bands[NL80211_BAND_5GHZ] = &__wl_band_5ghz_n;
+ 	}
+ 
+ 	return err;
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.8.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.8.patch
new file mode 100644
index 000000000000..20e8a9ae49d2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/linux-4.8.patch
@@ -0,0 +1,64 @@
+From d3f93542326a06d920c6eb89b703384290d37b8b Mon Sep 17 00:00:00 2001
+From: Alberto Milone <alberto.milone@canonical.com>
+Date: Fri, 2 Sep 2016 17:35:34 +0200
+Subject: [PATCH 1/1] Add support for Linux 4.8
+
+Orginal author: Krzysztof Kolasa
+---
+ src/wl/sys/wl_cfg80211_hybrid.c | 22 ++++++++++++++++++++++
+ 1 file changed, 22 insertions(+)
+
+diff --git a/src/wl/sys/wl_cfg80211_hybrid.c b/src/wl/sys/wl_cfg80211_hybrid.c
+index 2fc71fe..ec5e472 100644
+--- a/src/wl/sys/wl_cfg80211_hybrid.c
++++ b/src/wl/sys/wl_cfg80211_hybrid.c
+@@ -2388,8 +2388,16 @@ wl_bss_connect_done(struct wl_cfg80211_priv *wl, struct net_device *ndev,
+ 	s32 err = 0;
+ 
+ 	if (wl->scan_request) {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
++		struct cfg80211_scan_info info = {
++			.aborted = true,
++		};
++		WL_DBG(("%s: Aborting scan\n", __FUNCTION__));
++		cfg80211_scan_done(wl->scan_request, &info);
++#else
+ 		WL_DBG(("%s: Aborting scan\n", __FUNCTION__));
+ 		cfg80211_scan_done(wl->scan_request, true);     
++#endif
+ 		wl->scan_request = NULL;
+ 	}
+ 
+@@ -2490,7 +2498,14 @@ wl_notify_scan_status(struct wl_cfg80211_priv *wl, struct net_device *ndev,
+ 
+ scan_done_out:
+ 	if (wl->scan_request) {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
++		struct cfg80211_scan_info info = {
++			.aborted = false,
++		};
++		cfg80211_scan_done(wl->scan_request, &info);
++#else
+ 		cfg80211_scan_done(wl->scan_request, false);
++#endif
+ 		wl->scan_request = NULL;
+ 	}
+ 	rtnl_unlock();
+@@ -2909,7 +2924,14 @@ s32 wl_cfg80211_down(struct net_device *ndev)
+ 	s32 err = 0;
+ 
+ 	if (wl->scan_request) {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0)
++		struct cfg80211_scan_info info = {
++			.aborted = true,
++		};
++		cfg80211_scan_done(wl->scan_request, &info);
++#else
+ 		cfg80211_scan_done(wl->scan_request, true);	
++#endif
+ 		wl->scan_request = NULL;
+ 	}
+ 
+-- 
+2.7.4
+
diff --git a/nixpkgs/pkgs/os-specific/linux/broadcom-sta/null-pointer-fix.patch b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/null-pointer-fix.patch
new file mode 100644
index 000000000000..763797294307
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/broadcom-sta/null-pointer-fix.patch
@@ -0,0 +1,13 @@
+diff -urN a/src/wl/sys/wl_linux.c b/src/wl/sys/wl_linux.c
+--- a/src/wl/sys/wl_linux.c	2015-01-06 12:33:42.981659618 +0100
++++ b/src/wl/sys/wl_linux.c	2015-01-06 12:34:05.647395418 +0100
+@@ -2157,8 +2157,8 @@
+ 	wlif = WL_DEV_IF(dev);
+ 	wl = WL_INFO(dev);
+ 
++	skb->prev = NULL;
+ 	if (WL_ALL_PASSIVE_ENAB(wl) || (WL_RTR() && WL_CONFIG_SMP())) {
+-		skb->prev = NULL;
+ 
+ 		TXQ_LOCK(wl);
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/btfs/default.nix b/nixpkgs/pkgs/os-specific/linux/btfs/default.nix
new file mode 100644
index 000000000000..9c2692b037ef
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/btfs/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, pkgconfig,
+  python3, boost, fuse, libtorrentRasterbar, curl }:
+
+stdenv.mkDerivation rec {
+  name = "btfs-${version}";
+  version = "2.18";
+
+  src = fetchFromGitHub {
+    owner  = "johang";
+    repo   = "btfs";
+    rev    = "v${version}";
+    sha256 = "1cn21bxx43iqvac6scmwhkw0bql092sl48r6qfidbmhbw30xl5yf";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [
+    boost autoreconfHook
+    fuse libtorrentRasterbar curl
+  ];
+
+  preInstall = ''
+    substituteInPlace scripts/btplay \
+      --replace "/usr/bin/env python" "${python3.interpreter}"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A bittorrent filesystem based on FUSE";
+    homepage    = https://github.com/johang/btfs;
+    license     = licenses.gpl3;
+    maintainers = with maintainers; [ rnhmjoj ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/busybox/busybox-in-store.patch b/nixpkgs/pkgs/os-specific/linux/busybox/busybox-in-store.patch
new file mode 100644
index 000000000000..2d356b66b3ae
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/busybox/busybox-in-store.patch
@@ -0,0 +1,23 @@
+Allow BusyBox to be invoked as "<something>-busybox". This is
+necessary when it's run from the Nix store as <hash>-busybox during
+stdenv bootstrap.
+--- a/libbb/appletlib.c
++++ b/libbb/appletlib.c
+@@ -947,7 +947,7 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, const char *name, char **ar
+ static NORETURN void run_applet_and_exit(const char *name, char **argv)
+ {
+ #  if ENABLE_BUSYBOX
+-	if (is_prefixed_with(name, "busybox"))
++	if (strstr(name, "busybox") != 0)
+ 		exit(busybox_main(/*unused:*/ 0, argv));
+ #  endif
+ #  if NUM_APPLETS > 0
+@@ -1045,7 +1045,7 @@ int main(int argc UNUSED_PARAM, char **argv)
+
+ 	lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv));
+ # if !ENABLE_BUSYBOX
+-	if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox"))
++	if (argv[1] && strstr(bb_basename(argv[0]), "busybox") != 0)
+ 		argv++;
+ # endif
+ 	applet_name = argv[0];
diff --git a/nixpkgs/pkgs/os-specific/linux/busybox/default.nix b/nixpkgs/pkgs/os-specific/linux/busybox/default.nix
new file mode 100644
index 000000000000..4b2877250821
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/busybox/default.nix
@@ -0,0 +1,111 @@
+{ stdenv, lib, buildPackages, fetchurl
+, enableStatic ? false
+, enableMinimal ? false
+, useMusl ? stdenv.hostPlatform.libc == "musl", musl
+, extraConfig ? ""
+}:
+
+assert stdenv.hostPlatform.libc == "musl" -> useMusl;
+
+let
+  configParser = ''
+    function parseconfig {
+        while read LINE; do
+            NAME=`echo "$LINE" | cut -d \  -f 1`
+            OPTION=`echo "$LINE" | cut -d \  -f 2`
+
+            if ! [[ "$NAME" =~ ^CONFIG_ ]]; then continue; fi
+
+            echo "parseconfig: removing $NAME"
+            sed -i /$NAME'\(=\| \)'/d .config
+
+            echo "parseconfig: setting $NAME=$OPTION"
+            echo "$NAME=$OPTION" >> .config
+        done
+    }
+  '';
+
+  libcConfig = lib.optionalString useMusl ''
+    CONFIG_FEATURE_UTMP n
+    CONFIG_FEATURE_WTMP n
+  '';
+in
+
+stdenv.mkDerivation rec {
+  name = "busybox-1.30.1";
+
+  # Note to whoever is updating busybox: please verify that:
+  # nix-build pkgs/stdenv/linux/make-bootstrap-tools.nix -A test
+  # still builds after the update.
+  src = fetchurl {
+    url = "https://busybox.net/downloads/${name}.tar.bz2";
+    sha256 = "1p7vbnwj60q6zkzrzq3pa8ybb7mviv2aa5a8g7s4hh6kvfj0879x";
+  };
+
+  hardeningDisable = [ "format" "pie" ]
+    ++ lib.optionals enableStatic [ "fortify" ];
+
+  patches = [
+    ./busybox-in-store.patch
+  ];
+
+  postPatch = "patchShebangs .";
+
+  configurePhase = ''
+    export KCONFIG_NOTIMESTAMP=1
+    make ${if enableMinimal then "allnoconfig" else "defconfig"}
+
+    ${configParser}
+
+    cat << EOF | parseconfig
+
+    CONFIG_PREFIX "$out"
+    CONFIG_INSTALL_NO_USR y
+
+    CONFIG_LFS y
+
+    ${lib.optionalString enableStatic ''
+      CONFIG_STATIC y
+    ''}
+
+    # Use the external mount.cifs program.
+    CONFIG_FEATURE_MOUNT_CIFS n
+    CONFIG_FEATURE_MOUNT_HELPERS y
+
+    # Set paths for console fonts.
+    CONFIG_DEFAULT_SETFONT_DIR "/etc/kbd"
+
+    # Bump from 4KB, much faster I/O
+    CONFIG_FEATURE_COPYBUF_KB 64
+
+    ${extraConfig}
+    CONFIG_CROSS_COMPILER_PREFIX "${stdenv.cc.targetPrefix}"
+    ${libcConfig}
+    EOF
+
+    make oldconfig
+
+    runHook postConfigure
+  '';
+
+  postConfigure = lib.optionalString useMusl ''
+    makeFlagsArray+=("CC=${stdenv.cc.targetPrefix}cc -isystem ${musl.dev}/include -B${musl}/lib -L${musl}/lib")
+  '';
+
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
+
+  buildInputs = lib.optionals (enableStatic && !useMusl) [ stdenv.cc.libc stdenv.cc.libc.static ];
+
+  enableParallelBuilding = true;
+
+  doCheck = false; # tries to access the net
+
+  meta = with stdenv.lib; {
+    description = "Tiny versions of common UNIX utilities in a single small executable";
+    homepage = https://busybox.net/;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ ];
+    platforms = platforms.linux;
+    priority = 10;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/busybox/sandbox-shell.nix b/nixpkgs/pkgs/os-specific/linux/busybox/sandbox-shell.nix
new file mode 100644
index 000000000000..c2d82ebc487a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/busybox/sandbox-shell.nix
@@ -0,0 +1,27 @@
+{ busybox, stdenv}:
+
+# Minimal shell for use as basic /bin/sh in sandbox builds
+busybox.override {
+  # musl roadmap has RISC-V support projected for 1.1.20
+  useMusl = !stdenv.hostPlatform.isRiscV && stdenv.hostPlatform.libc != "bionic";
+  enableStatic = true;
+  enableMinimal = true;
+  extraConfig = ''
+    CONFIG_FEATURE_FANCY_ECHO y
+    CONFIG_FEATURE_SH_MATH y
+    CONFIG_FEATURE_SH_MATH_64 y
+
+    CONFIG_ASH y
+    CONFIG_ASH_OPTIMIZE_FOR_SIZE y
+
+    CONFIG_ASH_ALIAS y
+    CONFIG_ASH_BASH_COMPAT y
+    CONFIG_ASH_CMDCMD y
+    CONFIG_ASH_ECHO y
+    CONFIG_ASH_GETOPTS y
+    CONFIG_ASH_INTERNAL_GLOB y
+    CONFIG_ASH_JOB_CONTROL y
+    CONFIG_ASH_PRINTF y
+    CONFIG_ASH_TEST y
+  '';
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cachefilesd/default.nix b/nixpkgs/pkgs/os-specific/linux/cachefilesd/default.nix
new file mode 100644
index 000000000000..d77539fb89ed
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cachefilesd/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "cachefilesd-${version}";
+  version = "0.10.10";
+
+  src = fetchurl {
+    url = "https://people.redhat.com/dhowells/fscache/${name}.tar.bz2";
+    sha256 = "00hsw4cdlm13wijlygp8f0aq6gxdp0skbxs9r2vh5ggs3s2hj0qd";
+  };
+
+  installFlags = [
+    "ETCDIR=$(out)/etc"
+    "SBINDIR=$(out)/sbin"
+    "MANDIR=$(out)/share/man"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Local network file caching management daemon";
+    homepage = https://people.redhat.com/dhowells/fscache/;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/can-isotp/default.nix b/nixpkgs/pkgs/os-specific/linux/can-isotp/default.nix
new file mode 100644
index 000000000000..0c32c3f5e62a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/can-isotp/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, kernel, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "can-isotp-${version}";
+  version = "20180629";
+
+  hardeningDisable = [ "pic" ];
+  
+  src = fetchFromGitHub {
+    owner = "hartkopp";
+    repo = "can-isotp";
+    rev = "6003f9997587e6a563cebf1f246bcd0eb6deff3d";
+    sha256 = "0b2pqb0vd1wgv2zpl7lvfavqkzr8mrwhrv7zdqkq3rz9givcv8w7";
+  };
+
+  KERNELDIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
+  INSTALL_MOD_PATH = "\${out}";
+
+  buildPhase = ''
+    make modules
+  '';
+
+  installPhase = ''
+    make modules_install
+  '';
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+  
+  meta = with stdenv.lib; {
+    description = "Kernel module for ISO-TP (ISO 15765-2)";
+    homepage = "https://github.com/hartkopp/can-isotp";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.evck ];
+  };
+}  
diff --git a/nixpkgs/pkgs/os-specific/linux/can-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/can-utils/default.nix
new file mode 100644
index 000000000000..616c99c8f46a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/can-utils/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "can-utils-${version}";
+  # There are no releases (source archives or git tags), so use the date of the
+  # latest commit in git master as version number.
+  version = "20170830";
+
+  src = fetchFromGitHub {
+    owner = "linux-can";
+    repo = "can-utils";
+    rev = "5b518a0a5fa56856f804372a6b99b518dedb5386";
+    sha256 = "1ygzp8rjr8f1gs48mb1pz7psdgbfhlvr6kjdnmzbsqcml06zvrpr";
+  };
+
+  preConfigure = ''makeFlagsArray+=(PREFIX="$out")'';
+
+  meta = with stdenv.lib; {
+    description = "CAN userspace utilities and tools (for use with Linux SocketCAN)";
+    homepage = https://github.com/linux-can/can-utils;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.bjornfor ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cgmanager/default.nix b/nixpkgs/pkgs/os-specific/linux/cgmanager/default.nix
new file mode 100644
index 000000000000..6ba86036a52a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cgmanager/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl, pkgconfig, libnih, dbus, pam, popt }:
+
+stdenv.mkDerivation rec {
+  pname = "cgmanager";
+  version = "0.42";
+
+  src = fetchurl {
+    url = "https://linuxcontainers.org/downloads/${pname}/${pname}-${version}.tar.gz";
+    sha256 = "15np08h9jrvc1y1iafr8v654mzgsv5hshzc0n4p3pbf0rkra3h7c";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libnih dbus pam popt ];
+
+  configureFlags = [
+    "--with-init-script=systemd"
+    "--sysconfdir=/etc"
+    "--localstatedir=/var"
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = https://linuxcontainers.org/cgmanager/introduction/;
+    description = "A central privileged daemon that manages all your cgroups";
+    license = licenses.lgpl21;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/checkpolicy/default.nix b/nixpkgs/pkgs/os-specific/linux/checkpolicy/default.nix
new file mode 100644
index 000000000000..674b695b1eee
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/checkpolicy/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, bison, flex, libsepol }:
+
+stdenv.mkDerivation rec {
+  name = "checkpolicy-${version}";
+  version = "2.7";
+  inherit (libsepol) se_release se_url;
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/checkpolicy-${version}.tar.gz";
+    sha256 = "009j9jc0hi4l7k8f21hn8fm25n0mqgzdpd4nk30nds6d3nglf4sl";
+  };
+
+  nativeBuildInputs = [ bison flex ];
+  buildInputs = [ libsepol ];
+
+  makeFlags = [
+    "PREFIX=$(out)"
+    "LIBSEPOLA=${stdenv.lib.getLib libsepol}/lib/libsepol.a"
+  ];
+
+  meta = removeAttrs libsepol.meta ["outputsToInstall"] // {
+    description = "SELinux policy compiler";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/checksec/0001-attempt-to-modprobe-config-before-checking-kernel.patch b/nixpkgs/pkgs/os-specific/linux/checksec/0001-attempt-to-modprobe-config-before-checking-kernel.patch
new file mode 100644
index 000000000000..2caf52f3c0a3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/checksec/0001-attempt-to-modprobe-config-before-checking-kernel.patch
@@ -0,0 +1,27 @@
+From 6503848d9e0eb009e5f462116a963beacb208930 Mon Sep 17 00:00:00 2001
+From: Austin Seipp <aseipp@pobox.com>
+Date: Thu, 20 Feb 2014 00:11:44 -0600
+Subject: [PATCH] attempt to 'modprobe config' before checking kernel
+
+Signed-off-by: Austin Seipp <aseipp@pobox.com>
+---
+ checksec.sh | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/checksec.sh b/checksec.sh
+index dd1f72e..63acc29 100644
+--- a/checksec.sh
++++ b/checksec.sh
+@@ -337,7 +337,8 @@ kernelcheck() {
+   printf "  userspace processes, this option lists the status of kernel configuration\n"
+   printf "  options that harden the kernel itself against attack.\n\n"
+   printf "  Kernel config: "
+- 
++
++  modprobe configs 2> /dev/null
+   if [ -f /proc/config.gz ] ; then
+     kconfig="zcat /proc/config.gz"
+     printf "\033[32m/proc/config.gz\033[m\n\n"
+-- 
+1.8.3.2
+
diff --git a/nixpkgs/pkgs/os-specific/linux/checksec/default.nix b/nixpkgs/pkgs/os-specific/linux/checksec/default.nix
new file mode 100644
index 000000000000..6c927ae93afb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/checksec/default.nix
@@ -0,0 +1,43 @@
+{ stdenv, fetchurl, file, findutils, binutils-unwrapped, glibc, coreutils, sysctl }:
+
+stdenv.mkDerivation rec {
+  name = "checksec-${version}";
+  version = "1.5";
+
+  src = fetchurl {
+    url    = "https://www.trapkit.de/tools/checksec.sh";
+    sha256 = "0iq9v568mk7g7ksa1939g5f5sx7ffq8s8n2ncvphvlckjgysgf3p";
+  };
+
+  patches = [ ./0001-attempt-to-modprobe-config-before-checking-kernel.patch ];
+
+  unpackPhase = ''
+    mkdir ${name}
+    cp $src ${name}/checksec.sh
+    cd ${name}
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp checksec.sh $out/bin/checksec
+    chmod +x $out/bin/checksec
+    substituteInPlace $out/bin/checksec --replace /bin/bash ${stdenv.shell}
+    substituteInPlace $out/bin/checksec --replace /lib/libc.so.6 ${glibc.out}/lib/libc.so.6
+    substituteInPlace $out/bin/checksec --replace find ${findutils}/bin/find
+    substituteInPlace $out/bin/checksec --replace "file $" "${file}/bin/file $"
+    substituteInPlace $out/bin/checksec --replace "xargs file" "xargs ${file}/bin/file"
+    substituteInPlace $out/bin/checksec --replace " readelf -" " ${binutils-unwrapped}/bin/readelf -"
+    substituteInPlace $out/bin/checksec --replace "(readelf -" "(${binutils-unwrapped}/bin/readelf -"
+    substituteInPlace $out/bin/checksec --replace "command_exists readelf" "command_exists ${binutils-unwrapped}/bin/readelf"
+    substituteInPlace $out/bin/checksec --replace "/sbin/sysctl -" "${sysctl}/bin/sysctl -"
+    substituteInPlace $out/bin/checksec --replace "/usr/bin/id -" "${coreutils}/bin/id -"
+  '';
+
+  meta = {
+    description = "A tool for checking security bits on executables";
+    homepage    = "http://www.trapkit.de/tools/checksec.html";
+    license     = stdenv.lib.licenses.bsd3;
+    platforms   = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cifs-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/cifs-utils/default.nix
new file mode 100644
index 000000000000..7d98e51c1c73
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cifs-utils/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl, autoreconfHook, docutils, pkgconfig
+, kerberos, keyutils, pam, talloc }:
+
+stdenv.mkDerivation rec {
+  name = "cifs-utils-${version}";
+  version = "6.8";
+
+  src = fetchurl {
+    url = "mirror://samba/pub/linux-cifs/cifs-utils/${name}.tar.bz2";
+    sha256 = "0ygz3pagjpaj5ky11hzh4byyymb7fpmqiqkprn11zwj31h2zdlg7";
+  };
+
+  nativeBuildInputs = [ autoreconfHook docutils pkgconfig ];
+
+  buildInputs = [ kerberos keyutils pam talloc ];
+
+  makeFlags = "root_sbindir=$(out)/sbin";
+
+  meta = with stdenv.lib; {
+    homepage = http://www.samba.org/linux-cifs/cifs-utils/;
+    description = "Tools for managing Linux CIFS client filesystems";
+    platforms = platforms.linux;
+    license = licenses.lgpl3;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/compsize/default.nix b/nixpkgs/pkgs/os-specific/linux/compsize/default.nix
new file mode 100644
index 000000000000..a18011836f97
--- /dev/null
+++ b/nixpkgs/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/nixpkgs/pkgs/os-specific/linux/conky/default.nix b/nixpkgs/pkgs/os-specific/linux/conky/default.nix
new file mode 100644
index 000000000000..1af37c2168d1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/conky/default.nix
@@ -0,0 +1,143 @@
+{ config, stdenv, fetchFromGitHub, pkgconfig, cmake
+
+# dependencies
+, glib, libXinerama
+
+# optional features without extra dependencies
+, mpdSupport          ? true
+, ibmSupport          ? true # IBM/Lenovo notebooks
+
+# optional features with extra dependencies
+
+# ouch, this is ugly, but this gives the man page
+, docsSupport         ? true, docbook2x, libxslt ? null
+                            , man ? null, less ? null
+                            , docbook_xsl ? null , docbook_xml_dtd_44 ? null
+
+, ncursesSupport      ? true      , ncurses       ? null
+, x11Support          ? true      , xlibsWrapper           ? null
+, xdamageSupport      ? x11Support, libXdamage    ? null
+, doubleBufferSupport ? x11Support
+, imlib2Support       ? x11Support, imlib2        ? null
+
+, luaSupport          ? true      , lua           ? null
+, luaImlib2Support    ? luaSupport && imlib2Support
+, luaCairoSupport     ? luaSupport && x11Support, cairo ? null
+, toluapp ? null
+
+, wirelessSupport     ? true      , wirelesstools ? null
+, nvidiaSupport       ? false     , libXNVCtrl ? null
+, pulseSupport        ? config.pulseaudio or false, libpulseaudio ? null
+
+, curlSupport         ? true      , curl ? null
+, rssSupport          ? curlSupport
+, weatherMetarSupport ? curlSupport
+, weatherXoapSupport  ? curlSupport
+, journalSupport      ? true, systemd ? null
+, libxml2 ? null
+}:
+
+assert docsSupport         -> docbook2x != null && libxslt != null
+                           && man != null && less != null
+                           && docbook_xsl != null && docbook_xml_dtd_44 != null;
+
+assert ncursesSupport      -> ncurses != null;
+
+assert x11Support          -> xlibsWrapper != null;
+assert xdamageSupport      -> x11Support && libXdamage != null;
+assert imlib2Support       -> x11Support && imlib2     != null;
+assert luaSupport          -> lua != null;
+assert luaImlib2Support    -> luaSupport && imlib2Support
+                                         && toluapp != null;
+assert luaCairoSupport     -> luaSupport && toluapp != null
+                                         && cairo   != null;
+assert luaCairoSupport || luaImlib2Support
+                           -> lua.luaversion == "5.3";
+
+assert wirelessSupport     -> wirelesstools != null;
+assert nvidiaSupport       -> libXNVCtrl != null;
+assert pulseSupport        -> libpulseaudio != null;
+
+assert curlSupport         -> curl != null;
+assert rssSupport          -> curlSupport && libxml2 != null;
+assert weatherMetarSupport -> curlSupport;
+assert weatherXoapSupport  -> curlSupport && libxml2 != null;
+assert journalSupport      -> systemd != null;
+
+with stdenv.lib;
+
+stdenv.mkDerivation rec {
+  name = "conky-${version}";
+  version = "1.11.3";
+
+  src = fetchFromGitHub {
+    owner = "brndnmtthws";
+    repo = "conky";
+    rev = "v${version}";
+    sha256 = "0pdl31xvmy8niagzqx9sd2b6hc6lzwfiaz66m4djf1gz9bksc8qv";
+  };
+
+  postPatch = ''
+    sed -i -e '/include.*CheckIncludeFile)/i include(CheckIncludeFiles)' \
+      cmake/ConkyPlatformChecks.cmake
+  '' + optionalString docsSupport ''
+    # Drop examples, since they contain non-ASCII characters that break docbook2x :(
+    sed -i 's/ Example: .*$//' doc/config_settings.xml
+
+    substituteInPlace cmake/Conky.cmake --replace "# set(RELEASE true)" "set(RELEASE true)"
+  '';
+
+  NIX_LDFLAGS = "-lgcc_s";
+
+  nativeBuildInputs = [ cmake pkgconfig ];
+  buildInputs = [ glib libXinerama ]
+    ++ optionals docsSupport        [ docbook2x docbook_xsl docbook_xml_dtd_44 libxslt man less ]
+    ++ optional  ncursesSupport     ncurses
+    ++ optional  x11Support         xlibsWrapper
+    ++ optional  xdamageSupport     libXdamage
+    ++ optional  imlib2Support      imlib2
+    ++ optional  luaSupport         lua
+    ++ optionals luaImlib2Support   [ toluapp imlib2 ]
+    ++ optionals luaCairoSupport    [ toluapp cairo ]
+    ++ optional  wirelessSupport    wirelesstools
+    ++ optional  curlSupport        curl
+    ++ optional  rssSupport         libxml2
+    ++ optional  weatherXoapSupport libxml2
+    ++ optional  nvidiaSupport      libXNVCtrl
+    ++ optional  pulseSupport       libpulseaudio
+    ++ optional  journalSupport     systemd
+    ;
+
+  cmakeFlags = []
+    ++ optional docsSupport         "-DMAINTAINER_MODE=ON"
+    ++ optional curlSupport         "-DBUILD_CURL=ON"
+    ++ optional (!ibmSupport)       "-DBUILD_IBM=OFF"
+    ++ optional imlib2Support       "-DBUILD_IMLIB2=ON"
+    ++ optional luaCairoSupport     "-DBUILD_LUA_CAIRO=ON"
+    ++ optional luaImlib2Support    "-DBUILD_LUA_IMLIB2=ON"
+    ++ optional (!mpdSupport)       "-DBUILD_MPD=OFF"
+    ++ optional (!ncursesSupport)   "-DBUILD_NCURSES=OFF"
+    ++ optional rssSupport          "-DBUILD_RSS=ON"
+    ++ optional (!x11Support)       "-DBUILD_X11=OFF"
+    ++ optional xdamageSupport      "-DBUILD_XDAMAGE=ON"
+    ++ optional doubleBufferSupport "-DBUILD_XDBE=ON"
+    ++ optional weatherMetarSupport "-DBUILD_WEATHER_METAR=ON"
+    ++ optional weatherXoapSupport  "-DBUILD_WEATHER_XOAP=ON"
+    ++ optional wirelessSupport     "-DBUILD_WLAN=ON"
+    ++ optional nvidiaSupport       "-DBUILD_NVIDIA=ON"
+    ++ optional pulseSupport        "-DBUILD_PULSEAUDIO=ON"
+    ++ optional journalSupport      "-DBUILD_JOURNAL=ON"
+    ;
+
+  # `make -f src/CMakeFiles/conky.dir/build.make src/CMakeFiles/conky.dir/conky.cc.o`:
+  # src/conky.cc:137:23: fatal error: defconfig.h: No such file or directory
+  enableParallelBuilding = false;
+
+  meta = with stdenv.lib; {
+    homepage = http://conky.sourceforge.net/;
+    description = "Advanced, highly configurable system monitor based on torsmo";
+    maintainers = [ maintainers.guibert ];
+    license = licenses.gpl3Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/conntrack-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/conntrack-tools/default.nix
new file mode 100644
index 000000000000..755e88b46cbc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/conntrack-tools/default.nix
@@ -0,0 +1,27 @@
+{ fetchurl, stdenv, flex, bison, pkgconfig, libmnl, libnfnetlink
+, libnetfilter_conntrack, libnetfilter_queue, libnetfilter_cttimeout
+, libnetfilter_cthelper, systemd }:
+
+stdenv.mkDerivation rec {
+  name = "conntrack-tools-${version}";
+  version = "1.4.5";
+
+  src = fetchurl {
+    url = "https://www.netfilter.org/projects/conntrack-tools/files/${name}.tar.bz2";
+    sha256 = "0qm4m78hr6a4fbmnkw5nyjm1pzzhydzx0nz7f96iv1c4fsfdkiin";
+  };
+
+  buildInputs = [
+    libmnl libnfnetlink libnetfilter_conntrack libnetfilter_queue
+    libnetfilter_cttimeout libnetfilter_cthelper systemd
+  ];
+  nativeBuildInputs = [ flex bison pkgconfig ];
+
+  meta = with stdenv.lib; {
+    homepage = http://conntrack-tools.netfilter.org/;
+    description = "Connection tracking userspace tools";
+    platforms = platforms.linux;
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ fpletz ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/consoletools/default.nix b/nixpkgs/pkgs/os-specific/linux/consoletools/default.nix
new file mode 100644
index 000000000000..1064f628c108
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/consoletools/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl, SDL }:
+
+stdenv.mkDerivation rec {
+  name = "linuxconsoletools-${version}";
+  version = "1.6.0";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/linuxconsole/${name}.tar.bz2";
+    sha256 = "0il1m8pgw8f6b8qid035ixamv0w5fgh9pinx5vw4ayxn03nyzlnf";
+  };
+
+  buildInputs = [ SDL ];
+
+  makeFlags = [ "DESTDIR=$(out)"];
+
+  installFlags = ''PREFIX=""'';
+
+  meta = with stdenv.lib; {
+    homepage = https://sourceforge.net/projects/linuxconsole/;
+    description = "A set of tools for joysticks and serial peripherals";
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ pSub ebzzry ];
+
+    longDescription = ''
+      The included tools are:
+
+      ffcfstress(1)  - force-feedback stress test
+      ffmvforce(1)   - force-feedback orientation test
+      ffset(1)       - force-feedback configuration tool
+      fftest(1)      - general force-feedback test
+      jstest(1)      - joystick test
+      jscal(1)       - joystick calibration tool
+      inputattach(1) - connects legacy serial devices to the input layer
+    '';
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/conspy/default.nix b/nixpkgs/pkgs/os-specific/linux/conspy/default.nix
new file mode 100644
index 000000000000..32905b8ec39f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/conspy/default.nix
@@ -0,0 +1,37 @@
+{stdenv, fetchurl, autoconf, automake, ncurses}:
+let
+  s = # Generated upstream information
+  rec {
+    baseName="conspy";
+    version="1.14";
+    name="${baseName}-${version}";
+    hash="069k26xpzsvrn3197ix5yd294zvz03zi2xqj4fip6rlsw74habsf";
+    url="mirror://sourceforge/project/conspy/conspy-1.14-1/conspy-1.14.tar.gz";
+    sha256="069k26xpzsvrn3197ix5yd294zvz03zi2xqj4fip6rlsw74habsf";
+  };
+  buildInputs = [
+    autoconf automake ncurses
+  ];
+in
+stdenv.mkDerivation {
+  inherit (s) name version;
+  inherit buildInputs;
+  src = fetchurl {
+    inherit (s) url sha256;
+    curlOpts = " -A application/octet-stream ";
+  };
+  preConfigure = ''
+    touch NEWS
+    echo "EPL 1.0" > COPYING
+    aclocal
+    automake --add-missing
+    autoconf
+  '';
+  meta = {
+    inherit (s) version;
+    description = "Linux text console viewer";
+    license = stdenv.lib.licenses.epl10 ;
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/conspy/default.upstream b/nixpkgs/pkgs/os-specific/linux/conspy/default.upstream
new file mode 100644
index 000000000000..3f9ff3e4a820
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/conspy/default.upstream
@@ -0,0 +1,5 @@
+url https://sourceforge.net/projects/conspy/files/
+version_link 'conspy-[-0-9.]+/$'
+version_link '[-0-9.]+[.]tar[.][a-z0-9]+/download$'
+SF_redirect
+version '.*-([-0-9.]+)[.]tar[.].*' '\1'
diff --git a/nixpkgs/pkgs/os-specific/linux/cpufrequtils/default.nix b/nixpkgs/pkgs/os-specific/linux/cpufrequtils/default.nix
new file mode 100644
index 000000000000..04da31176da2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cpufrequtils/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchurl, libtool, gettext }:
+
+stdenv.mkDerivation rec {
+  name = "cpufrequtils-008";
+
+  src = fetchurl {
+    url = "http://ftp.be.debian.org/pub/linux/utils/kernel/cpufreq/${name}.tar.gz";
+    sha256 = "127i38d4w1hv2dzdy756gmbhq25q3k34nqb2s0xlhsfhhdqs0lq0";
+  };
+
+  patches = [
+    # I am not 100% sure that this is ok, but it breaks repeatable builds.
+    ./remove-pot-creation-date.patch
+  ];
+
+  patchPhase = ''
+    sed -e "s@= /usr/bin/@= @g" \
+      -e "s@/usr/@$out/@" \
+      -i Makefile
+  '';
+
+  buildInputs = [ stdenv.cc.libc.linuxHeaders libtool gettext ];
+
+  meta = with stdenv.lib; {
+    description = "Tools to display or change the CPU governor settings";
+    homepage = http://ftp.be.debian.org/pub/linux/utils/kernel/cpufreq/cpufrequtils.html;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cpufrequtils/remove-pot-creation-date.patch b/nixpkgs/pkgs/os-specific/linux/cpufrequtils/remove-pot-creation-date.patch
new file mode 100644
index 000000000000..0116ed9eab0c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cpufrequtils/remove-pot-creation-date.patch
@@ -0,0 +1,24 @@
+diff -u cpufrequtils-008/Makefile cpufrequtils-008.new/Makefile
+--- cpufrequtils-008/Makefile	2012-05-06 01:17:18.000000000 +0200
++++ cpufrequtils-008.new/Makefile	2013-08-16 20:52:29.961086536 +0200
+@@ -205,7 +205,8 @@
+ 	@xgettext --default-domain=$(PACKAGE) --add-comments \
+ 		--keyword=_ --keyword=N_ $(UTIL_SRC) && \
+ 	test -f $(PACKAGE).po && \
+-	mv -f $(PACKAGE).po po/$(PACKAGE).pot
++	mv -f $(PACKAGE).po po/$(PACKAGE).pot && \
++        sed -i -e'/POT-Creation/d' po/*.pot
+ 
+ update-gmo: po/$(PACKAGE).pot
+ 	 @for HLANG in $(LANGUAGES); do \
+@@ -217,6 +218,7 @@
+ 			echo "msgmerge for $$HLANG failed!"; \
+ 			rm -f po/$$HLANG.new.po; \
+ 		fi; \
++		sed -i -e'/POT-Creation/d' po/*.po; \
+ 		msgfmt --statistics -o po/$$HLANG.gmo po/$$HLANG.po; \
+ 	done;
+ 
+Common subdirectories: cpufrequtils-008/man and cpufrequtils-008.new/man
+Common subdirectories: cpufrequtils-008/po and cpufrequtils-008.new/po
+Common subdirectories: cpufrequtils-008/utils and cpufrequtils-008.new/utils
diff --git a/nixpkgs/pkgs/os-specific/linux/cpupower/default.nix b/nixpkgs/pkgs/os-specific/linux/cpupower/default.nix
new file mode 100644
index 000000000000..1b307da8cb80
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cpupower/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, buildPackages, kernel, pciutils, gettext }:
+
+stdenv.mkDerivation {
+  pname = "cpupower";
+  inherit (kernel) version src;
+
+  nativeBuildInputs = [ gettext ];
+  buildInputs = [ pciutils ];
+
+  postPatch = ''
+    cd tools/power/cpupower
+    sed -i 's,/bin/true,${buildPackages.coreutils}/bin/true,' Makefile
+    sed -i 's,/bin/pwd,${buildPackages.coreutils}/bin/pwd,' Makefile
+    sed -i 's,/usr/bin/install,${buildPackages.coreutils}/bin/install,' Makefile
+  '';
+
+  makeFlags = [ "CROSS=${stdenv.cc.targetPrefix}" ];
+
+  installFlags = stdenv.lib.mapAttrsToList
+    (n: v: "${n}dir=${placeholder "out"}/${v}") {
+    bin = "bin";
+    sbin = "sbin";
+    man = "share/man";
+    include = "include";
+    lib = "lib";
+    locale = "share/locale";
+    doc = "share/doc/cpupower";
+    conf = "etc";
+    bash_completion_ = "share/bash-completion/completions";
+  };
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "Tool to examine and tune power saving features";
+    homepage = https://www.kernel.org/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cpuset/default.nix b/nixpkgs/pkgs/os-specific/linux/cpuset/default.nix
new file mode 100644
index 000000000000..5791145d52af
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cpuset/default.nix
@@ -0,0 +1,27 @@
+{ stdenv
+, fetchFromGitHub
+, python2Packages
+}:
+
+python2Packages.buildPythonApplication rec {
+  pname = "cpuset";
+  version = "1.5.8";
+
+  propagatedBuildInputs = [ ];
+
+  makeFlags = [ "prefix=$(out)" ];
+
+  src = fetchFromGitHub {
+    owner = "wykurz";
+    repo = "cpuset";
+    rev = "v${version}";
+    sha256 = "19fl2sn470yrnm2q508giggjwy5b6r2gd94gvwfbdlhf0r9dsbbm";
+  };
+
+  meta = with stdenv.lib; {
+    description = "Cpuset is a Python application that forms a wrapper around the standard Linux filesystem calls to make using the cpusets facilities in the Linux kernel easier.";
+    homepage    = https://github.com/wykurz/cpuset;
+    license     = licenses.gpl2;
+    maintainers = with maintainers; [ wykurz ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cramfsswap/builder.sh b/nixpkgs/pkgs/os-specific/linux/cramfsswap/builder.sh
new file mode 100644
index 000000000000..51a5b11dda69
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cramfsswap/builder.sh
@@ -0,0 +1,6 @@
+source $stdenv/setup
+
+export DESTDIR=$out
+mkdir -p $out/usr/bin
+
+genericBuild
diff --git a/nixpkgs/pkgs/os-specific/linux/cramfsswap/default.nix b/nixpkgs/pkgs/os-specific/linux/cramfsswap/default.nix
new file mode 100644
index 000000000000..d183bb25cb56
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cramfsswap/default.nix
@@ -0,0 +1,19 @@
+{stdenv, fetchurl, zlib}:
+
+stdenv.mkDerivation {
+  name = "cramfsswap-1.4.1";
+  builder = ./builder.sh;
+  src = fetchurl {
+    url = mirror://debian/pool/main/c/cramfsswap/cramfsswap_1.4.1.tar.gz;
+    sha256 = "0c6lbx1inkbcvvhh3y6fvfaq3w7d1zv7psgpjs5f3zjk1jysi9qd";
+  };
+
+  buildInputs = [zlib];
+
+  meta = with stdenv.lib; {
+    description = "swap endianess of a cram filesystem (cramfs)";
+    homepage = "https://packages.debian.org/sid/utils/cramfsswap";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/crda/default.nix b/nixpkgs/pkgs/os-specific/linux/crda/default.nix
new file mode 100644
index 000000000000..940913d6a6c8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/crda/default.nix
@@ -0,0 +1,57 @@
+{ stdenv, fetchurl, libgcrypt, libnl, pkgconfig, python2Packages, wireless-regdb }:
+
+stdenv.mkDerivation rec {
+  name = "crda-${version}";
+  version = "3.18";
+
+  src = fetchurl {
+    sha256 = "1gydiqgb08d9gbx4l6gv98zg3pljc984m50hmn3ysxcbkxkvkz23";
+    url = "http://kernel.org/pub/software/network/crda/crda-${version}.tar.xz";
+  };
+
+  buildInputs = [ libgcrypt libnl ];
+  nativeBuildInputs = [
+    pkgconfig python2Packages.m2crypto python2Packages.python
+  ];
+
+  postPatch = ''
+    patchShebangs utils/
+    substituteInPlace Makefile --replace ldconfig true
+    sed -i crda.c \
+      -e "/\/usr\/.*\/regulatory.bin/d" \
+      -e "s|/lib/crda|${wireless-regdb}/lib/crda|g"
+  '';
+
+  makeFlags = [
+    "PREFIX=$(out)"
+    "SBINDIR=$(out)/bin/"
+    "UDEV_RULE_DIR=$(out)/lib/udev/rules.d/"
+    "REG_BIN=${wireless-regdb}/lib/crda/regulatory.bin"
+  ];
+
+  NIX_CFLAGS_COMPILE = "-Wno-error=unused-const-variable";
+
+  buildFlags = [ "all_noverify" ];
+  enableParallelBuilding = true;
+
+  doCheck = true;
+  checkTarget = "verify";
+
+  meta = with stdenv.lib; {
+    description = "Linux wireless Central Regulatory Domain Agent";
+    longDescription = ''
+      CRDA acts as the udev helper for communication between the kernel and
+      userspace for regulatory compliance. It relies on nl80211 for communication.
+
+      CRDA is intended to be run only through udev communication from the kernel.
+      To use it under NixOS, add
+
+        services.udev.packages = [ pkgs.crda ];
+
+      to the system configuration.
+    '';
+    homepage = http://drvbp1.linux-foundation.org/~mcgrof/rel-html/crda/;
+    license = licenses.free; # "copyleft-next 0.3.0", as yet without a web site
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/criu/default.nix b/nixpkgs/pkgs/os-specific/linux/criu/default.nix
new file mode 100644
index 000000000000..832167b6f26a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/criu/default.nix
@@ -0,0 +1,46 @@
+{ stdenv, fetchurl, protobuf, protobufc, asciidoc
+, xmlto, docbook_xsl, libpaper, libnl, libcap, libnet, pkgconfig
+, python }:
+
+stdenv.mkDerivation rec {
+  name    = "criu-${version}";
+  version = "3.9";
+
+  src = fetchurl {
+    url    = "https://download.openvz.org/criu/${name}.tar.bz2";
+    sha256 = "0l71lmklr42pc2bj37pkp7y8va8bx42n9f6i4q4idsx4wrdd75fx";
+  };
+
+  enableParallelBuilding = true;
+  nativeBuildInputs = [ pkgconfig docbook_xsl ];
+  buildInputs = [ protobuf protobufc asciidoc xmlto libpaper libnl libcap libnet python ];
+
+  postPatch = ''
+    substituteInPlace ./Documentation/Makefile --replace "2>/dev/null" ""
+    substituteInPlace ./Documentation/Makefile --replace "-m custom.xsl" "-m custom.xsl --skip-validation -x ${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl"
+    substituteInPlace ./criu/Makefile --replace "-I/usr/include/libnl3" "-I${libnl.dev}/include/libnl3"
+    substituteInPlace ./Makefile --replace "head-name := \$(shell git tag -l v\$(CRIU_VERSION))" "head-name = ${version}.0"
+    ln -sf ${protobuf}/include/google/protobuf/descriptor.proto ./images/google/protobuf/descriptor.proto
+  '';
+
+  buildPhase = "make PREFIX=$out";
+
+  makeFlags = "PREFIX=$(out)";
+
+  hardeningDisable = [ "stackprotector" "fortify" ];
+  # dropping fortify here as well as package uses it by default:
+  # command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
+
+  installPhase = ''
+    mkdir -p $out/etc/logrotate.d
+    make install PREFIX=$out LIBDIR=$out/lib ASCIIDOC=${asciidoc}/bin/asciidoc XMLTO=${xmlto}/bin/xmlto
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Userspace checkpoint/restore for Linux";
+    homepage    = https://criu.org;
+    license     = licenses.gpl2;
+    platforms   = [ "x86_64-linux" ];
+    maintainers = [ maintainers.thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cryptodev/default.nix b/nixpkgs/pkgs/os-specific/linux/cryptodev/default.nix
new file mode 100644
index 000000000000..c146e18f68d5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cryptodev/default.nix
@@ -0,0 +1,27 @@
+{ fetchurl, stdenv, kernel ? false }:
+
+stdenv.mkDerivation rec {
+  pname = "cryptodev-linux-1.9";
+  name = "${pname}-${kernel.version}";
+
+  src = fetchurl {
+    urls = [
+      "http://nwl.cc/pub/cryptodev-linux/${pname}.tar.gz"
+    ];
+    sha256 = "0l3r8s71vkd0s2h01r7fhqnc3j8cqw4msibrdxvps9hfnd4hnk4z";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  KERNEL_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
+  INSTALL_MOD_PATH = "\${out}";
+  prefix = "\${out}";
+
+  meta = {
+    description = "Device that allows access to Linux kernel cryptographic drivers";
+    homepage = http://cryptodev-linux.org/;
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+    broken = !stdenv.lib.versionOlder kernel.version "4.13";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cryptsetup/default.nix b/nixpkgs/pkgs/os-specific/linux/cryptsetup/default.nix
new file mode 100644
index 000000000000..fac62597013c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cryptsetup/default.nix
@@ -0,0 +1,53 @@
+{ stdenv, fetchurl, fetchpatch, lvm2, json_c
+, openssl, libuuid, pkgconfig, popt
+, enablePython ? false, python2 ? null }:
+
+assert enablePython -> python2 != null;
+
+stdenv.mkDerivation rec {
+  name = "cryptsetup-2.1.0";
+
+  outputs = [ "out" "dev" "man" ];
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/cryptsetup/v2.1/${name}.tar.xz";
+    sha256 = "15y8n547garz0x5kqv09gscdsrz0c0y1y6c5cp8pccwg3xsb5vm3";
+  };
+
+  # Disable 4 test cases that fail in a sandbox
+  patches = [ ./disable-failing-tests.patch ];
+
+  postPatch = ''
+    patchShebangs tests
+    ${stdenv.lib.optionalString enablePython ''
+      patchShebangs ./python/pycryptsetup-test.py
+    ''}
+
+    # O_DIRECT is filesystem dependent and fails in a sandbox (on tmpfs)
+    # and on several filesystem types (btrfs, zfs) without sandboxing.
+    # Remove it, see discussion in #46151
+    substituteInPlace tests/unit-utils-io.c --replace "| O_DIRECT" ""
+  '';
+
+  NIX_LDFLAGS = "-lgcc_s";
+
+  configureFlags = [
+    "--disable-kernel_crypto"
+    "--enable-cryptsetup-reencrypt"
+    "--with-crypto_backend=openssl"
+  ] ++ stdenv.lib.optional enablePython "--enable-python";
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ lvm2 json_c openssl libuuid popt ]
+    ++ stdenv.lib.optional enablePython python2;
+
+  doCheck = true;
+
+  meta = {
+    homepage = https://gitlab.com/cryptsetup/cryptsetup/;
+    description = "LUKS for dm-crypt";
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = with stdenv.lib.maintainers; [ ];
+    platforms = with stdenv.lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/cryptsetup/disable-failing-tests.patch b/nixpkgs/pkgs/os-specific/linux/cryptsetup/disable-failing-tests.patch
new file mode 100644
index 000000000000..1504bf3e1511
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/cryptsetup/disable-failing-tests.patch
@@ -0,0 +1,19 @@
+diff -ur a/tests/blockwise-compat b/tests/blockwise-compat
+--- a/tests/blockwise-compat	2018-09-08 12:23:11.706555098 +0200
++++ b/tests/blockwise-compat	2018-09-08 12:24:24.444393460 +0200
+@@ -148,15 +148,11 @@
+ 	# device/file fn_name length
+ 	RUN "P" $1 read_buffer $BSIZE
+ 	RUN "P" $1 read_buffer $((2*BSIZE))
+-	RUN "F" $1 read_buffer $((BSIZE-1))
+-	RUN "F" $1 read_buffer $((BSIZE+1))
+ 	RUN "P" $1 read_buffer 0
+ 
+ 	RUN "P" $1 write_buffer $BSIZE
+ 	RUN "P" $1 write_buffer $((2*BSIZE))
+ 
+-	RUN "F" $1 write_buffer $((BSIZE-1))
+-	RUN "F" $1 write_buffer $((BSIZE+1))
+ 	RUN "F" $1 write_buffer 0
+ 
+ 	# basic blockwise functions
diff --git a/nixpkgs/pkgs/os-specific/linux/dbus-broker/default.nix b/nixpkgs/pkgs/os-specific/linux/dbus-broker/default.nix
new file mode 100644
index 000000000000..880b620d87cf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dbus-broker/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchFromGitHub, docutils, meson, ninja, pkgconfig
+, dbus, linuxHeaders, systemd }:
+
+stdenv.mkDerivation rec {
+  name = "dbus-broker-${version}";
+  version = "17";
+
+  src = fetchFromGitHub {
+    owner  = "bus1";
+    repo   = "dbus-broker";
+    rev    = "v${version}";
+    sha256 = "19q5f1c658jdxvr2k2rb2xsnspybqjii4rifnlkzi1qzh0r152md";
+    fetchSubmodules = true;
+  };
+
+  nativeBuildInputs = [ docutils meson ninja pkgconfig ];
+
+  buildInputs = [ dbus linuxHeaders systemd ];
+
+  PKG_CONFIG_SYSTEMD_SYSTEMDSYSTEMUNITDIR = "${placeholder "out"}/lib/systemd/system";
+  PKG_CONFIG_SYSTEMD_SYSTEMDUSERUNITDIR = "${placeholder "out"}/lib/systemd/user";
+
+  postInstall = ''
+    install -Dm644 $src/README.md $out/share/doc/dbus-broker/README
+
+    sed -i $out/lib/systemd/{system,user}/dbus-broker.service \
+      -e 's,^ExecReload.*busctl,ExecReload=${systemd}/bin/busctl,'
+  '';
+
+  doCheck = true;
+
+  meta = with stdenv.lib; {
+    description = "Linux D-Bus Message Broker";
+    homepage    = https://github.com/bus1/dbus-broker/wiki;
+    license     = licenses.asl20;
+    platforms   = platforms.linux;
+    maintainers = with maintainers; [ peterhoeg ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/devmem2/default.nix b/nixpkgs/pkgs/os-specific/linux/devmem2/default.nix
new file mode 100644
index 000000000000..cd1400b41fc2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/devmem2/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "devmem2-2004-08-05";
+
+  src = fetchurl {
+    urls = [
+      "http://lartmaker.nl/lartware/port/devmem2.c"
+      "https://raw.githubusercontent.com/hackndev/tools/7ed212230f8fbb1da3424a15ee88de3279bf96ec/devmem2.c"
+    ];
+    sha256 = "14f1k7v6i1yaxg4xcaaf5i4aqn0yabba857zjnbg9wiymy82qf7c";
+  };
+
+  hardeningDisable = [ "format" ];  # fix compile error
+
+  buildCommand = ''
+    $CC "$src" -o devmem2
+    install -D devmem2 "$out/bin/devmem2"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Simple program to read/write from/to any location in memory";
+    homepage = http://lartmaker.nl/lartware/port/;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ bjornfor ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/directvnc/default.nix b/nixpkgs/pkgs/os-specific/linux/directvnc/default.nix
new file mode 100644
index 000000000000..e8c1e9bfe5e5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/directvnc/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, pkgconfig, directfb, zlib, libjpeg, xorgproto }:
+
+stdenv.mkDerivation rec {
+  name = "directvnc-${version}";
+  version = "0.7.7.2015-04-16";
+
+  src = fetchFromGitHub {
+    owner = "drinkmilk";
+    repo = "directvnc";
+    rev = "d336f586c5865da68873960092b7b5fbc9f8617a";
+    sha256 = "16x7mr7x728qw7nbi6rqhrwsy73zsbpiz8pbgfzfl2aqhfdiz88b";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+
+  buildInputs = [ directfb zlib libjpeg xorgproto ];
+
+  meta = with stdenv.lib; {
+    description = "DirectFB VNC client";
+    homepage = http://drinkmilk.github.io/directvnc/;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.raskin ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/disk-indicator/default.nix b/nixpkgs/pkgs/os-specific/linux/disk-indicator/default.nix
new file mode 100644
index 000000000000..46ebc923e3b2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/disk-indicator/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchgit, libX11 }:
+
+stdenv.mkDerivation {
+  name = "disk-indicator-2014-05-19";
+
+  src = fetchgit {
+    url = git://github.com/MeanEYE/Disk-Indicator.git;
+    rev = "51ef4afd8141b8d0659cbc7dc62189c56ae9c2da";
+    sha256 = "10jx6mx9qarn21p2l2jayxkn1gmqhvck1wymgsr4jmbwxl8ra5kd";
+  };
+
+  buildInputs = [ libX11 ];
+
+  patchPhase = ''
+    substituteInPlace ./makefile --replace "COMPILER=c99" "COMPILER=gcc -std=c99"
+    substituteInPlace ./makefile --replace "COMPILE_FLAGS=" "COMPILE_FLAGS=-O2 "
+  '';
+
+  buildPhase = "make -f makefile";
+
+  NIX_CFLAGS_COMPILE = "-Wno-error=cpp";
+
+  hardeningDisable = [ "fortify" ];
+
+  installPhase = ''
+    mkdir -p "$out/bin"
+    cp ./disk_indicator "$out/bin/"
+  '';
+
+  meta = {
+    homepage = https://github.com/MeanEYE/Disk-Indicator;
+    description = "A program that will turn a LED into a hard disk indicator";
+    longDescription = ''
+      Small program for Linux that will turn your Scroll, Caps or Num Lock LED
+      or LED on your ThinkPad laptop into a hard disk activity indicator.
+    '';
+    license = stdenv.lib.licenses.gpl3;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/displaylink/default.nix b/nixpkgs/pkgs/os-specific/linux/displaylink/default.nix
new file mode 100644
index 000000000000..9da5170c2e5d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/displaylink/default.nix
@@ -0,0 +1,74 @@
+{ stdenv, lib, unzip, utillinux,
+  libusb1, evdi, systemd, makeWrapper, requireFile, substituteAll }:
+
+let
+  arch =
+    if stdenv.hostPlatform.system == "x86_64-linux" then "x64"
+    else if stdenv.hostPlatform.system == "i686-linux" then "x86"
+    else throw "Unsupported architecture";
+  bins = "${arch}-ubuntu-1604";
+  libPath = lib.makeLibraryPath [ stdenv.cc.cc utillinux libusb1 evdi ];
+
+in stdenv.mkDerivation rec {
+  name = "displaylink-${version}";
+  version = "4.4.24";
+
+  src = requireFile rec {
+    name = "displaylink.zip";
+    sha256 = "0c02mg7vbijpfpk9imh0hmls1yiglc216zfllw5ar86r1slhd5y0";
+    message = ''
+      In order to install the DisplayLink drivers, you must first
+      comply with DisplayLink's EULA and download the binaries and
+      sources from here:
+
+      http://www.displaylink.com/downloads/file?id=1261
+
+      Once you have downloaded the file, please use the following
+      commands and re-run the installation:
+
+      mv \$PWD/"DisplayLink USB Graphics Software for Ubuntu ${version}.zip" \$PWD/${name}
+      nix-prefetch-url file://\$PWD/${name}
+    '';
+  };
+
+  nativeBuildInputs = [ unzip makeWrapper ];
+
+  unpackPhase = ''
+    unzip $src
+    chmod +x displaylink-driver-${version}.run
+    ./displaylink-driver-${version}.run --target . --noexec
+  '';
+
+  patches = [ (substituteAll {
+    src = ./udev-installer.patch;
+    inherit systemd;
+  })];
+
+  installPhase = ''
+    sed -i "s,/opt/displaylink/udev.sh,$out/lib/udev/displaylink.sh,g" udev-installer.sh
+    ( source udev-installer.sh
+      mkdir -p $out/lib/udev/rules.d
+      main systemd "$out/lib/udev/rules.d/99-displaylink.rules" "$out/lib/udev/displaylink.sh"
+    )
+
+    install -Dt $out/lib/displaylink *.spkg
+    install -Dm755 ${bins}/DisplayLinkManager $out/bin/DisplayLinkManager
+    patchelf \
+      --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
+      --set-rpath ${libPath} \
+      $out/bin/DisplayLinkManager
+    wrapProgram $out/bin/DisplayLinkManager \
+      --run "cd $out/lib/displaylink"
+  '';
+
+  dontStrip = true;
+  dontPatchELF = true;
+
+
+  meta = with stdenv.lib; {
+    description = "DisplayLink DL-5xxx, DL-41xx and DL-3x00 Driver for Linux";
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    license = licenses.unfree;
+    homepage = http://www.displaylink.com/;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/displaylink/udev-installer.patch b/nixpkgs/pkgs/os-specific/linux/displaylink/udev-installer.patch
new file mode 100644
index 000000000000..3e62e20c3150
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/displaylink/udev-installer.patch
@@ -0,0 +1,18 @@
+--- a/udev-installer.sh	2018-12-09 12:05:53.772318942 +0100
++++ b/udev-installer.sh	2018-12-09 12:06:19.939947629 +0100
+@@ -21,12 +21,12 @@
+   cat <<'EOF'
+ start_service()
+ {
+-  systemctl start dlm
++  @systemd@/bin/systemctl start --no-block dlm
+ }
+ 
+ stop_service()
+ {
+-  systemctl stop dlm
++  @systemd@/bin/systemctl stop dlm
+ }
+ 
+ EOF
+
diff --git a/nixpkgs/pkgs/os-specific/linux/dmidecode/default.nix b/nixpkgs/pkgs/os-specific/linux/dmidecode/default.nix
new file mode 100644
index 000000000000..a4ec902f762d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dmidecode/default.nix
@@ -0,0 +1,19 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "dmidecode-3.2";
+
+  src = fetchurl {
+    url = "mirror://savannah/dmidecode/${name}.tar.xz";
+    sha256 = "1pcfhcgs2ifdjwp7amnsr3lq95pgxpr150bjhdinvl505px0cw07";
+  };
+
+  makeFlags = "prefix=$(out)";
+
+  meta = with stdenv.lib; {
+    homepage = https://www.nongnu.org/dmidecode/;
+    description = "A tool that reads information about your system's hardware from the BIOS according to the SMBIOS/DMI standard";
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/dmraid/default.nix b/nixpkgs/pkgs/os-specific/linux/dmraid/default.nix
new file mode 100644
index 000000000000..129ccb304564
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dmraid/default.nix
@@ -0,0 +1,49 @@
+{ stdenv, fetchurl, fetchpatch, lvm2 }:
+
+stdenv.mkDerivation rec {
+  name = "dmraid-1.0.0.rc16";
+
+  src = fetchurl {
+    url = "https://people.redhat.com/~heinzm/sw/dmraid/src/old/${name}.tar.bz2";
+    sha256 = "0m92971gyqp61darxbiri6a48jz3wq3gkp8r2k39320z0i6w8jgq";
+  };
+
+  patches = [ ./hardening-format.patch ]
+    ++ stdenv.lib.optionals stdenv.hostPlatform.isMusl [
+      (fetchpatch {
+        url = "https://raw.githubusercontent.com/void-linux/void-packages/fceed4b8e96b3c1da07babf6f67b6ed1588a28b2/srcpkgs/dmraid/patches/006-musl-libc.patch";
+        sha256 = "1j8xda0fpz8lxjxnqdidy7qb866qrzwpbca56yjdg6vf4x21hx6w";
+        stripLen = 2;
+        extraPrefix = "1.0.0.rc16/";
+      })
+      (fetchpatch {
+        url = "https://raw.githubusercontent.com/void-linux/void-packages/fceed4b8e96b3c1da07babf6f67b6ed1588a28b2/srcpkgs/dmraid/patches/007-fix-loff_t-musl.patch";
+        sha256 = "0msnq39qnzg3b1pdksnz1dgqwa3ak03g41pqh0lw3h7w5rjc016k";
+        stripLen = 2;
+        extraPrefix = "1.0.0.rc16/";
+      })
+    ];
+
+  postPatch = ''
+    sed -i 's/\[\[[^]]*\]\]/[ "''$''${n##*.}" = "so" ]/' */lib/Makefile.in
+  '' + stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
+    NIX_CFLAGS_COMPILE+=" -D_GNU_SOURCE"
+  '';
+
+  preConfigure = "cd */";
+
+  buildInputs = [ lvm2 ];
+
+  meta = {
+    description = "Old-style RAID configuration utility";
+    longDescription = ''
+      Old RAID configuration utility (still under development, though).
+      It is fully compatible with modern kernels and mdadm recognizes
+      its volumes. May be needed for rescuing an older system or nuking
+      the metadata when reformatting.
+    '';
+    maintainers = [ stdenv.lib.maintainers.raskin ];
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.gpl2Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/dmraid/hardening-format.patch b/nixpkgs/pkgs/os-specific/linux/dmraid/hardening-format.patch
new file mode 100644
index 000000000000..f91a7fb18aa0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dmraid/hardening-format.patch
@@ -0,0 +1,18 @@
+--- a/1.0.0.rc16/lib/events/libdmraid-events-isw.c	2016-01-29 05:16:57.455425454 +0000
++++ b/1.0.0.rc16/lib/events/libdmraid-events-isw.c	2016-01-29 05:17:55.520564013 +0000
+@@ -838,13 +838,13 @@
+ 
+ 	sz = _log_all_devs(log_type, rs, NULL, 0);
+ 	if (!sz) {
+-		syslog(LOG_ERR, msg[0]);
++		syslog(LOG_ERR, "%s", msg[0]);
+ 		return;
+ 	}
+ 
+ 	str = dm_malloc(++sz);
+ 	if (!str) {
+-		syslog(LOG_ERR, msg[1]);
++		syslog(LOG_ERR, "%s", msg[1]);
+ 		return;
+ 	}
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/dmtcp/default.nix b/nixpkgs/pkgs/os-specific/linux/dmtcp/default.nix
new file mode 100644
index 000000000000..534e57354474
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dmtcp/default.nix
@@ -0,0 +1,47 @@
+{ stdenv, fetchFromGitHub, bash, perl, python }:
+
+stdenv.mkDerivation rec {
+  name = "dmtcp-${version}";
+  version = "2.5.2";
+
+  src = fetchFromGitHub {
+    owner = "dmtcp";
+    repo = "dmtcp";
+    rev = version;
+    sha256 = "1sq38in4wk855yhfnzbs9xpnps97fhja93w08xjmx7szzm33g5a8";
+  };
+
+  dontDisableStatic = true;
+
+  patches = [ ./ld-linux-so-buffer-size.patch ];
+
+  postPatch = ''
+    patchShebangs .
+
+    substituteInPlace configure \
+      --replace '#define ELF_INTERPRETER "$interp"' \
+                "#define ELF_INTERPRETER \"$(cat $NIX_CC/nix-support/dynamic-linker)\""
+    substituteInPlace src/dmtcp_coordinator.cpp \
+      --replace /bin/bash ${stdenv.shell}
+    substituteInPlace util/gdb-add-symbol-file \
+      --replace /bin/bash ${stdenv.shell}
+    substituteInPlace test/autotest.py \
+      --replace /bin/bash ${bash}/bin/bash \
+      --replace /usr/bin/perl ${perl}/bin/perl \
+      --replace /usr/bin/python ${python}/bin/python \
+      --replace "os.environ['USER']" "\"nixbld1\"" \
+      --replace "os.getenv('USER')" "\"nixbld1\""
+  '';
+
+  meta = {
+    description = "Distributed MultiThreaded Checkpointing";
+    longDescription = ''
+      DMTCP (Distributed MultiThreaded Checkpointing) is a tool to
+      transparently checkpointing the state of an arbitrary group of
+      programs spread across many machines and connected by sockets. It does
+      not modify the user's program or the operating system.
+    '';
+    homepage = http://dmtcp.sourceforge.net/;
+    license = stdenv.lib.licenses.lgpl3Plus; # most files seem this or LGPL-2.1+
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/dmtcp/ld-linux-so-buffer-size.patch b/nixpkgs/pkgs/os-specific/linux/dmtcp/ld-linux-so-buffer-size.patch
new file mode 100644
index 000000000000..5a81dad0cc90
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dmtcp/ld-linux-so-buffer-size.patch
@@ -0,0 +1,11 @@
+--- dmtcp-2.5.1-src/src/util_exec.cpp	2017-09-19 13:36:22.947587034 +0200
++++ dmtcp-2.5.1-src/src/util_exec.cpp	2017-09-19 13:36:32.221313460 +0200
+@@ -178,7 +178,7 @@
+ 
+ static string ld_linux_so_path(int version, bool is32bitElf = false)
+ {
+-  char buf[80];
++  char buf[128];
+ #if (defined(__x86_64__) || defined(__aarch64__)) && !defined(CONFIG_M32)
+   if (is32bitElf) {
+     sprintf(buf, "/lib/ld-linux.so.%d", version);
diff --git a/nixpkgs/pkgs/os-specific/linux/dpdk/default.nix b/nixpkgs/pkgs/os-specific/linux/dpdk/default.nix
new file mode 100644
index 000000000000..13614493f610
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dpdk/default.nix
@@ -0,0 +1,64 @@
+{ stdenv, lib, kernel, fetchurl, pkgconfig, numactl, shared ? false }:
+
+let
+
+  kver = kernel.modDirVersion or null;
+
+  mod = kernel != null;
+
+in stdenv.mkDerivation rec {
+  name = "dpdk-${version}" + lib.optionalString mod "-${kernel.version}";
+  version = "17.11.2";
+
+  src = fetchurl {
+    url = "https://fast.dpdk.org/rel/dpdk-${version}.tar.xz";
+    sha256 = "19m5l3jkrns8r1zbjb6ry18w50ff36kbl5b5g6pfcp9p57sfisd2";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ numactl ] ++ lib.optional mod kernel.moduleBuildDependencies;
+
+  RTE_KERNELDIR = if mod then "${kernel.dev}/lib/modules/${kver}/build" else "/var/empty";
+  RTE_TARGET = "x86_64-native-linuxapp-gcc";
+
+  # we need sse3 instructions to build
+  NIX_CFLAGS_COMPILE = [ "-msse3" ];
+  hardeningDisable = [ "pic" ];
+
+  postPatch = ''
+    cat >>config/defconfig_$RTE_TARGET <<EOF
+# Build static or shared libraries.
+CONFIG_RTE_BUILD_SHARED_LIB=${if shared then "y" else "n"}
+EOF
+  '' + lib.optionalString (!mod) ''
+    cat >>config/defconfig_$RTE_TARGET <<EOF
+# Do not build kernel modules.
+CONFIG_RTE_EAL_IGB_UIO=n
+CONFIG_RTE_KNI_KMOD=n
+EOF
+  '';
+
+  configurePhase = ''
+    make T=${RTE_TARGET} config
+  '';
+
+  installTargets = [ "install-runtime" "install-sdk" "install-kmod" ]; # skip install-doc
+
+  installFlags = [
+    "prefix=$(out)"
+  ] ++ lib.optionals mod [
+    "kerneldir=$(kmod)/lib/modules/${kver}"
+  ];
+
+  outputs = [ "out" ] ++ lib.optional mod "kmod";
+
+  enableParallelBuilding = true;
+
+  meta = with lib; {
+    description = "Set of libraries and drivers for fast packet processing";
+    homepage = http://dpdk.org/;
+    license = with licenses; [ lgpl21 gpl2 bsd2 ];
+    platforms =  [ "x86_64-linux" ];
+    maintainers = with maintainers; [ domenkozar orivej ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/drbd/default.nix b/nixpkgs/pkgs/os-specific/linux/drbd/default.nix
new file mode 100644
index 000000000000..5e990511eed7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/drbd/default.nix
@@ -0,0 +1,43 @@
+{ stdenv, fetchurl, flex, systemd, perl }:
+
+stdenv.mkDerivation rec {
+  name = "drbd-8.4.4";
+
+  src = fetchurl {
+    url = "http://oss.linbit.com/drbd/8.4/${name}.tar.gz";
+    sha256 = "1w4889h1ak7gy9w33kd4fgjlfpgmp6hzfya16p1pkc13bjf22mm0";
+  };
+
+  patches = [ ./pass-force.patch ];
+
+  buildInputs = [ flex perl ];
+
+  configureFlags = [
+    "--without-distro"
+    "--without-pacemaker"
+    "--localstatedir=/var"
+    "--sysconfdir=/etc"
+  ];
+
+  preConfigure =
+    ''
+      export PATH=${systemd}/sbin:$PATH
+      substituteInPlace user/Makefile.in \
+        --replace /sbin '$(sbindir)'
+      substituteInPlace user/legacy/Makefile.in \
+        --replace '$(DESTDIR)/lib/drbd' '$(DESTDIR)$(LIBDIR)'
+      substituteInPlace user/drbdadm_usage_cnt.c --replace /lib/drbd $out/lib/drbd
+      substituteInPlace scripts/drbd.rules --replace /usr/sbin/drbdadm $out/sbin/drbdadm
+    '';
+
+  makeFlags = "SHELL=${stdenv.shell}";
+
+  installFlags = "localstatedir=$(TMPDIR)/var sysconfdir=$(out)/etc INITDIR=$(out)/etc/init.d";
+
+  meta = with stdenv.lib; {
+    homepage = http://www.drbd.org/;
+    description = "Distributed Replicated Block Device, a distributed storage system for Linux";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/drbd/pass-force.patch b/nixpkgs/pkgs/os-specific/linux/drbd/pass-force.patch
new file mode 100644
index 000000000000..8f0201100f72
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/drbd/pass-force.patch
@@ -0,0 +1,15 @@
+Propagate the --force flag in the legacy drbdadm to drbdsetup.
+Otherwise "drbdadm primary --force" won't work as expected (the kernel
+will say "State change failed: Need access to UpToDate data").
+
+diff -ru -x '*~' drbd-8.4.0-orig/user/legacy/drbdadm_main.c drbd-8.4.0/user/legacy/drbdadm_main.c
+--- drbd-8.4.0-orig/user/legacy/drbdadm_main.c	2011-07-07 06:55:39.000000000 -0400
++++ drbd-8.4.0/user/legacy/drbdadm_main.c	2011-11-02 14:51:04.000000000 -0400
+@@ -1547,6 +1547,7 @@
+ 	for (i = 0; i < soi; i++) {
+ 		argv[NA(argc)] = setup_opts[i];
+ 	}
++	if (force) argv[NA(argc)] = "--force";
+ 	argv[NA(argc)] = 0;
+ 
+ 	setenv("DRBD_RESOURCE", res->name, 1);
diff --git a/nixpkgs/pkgs/os-specific/linux/dropwatch/default.nix b/nixpkgs/pkgs/os-specific/linux/dropwatch/default.nix
new file mode 100644
index 000000000000..936dbf719a87
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dropwatch/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, pkgconfig
+, libnl, readline, libbfd, ncurses, zlib }:
+
+stdenv.mkDerivation rec {
+  pname = "dropwatch";
+  version = "1.5";
+  name = "${pname}-${version}";
+
+  src = fetchFromGitHub {
+    owner = "nhorman";
+    repo = pname;
+    rev = version;
+    sha256 = "085hyyl28v0vpxfnmzchl97fjfnzj46ynhkg6y4i6h194y0d99m7";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+
+  buildInputs = [ libbfd libnl ncurses readline zlib ];
+
+  # To avoid running into https://sourceware.org/bugzilla/show_bug.cgi?id=14243 we need to define:
+  NIX_CFLAGS_COMPILE = [
+    "-DPACKAGE=${pname}"
+    "-DPACKAGE_VERSION=${version}"
+  ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "Kernel dropped packet monitor";
+    homepage = https://github.com/nhorman/dropwatch;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.c0bw3b ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/dstat/default.nix b/nixpkgs/pkgs/os-specific/linux/dstat/default.nix
new file mode 100644
index 000000000000..63b766b21a5c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/dstat/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, python2Packages }:
+
+python2Packages.buildPythonApplication rec {
+  name = "dstat-${version}";
+  format = "other";
+  version = "0.7.3";
+
+  src = fetchurl {
+    url = "https://github.com/dagwieers/dstat/archive/${version}.tar.gz";
+    sha256 = "16286z3y2lc9nsq8njzjkv6k2vyxrj9xiixj1k3gnsbvhlhkirj6";
+  };
+
+  propagatedBuildInputs = with python2Packages; [ python-wifi ];
+
+  makeFlags = [ "prefix=$(out)" ];
+
+  meta = with stdenv.lib; {
+    homepage = http://dag.wieers.com/home-made/dstat/;
+    description = "Versatile resource statistics tool";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/e1000e/default.nix b/nixpkgs/pkgs/os-specific/linux/e1000e/default.nix
new file mode 100644
index 000000000000..38ef803d8e52
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/e1000e/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, fetchurl, kernel }:
+
+assert stdenv.lib.versionOlder kernel.version "4.10";
+
+stdenv.mkDerivation rec {
+  name = "e1000e-${version}-${kernel.version}";
+  version = "3.3.5.3";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/e1000/e1000e-${version}.tar.gz";
+    sha256 = "1ajz3vdnf1y307k585w95r6jlh4ah8d74bq36gdkjl1z5hgiqi9q";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  configurePhase = ''
+    cd src
+    kernel_version=${kernel.modDirVersion}
+    sed -i -e 's|/lib/modules|${kernel.dev}/lib/modules|' Makefile
+    export makeFlags="BUILD_KERNEL=$kernel_version"
+  '';
+
+  installPhase = ''
+    install -v -D -m 644 e1000e.ko "$out/lib/modules/$kernel_version/kernel/drivers/net/e1000e/e1000e.ko"
+  '';
+
+  dontStrip = true;
+
+  enableParallelBuilding = true;
+
+  meta = {
+    description = "Linux kernel drivers for Intel Ethernet adapters and LOMs (LAN On Motherboard)";
+    homepage = http://e1000.sf.net/;
+    license = stdenv.lib.licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/earlyoom/default.nix b/nixpkgs/pkgs/os-specific/linux/earlyoom/default.nix
new file mode 100644
index 000000000000..5154f68cde4e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/earlyoom/default.nix
@@ -0,0 +1,26 @@
+{ lib, stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "earlyoom-${VERSION}";
+  # This environment variable is read by make to set the build version.
+  VERSION = "1.2";
+
+  src = fetchFromGitHub {
+    owner = "rfjakob";
+    repo = "earlyoom";
+    rev = "v${VERSION}";
+    sha256 = "0bpqlbsjcmcizgw75j1zyw1sp2cgwhaar9y70sibw1km011yqbzd";
+  };
+
+  installPhase = ''
+    install -D earlyoom $out/bin/earlyoom
+  '';
+
+  meta = {
+    description = "Early OOM Daemon for Linux";
+    homepage    = https://github.com/rfjakob/earlyoom;
+    license     = lib.licenses.mit;
+    platforms   = lib.platforms.linux;
+    maintainers = with lib.maintainers; [ ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ebtables/default.nix b/nixpkgs/pkgs/os-specific/linux/ebtables/default.nix
new file mode 100644
index 000000000000..9d92575b6687
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ebtables/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "ebtables-${version}";
+  version = "2.0.10-4";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/ebtables/ebtables-v${version}.tar.gz";
+    sha256 = "0pa5ljlk970yfyhpf3iqwfpbc30j8mgn90fapw9cfz909x47nvyw";
+  };
+
+  makeFlags =
+    [ "LIBDIR=$(out)/lib" "BINDIR=$(out)/sbin" "MANDIR=$(out)/share/man"
+      "ETCDIR=$(out)/etc" "INITDIR=$(TMPDIR)" "SYSCONFIGDIR=$(out)/etc/sysconfig"
+      "LOCALSTATEDIR=/var"
+    ];
+
+  preBuild =
+    ''
+      substituteInPlace Makefile --replace '-o root -g root' ""
+    '';
+
+  NIX_CFLAGS_COMPILE = "-Wno-error";
+
+  preInstall = "mkdir -p $out/etc/sysconfig";
+
+  meta = with stdenv.lib; {
+    description = "A filtering tool for Linux-based bridging firewalls";
+    homepage = http://ebtables.sourceforge.net/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/edac-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/edac-utils/default.nix
new file mode 100644
index 000000000000..eabd08485536
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/edac-utils/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchFromGitHub, perl, makeWrapper
+, sysfsutils, dmidecode, kmod }:
+
+stdenv.mkDerivation {
+  name = "edac-utils-2015-01-07";
+
+  src = fetchFromGitHub {
+    owner = "grondo";
+    repo = "edac-utils";
+    rev = "f9aa96205f610de39a79ff43c7478b7ef02e3138";
+    sha256 = "1dmfqb15ffldl5zirbmwiqzpxbcc2ny9rpfvxcfvpmh5b69knvdg";
+  };
+
+  nativeBuildInputs = [ perl makeWrapper ];
+  buildInputs = [ sysfsutils ];
+
+  configureFlags = [
+    "--sysconfdir=/etc"
+    "--localstatedir=/var"
+  ];
+
+  installFlags = [
+    "sysconfdir=\${out}/etc"
+  ];
+
+  postInstall = ''
+    wrapProgram "$out/sbin/edac-ctl" \
+      --set PATH ${stdenv.lib.makeBinPath [ dmidecode kmod ]}
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/grondo/edac-utils;
+    description = "Handles the reporting of hardware-related memory errors";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ena/default.nix b/nixpkgs/pkgs/os-specific/linux/ena/default.nix
new file mode 100644
index 000000000000..495cd49e3f48
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ena/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+stdenv.mkDerivation rec {
+  version = "2.0.2";
+  name = "ena-${version}-${kernel.version}";
+
+  src = fetchFromGitHub {
+    owner = "amzn";
+    repo = "amzn-drivers";
+    rev = "ena_linux_${version}";
+    sha256 = "0vb8s0w7ddwajk5gj5nqqlqc63p8p556f9ccwviwda2zvgqmk2pb";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  # linux 3.12
+  NIX_CFLAGS_COMPILE = "-Wno-error=implicit-function-declaration";
+
+  configurePhase = ''
+    cd kernel/linux/ena
+    substituteInPlace Makefile --replace '/lib/modules/$(BUILD_KERNEL)' ${kernel.dev}/lib/modules/${kernel.modDirVersion}
+  '';
+
+  installPhase = ''
+    strip -S ena.ko
+    dest=$out/lib/modules/${kernel.modDirVersion}/misc
+    mkdir -p $dest
+    cp ena.ko $dest/
+    xz $dest/ena.ko
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Amazon Elastic Network Adapter (ENA) driver for Linux";
+    homepage = https://github.com/amzn/amzn-drivers;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.eelco ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/eudev/default.nix b/nixpkgs/pkgs/os-specific/linux/eudev/default.nix
new file mode 100644
index 000000000000..7e8c9e413380
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/eudev/default.nix
@@ -0,0 +1,60 @@
+{stdenv, fetchurl, pkgconfig, glib, gperf, utillinux, kmod}:
+let
+  s = # Generated upstream information
+  rec {
+    baseName="eudev";
+    version = "3.2.7";
+    name="${baseName}-${version}";
+    url="http://dev.gentoo.org/~blueness/eudev/eudev-${version}.tar.gz";
+    sha256 = "0qphgfw1vh2f73yjggkh5icxfq5gg811a0j6b22zkhaks95n211h";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [
+    glib gperf utillinux kmod
+  ];
+in
+stdenv.mkDerivation {
+  inherit (s) name version;
+  inherit nativeBuildInputs buildInputs;
+  src = fetchurl {
+    inherit (s) url sha256;
+  };
+  patches = [
+  ];
+
+  configureFlags = [
+    "--localstatedir=/var"
+    "--sysconfdir=/etc"
+  ];
+  makeFlags = [
+    "hwdb_bin=/var/lib/udev/hwdb.bin"
+    "udevrulesdir=/etc/udev/rules.d"
+    ];
+
+  preInstall = ''
+    # Disable install-exec-hook target as it conflicts with our move-sbin setup-hook
+    sed -i 's;$(MAKE) $(AM_MAKEFLAGS) install-exec-hook;$(MAKE) $(AM_MAKEFLAGS);g' src/udev/Makefile
+  '';
+
+  installFlags =
+    [
+    "localstatedir=$(TMPDIR)/var"
+    "sysconfdir=$(out)/etc"
+    "udevconfdir=$(out)/etc/udev"
+    "udevhwdbbin=$(out)/var/lib/udev/hwdb.bin"
+    "udevhwdbdir=$(out)/var/lib/udev/hwdb.d"
+    "udevrulesdir=$(out)/var/lib/udev/rules.d"
+    ];
+  enableParallelBuilding = true;
+  meta = {
+    inherit (s) version;
+    description = ''An udev fork by Gentoo'';
+    license = stdenv.lib.licenses.gpl2Plus ;
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+    homepage = ''https://www.gentoo.org/proj/en/eudev/'';
+    downloadPage = ''http://dev.gentoo.org/~blueness/eudev/'';
+    updateWalker = true;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/evdi/default.nix b/nixpkgs/pkgs/os-specific/linux/evdi/default.nix
new file mode 100644
index 000000000000..40963d32860b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/evdi/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchFromGitHub, kernel, libdrm }:
+
+stdenv.mkDerivation rec {
+  name = "evdi-${version}";
+  version = "1.6.0";
+
+  src = fetchFromGitHub {
+    owner = "DisplayLink";
+    repo = "evdi";
+    rev = "v${version}";
+    sha256 = "1mv2sydynhqxhzyqqma4hjpm8y7pzxpg1gdmwnjq8h2680q70m91";
+  };
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  buildInputs = [ kernel libdrm ];
+
+  makeFlags = [ "KVER=${kernel.modDirVersion}" "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" ];
+
+  hardeningDisable = [ "format" "pic" "fortify" ];
+
+  installPhase = ''
+    install -Dm755 module/evdi.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/gpu/drm/evdi/evdi.ko
+    install -Dm755 library/libevdi.so $out/lib/libevdi.so
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Extensible Virtual Display Interface";
+    platforms = platforms.linux;
+    license = with licenses; [ lgpl21 gpl2 ];
+    homepage = https://www.displaylink.com/;
+    broken = versionOlder kernel.version "4.9" || versionAtLeast kernel.version "4.18" || stdenv.isAarch64;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/eventstat/default.nix b/nixpkgs/pkgs/os-specific/linux/eventstat/default.nix
new file mode 100644
index 000000000000..cf3522b5f2fa
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/eventstat/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, lib, fetchzip, ncurses }:
+
+stdenv.mkDerivation rec {
+  name = "eventstat-${version}";
+  version = "0.04.05";
+  src = fetchzip {
+    url = "http://kernel.ubuntu.com/~cking/tarballs/eventstat/eventstat-${version}.tar.gz";
+    sha256 = "1s9d6wl7f8cyn21fwj894dhfvl6f6f2h5xv26hg1yk3zfb5rmyn7";
+  };
+  buildInputs = [ ncurses ];
+  installFlags = [ "DESTDIR=$(out)" ];
+  postInstall = ''
+    mv $out/usr/* $out
+    rm -r $out/usr
+  '';
+  meta = with lib; {
+    description = "Simple monitoring of system events";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ cstrahan ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/exfat/default.nix b/nixpkgs/pkgs/os-specific/linux/exfat/default.nix
new file mode 100644
index 000000000000..036cd3f28a1b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/exfat/default.nix
@@ -0,0 +1,46 @@
+{ stdenv, lib, fetchFromGitHub, fetchpatch, kernel }:
+
+
+# Upstream build for kernel 4.1 is broken, 3.12 and below seems to be working
+assert lib.versionAtLeast kernel.version  "4.2" || lib.versionOlder kernel.version "4.0";
+
+stdenv.mkDerivation rec {
+  name = "exfat-nofuse-${version}-${kernel.version}";
+  version = "2018-04-16";
+
+  src = fetchFromGitHub {
+    owner = "dorimanx";
+    repo = "exfat-nofuse";
+    rev = "01c30ad52625a7261e1b0d874553b6ca7af25966";
+    sha256 = "0n1ibamf1yj8iqapc86lfscnky9p07ngsi4f2kpv3d5r2s6mzsh6";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  makeFlags = [
+    "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  ];
+
+  installPhase = ''
+    install -m644 -b -D exfat.ko $out/lib/modules/${kernel.modDirVersion}/kernel/fs/exfat/exfat.ko
+  '';
+
+  patches = [
+    # fix compile-errors in 4.18 and 4.20
+    # ref: https://github.com/dorimanx/exfat-nofuse/pull/137
+    (fetchpatch {
+      url = https://github.com/dorimanx/exfat-nofuse/compare/01c30ad52625a7261e1b0d874553b6ca7af25966...f93a47e6414d567a1e7f6ab7f34b015b20f9a050.patch ;
+      sha256 = "0w57pi9h6dwjxfgc3zpwy6sr4zw42hn1zj72f7wgfpqrx6d8xkh5";
+    } )
+  ];
+
+  meta = {
+    description = "exfat kernel module";
+    homepage = https://github.com/dorimanx/exfat-nofuse;
+    license = lib.licenses.gpl2;
+    maintainers = with lib.maintainers; [ makefu ];
+    platforms = lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/facetimehd/default.nix b/nixpkgs/pkgs/os-specific/linux/facetimehd/default.nix
new file mode 100644
index 000000000000..d65018c600ec
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/facetimehd/default.nix
@@ -0,0 +1,61 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+# facetimehd is not supported for kernels older than 3.19";
+assert stdenv.lib.versionAtLeast kernel.version "3.19";
+
+let
+  # Note: When updating this revision:
+  # 1. Also update pkgs/os-specific/linux/firmware/facetimehd-firmware/
+  # 2. Test the module and firmware change via:
+  #    a. Give some applications a try (Skype, Hangouts, Cheese, etc.)
+  #    b. Run: journalctl -f
+  #    c. Then close the lid
+  #    d. Then open the lid (and maybe press a key to wake it up)
+  #    e. see if the module loads back (apps using the camera won't
+  #       recover and will have to be restarted) and the camera
+  #       still works.
+  srcParams = if (stdenv.lib.versionAtLeast kernel.version "4.8") then
+    { # Use mainline branch
+      version = "unstable-2016-10-09";
+      rev = "887d0f531ef7b91457be519474136c3355c5132b";
+      sha256 = "0bayahnxar1q6wvf9cb6p8gsfw98w0wqp715hs4r7apmddwk9v7n";
+    }
+  else
+    { # Use master branch (broken on 4.8)
+      version = "unstable-2016-05-02";
+      rev = "5a7083bd98b38ef3bd223f7ee531d58f4fb0fe7c";
+      sha256 = "0d455kajvn5xav9iilqy7s1qvsy4yb8vzjjxx7bvcgp7aj9ljvdp";
+    }
+  ;
+in
+
+stdenv.mkDerivation rec {
+  name = "facetimehd-${version}-${kernel.version}";
+  version = srcParams.version;
+
+  src = fetchFromGitHub {
+    owner = "patjak";
+    repo = "bcwc_pcie";
+    inherit (srcParams) rev sha256;
+  };
+
+  preConfigure = ''
+    export INSTALL_MOD_PATH="$out"
+  '';
+
+  hardeningDisable = [ "pic" ];
+  
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  makeFlags = [
+    "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/patjak/bcwc_pcie;
+    description = "Linux driver for the Facetime HD (Broadcom 1570) PCIe webcam";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ womfoo grahamc ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fatrace/default.nix b/nixpkgs/pkgs/os-specific/linux/fatrace/default.nix
new file mode 100644
index 000000000000..94ea85f433d9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fatrace/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl, python3, which }:
+
+stdenv.mkDerivation rec {
+  name = "fatrace-${version}";
+  version = "0.13";
+
+  src = fetchurl {
+    url = "https://launchpad.net/fatrace/trunk/${version}/+download/${name}.tar.bz2";
+    sha256 = "0hrh45bpzncw0jkxw3x2smh748r65k2yxvfai466043bi5q0d2vx";
+  };
+
+  buildInputs = [ python3 which ];
+
+  postPatch = ''
+    substituteInPlace power-usage-report \
+      --replace "'which'" "'${which}/bin/which'"
+
+    # Avoid a glibc >= 2.25 deprecation warning that gets fatal via -Werror.
+    sed 1i'#include <sys/sysmacros.h>' -i fatrace.c
+  '';
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  meta = with stdenv.lib; {
+    description = "Report system-wide file access events";
+    homepage = https://launchpad.net/fatrace/;
+    license = licenses.gpl3Plus;
+    longDescription = ''
+      fatrace reports file access events from all running processes.
+      Its main purpose is to find processes which keep waking up the disk
+      unnecessarily and thus prevent some power saving.
+      Requires a Linux kernel with the FANOTIFY configuration option enabled.
+      Enabling X86_MSR is also recommended for power-usage-report on x86.
+    '';
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fbterm/default.nix b/nixpkgs/pkgs/os-specific/linux/fbterm/default.nix
new file mode 100644
index 000000000000..defb45d7a861
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fbterm/default.nix
@@ -0,0 +1,60 @@
+{stdenv, lib, fetchurl, gpm, freetype, fontconfig, pkgconfig, ncurses, libx86}:
+let
+  s = # Generated upstream information
+  rec {
+    baseName="fbterm";
+    version="1.7.0";
+    name="fbterm-1.7.0";
+    hash="0pciv5by989vzvjxsv1jsv4bdp4m8j0nfbl29jm5fwi12w4603vj";
+    url = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/fbterm/fbterm-1.7.0.tar.gz";
+    sha256="0pciv5by989vzvjxsv1jsv4bdp4m8j0nfbl29jm5fwi12w4603vj";
+  };
+  buildInputs = [gpm freetype fontconfig ncurses]
+    ++ lib.optional (stdenv.isi686 || stdenv.isx86_64) libx86;
+in
+stdenv.mkDerivation {
+  inherit (s) name version;
+  src = fetchurl {
+    inherit (s) url sha256;
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  inherit buildInputs;
+
+  preConfigure = ''
+    sed -e '/ifdef SYS_signalfd/atypedef long long loff_t;' -i src/fbterm.cpp
+    sed -e '/install-exec-hook:/,/^[^\t]/{d}; /.NOEXPORT/iinstall-exec-hook:\
+    ' -i src/Makefile.in
+    export HOME=$PWD;
+    export NIX_LDFLAGS="$NIX_LDFLAGS -lfreetype"
+  '';
+  preBuild = ''
+    mkdir -p "$out/share/terminfo"
+    tic -a -v2 -o"$out/share/terminfo" terminfo/fbterm
+  '';
+
+  patches = [
+    # fixes from Arch Linux package
+    (fetchurl {
+      url = "https://raw.githubusercontent.com/glitsj16/fbterm-patched/d1fe03313be4654dd0a1c0bb5f51530732345134/gcc-6-build-fixes.patch";
+      sha256 = "1kl9fjnrri6pamjdl4jpkqxk5wxcf6jcchv5801xz8vxp4542m40";
+    })
+    (fetchurl {
+      url = "https://raw.githubusercontent.com/glitsj16/fbterm-patched/d1fe03313be4654dd0a1c0bb5f51530732345134/insertmode-fix.patch";
+      sha256 = "1bad9mqcfpqb94lpx23lsamlhplil73ahzin2xjva0gl3gr1038l";
+    })
+    (fetchurl {
+      url = "https://raw.githubusercontent.com/glitsj16/fbterm-patched/d1fe03313be4654dd0a1c0bb5f51530732345134/miscoloring-fix.patch";
+      sha256 = "1mjszji0jgs2jsagjp671fv0d1983wmxv009ff1jfhi9pbay6jd0";
+    })
+  ];
+
+  meta = with stdenv.lib; {
+    inherit (s) version;
+    description = "Framebuffer terminal emulator";
+    homepage = https://code.google.com/archive/p/fbterm/;
+    maintainers = [ maintainers.raskin ];
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ffado/default.nix b/nixpkgs/pkgs/os-specific/linux/ffado/default.nix
new file mode 100644
index 000000000000..027706c25b7b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ffado/default.nix
@@ -0,0 +1,67 @@
+{ stdenv, fetchurl, scons, pkgconfig, which, makeWrapper, python
+, expat, libraw1394, libconfig, libavc1394, libiec61883, libxmlxx
+, glibmm
+, alsaLib, dbus, dbus_cplusplus
+, pyqt4, dbus-python
+}:
+
+stdenv.mkDerivation rec {
+  name = "ffado-${version}";
+  version = "2.4.0";
+
+  src = fetchurl {
+    url = "http://www.ffado.org/files/libffado-${version}.tgz";
+    sha256 = "14rprlcd0gpvg9kljh0zzjzd2rc9hbqqpjidshxxjvvfh4r00f4f";
+  };
+
+  outputs = [ "out" "bin" "dev" ];
+
+  nativeBuildInputs = [ scons pkgconfig which makeWrapper python ];
+
+  prefixKey = "PREFIX=";
+  sconsFlags = [
+    "DEBUG=False"
+    "ENABLE_ALL=True"
+    "SERIALIZE_USE_EXPAT=True"
+    "BUILD_TESTS=False"
+    "WILL_DEAL_WITH_XDG_MYSELF=True"
+    "BUILD_MIXER=True"
+  ];
+
+  configurePhase = ''
+    mkdir -p $out/lib/udev/rules.d $bin/bin $dev/include \
+             $out/lib/${python.libPrefix}/site-packages
+    sconsFlagsArray+=(UDEVDIR=$out/lib/udev/rules.d)
+    sconsFlagsArray+=(PYPKGDIR=$out/lib/${python.libPrefix}/site-packages)
+    sconsFlagsArray+=(BINDIR=$bin/bin)
+    sconsFlagsArray+=(INCLUDEDIR=$dev/include)
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE $(pkg-config --cflags libxml++-2.6)"
+  '';
+
+  buildInputs = [
+    expat libraw1394 libconfig libavc1394 libiec61883 dbus dbus_cplusplus
+    libxmlxx pyqt4 dbus-python glibmm
+  ];
+
+  postPatch = ''
+    sed '1iimport sys' -i SConstruct
+  '';
+
+  postInstall = ''
+    for exe in $bin/bin/ffado-mixer $bin/bin/ffado-diag; do
+      wrapProgram $exe \
+        --prefix PYTHONPATH : $out/lib/${python.libPrefix}/site-packages \
+        --prefix PYTHONPATH : $out/share/libffado/python \
+        --prefix PYTHONPATH : ${pyqt4}/lib/${python.libPrefix}/site-packages \
+        --prefix PYTHONPATH : ${dbus-python}/lib/${python.libPrefix}/site-packages
+    done
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://www.ffado.org;
+    description = "FireWire audio drivers";
+    license = licenses.gpl3;
+    maintainers = with maintainers; [ goibhniu ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firejail/default.nix b/nixpkgs/pkgs/os-specific/linux/firejail/default.nix
new file mode 100644
index 000000000000..96cc8769a06e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firejail/default.nix
@@ -0,0 +1,59 @@
+{stdenv, fetchurl, which}:
+let
+  s = # Generated upstream information
+  rec {
+    baseName="firejail";
+    version="0.9.58.2";
+    name="${baseName}-${version}";
+    hash="0ck40b5g1gr5w25qa1lnamwkqnnnbyl14na5c8bq0za0qpf2f8jx";
+    url="https://vorboss.dl.sourceforge.net/project/firejail/firejail/firejail-0.9.58.2.tar.xz";
+    sha256="0ck40b5g1gr5w25qa1lnamwkqnnnbyl14na5c8bq0za0qpf2f8jx";
+  };
+  buildInputs = [
+    which
+  ];
+in
+stdenv.mkDerivation {
+  inherit (s) name version;
+  inherit buildInputs;
+  src = fetchurl {
+    inherit (s) url sha256;
+    name = "${s.name}.tar.bz2";
+  };
+
+  prePatch = ''
+    # Allow whitelisting ~/.nix-profile
+    substituteInPlace etc/firejail.config --replace \
+      '# follow-symlink-as-user yes' \
+      'follow-symlink-as-user no'
+  '';
+
+  preConfigure = ''
+    sed -e 's@/bin/bash@${stdenv.shell}@g' -i $( grep -lr /bin/bash .)
+    sed -e "s@/bin/cp@$(which cp)@g" -i $( grep -lr /bin/cp .)
+  '';
+
+  preBuild = ''
+    sed -e "s@/etc/@$out/etc/@g" -e "/chmod u+s/d" -i Makefile
+  '';
+
+  # We need to set the directory for the .local override files back to
+  # /etc/firejail so we can actually override them
+  postInstall = ''
+    sed -E -e 's@^include (.*)(/firejail/.*.local)$@include /etc\2@g' -i $out/etc/firejail/*.profile
+  '';
+
+  # At high parallelism, the build sometimes fails with:
+  # bash: src/fsec-optimize/fsec-optimize: No such file or directory
+  enableParallelBuilding = false;
+
+  meta = {
+    inherit (s) version;
+    description = ''Namespace-based sandboxing tool for Linux'';
+    license = stdenv.lib.licenses.gpl2Plus ;
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+    homepage = https://l3net.wordpress.com/projects/firejail/;
+    downloadPage = "https://sourceforge.net/projects/firejail/files/firejail/";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firejail/default.upstream b/nixpkgs/pkgs/os-specific/linux/firejail/default.upstream
new file mode 100644
index 000000000000..0e6576c44a80
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firejail/default.upstream
@@ -0,0 +1,3 @@
+url https://sourceforge.net/projects/firejail/files/firejail/
+version_link '[-][0-9.]+[.]tar[.][a-z0-9]+/download$'
+SF_redirect
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/default.nix
new file mode 100644
index 000000000000..8aa78e65dec1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/default.nix
@@ -0,0 +1,21 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "b43-fwcutter-019";
+
+  src = fetchurl {
+    url = "https://bues.ch/b43/fwcutter/${name}.tar.bz2";
+    sha256 = "1ki1f5fy3yrw843r697f8mqqdz0pbsbqnvg4yzkhibpn1lqqbsnn";
+  };
+
+  patches = [ ./no-root-install.patch ];
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  meta = {
+    description = "Firmware extractor for cards supported by the b43 kernel module";
+    homepage = http://wireless.kernel.org/en/users/Drivers/b43;
+    license = stdenv.lib.licenses.free;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/no-root-install.patch b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/no-root-install.patch
new file mode 100644
index 000000000000..578812e0ad0b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware-cutter/no-root-install.patch
@@ -0,0 +1,18 @@
+diff -Naur b43-fwcutter-015-orig/Makefile b43-fwcutter-015/Makefile
+--- b43-fwcutter-015-orig/Makefile	2011-08-21 08:17:01.000000000 -0400
++++ b43-fwcutter-015/Makefile	2012-07-13 17:57:53.002154557 -0400
+@@ -51,10 +51,10 @@
+ 	$(QUIET_CC) $(CFLAGS) -o $(BIN) $(call OBJS,$(SRCS)) $(LDFLAGS)
+ 
+ install: all
+-	install -d -o 0 -g 0 -m 755 $(PREFIX)/bin/
+-	install -o 0 -g 0 -m 755 $(BIN) $(PREFIX)/bin/
+-	install -d -o 0 -g 0 -m 755 $(PREFIX)/man/man1/
+-	install -o 0 -g 0 -m 644 $(BIN).1 $(PREFIX)/man/man1/
++	install -d -m 755 $(PREFIX)/bin/
++	install -m 755 $(BIN) $(PREFIX)/bin/
++	install -d -m 755 $(PREFIX)/man/man1/
++	install -m 644 $(BIN).1 $(PREFIX)/man/man1/
+ 
+ clean:
+ 	-rm -Rf obj dep *.orig *.rej *~
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix
new file mode 100644
index 000000000000..1cc0e7ae4ca7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/5.1.138.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchurl, b43FirmwareCutter }:
+
+let version = "5.100.138"; in
+
+stdenv.mkDerivation {
+  name = "b43-firmware-${version}";
+
+  src = fetchurl {
+    url = "http://www.lwfinger.com/b43-firmware/broadcom-wl-${version}.tar.bz2";
+    sha256 = "0vz4ka8gycf72gmnaq61k8rh8y17j1wm2k3fidxvcqjvmix0drzi";
+  };
+
+  buildInputs = [ b43FirmwareCutter ];
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  installPhase = ''
+    mkdir -p $out/lib/firmware
+    b43-fwcutter -w $out/lib/firmware linux/wl_apsta.o
+  '';
+
+  meta = {
+    description = "Firmware for cards supported by the b43 kernel module";
+    homepage = http://wireless.kernel.org/en/users/Drivers/b43;
+    license = stdenv.lib.licenses.unfree;
+  };
+}
+
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/6.30.163.46.nix b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/6.30.163.46.nix
new file mode 100644
index 000000000000..2637beb517a3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/b43-firmware/6.30.163.46.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchurl, b43FirmwareCutter }:
+
+stdenv.mkDerivation rec {
+  name = "b43-firmware-${version}";
+  version = "6.30.163.46";
+
+  src = fetchurl {
+    url = "http://www.lwfinger.com/b43-firmware/broadcom-wl-${version}.tar.bz2";
+    sha256 = "0baw6gcnrhxbb447msv34xg6rmlcj0gm3ahxwvdwfcvq4xmknz50";
+  };
+
+  buildInputs = [ b43FirmwareCutter ];
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  sourceRoot = ".";
+
+  installPhase = ''
+    mkdir $out
+    b43-fwcutter -w $out *.wl_apsta.o
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Firmware for cards supported by the b43 kernel module";
+    homepage = http://wireless.kernel.org/en/users/Drivers/b43;
+    downloadPage = http://www.lwfinger.com/b43-firmware;
+    license = licenses.unfree;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/broadcom-bt-firmware/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/broadcom-bt-firmware/default.nix
new file mode 100644
index 000000000000..a57a6f1d70f6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/broadcom-bt-firmware/default.nix
@@ -0,0 +1,46 @@
+{ stdenv, fetchurl, cabextract, bt-fw-converter }:
+
+# Kernels between 4.2 and 4.7 will not work with
+# this packages as they expect the firmware to be named "BCM.hcd"
+# see: https://github.com/NixOS/nixpkgs/pull/25478#issuecomment-299034865
+stdenv.mkDerivation rec {
+  name = "broadcom-bt-firmware-${version}";
+  version = "12.0.1.1012";
+
+  src = fetchurl {
+    url = "http://download.windowsupdate.com/c/msdownload/update/driver/drvs/2017/04/852bb503-de7b-4810-a7dd-cbab62742f09_7cf83a4c194116648d17707ae37d564f9c70bec2.cab";
+    sha256 = "1b1qjwxjk4y91l3iz157kms8601n0mmiik32cs6w9b1q4sl4pxx9";
+  };
+
+  nativeBuildInputs = [ cabextract bt-fw-converter ];
+
+  unpackCmd = ''
+    mkdir -p ${name}
+    cabextract $src --directory ${name}
+  '';
+
+  installPhase = ''
+    mkdir -p $out/lib/firmware/brcm
+    bt-fw-converter -f bcbtums.inf -o $out/lib/firmware/brcm
+    for filename in $out/lib/firmware/brcm/*.hcd
+    do
+      linkname=$(basename $filename | awk 'match($0,/^(BCM)[0-9A-Z]+(-[0-9a-z]{4}-[0-9a-z]{4}\.hcd)$/,c) { print c[1]c[2] }')
+      if ! [ -z $linkname ]
+      then
+        ln -s --relative -T $filename $out/lib/firmware/brcm/$linkname
+      fi
+    done
+  '';
+
+  outputHashMode = "recursive";
+  outputHashAlgo = "sha256";
+  outputHash = "042frb2dmrqfj8q83h5p769q6hg2b3i8fgnyvs9r9a71z7pbsagq";
+
+  meta = with stdenv.lib; {
+    description = "Firmware for Broadcom WIDCOMM® Bluetooth devices";
+    homepage = http://www.catalog.update.microsoft.com/Search.aspx?q=Broadcom+bluetooth;
+    license = licenses.unfree;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ zraexy ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/bt-fw-converter/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/bt-fw-converter/default.nix
new file mode 100644
index 000000000000..8927e1a28e7c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/bt-fw-converter/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchurl, makeWrapper, perl, perlPackages, bluez }:
+
+stdenv.mkDerivation  rec {
+  name = "bt-fw-converter-${version}";
+  version = "2017-02-19";
+  rev = "2d8b34402df01c6f7f4b8622de9e8b82fadf4153";
+
+  src = fetchurl {
+    url = "https://raw.githubusercontent.com/winterheart/broadcom-bt-firmware/${rev}/tools/bt-fw-converter.pl";
+    sha256 = "c259b414a4a273c89a0fa7159b3ef73d1ea62b6de91c3a7c2fcc832868e39f4b";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+
+  buildInputs = [ perl perlPackages.RegexpGrammars bluez ];
+
+  unpackCmd = ''
+    mkdir -p ${name}
+    cp $src ${name}/bt-fw-converter.pl
+  '';
+
+  installPhase = ''
+    install -D -m755 bt-fw-converter.pl $out/bin/bt-fw-converter
+    substituteInPlace $out/bin/bt-fw-converter --replace /usr/bin/hex2hcd ${bluez}/bin/hex2hcd
+    wrapProgram $out/bin/bt-fw-converter --set PERL5LIB $PERL5LIB
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/winterheart/broadcom-bt-firmware/;
+    description = "A tool that converts hex to hcd based on inf file";
+    license = licenses.mit;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ zraexy ];
+  };
+} 
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/facetimehd-firmware/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/facetimehd-firmware/default.nix
new file mode 100644
index 000000000000..5f8f6c542521
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/facetimehd-firmware/default.nix
@@ -0,0 +1,64 @@
+{ stdenv, fetchurl, cpio, xz, pkgs }:
+
+let
+
+  version = "1.43_4";
+
+
+  # Updated according to https://github.com/patjak/bcwc_pcie/pull/81/files
+  # and https://github.com/patjak/bcwc_pcie/blob/5a7083bd98b38ef3bd223f7ee531d58f4fb0fe7c/firmware/Makefile#L3-L9
+  # and https://github.com/patjak/bcwc_pcie/blob/5a7083bd98b38ef3bd223f7ee531d58f4fb0fe7c/firmware/extract-firmware.sh
+
+  # From the Makefile:
+  dmgUrl = "https://support.apple.com/downloads/DL1877/en_US/osxupd10.11.5.dmg";
+  dmgRange = "205261917-208085450"; # the whole download is 1.3GB, this cuts it down to 2MB
+  # Notes:
+  # 1. Be sure to update the sha256 below in the fetch_url
+  # 2. Be sure to update the homepage in the meta
+
+  # Also from the Makefile (OS_DRV, OS_DRV_DIR), but seems to not change:
+  firmwareIn = "./System/Library/Extensions/AppleCameraInterface.kext/Contents/MacOS/AppleCameraInterface";
+  firmwareOut = "firmware.bin";
+
+  # The following are from the extract-firmware.sh
+  firmwareOffset = "81920"; # Variable: firmw_offsets
+  firmwareSize = "603715"; # Variable: firmw_sizes
+
+
+  # separated this here as the script will fail without the 'exit 0'
+  unpack = pkgs.writeScriptBin "unpack" ''
+    xzcat -Q $src | cpio --format odc -i -d ${firmwareIn}
+    exit 0
+  '';
+
+in
+
+stdenv.mkDerivation {
+
+  name = "facetimehd-firmware-${version}";
+  src = fetchurl {
+    url = dmgUrl;
+    sha256 = "0xqkl4yds0n9fdjvnk0v5mj382q02crry6wm2q7j3ncdqwsv02sv";
+    curlOpts = "-r ${dmgRange}";
+  };
+
+  phases = [ "buildPhase" ];
+
+  buildInputs = [ cpio xz ];
+
+  buildPhase = ''
+    ${unpack}/bin/unpack
+    dd bs=1 skip=${firmwareOffset} count=${firmwareSize} if=${firmwareIn} of=${firmwareOut}.gz &> /dev/null
+    mkdir -p $out/lib/firmware/facetimehd
+    gunzip -c ${firmwareOut}.gz > $out/lib/firmware/facetimehd/${firmwareOut}
+  '';
+
+  meta = with stdenv.lib; {
+    description = "facetimehd firmware";
+    homepage = https://support.apple.com/downloads/DL1877;
+    license = licenses.unfree;
+    maintainers = with maintainers; [ womfoo grahamc ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix
new file mode 100644
index 000000000000..ee0a02763d14
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchgit }:
+
+stdenv.mkDerivation rec {
+  name = "firmware-linux-nonfree-${version}";
+  version = "2019-03-12";
+
+  src = fetchgit {
+    url = "https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git";
+    rev = "20190312";
+    sha256 = "1wk8l75rg7idvsyli29a1fii4xwz3vnm8d65fjw8d3azihdrhbyy";
+  };
+
+  installFlags = [ "DESTDIR=$(out)" ];
+
+  # Firmware blobs do not need fixing and should not be modified
+  dontFixup = true;
+
+  meta = with stdenv.lib; {
+    description = "Binary firmware collection packaged by kernel.org";
+    homepage = http://packages.debian.org/sid/firmware-linux-nonfree;
+    license = licenses.unfreeRedistributableFirmware;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ fpletz ];
+    priority = 6; # give precedence to kernel firmware
+  };
+
+  passthru = { inherit version; };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/add-option-for-installation-sysconfdir.patch b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/add-option-for-installation-sysconfdir.patch
new file mode 100644
index 000000000000..d77053f5d397
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/add-option-for-installation-sysconfdir.patch
@@ -0,0 +1,171 @@
+From 44887227f7f617cbf84713ec45685cb4999039ff Mon Sep 17 00:00:00 2001
+From: Jan Tojnar <jtojnar@gmail.com>
+Date: Tue, 30 Oct 2018 22:26:30 +0100
+Subject: [PATCH] build: Add option for installation sysconfdir
+
+On NixOS, sysconfdir is read-only by default, and packages are not supposed to
+install files there. Instead, NixOS has a concept of modules that declaratively
+describe the system configuration.
+
+We still want to install the config files and certificates to fwupd prefix,
+so that the modules can use them as they see fit, but at the same time, we
+cannot set sysconfdir=${prefix}/etc because the daemon needs to read the
+configuration from the directory created by the module.
+
+With autotools, we could easily solve this by passing a the sysconfdir inside
+prefix only to `make install`, but Meson does not support anything like that.
+Until we manage to convince Meson to support install flags, we need to create
+our own install flag.
+---
+ data/meson.build                 | 4 ++--
+ data/pki/meson.build             | 8 ++++----
+ data/remotes.d/meson.build       | 6 +++---
+ meson.build                      | 6 ++++++
+ meson_options.txt                | 1 +
+ plugins/redfish/meson.build      | 2 +-
+ plugins/uefi/meson.build         | 2 +-
+ 7 files changed, 18 insertions(+), 11 deletions(-)
+
+diff --git a/data/meson.build b/data/meson.build
+index 8dd2ac9a..d4ad1cbc 100644
+--- a/data/meson.build
++++ b/data/meson.build
+@@ -9,7 +9,7 @@ if get_option('tests') and get_option('daemon')
+ endif
+ 
+ install_data(['daemon.conf'],
+-  install_dir : join_paths(sysconfdir, 'fwupd')
++  install_dir : join_paths(sysconfdir_install, 'fwupd')
+ )
+ 
+ install_data(['org.freedesktop.fwupd.metainfo.xml'],
+@@ -17,7 +17,7 @@ install_data(['org.freedesktop.fwupd.metainfo.xml'],
+ )
+ 
+ install_data(['org.freedesktop.fwupd.conf'],
+-  install_dir : join_paths(sysconfdir, 'dbus-1', 'system.d')
++  install_dir : join_paths(sysconfdir_install, 'dbus-1', 'system.d')
+ )
+ 
+ install_data(['metadata.xml'],
+diff --git a/data/pki/meson.build b/data/pki/meson.build
+index eefcc914..dc801fa1 100644
+--- a/data/pki/meson.build
++++ b/data/pki/meson.build
+@@ -4,14 +4,14 @@ if get_option('gpg')
+       'GPG-KEY-Linux-Foundation-Firmware',
+       'GPG-KEY-Linux-Vendor-Firmware-Service',
+     ],
+-    install_dir : join_paths(sysconfdir, 'pki', 'fwupd')
++    install_dir : join_paths(sysconfdir_install, 'pki', 'fwupd')
+   )
+ 
+   install_data([
+       'GPG-KEY-Linux-Foundation-Metadata',
+       'GPG-KEY-Linux-Vendor-Firmware-Service',
+     ],
+-    install_dir : join_paths(sysconfdir, 'pki', 'fwupd-metadata')
++    install_dir : join_paths(sysconfdir_install, 'pki', 'fwupd-metadata')
+   )
+ endif
+ 
+@@ -19,12 +19,12 @@ if get_option('pkcs7')
+   install_data([
+       'LVFS-CA.pem',
+     ],
+-    install_dir : join_paths(sysconfdir, 'pki', 'fwupd')
++    install_dir : join_paths(sysconfdir_install, 'pki', 'fwupd')
+   )
+   install_data([
+       'LVFS-CA.pem',
+     ],
+-    install_dir : join_paths(sysconfdir, 'pki', 'fwupd-metadata')
++    install_dir : join_paths(sysconfdir_install, 'pki', 'fwupd-metadata')
+   )
+ endif
+ 
+diff --git a/data/remotes.d/meson.build b/data/remotes.d/meson.build
+index 824291fc..d0599a00 100644
+--- a/data/remotes.d/meson.build
++++ b/data/remotes.d/meson.build
+@@ -3,7 +3,7 @@ if get_option('daemon') and get_option('lvfs')
+       'lvfs.conf',
+       'lvfs-testing.conf',
+     ],
+-    install_dir : join_paths(sysconfdir, 'fwupd', 'remotes.d')
++    install_dir : join_paths(sysconfdir_install, 'fwupd', 'remotes.d')
+   )
+   i18n.merge_file(
+     input: 'lvfs.metainfo.xml',
+@@ -37,12 +37,12 @@ configure_file(
+   output : 'fwupd.conf',
+   configuration : con2,
+   install: true,
+-  install_dir: join_paths(sysconfdir, 'fwupd', 'remotes.d'),
++  install_dir: join_paths(sysconfdir_install, 'fwupd', 'remotes.d'),
+ )
+ configure_file(
+   input : 'vendor.conf',
+   output : 'vendor.conf',
+   configuration : con2,
+   install: true,
+-  install_dir: join_paths(sysconfdir, 'fwupd', 'remotes.d'),
++  install_dir: join_paths(sysconfdir_install, 'fwupd', 'remotes.d'),
+ )
+diff --git a/meson.build b/meson.build
+index b6df98b3..d672ee37 100644
+--- a/meson.build
++++ b/meson.build
+@@ -145,6 +145,12 @@ localstatedir = join_paths(prefix, get_option('localstatedir'))
+ mandir = join_paths(prefix, get_option('mandir'))
+ localedir = join_paths(prefix, get_option('localedir'))
+ 
++if get_option('sysconfdir_install') != ''
++  sysconfdir_install = join_paths(prefix, get_option('sysconfdir_install'))
++else
++  sysconfdir_install = sysconfdir
++endif
++
+ gio = dependency('gio-2.0', version : '>= 2.45.8')
+ if gio.version().version_compare ('>= 2.55.0')
+   conf.set('HAVE_GIO_2_55_0', '1')
+diff --git a/meson_options.txt b/meson_options.txt
+index 23ef8cdb..db8f93b6 100644
+--- a/meson_options.txt
++++ b/meson_options.txt
+@@ -17,6 +17,7 @@ option('plugin_uefi', type : 'boolean', value : true, description : 'enable UEFI
+ option('plugin_nvme', type : 'boolean', value : true, description : 'enable NVMe support')
+ option('systemd', type : 'boolean', value : true, description : 'enable systemd support')
+ option('systemdunitdir', type: 'string', value: '', description: 'Directory for systemd units')
++option('sysconfdir_install', type: 'string', value: '', description: 'sysconfdir to use during installation')
+ option('tests', type : 'boolean', value : true, description : 'enable tests')
+ option('udevdir', type: 'string', value: '', description: 'Directory for udev rules')
+ option('efi-cc', type : 'string', value : 'gcc', description : 'the compiler to use for EFI modules')
+diff --git a/plugins/redfish/meson.build b/plugins/redfish/meson.build
+index ef07bd81..d2c7e259 100644
+--- a/plugins/redfish/meson.build
++++ b/plugins/redfish/meson.build
+@@ -25,7 +25,7 @@ shared_module('fu_plugin_redfish',
+ )
+ 
+ install_data(['redfish.conf'],
+-  install_dir:  join_paths(sysconfdir, 'fwupd')
++  install_dir:  join_paths(sysconfdir_install, 'fwupd')
+ )
+ 
+ if get_option('tests')
+diff --git a/plugins/uefi/meson.build b/plugins/uefi/meson.build
+index 09ebdf82..02fc0661 100644
+--- a/plugins/uefi/meson.build
++++ b/plugins/uefi/meson.build
+@@ -73,7 +73,7 @@ executable(
+ )
+ 
+ install_data(['uefi.conf'],
+-  install_dir:  join_paths(sysconfdir, 'fwupd')
++  install_dir:  join_paths(sysconfdir_install, 'fwupd')
+ )
+ 
+ if get_option('tests')
+-- 
+2.19.1
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/default.nix
new file mode 100644
index 000000000000..cf6e2bf60407
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/default.nix
@@ -0,0 +1,137 @@
+{ stdenv, fetchurl, substituteAll, gtk-doc, pkgconfig, gobject-introspection, intltool
+, libgudev, polkit, libxmlb, gusb, sqlite, libarchive, glib-networking
+, libsoup, help2man, gpgme, libxslt, elfutils, libsmbios, efivar, glibcLocales
+, gnu-efi, libyaml, valgrind, meson, libuuid, colord, docbook_xml_dtd_43, docbook_xsl
+, ninja, gcab, gnutls, python3, wrapGAppsHook, json-glib, bash-completion
+, shared-mime-info, umockdev, vala, makeFontsConf, freefont_ttf
+, cairo, freetype, fontconfig, pango
+}:
+
+# Updating? Keep $out/etc synchronized with passthru.filesInstalledToEtc
+
+let
+  python = python3.withPackages (p: with p; [ pygobject3 pycairo pillow ]);
+  installedTestsPython = python3.withPackages (p: with p; [ pygobject3 requests ]);
+
+  fontsConf = makeFontsConf {
+    fontDirectories = [ freefont_ttf ];
+  };
+in stdenv.mkDerivation rec {
+  pname = "fwupd";
+  version = "1.2.3";
+
+  src = fetchurl {
+    url = "https://people.freedesktop.org/~hughsient/releases/fwupd-${version}.tar.xz";
+    sha256 = "11qpgincndahq96rbm2kgcy9kw5n9cmbbilsrqcqcyk7mvv464sl";
+  };
+
+  outputs = [ "out" "lib" "dev" "devdoc" "man" "installedTests" ];
+
+  nativeBuildInputs = [
+    meson ninja gtk-doc pkgconfig gobject-introspection intltool glibcLocales shared-mime-info
+    valgrind gcab docbook_xml_dtd_43 docbook_xsl help2man libxslt python wrapGAppsHook vala
+  ];
+  buildInputs = [
+    polkit libxmlb gusb sqlite libarchive libsoup elfutils libsmbios gnu-efi libyaml
+    libgudev colord gpgme libuuid gnutls glib-networking efivar json-glib umockdev
+    bash-completion cairo freetype fontconfig pango
+  ];
+
+  LC_ALL = "en_US.UTF-8"; # For po/make-images
+
+  patches = [
+    ./fix-paths.patch
+    ./add-option-for-installation-sysconfdir.patch
+
+    # installed tests are installed to different output
+    # we also cannot have fwupd-tests.conf in $out/etc since it would form a cycle
+    (substituteAll {
+      src = ./installed-tests-path.patch;
+      # needs a different set of modules than po/make-images
+      inherit installedTestsPython;
+    })
+  ];
+
+  postPatch = ''
+    patchShebangs .
+
+    # we cannot use placeholder in substituteAll
+    # https://github.com/NixOS/nix/issues/1846
+    substituteInPlace data/installed-tests/meson.build --subst-var installedTests
+
+    # install plug-ins to out, they are not really part of the library
+    substituteInPlace meson.build \
+      --replace "plugin_dir = join_paths(libdir, 'fwupd-plugins-3')" \
+                "plugin_dir = join_paths('${placeholder "out"}', 'fwupd_plugins-3')"
+  '';
+
+  # /etc/os-release not available in sandbox
+  # doCheck = true;
+
+  preFixup = ''
+    gappsWrapperArgs+=(--prefix XDG_DATA_DIRS : "${shared-mime-info}/share")
+  '';
+
+  mesonFlags = [
+    "-Dplugin_dummy=true"
+    "-Dudevdir=lib/udev"
+    "-Dsystemdunitdir=lib/systemd/system"
+    "-Defi-libdir=${gnu-efi}/lib"
+    "-Defi-ldsdir=${gnu-efi}/lib"
+    "-Defi-includedir=${gnu-efi}/include/efi"
+    "--localstatedir=/var"
+    "--sysconfdir=/etc"
+    "-Dsysconfdir_install=${placeholder "out"}/etc"
+  ];
+
+  # TODO: We need to be able to override the directory flags from meson setup hook
+  # better – declaring them multiple times might become an error.
+  preConfigure = ''
+    mesonFlagsArray+=("--libexecdir=$out/libexec")
+  '';
+
+  postInstall = ''
+    moveToOutput share/installed-tests "$installedTests"
+    wrapProgram $installedTests/share/installed-tests/fwupd/hardware.py \
+      --prefix GI_TYPELIB_PATH : "$out/lib/girepository-1.0:${libsoup}/lib/girepository-1.0"
+  '';
+
+  FONTCONFIG_FILE = fontsConf; # Fontconfig error: Cannot load default config file
+
+  # TODO: wrapGAppsHook wraps efi capsule even though it is not elf
+  dontWrapGApps = true;
+  # so we need to wrap the executables manually
+  postFixup = ''
+    find -L "$out/bin" "$out/libexec" -type f -executable -print0 \
+      | while IFS= read -r -d ''' file; do
+      if [[ "''${file}" != *.efi ]]; then
+        echo "Wrapping program ''${file}"
+        wrapProgram "''${file}" "''${gappsWrapperArgs[@]}"
+      fi
+    done
+  '';
+
+  # /etc/fwupd/uefi.conf is created by the services.hardware.fwupd NixOS module
+  passthru = {
+    filesInstalledToEtc = [
+      "fwupd/remotes.d/fwupd.conf"
+      "fwupd/remotes.d/lvfs-testing.conf"
+      "fwupd/remotes.d/lvfs.conf"
+      "fwupd/remotes.d/vendor.conf"
+      "pki/fwupd/GPG-KEY-Hughski-Limited"
+      "pki/fwupd/GPG-KEY-Linux-Foundation-Firmware"
+      "pki/fwupd/GPG-KEY-Linux-Vendor-Firmware-Service"
+      "pki/fwupd/LVFS-CA.pem"
+      "pki/fwupd-metadata/GPG-KEY-Linux-Foundation-Metadata"
+      "pki/fwupd-metadata/GPG-KEY-Linux-Vendor-Firmware-Service"
+      "pki/fwupd-metadata/LVFS-CA.pem"
+    ];
+  };
+
+  meta = with stdenv.lib; {
+    homepage = https://fwupd.org/;
+    maintainers = with maintainers; [];
+    license = [ licenses.gpl2 ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/fix-paths.patch b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/fix-paths.patch
new file mode 100644
index 000000000000..d1024438d8a7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/fix-paths.patch
@@ -0,0 +1,15 @@
+--- a/data/builder/meson.build
++++ b/data/builder/meson.build
+@@ -1,3 +0,0 @@
+-install_data('README.md',
+-  install_dir : join_paths(localstatedir, 'lib', 'fwupd', 'builder')
+-)
+--- a/meson_post_install.sh
++++ b/meson_post_install.sh
+@@ -11,6 +11,4 @@
+     echo 'Updating systemd deps'
+     mkdir -p ${DESTDIR}${SYSTEMDUNITDIR}/system-update.target.wants
+     ln -sf ../fwupd-offline-update.service ${DESTDIR}${SYSTEMDUNITDIR}/system-update.target.wants/fwupd-offline-update.service
+-    echo 'Creating stateful directory'
+-    mkdir -p ${DESTDIR}${LOCALSTATEDIR}/lib/fwupd
+ #fi
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/installed-tests-path.patch b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/installed-tests-path.patch
new file mode 100644
index 000000000000..6c4b6b62a0cd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/fwupd/installed-tests-path.patch
@@ -0,0 +1,25 @@
+--- a/data/installed-tests/hardware.py
++++ b/data/installed-tests/hardware.py
+@@ -1,4 +1,4 @@
+-#!/usr/bin/python3
++#!@installedTestsPython@/bin/python3
+ # pylint: disable=wrong-import-position,too-many-locals,unused-argument,wrong-import-order
+ #
+ # Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
+--- a/data/installed-tests/meson.build
++++ b/data/installed-tests/meson.build
+@@ -1,6 +1,6 @@
+ con2 = configuration_data()
+ con2.set('installedtestsdir',
+-         join_paths(datadir, 'installed-tests', 'fwupd'))
++         join_paths('@installedTests@', 'share', 'installed-tests', 'fwupd'))
+ con2.set('bindir', bindir)
+ 
+ configure_file(
+@@ -52,5 +52,5 @@
+   output : 'fwupd-tests.conf',
+   configuration : con2,
+   install: true,
+-  install_dir: join_paths(sysconfdir, 'fwupd', 'remotes.d'),
++  install_dir: join_paths('@installedTests@', 'etc', 'fwupd', 'remotes.d'),
+ )
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/default.nix
new file mode 100644
index 000000000000..5b14546c90fd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/default.nix
@@ -0,0 +1,60 @@
+{ efivar, fetchurl, gettext, gnu-efi, libsmbios, pkgconfig, popt, stdenv }:
+let
+  version = "12";
+in stdenv.mkDerivation {
+  name = "fwupdate-${version}";
+  src = fetchurl {
+    url = "https://github.com/rhinstaller/fwupdate/releases/download/${version}/fwupdate-${version}.tar.bz2";
+    sha256 = "00w7jsg7wrlq4cpfz26m9rbv2jwyf0sansf343vfq02fy5lxars1";
+  };
+
+  patches = [
+    ./do-not-create-sharedstatedir.patch
+  ];
+
+  NIX_CFLAGS_COMPILE = [ "-I${gnu-efi}/include/efi" ];
+
+  # TODO: Just apply the disable to the efi subdir
+  hardeningDisable = [ "stackprotector" ];
+
+  makeFlags = [
+    "EFIDIR=nixos"
+    "prefix=$(out)"
+    "LIBDIR=$(out)/lib"
+    "GNUEFIDIR=${gnu-efi}/lib"
+    "ESPMOUNTPOINT=$(out)/boot"
+  ];
+
+  nativeBuildInputs = [
+    pkgconfig
+    gettext
+  ];
+
+  buildInputs = [
+    gnu-efi
+    libsmbios
+    popt
+  ];
+
+  propagatedBuildInputs = [
+    efivar
+  ];
+
+  # TODO: fix wrt cross-compilation
+  preConfigure = ''
+    arch=$(cc -dumpmachine | cut -f1 -d- | sed 's,i[3456789]86,ia32,' )
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE -I${gnu-efi}/include/efi/$arch"
+  '';
+
+  postInstall = ''
+    rm -rf $out/src
+    rm -rf $out/lib/debug
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Tools for using the ESRT and UpdateCapsule() to apply firmware updates";
+    maintainers = with maintainers; [ ];
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/do-not-create-sharedstatedir.patch b/nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/do-not-create-sharedstatedir.patch
new file mode 100644
index 000000000000..b8588ef2b11a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/fwupdate/do-not-create-sharedstatedir.patch
@@ -0,0 +1,10 @@
+--- a/linux/Makefile
++++ b/linux/Makefile
+@@ -131,7 +131,6 @@
+ 		ln -fs $(x) $(patsubst %.so.1.$(VERSION),%.so.1,$(DESTDIR)$(libdir)/$(x)) ;\
+ 		ln -fs $(x) $(patsubst %.so.1.$(VERSION),%.so,$(DESTDIR)$(libdir)/$(x)) ;\
+ 		)
+-	$(INSTALL) -d -m 755 $(DESTDIR)$(sharedstatedir)/fwupdate/
+ 	$(INSTALL) -d -m 755 $(DESTDIR)$(libexecdir)/fwupdate/
+ 	$(INSTALL) -m 755 cleanup $(DESTDIR)$(libexecdir)/fwupdate/cleanup
+ 	$(INSTALL) -d -m 755 $(DESTDIR)$(libdatadir)/systemd/system
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/intel2200BGFirmware/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/intel2200BGFirmware/default.nix
new file mode 100644
index 000000000000..372be2d71f2c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/intel2200BGFirmware/default.nix
@@ -0,0 +1,25 @@
+{ lib, fetchzip }:
+
+let version = "3.1"; in
+
+fetchzip {
+  name = "intel2200BGFirmware-${version}";
+  url = "https://src.fedoraproject.org/repo/pkgs/ipw2200-firmware/ipw2200-fw-${version}.tgz/eaba788643c7cc7483dd67ace70f6e99/ipw2200-fw-${version}.tgz";
+  sha256 = "0zjyjndyc401pn5x5lgypxdal21n82ymi3vbb2ja1b89yszj432b";
+
+  postFetch = ''
+    tar -xzvf $downloadedFile --strip-components=1
+    install -D -m644 ipw2200-bss.fw     $out/lib/firmware/ipw2200-bss.fw
+    install -D -m644 ipw2200-ibss.fw    $out/lib/firmware/ipw2200-ibss.fw
+    install -D -m644 ipw2200-sniffer.fw $out/lib/firmware/ipw2200-sniffer.fw
+    install -D -m644 LICENSE.ipw2200-fw $out/share/doc/intel2200BGFirmware/LICENSE
+  '';
+
+  meta = with lib; {
+    description = "Firmware for Intel 2200BG cards";
+    homepage = http://ipw2200.sourceforge.net/firmware.php;
+    license = licenses.unfreeRedistributableFirmware;
+    maintainers = with maintainers; [ sternenseemann ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/openelec-dvb-firmware/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/openelec-dvb-firmware/default.nix
new file mode 100644
index 000000000000..b60ce6f1b4af
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/openelec-dvb-firmware/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "openelec-dvb-firmware-${version}";
+  version = "0.0.51";
+
+  src = fetchurl {
+    url = "https://github.com/OpenELEC/dvb-firmware/archive/${version}.tar.gz";
+    sha256 = "cef3ce537d213e020af794cecf9de207e2882c375ceda39102eb6fa2580bad8d";
+  };
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  installPhase = ''
+    DESTDIR="$out" ./install
+    find $out \( -name 'README.*' -or -name 'LICEN[SC]E.*' -or -name '*.txt' \) | xargs rm
+  '';
+
+  meta = with stdenv.lib; {
+    description = "DVB firmware from OpenELEC";
+    homepage = https://github.com/OpenELEC/dvb-firmware;
+    license = licenses.unfreeRedistributableFirmware;
+    platforms = platforms.linux;
+    priority = 7;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi-wireless/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi-wireless/default.nix
new file mode 100644
index 000000000000..89b4f70264eb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi-wireless/default.nix
@@ -0,0 +1,53 @@
+{ stdenv, fetchurl, fetchFromGitHub, dpkg }:
+
+stdenv.mkDerivation rec {
+  name = "raspberrypi-wireless-firmware-${version}";
+  version = "2018-08-20";
+
+  srcs = [
+    (fetchFromGitHub {
+      name = "bluez-firmware";
+      owner = "RPi-Distro";
+      repo = "bluez-firmware";
+      rev = "ade2bae1aaaebede09abb8fb546f767a0e4c7804";
+      sha256 = "07gm76gxp5anv6paryvxcp34a86fkny8kdlzqhzcpfczzglkp6ag";
+    })
+    (fetchFromGitHub {
+      name = "firmware-nonfree";
+      owner = "RPi-Distro";
+      repo = "firmware-nonfree";
+      rev = "b518de45ced519e8f7a499f4778100173402ae43";
+      sha256 = "1d5026ic9awji6c67irpwsxpxgsc0dhn11d3abkxi2vvra1pir4g";
+    })
+  ];
+
+  sourceRoot = ".";
+
+  dontBuild = true;
+  # Firmware blobs do not need fixing and should not be modified
+  dontFixup = true;
+
+  installPhase = ''
+    mkdir -p "$out/lib/firmware/brcm"
+
+    # Wifi firmware
+    for filename in firmware-nonfree/brcm/brcmfmac434??-sdio.*; do
+      cp "$filename" "$out/lib/firmware/brcm"
+    done
+
+    # Bluetooth firmware
+    cp bluez-firmware/broadcom/*.hcd "$out/lib/firmware/brcm"
+  '';
+
+  outputHashMode = "recursive";
+  outputHashAlgo = "sha256";
+  outputHash = "1s5gb00v42s5izbaw8irs1fwvhh7z9wl07czc0nkw6p91871ivb7";
+
+  meta = with stdenv.lib; {
+    description = "Firmware for builtin Wifi/Bluetooth devices in the Raspberry Pi 3 and Zero W";
+    homepage = https://github.com/RPi-Distro/firmware-nonfree;
+    license = licenses.unfreeRedistributableFirmware;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ lopsided98 ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/default.nix
new file mode 100644
index 000000000000..8965e5d60d78
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "raspberrypi-firmware-${version}";
+  version = "1.20181112";
+
+  src = fetchFromGitHub {
+    owner = "raspberrypi";
+    repo = "firmware";
+    rev = version;
+    sha256 = "0jjxr8k8vdziynj8101ikcc9hmm61r2la51nrx6zv8a7j9a4m5zg";
+  };
+
+  installPhase = ''
+    mkdir -p $out/share/raspberrypi/boot
+    cp -R boot/* $out/share/raspberrypi/boot
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Firmware for the Raspberry Pi board";
+    homepage = https://github.com/raspberrypi/firmware;
+    license = licenses.unfreeRedistributableFirmware; # See https://github.com/raspberrypi/firmware/blob/master/boot/LICENCE.broadcom
+    platforms = [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ];
+    maintainers = with maintainers; [ dezgeg tavyc ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools-dont-install-sysv-init-scripts.patch b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools-dont-install-sysv-init-scripts.patch
new file mode 100644
index 000000000000..e12aeeb0cdb8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools-dont-install-sysv-init-scripts.patch
@@ -0,0 +1,20 @@
+diff --git a/interface/vmcs_host/linux/vcfiled/CMakeLists.txt b/interface/vmcs_host/linux/vcfiled/CMakeLists.txt
+index aed0e83..b325676 100644
+--- a/interface/vmcs_host/linux/vcfiled/CMakeLists.txt
++++ b/interface/vmcs_host/linux/vcfiled/CMakeLists.txt
+@@ -17,15 +17,6 @@ target_link_libraries(vcfiled
+ install(TARGETS vcfiled 
+         RUNTIME DESTINATION sbin)
+ 
+-configure_file (etc/init.d/vcfiled ${PROJECT_BINARY_DIR}/etc/init.d/vcfiled)
+-
+-# script to start up vcfiled at start of day
+-install(PROGRAMS ${PROJECT_BINARY_DIR}/etc/init.d/vcfiled
+-        DESTINATION /etc/init.d)
+-# install locally to the installation directory too
+-install(PROGRAMS ${PROJECT_BINARY_DIR}/etc/init.d/vcfiled
+-        DESTINATION ${VMCS_INSTALL_PREFIX}/share/install)
+-
+ # test program for vcfiled_check library
+ add_executable(vcfiled_lock_test vcfiled_lock_test.c)
+ target_link_libraries(vcfiled_lock_test vcfiled_check)
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools.nix b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools.nix
new file mode 100644
index 000000000000..4685f6757179
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/raspberrypi/tools.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchFromGitHub, cmake, pkgconfig }:
+
+stdenv.mkDerivation rec {
+  name = "raspberrypi-tools-${version}";
+  version = "2018-10-03";
+
+  src = fetchFromGitHub {
+    owner = "raspberrypi";
+    repo = "userland";
+    rev = "de4a7f2e3c391e2d3bc76af31864270e7802d9ac";
+    sha256 = "0w96xa98ngdk9m6wv185w8waa7wm2hkn2bhxz52zd477hchzrxlg";
+  };
+
+  patches = [ ./tools-dont-install-sysv-init-scripts.patch ];
+
+  nativeBuildInputs = [ cmake pkgconfig ];
+
+  preConfigure = ''
+    cmakeFlagsArray+=("-DVMCS_INSTALL_PREFIX=$out")
+  '' + stdenv.lib.optionalString stdenv.isAarch64 ''
+    cmakeFlagsArray+=("-DARM64=1")
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Userland tools for the Raspberry Pi board";
+    homepage = https://github.com/raspberrypi/userland;
+    license = licenses.bsd3;
+    platforms = [ "armv6l-linux" "armv7l-linux" "aarch64-linux" ];
+    maintainers = with maintainers; [ dezgeg tavyc ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/rt5677/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/rt5677/default.nix
new file mode 100644
index 000000000000..af0c07d10596
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/rt5677/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchgit }:
+
+stdenv.mkDerivation {
+  name = "rt5677-firmware";
+
+  src = fetchgit {
+    url = "https://github.com/raphael/linux-samus";
+    rev = "995de6c2093797905fbcd79f1a3625dd3f50be37";
+    sha256 = "0a6lz9wadm47cmva136q6wd0lw03bmymf9ispnzb091a7skwacry";
+  };
+
+
+  installPhase = ''
+    mkdir -p $out/lib/firmware
+    cp ./firmware/rt5677_elf_vad $out/lib/firmware
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Firmware for Realtek rt5677 device";
+    license = licenses.unfreeRedistributableFirmware;
+    maintainers = [ maintainers.zohl ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/rtl8192su-firmware/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/rtl8192su-firmware/default.nix
new file mode 100644
index 000000000000..d8d4c37fd886
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/rtl8192su-firmware/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, fetchFromGitHub }:
+with stdenv.lib;
+stdenv.mkDerivation {
+  name = "rtl8192su-unstable-2016-10-05";
+
+  src = fetchFromGitHub {
+    owner = "chunkeey";
+    repo = "rtl8192su";
+    rev = "c00112c9a14133290fe30bd3b44e45196994cb1c";
+    sha256 = "0j3c35paapq1icmxq0mg7pm2xa2m69q7bkfmwgq99d682yr2cb5l";
+  };
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  installPhase = ''
+    for i in rtl8192sfw.bin \
+             rtl8192sufw-ap.bin \
+             rtl8192sufw-apple.bin \
+             rtl8192sufw-windows.bin \
+             rtl8712u-linux-firmware-bad.bin \
+             rtl8712u-most-recent-v2.6.6-bad.bin \
+             rtl8712u-most-recent-v2.6.6-bad.bin \
+             rtl8712u-oldest-but-good.bin;
+    do
+      install -D -pm644 firmwares/$i $out/lib/firmware/rtlwifi/$i
+    done
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Firmware for Realtek RTL8188SU/RTL8191SU/RTL8192SU";
+    homepage = https://github.com/chunkeey/rtl8192su;
+    license = licenses.unfreeRedistributableFirmware;
+    maintainers = with maintainers; [ mic92 ];
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/rtl8723bs-firmware/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/rtl8723bs-firmware/default.nix
new file mode 100644
index 000000000000..eea6f2893f22
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/rtl8723bs-firmware/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, linuxPackages }:
+with stdenv.lib;
+stdenv.mkDerivation {
+  name = "rtl8723bs-firmware-${linuxPackages.rtl8723bs.version}";
+  inherit (linuxPackages.rtl8723bs) src;
+
+  phases = [ "unpackPhase" "installPhase" ];
+
+  installPhase = ''
+    mkdir -p                "$out/lib/firmware/rtlwifi"
+    cp rtl8723bs_nic.bin    "$out/lib/firmware/rtlwifi"
+    cp rtl8723bs_wowlan.bin "$out/lib/firmware/rtlwifi"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Firmware for RealTek 8723bs";
+    homepage = https://github.com/hadess/rtl8723bs;
+    license = licenses.unfreeRedistributableFirmware;
+    maintainers = with maintainers; [ elitak ];
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/rtlwifi_new-firmware/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/rtlwifi_new-firmware/default.nix
new file mode 100644
index 000000000000..673ef686e488
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/rtlwifi_new-firmware/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, lib, linuxPackages }:
+
+with lib;
+
+stdenv.mkDerivation rec {
+  name = "rtlwifi_new-firmware-${linuxPackages.rtlwifi_new.version}";
+  inherit (linuxPackages.rtlwifi_new) src;
+
+  dontBuild = true;
+
+  installPhase = ''
+    mkdir -p "$out/lib/firmware"
+    cp -rf firmware/rtlwifi/ "$out/lib/firmware"
+  '';
+
+  meta = {
+    description = "Firmware for the newest Realtek rtlwifi codes";
+    inherit (src.meta) homepage;
+    license = licenses.unfreeRedistributableFirmware;
+    platforms = with platforms; linux;
+    maintainers = with maintainers; [ tvorog ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/firmware/zd1211/default.nix b/nixpkgs/pkgs/os-specific/linux/firmware/zd1211/default.nix
new file mode 100644
index 000000000000..2c9db47539f7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/firmware/zd1211/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchzip }:
+
+let
+  pname = "zd1211-firmware";
+  version = "1.5";
+in fetchzip rec {
+  name = "${pname}-${version}";
+  url = "mirror://sourceforge/zd1211/${name}.tar.bz2";
+
+  postFetch = ''
+    tar -xjvf $downloadedFile
+    mkdir -p $out/lib/firmware/zd1211
+    cp zd1211-firmware/* $out/lib/firmware/zd1211
+  '';
+
+  sha256 = "0sj2zl3r0549mjz37xy6iilm1hm7ak5ax02gwrn81r5yvphqzd52";
+
+  meta = {
+    description = "Firmware for the ZyDAS ZD1211(b) 802.11a/b/g USB WLAN chip";
+    homepage = https://sourceforge.net/projects/zd1211/;
+    license = "GPL";
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/flashbench/default.nix b/nixpkgs/pkgs/os-specific/linux/flashbench/default.nix
new file mode 100644
index 000000000000..0a6364f07df5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/flashbench/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchgit }:
+
+stdenv.mkDerivation rec {
+  name = "flashbench-${version}";
+  version = "2012-06-06";
+
+  src = fetchgit {
+    url = "https://github.com/bradfa/flashbench.git";
+    rev = "2e30b1968a66147412f21002ea844122a0d5e2f0";
+    sha256 = "037rhd2alwfip9qk78cy8fwwnc2kdyzccsyc7v2zpmvl4vvpvnhg";
+  };
+
+  installPhase = ''
+    install -d -m755 $out/bin $out/share/doc/flashbench
+    install -v -m755 flashbench $out/bin
+    install -v -m755 erase $out/bin/flashbench-erase
+    install -v -m644 README $out/share/doc/flashbench
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Testing tool for flash based memory devices";
+    homepage = https://github.com/bradfa/flashbench;
+    platforms = platforms.linux;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.rycee ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fnotifystat/default.nix b/nixpkgs/pkgs/os-specific/linux/fnotifystat/default.nix
new file mode 100644
index 000000000000..eb87d8aa7251
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fnotifystat/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, lib, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "fnotifystat-${version}";
+  version = "0.02.01";
+  src = fetchurl {
+    url = "http://kernel.ubuntu.com/~cking/tarballs/fnotifystat/fnotifystat-${version}.tar.gz";
+    sha256 = "18p6rqb3bhs2ih6mnp57j0cyawjm0iwky6y3ays54alkxqaz8gmx";
+  };
+  installFlags = [ "DESTDIR=$(out)" ];
+  postInstall = ''
+    mv $out/usr/* $out
+    rm -r $out/usr
+  '';
+  meta = with lib; {
+    description = "File activity monitoring tool";
+    homepage = http://kernel.ubuntu.com/~cking/fnotifystat/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ womfoo ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/forkstat/default.nix b/nixpkgs/pkgs/os-specific/linux/forkstat/default.nix
new file mode 100644
index 000000000000..5d304d8ac035
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/forkstat/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, lib, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "forkstat-${version}";
+  version = "0.02.09";
+  src = fetchurl {
+    url = "http://kernel.ubuntu.com/~cking/tarballs/forkstat/forkstat-${version}.tar.xz";
+    sha256 = "1h5ha9w6rawh9kx39swjxs029202qxi0j9w38y7ilwq5pj447bxw";
+  };
+  installFlags = [ "DESTDIR=$(out)" ];
+  postInstall = ''
+    mv $out/usr/* $out
+    rm -r $out/usr
+  '';
+  meta = with lib; {
+    description = "Process fork/exec/exit monitoring tool";
+    homepage = http://kernel.ubuntu.com/~cking/forkstat/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ womfoo ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/forktty/default.nix b/nixpkgs/pkgs/os-specific/linux/forktty/default.nix
new file mode 100644
index 000000000000..6402b5c69d82
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/forktty/default.nix
@@ -0,0 +1,36 @@
+{stdenv, fetchurl}:
+let
+  s = # Generated upstream information
+  rec {
+    baseName="forktty";
+    version="1.3";
+    name="${baseName}-${version}";
+    hash="0nd55zdqly6nl98k9lc7j751x86cw9hayx1qn0725f22r1x3j5zb";
+    url="http://sunsite.unc.edu/pub/linux/utils/terminal/forktty-1.3.tgz";
+    sha256="0nd55zdqly6nl98k9lc7j751x86cw9hayx1qn0725f22r1x3j5zb";
+  };
+  buildInputs = [
+  ];
+in
+stdenv.mkDerivation {
+  inherit (s) name version;
+  inherit buildInputs;
+  src = fetchurl {
+    inherit (s) url sha256;
+  };
+  preBuild = ''
+    sed -e s@/usr/bin/ginstall@install@g -i Makefile
+  '';
+  preInstall = ''
+    mkdir -p "$out/bin"
+    mkdir -p "$out/share/man/man8"
+  '';
+  makeFlags='' prefix="''${out}" manprefix="''${out}/share/" '';
+  meta = {
+    inherit (s) version;
+    description = ''Tool to detach from controlling TTY and attach to another'';
+    license = stdenv.lib.licenses.gpl2 ;
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/forktty/default.upstream b/nixpkgs/pkgs/os-specific/linux/forktty/default.upstream
new file mode 100644
index 000000000000..45cb775a0ae3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/forktty/default.upstream
@@ -0,0 +1,2 @@
+url http://sunsite.unc.edu/pub/linux/utils/terminal/
+version_link 'forktty.*tgz'
diff --git a/nixpkgs/pkgs/os-specific/linux/freefall/default.nix b/nixpkgs/pkgs/os-specific/linux/freefall/default.nix
new file mode 100644
index 000000000000..a091b2f17c5e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/freefall/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, kernel }:
+
+stdenv.mkDerivation rec {
+  inherit (kernel) version src;
+
+  name = "freefall-${version}";
+
+  postPatch = ''
+    cd tools/laptop/freefall
+
+    # Default time-out is a little low, probably because the AC/lid status
+    # functions were never implemented. Because no-one still uses HDDs, right?
+    substituteInPlace freefall.c --replace "alarm(2)" "alarm(5)"
+  '';
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  meta = with stdenv.lib; {
+    inherit (kernel.meta) homepage license;
+
+    description = "Free-fall protection for spinning HP/Dell laptop hard drives";
+    longDescription = ''
+      Provides a shock protection facility in modern laptops with spinning hard
+      drives, by stopping all input/output operations on the internal hard drive
+      and parking its heads on the ramp when critical situations are anticipated.
+      Requires support for the ATA/ATAPI-7 IDLE IMMEDIATE command with unload
+      feature, which should cause the drive to switch to idle mode and unload the
+      disk heads, and an accelerometer device. It has no effect on SSD devices!
+    '';
+
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fscrypt/default.nix b/nixpkgs/pkgs/os-specific/linux/fscrypt/default.nix
new file mode 100644
index 000000000000..da787d84d79d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fscrypt/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, buildGoPackage, fetchFromGitHub, pam }:
+
+# Don't use this for anything important yet!
+
+buildGoPackage rec {
+  name = "fscrypt-${version}";
+  version = "0.2.4";
+
+  goPackagePath = "github.com/google/fscrypt";
+
+  src = fetchFromGitHub {
+    owner = "google";
+    repo = "fscrypt";
+    rev = "v${version}";
+    sha256 = "10gbyqzgi30as1crvqbb4rc5p8zzbzk1q5j080h1gnz56qzwivr8";
+  };
+
+  buildInputs = [ pam ];
+
+  meta = with stdenv.lib; {
+    description =
+      "A high-level tool for the management of Linux filesystem encryption";
+    longDescription = ''
+      This tool manages metadata, key generation, key wrapping, PAM integration,
+      and provides a uniform interface for creating and modifying encrypted
+      directories.
+    '';
+    inherit (src.meta) homepage;
+    license = licenses.asl20;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ primeos ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fscryptctl/default.nix b/nixpkgs/pkgs/os-specific/linux/fscryptctl/default.nix
new file mode 100644
index 000000000000..8622dc001a87
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fscryptctl/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchFromGitHub }:
+
+# Don't use this for anything important yet!
+
+stdenv.mkDerivation rec {
+  name = "fscryptctl-unstable-${version}";
+  version = "2017-10-23";
+
+  goPackagePath = "github.com/google/fscrypt";
+
+  src = fetchFromGitHub {
+    owner = "google";
+    repo = "fscryptctl";
+    rev = "142326810eb19d6794793db6d24d0775a15aa8e5";
+    sha256 = "1853hlpklisbqnkb7a921dsf0vp2nr2im26zpmrs592cnpsvk3hb";
+  };
+
+  makeFlags = [ "DESTDIR=$(out)/bin" ];
+
+  meta = with stdenv.lib; {
+    description = ''
+      A low-level tool that handles raw keys and manages policies for Linux
+      filesystem encryption
+    '';
+    inherit (src.meta) homepage;
+    license = licenses.asl20;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ primeos ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fswebcam/default.nix b/nixpkgs/pkgs/os-specific/linux/fswebcam/default.nix
new file mode 100644
index 000000000000..b7f47f12b15b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fswebcam/default.nix
@@ -0,0 +1,20 @@
+{ stdenv, fetchurl, libv4l, gd }:
+
+stdenv.mkDerivation rec {
+  name = "fswebcam-20140113";
+
+  src = fetchurl {
+    url = "https://www.sanslogic.co.uk/fswebcam/files/${name}.tar.gz";
+    sha256 = "3ee389f72a7737700d22e0c954720b1e3bbadc8a0daad6426c25489ba9dc3199";
+  };
+
+  buildInputs =
+    [ libv4l gd ];
+
+  meta = {
+    description = "Neat and simple webcam app";
+    homepage = http://www.sanslogic.co.uk/fswebcam;
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ftop/default.nix b/nixpkgs/pkgs/os-specific/linux/ftop/default.nix
new file mode 100644
index 000000000000..915431c0cb1f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ftop/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl, ncurses }:
+
+stdenv.mkDerivation rec {
+  name = "ftop-${version}";
+  version = "1.0";
+
+  src = fetchurl {
+    url = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/ftop/${name}.tar.bz2";
+    sha256 = "3a705f4f291384344cd32c3dd5f5f6a7cd7cea7624c83cb7e923966dbcd47f82";
+  };
+
+  buildInputs = [ ncurses ];
+
+  patches = [
+    ./ftop-fix_buffer_overflow.patch
+    ./ftop-fix_printf_format.patch
+  ];
+  patchFlags = [ "-p0" ];
+
+  postPatch = ''
+    substituteInPlace configure --replace "curses" "ncurses"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Show progress of open files and file systems";
+    homepage = https://code.google.com/archive/p/ftop/;
+    license = licenses.gpl3Plus;
+    longDescription = ''
+      ftop is to files what top is to processes. The progress of all open files
+      and file systems can be monitored. If run as a regular user, the set of
+      open files will be limited to those in that user's processes (which is
+      generally all that is of interest to the user).
+      As with top, the items are displayed in order from most to least active.
+    '';
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_buffer_overflow.patch b/nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_buffer_overflow.patch
new file mode 100644
index 000000000000..f10fa6a33b85
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_buffer_overflow.patch
@@ -0,0 +1,11 @@
+--- src/ftop.c.orig	2010-06-15 21:42:15.000000000 +0200
++++ src/ftop.c	2010-06-15 21:45:38.000000000 +0200
+@@ -935,7 +935,7 @@
+     {
+         if (bar_used > 0)
+         {
+-            snprintf(rate_buf, bar_used + 1, "%s", tmp_buf);
++            snprintf(rate_buf, bar_used >= sizeof(rate_buf) ? sizeof(rate_buf) : bar_used + 1, "%s", tmp_buf);
+             p_attron(p, A_REVERSE);
+             p_printf(p, "%s", rate_buf);
+             if (bar_used > bytes)
diff --git a/nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_printf_format.patch b/nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_printf_format.patch
new file mode 100644
index 000000000000..afb04306428a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ftop/ftop-fix_printf_format.patch
@@ -0,0 +1,20 @@
+--- src/ftop.c.orig	2010-06-15 23:14:50.000000000 +0200
++++ src/ftop.c	2010-06-15 23:15:52.000000000 +0200
+@@ -222,7 +222,7 @@
+     p_eol(p, part);
+ 
+     cols = snprintf(tmp_buf, sizeof(tmp_buf),
+-                    "Processes:  %u total, %u unreadable",
++                    "Processes:  %zu total, %zu unreadable",
+                     s->num_processes + s->num_unreadable_processes,
+                     s->num_unreadable_processes);
+ 
+@@ -244,7 +244,7 @@
+     p_eol(p, part);
+ 
+     snprintf(tmp_buf, sizeof(tmp_buf),
+-             "Open Files: %u regular, %u dir, %u chr, %u blk, %u pipe, %u sock, %u misc",
++             "Open Files: %zu regular, %zu dir, %zu chr, %zu blk, %zu pipe, %zu sock, %zu misc",
+              s->num_reg, s->num_dir, s->num_chr, s->num_blk, s->num_pipe,
+              s->num_sock, s->num_misc);
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/fuse/common.nix b/nixpkgs/pkgs/os-specific/linux/fuse/common.nix
new file mode 100644
index 000000000000..15470479a3a2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fuse/common.nix
@@ -0,0 +1,87 @@
+{ version, sha256Hash }:
+
+{ stdenv, fetchFromGitHub, fetchpatch
+, fusePackages, utillinux, gettext
+, meson, ninja, pkgconfig
+, autoreconfHook
+, python3Packages, which
+}:
+
+let
+  isFuse3 = stdenv.lib.hasPrefix "3" version;
+in stdenv.mkDerivation rec {
+  name = "fuse-${version}";
+
+  src = fetchFromGitHub {
+    owner = "libfuse";
+    repo = "libfuse";
+    rev = name;
+    sha256 = sha256Hash;
+  };
+
+  preAutoreconf = "touch config.rpath";
+
+  patches =
+    stdenv.lib.optional
+      (!isFuse3 && stdenv.isAarch64)
+      (fetchpatch {
+        url = "https://github.com/libfuse/libfuse/commit/914871b20a901e3e1e981c92bc42b1c93b7ab81b.patch";
+        sha256 = "1w4j6f1awjrycycpvmlv0x5v9gprllh4dnbjxl4dyl2jgbkaw6pa";
+      })
+    ++ stdenv.lib.optional isFuse3 ./fuse3-install.patch;
+
+  nativeBuildInputs = if isFuse3
+    then [ meson ninja pkgconfig ]
+    else [ autoreconfHook gettext ];
+
+  outputs = [ "out" ] ++ stdenv.lib.optional isFuse3 "common";
+
+  mesonFlags = stdenv.lib.optional isFuse3 "-Dudevrulesdir=etc/udev/rules.d";
+
+  preConfigure = ''
+    export MOUNT_FUSE_PATH=$out/sbin
+    export INIT_D_PATH=$TMPDIR/etc/init.d
+    export UDEV_RULES_PATH=$out/etc/udev/rules.d
+
+    # Ensure that FUSE calls the setuid wrapper, not
+    # $out/bin/fusermount. It falls back to calling fusermount in
+    # $PATH, so it should also work on non-NixOS systems.
+    export NIX_CFLAGS_COMPILE="-DFUSERMOUNT_DIR=\"/run/wrappers/bin\""
+
+    sed -e 's@/bin/@${utillinux}/bin/@g' -i lib/mount_util.c
+    '' + (if isFuse3 then ''
+      # The configure phase will delete these files (temporary workaround for
+      # ./fuse3-install_man.patch)
+      install -D -m444 doc/fusermount3.1 $out/share/man/man1/fusermount3.1
+      install -D -m444 doc/mount.fuse3.8 $out/share/man/man8/mount.fuse3.8
+    '' else ''
+      sed -e 's@CONFIG_RPATH=/usr/share/gettext/config.rpath@CONFIG_RPATH=${gettext}/share/gettext/config.rpath@' -i makeconf.sh
+      ./makeconf.sh
+    '');
+
+  checkInputs = [ which ] ++ (with python3Packages; [ python pytest ]);
+
+  checkPhase = ''
+    python3 -m pytest test/
+  '';
+
+  doCheck = false; # v2: no tests, v3: all tests get skipped in a sandbox
+
+  postFixup = "cd $out\n" + (if isFuse3 then ''
+    install -D -m444 etc/fuse.conf $common/etc/fuse.conf
+    install -D -m444 etc/udev/rules.d/99-fuse3.rules $common/etc/udev/rules.d/99-fuse.rules
+  '' else ''
+    cp ${fusePackages.fuse_3.common}/etc/fuse.conf etc/fuse.conf
+    cp ${fusePackages.fuse_3.common}/etc/udev/rules.d/99-fuse.rules etc/udev/rules.d/99-fuse.rules
+  '');
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    inherit (src.meta) homepage;
+    description = "Kernel module and library that allows filesystems to be implemented in user space";
+    platforms = platforms.linux;
+    license = with licenses; [ gpl2 lgpl21 ];
+    maintainers = [ maintainers.primeos ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fuse/default.nix b/nixpkgs/pkgs/os-specific/linux/fuse/default.nix
new file mode 100644
index 000000000000..0c4df18afb39
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fuse/default.nix
@@ -0,0 +1,17 @@
+{ callPackage, utillinux }:
+
+let
+  mkFuse = args: callPackage (import ./common.nix args) {
+    inherit utillinux;
+  };
+in {
+  fuse_2 = mkFuse {
+    version = "2.9.9";
+    sha256Hash = "1yxxvm58c30pc022nl1wlg8fljqpmwnchkywic3r74zirvlcq23n";
+  };
+
+  fuse_3 = mkFuse {
+    version = "3.4.2";
+    sha256Hash = "1w39fkasq9314qx141xb8v5qqcfvqbpr3higc4vv8y4b4i58fapi";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fuse/fuse3-install.patch b/nixpkgs/pkgs/os-specific/linux/fuse/fuse3-install.patch
new file mode 100644
index 000000000000..320c328cbd92
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fuse/fuse3-install.patch
@@ -0,0 +1,34 @@
+--- a/util/install_helper.sh	2018-08-31 21:22:34.580563286 +0200
++++ b/util/install_helper.sh	2018-08-31 21:30:54.837939149 +0200
+@@ -22,30 +22,11 @@
+     DESTDIR="${DESTDIR%/}"
+ fi
+ 
+-chown root:root "${DESTDIR}${bindir}/fusermount3"
+-chmod u+s "${DESTDIR}${bindir}/fusermount3"
+-
+ install -D -m 644 "${MESON_SOURCE_ROOT}/util/fuse.conf" \
+ 	"${DESTDIR}${sysconfdir}/fuse.conf"
+ 
+-
+-if test ! -e "${DESTDIR}/dev/fuse"; then
+-    mkdir -p "${DESTDIR}/dev"
+-    mknod "${DESTDIR}/dev/fuse" -m 0666 c 10 229
+-fi
+-
+ install -D -m 644 "${MESON_SOURCE_ROOT}/util/udev.rules" \
+-        "${DESTDIR}${udevrulesdir}/99-fuse3.rules"
++        "${sysconfdir}/udev/rules.d/99-fuse3.rules"
+ 
+ install -D -m 755 "${MESON_SOURCE_ROOT}/util/init_script" \
+         "${DESTDIR}${sysconfdir}/init.d/fuse3"
+-
+-
+-if test -x /usr/sbin/update-rc.d && test -z "${DESTDIR}"; then
+-    /usr/sbin/update-rc.d fuse3 start 34 S . start 41 0 6 . || /bin/true
+-else
+-    echo "== FURTHER ACTION REQUIRED =="
+-    echo "Make sure that your init system will start the ${sysconfdir}/init.d/fuse3 init script"
+-fi
+-
+-
diff --git a/nixpkgs/pkgs/os-specific/linux/fwts/default.nix b/nixpkgs/pkgs/os-specific/linux/fwts/default.nix
new file mode 100644
index 000000000000..4bd811496b1c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fwts/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, fetchzip, autoreconfHook, pkgconfig, glib, libtool, pcre
+, json_c, flex, bison, dtc, pciutils, dmidecode, iasl, libbsd }:
+
+stdenv.mkDerivation rec {
+  name = "fwts-${version}";
+  version = "19.02.00";
+
+  src = fetchzip {
+    url = "http://fwts.ubuntu.com/release/fwts-V${version}.tar.gz";
+    sha256 = "1rjyfscchman9ih0473hgzvfzrvkfwl5bjf7c9ksr3d9plz3n7ad";
+    stripRoot = false;
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig libtool ];
+  buildInputs = [ glib pcre json_c flex bison dtc pciutils dmidecode iasl libbsd ];
+
+  postPatch = ''
+    substituteInPlace src/lib/include/fwts_binpaths.h --replace "/usr/bin/lspci"      "${pciutils}/bin/lspci"
+    substituteInPlace src/lib/include/fwts_binpaths.h --replace "/usr/sbin/dmidecode" "${dmidecode}/bin/dmidecode"
+    substituteInPlace src/lib/include/fwts_binpaths.h --replace "/usr/bin/iasl"       "${iasl}/bin/iasl"
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    homepage = "https://wiki.ubuntu.com/FirmwareTestSuite";
+    description = "Firmware Test Suite";
+    platforms = platforms.linux;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ tadfisher ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/fxload/default.nix b/nixpkgs/pkgs/os-specific/linux/fxload/default.nix
new file mode 100644
index 000000000000..61bd2a229ab6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/fxload/default.nix
@@ -0,0 +1,36 @@
+{stdenv, fetchurl}:
+
+stdenv.mkDerivation {
+  name = "fxload-2002_04_11";
+
+  src = fetchurl {
+    url = mirror://sourceforge/linux-hotplug/fxload-2002_04_11.tar.gz;
+    sha256 = "1hql93bp3dxrv1p67nc63xsbqwljyynm997ysldrc3n9ifi6s48m";
+  };
+
+  patches = [
+    # Will be needed after linux-headers is updated to >= 2.6.21.
+    (fetchurl {
+      url = "http://sources.gentoo.org/viewcvs.py/*checkout*/gentoo-x86/sys-apps/fxload/files/fxload-20020411-linux-headers-2.6.21.patch?rev=1.1";
+      sha256 = "0ij0c8nr1rbyl5wmyv1cklhkxglvsqz32h21cjw4bjm151kgmk7p";
+    })
+  ];
+
+  preBuild = ''
+    substituteInPlace Makefile --replace /usr /
+    makeFlagsArray=(INSTALL=install prefix=$out)
+  '';
+
+  preInstall = ''
+    mkdir -p $out/sbin
+    mkdir -p $out/share/man/man8
+    mkdir -p $out/share/usb
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://linux-hotplug.sourceforge.net/?selected=usb;
+    description = "Tool to upload firmware to Cypress EZ-USB microcontrollers";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/gfxtablet/default.nix b/nixpkgs/pkgs/os-specific/linux/gfxtablet/default.nix
new file mode 100644
index 000000000000..9fc052c5ac1b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/gfxtablet/default.nix
@@ -0,0 +1,33 @@
+{stdenv, fetchFromGitHub, linuxHeaders}:
+
+stdenv.mkDerivation rec {
+  version = "1.4";
+  name = "gfxtablet-uinput-driver-${version}";
+
+  buildInputs = [
+    linuxHeaders
+  ];
+
+  src = fetchFromGitHub {
+    owner = "rfc2822";
+    repo = "GfxTablet";
+    rev = "android-app-${version}";
+    sha256 = "1i2m98yypfa9phshlmvjlgw7axfisxmldzrvnbzm5spvv5s4kvvb";
+  };
+
+  preBuild = ''cd driver-uinput'';
+
+  installPhase = ''
+    mkdir -p "$out/bin"
+    cp networktablet "$out/bin"
+    mkdir -p "$out/share/doc/gfxtablet/"
+    cp ../*.md "$out/share/doc/gfxtablet/"
+  '';
+
+  meta = {
+    description = ''Uinput driver for Android GfxTablet tablet-as-input-device app'';
+    license = stdenv.lib.licenses.mit ;
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/gogoclient/config-paths.patch b/nixpkgs/pkgs/os-specific/linux/gogoclient/config-paths.patch
new file mode 100644
index 000000000000..88358038bc7e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/gogoclient/config-paths.patch
@@ -0,0 +1,39 @@
+diff -urN gogoc-1_2-RELEASE/gogoc-tsp/conf/gogoc.conf.in gogoc-1_2-RELEASE-fix/gogoc-tsp/conf/gogoc.conf.in
+--- gogoc-1_2-RELEASE/gogoc-tsp/conf/gogoc.conf.in	2009-11-20 17:53:12.000000000 +0100
++++ gogoc-1_2-RELEASE-fix/gogoc-tsp/conf/gogoc.conf.in	2012-02-25 15:16:12.758849219 +0100
+@@ -224,7 +224,7 @@
+ #
+ #   broker_list=<file_name>
+ #  
+-broker_list=tsp-broker-list.txt
++broker_list=/var/lib/gogoc/tsp-broker-list.txt
+ 
+ #
+ # Last Server Used File Name:
+@@ -234,7 +234,7 @@
+ #
+ #   last_server=<file_name>
+ #
+-last_server=tsp-last-server.txt
++last_server=/var/lib/gogoc/tsp-last-server.txt
+ 
+ #
+ # Always Use Last Known Working Server:
+@@ -294,7 +294,7 @@
+ #
+ #   log_filename=<file_name>
+ #
+-log_filename=gogoc.log
++log_filename=/var/log/gogoc.log
+ 
+ #
+ # Log File Rotation:
+@@ -313,7 +313,7 @@
+ #
+ #   log_rotation=<yes|no>
+ #
+-log_rotation=yes
++log_rotation=no
+ 
+ #
+ # Log File Rotation Size:
diff --git a/nixpkgs/pkgs/os-specific/linux/gogoclient/default.nix b/nixpkgs/pkgs/os-specific/linux/gogoclient/default.nix
new file mode 100644
index 000000000000..942cafd03435
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/gogoclient/default.nix
@@ -0,0 +1,44 @@
+{stdenv, fetchurl, openssl, nettools, iproute, sysctl}:
+
+let baseName = "gogoclient";
+    version  = "1.2";
+in
+
+stdenv.mkDerivation rec {
+  name = "${baseName}-${version}";
+
+  src = fetchurl {
+    #url = http://gogo6.com/downloads/gogoc-1_2-RELEASE.tar.gz;
+    url = https://src.fedoraproject.org/repo/pkgs/gogoc/gogoc-1_2-RELEASE.tar.gz/41177ed683cf511cc206c7782c37baa9/gogoc-1_2-RELEASE.tar.gz;
+    sha256 = "a0ef45c0bd1fc9964dc8ac059b7d78c12674bf67ef641740554e166fa99a2f49";
+  };
+  patches = [./gcc46-include-fix.patch ./config-paths.patch ];
+  makeFlags = ["target=linux"];
+  installFlags = ["installdir=$(out)"];
+
+  hardeningDisable = [ "format" ];
+
+  buildInputs = [openssl];
+
+  preFixup = ''
+    mkdir -p $out/share/${name}
+    chmod 444 $out/bin/gogoc.conf
+    mv $out/bin/gogoc.conf $out/share/${name}/gogoc.conf.sample
+    rm $out/bin/gogoc.conf.sample
+
+    substituteInPlace "$out/template/linux.sh" \
+      --replace "/sbin/ifconfig" "${nettools}/bin/ifconfig" \
+      --replace "/sbin/route"    "${nettools}/bin/route" \
+      --replace "/sbin/ip"       "${iproute}/sbin/ip" \
+      --replace "/sbin/sysctl"   "${sysctl}/bin/sysctl"
+    sed -i -e 's/^.*Exec \$route -A.*$/& metric 128/' $out/template/linux.sh
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://ipv6.ernet.in/Tunnel_broker;
+    description = "Client to connect to the Freenet6 IPv6 tunnel broker service";
+    maintainers = [ maintainers.bluescreen303 ];
+    license = licenses.bsd3;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/gogoclient/gcc46-include-fix.patch b/nixpkgs/pkgs/os-specific/linux/gogoclient/gcc46-include-fix.patch
new file mode 100644
index 000000000000..22ecad187d62
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/gogoclient/gcc46-include-fix.patch
@@ -0,0 +1,22 @@
+diff -urN gogoc-1_2-RELEASE/gogoc-messaging/src/clientmsgsender.cc gogoc-1_2-RELEASE-fix/gogoc-messaging/src/clientmsgsender.cc
+--- gogoc-1_2-RELEASE/gogoc-messaging/src/clientmsgsender.cc	2009-11-20 17:34:55.000000000 +0100
++++ gogoc-1_2-RELEASE-fix/gogoc-messaging/src/clientmsgsender.cc	2012-02-25 15:06:20.764698284 +0100
+@@ -15,6 +15,7 @@
+ // **************************************************************************
+ #include <gogocmessaging/clientmsgsender.h>
+ #include <assert.h>
++#include <stddef.h>
+ 
+ 
+ namespace gogocmessaging
+diff -urN gogoc-1_2-RELEASE/gogoc-messaging/src/servermsgsender.cc gogoc-1_2-RELEASE-fix/gogoc-messaging/src/servermsgsender.cc
+--- gogoc-1_2-RELEASE/gogoc-messaging/src/servermsgsender.cc	2009-11-20 17:34:56.000000000 +0100
++++ gogoc-1_2-RELEASE-fix/gogoc-messaging/src/servermsgsender.cc	2012-02-25 15:06:36.722740288 +0100
+@@ -15,6 +15,7 @@
+ // **************************************************************************
+ #include <gogocmessaging/servermsgsender.h>
+ #include <assert.h>
++#include <stddef.h>
+ 
+ 
+ namespace gogocmessaging
diff --git a/nixpkgs/pkgs/os-specific/linux/google-authenticator/default.nix b/nixpkgs/pkgs/os-specific/linux/google-authenticator/default.nix
new file mode 100644
index 000000000000..8ae5785eea8b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/google-authenticator/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, lib, fetchurl, autoreconfHook, pam, qrencode }:
+
+stdenv.mkDerivation rec {
+  name = "google-authenticator-libpam-${version}";
+  version = "1.05";
+
+  src = fetchurl {
+    url = "https://github.com/google/google-authenticator-libpam/archive/${version}.tar.gz";
+    sha256 = "026vljmddi0zqcb3c0vdpabmi4r17kahc00mh6fs3qbyjbb14946";
+  };
+
+  nativeBuildInputs = [ autoreconfHook ];
+  buildInputs = [ pam ];
+
+  preConfigure = ''
+    sed -i "s|libqrencode.so.4|${qrencode.out}/lib/libqrencode.so.4|" src/google-authenticator.c
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin $out/lib/security
+    cp ./.libs/pam_google_authenticator.so $out/lib/security
+    cp google-authenticator $out/bin
+  '';
+
+  meta = with lib; {
+    homepage = https://github.com/google/google-authenticator-libpam;
+    description = "Two-step verification, with pam module";
+    license = licenses.asl20;
+    maintainers = with maintainers; [ aneeshusa ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/gpu-switch/default.nix b/nixpkgs/pkgs/os-specific/linux/gpu-switch/default.nix
new file mode 100644
index 000000000000..d56253c6cedd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/gpu-switch/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, lib, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "gpu-switch-unstable-${version}";
+  version = "2017-04-28";
+  src = fetchFromGitHub {
+    owner = "0xbb";
+    repo = "gpu-switch";
+    rev = "a365f56d435c8ef84c4dd2ab935ede4992359e31";
+    sha256 = "1jnh43nijkqd83h7piq7225ixziggyzaalabgissyxdyz6szcn0r";
+  };
+  installPhase = ''
+    mkdir -p $out/bin
+    cp gpu-switch $out/bin/
+  '';
+  meta = with lib; {
+    description = "Application that allows to switch between the graphic cards of dual-GPU MacBook Pro models";
+    homepage = https://github.com/0xbb/gpu-switch;
+    license = licenses.mit;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.msiedlarek ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/gradm/default.nix b/nixpkgs/pkgs/os-specific/linux/gradm/default.nix
new file mode 100644
index 000000000000..7f64ed227719
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/gradm/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, fetchurl
+, bison, flex
+, pam
+}:
+
+stdenv.mkDerivation rec {
+  name    = "gradm-${version}";
+  version = "3.1-201608131257";
+
+  src  = fetchurl {
+    url    = "http://grsecurity.net/stable/${name}.tar.gz";
+    sha256 = "0y5565rhil5ciprwz7nx4s4ah7dsxx7zrkg42dbq0mcg8m316xrb";
+  };
+
+  nativeBuildInputs = [ bison flex ];
+  buildInputs = [ pam ];
+
+  enableParallelBuilding = true;
+
+  makeFlags = [
+    "DESTDIR=$(out)"
+    "LEX=${flex}/bin/flex"
+    "MANDIR=/share/man"
+    "MKNOD=true"
+  ];
+
+  preBuild = ''
+    substituteInPlace Makefile \
+      --replace "/usr/bin/" "" \
+      --replace "/usr/include/security/pam_" "${pam}/include/security/pam_"
+
+    substituteInPlace gradm_defs.h \
+      --replace "/sbin/grlearn" "$out/bin/grlearn" \
+      --replace "/sbin/gradm" "$out/bin/gradm" \
+      --replace "/sbin/gradm_pam" "$out/bin/gradm_pam"
+
+    echo 'inherit-learn /nix/store' >>learn_config
+
+    mkdir -p "$out/etc/udev/rules.d"
+  '';
+
+  postInstall = ''rmdir $out/dev'';
+
+  meta = with stdenv.lib; {
+    description = "grsecurity RBAC administration and policy analysis utility";
+    homepage    = "https://grsecurity.net";
+    license     = licenses.gpl2;
+    platforms   = platforms.linux;
+    maintainers = with maintainers; [ thoughtpolice joachifm ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/guvcview/default.nix b/nixpkgs/pkgs/os-specific/linux/guvcview/default.nix
new file mode 100644
index 000000000000..acafa0376f5c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/guvcview/default.nix
@@ -0,0 +1,37 @@
+{ config, stdenv, fetchurl, intltool, pkgconfig
+, gtk3, portaudio, SDL2, ffmpeg, udev, libusb1, libv4l, alsaLib, gsl
+, pulseaudioSupport ? config.pulseaudio or stdenv.isLinux, libpulseaudio ? null }:
+
+assert pulseaudioSupport -> libpulseaudio != null;
+
+stdenv.mkDerivation rec {
+  version = "2.0.6";
+  name = "guvcview-${version}";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/project/guvcview/source/guvcview-src-${version}.tar.gz";
+    sha256 = "11byyfpkcik7wvf2qic77zjamfr2rhji97dpj1gy2fg1bvpiqf4m";
+  };
+
+  buildInputs =
+    [ SDL2
+      alsaLib
+      ffmpeg
+      gtk3
+      intltool
+      libusb1
+      libv4l
+      pkgconfig
+      portaudio
+      udev
+      gsl
+    ] ++ stdenv.lib.optional pulseaudioSupport libpulseaudio;
+
+  meta = with stdenv.lib; {
+    description = "A simple interface for devices supported by the linux UVC driver";
+    homepage = http://guvcview.sourceforge.net;
+    maintainers = [ maintainers.coconnor ];
+    license = licenses.gpl3;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/hal-flash/default.nix b/nixpkgs/pkgs/os-specific/linux/hal-flash/default.nix
new file mode 100644
index 000000000000..27b85fbfc89a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hal-flash/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchurl, autoconf, automake, dbus, glib, libtool, pkgconfig, udisks2 }:
+
+stdenv.mkDerivation {
+  name = "hal-flash-0.3.3";
+
+  src = fetchurl {
+    url = "https://github.com/cshorler/hal-flash/archive/v0.3.3.tar.gz";
+    sha256 = "0dw9bx190mrh0dycw4rfvfmwwvh2sgypffr99nfnr36b38jrd6y6";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ autoconf automake dbus glib libtool udisks2 ];
+
+  preConfigure = "libtoolize && aclocal && autoconf && automake --add-missing";
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/cshorler/hal-flash;
+    description = "libhal stub library to satisfy the Flash Player DRM requirements";
+    longDescription =
+      ''
+        Stub library based loosely upon libhal.[ch] from the hal-0.5.14
+        package.  Provides the minimum necessary functionality to enable
+        libflashplayer.so/libadobecp.so to play back DRM content.
+      '';
+    license = with licenses; [ afl21 gpl2 ];
+    maintainers = with maintainers; [ malyn ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/hd-idle/default.nix b/nixpkgs/pkgs/os-specific/linux/hd-idle/default.nix
new file mode 100644
index 000000000000..911854384162
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hd-idle/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "hd-idle-1.05";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/project/hd-idle/${name}.tgz";
+    sha256 = "031sm996s0rhy3z91b9xvyimsj2yd2fhsww2al2hxda5s5wzxzjf";
+  };
+
+  prePatch = ''
+    substituteInPlace Makefile \
+      --replace "-g root -o root" ""
+  '';
+
+  installFlags = [ "TARGET_DIR=$(out)" ];
+
+  meta = with stdenv.lib; {
+    description = "Spins down external disks after a period of idle time";
+    homepage = http://hd-idle.sourceforge.net/;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.rycee ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/hdapsd/default.nix b/nixpkgs/pkgs/os-specific/linux/hdapsd/default.nix
new file mode 100644
index 000000000000..53924a782df7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hdapsd/default.nix
@@ -0,0 +1,21 @@
+{ stdenv, fetchurl }:
+
+let version = "20141203"; in
+stdenv.mkDerivation rec {
+  name = "hdapsd-"+version;
+
+  src = fetchurl {
+    url = "https://github.com/evgeni/hdapsd/releases/download/${version}/hdapsd-${version}.tar.gz";
+    sha256 = "0ppgrfabd0ivx9hyny3c3rv4rphjyxcdsd5svx5pgfai49mxnl36";
+  };
+
+  postInstall = builtins.readFile ./postInstall.sh;
+
+  meta = with stdenv.lib;
+    { description = "Hard Drive Active Protection System Daemon";
+      homepage = "http://hdaps.sf.net/";
+      license = licenses.gpl2;
+      platforms = platforms.linux;
+      maintainers = [ maintainers.ehmry ];
+    };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/hdapsd/postInstall.sh b/nixpkgs/pkgs/os-specific/linux/hdapsd/postInstall.sh
new file mode 100644
index 000000000000..37867817bf63
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hdapsd/postInstall.sh
@@ -0,0 +1,7 @@
+mkdir -p $out/lib/udev/rules.d $out/lib/systemd/system
+cp misc/hdapsd.rules $out/lib/udev/rules.d
+SBIN_REWRITE="s|@sbindir@|$out/bin|g"
+for i in misc/*.service.in
+do sed $SBIN_REWRITE "$i" > "$out/lib/systemd/system/$(basename ${i%.in})"
+done
+
diff --git a/nixpkgs/pkgs/os-specific/linux/hdparm/default.nix b/nixpkgs/pkgs/os-specific/linux/hdparm/default.nix
new file mode 100644
index 000000000000..542d99eeabe8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hdparm/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "hdparm-9.58";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/hdparm/${name}.tar.gz";
+    sha256 = "03z1qm8zbgpxagk3994lvp24yqsshjibkwg05v9p3q1w7y48xrws";
+
+  };
+
+  preBuild = ''
+    makeFlagsArray=(sbindir=$out/sbin manprefix=$out)
+    '';
+
+  meta = with stdenv.lib; {
+    description = "A tool to get/set ATA/SATA drive parameters under Linux";
+    homepage = https://sourceforge.net/projects/hdparm/;
+    platforms = platforms.linux;
+    license = licenses.bsd2;
+    maintainers = [ maintainers.fuuzetsu ];
+  };
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/hibernate/default.nix b/nixpkgs/pkgs/os-specific/linux/hibernate/default.nix
new file mode 100644
index 000000000000..15bdabcc3dc8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hibernate/default.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchurl, gawk }:
+
+let version = "2.0";
+in
+  stdenv.mkDerivation rec {
+    name = "hibernate-${version}";
+    src = fetchurl {
+      url = "http://tuxonice.nigelcunningham.com.au/files/hibernate-script-${version}.tar.gz";
+      sha256 = "0ib5bac3spbcwmhf8f9apjbll8x7fgqj4k1s5q3srijh793rfifh";
+    };
+
+    patches = [ ./install.patch ./gen-manpages.patch ./hibernate.patch ];
+
+    buildInputs = [ gawk ];
+
+    installPhase = ''
+      # FIXME: Storing config files under `$out/etc' is not very useful.
+
+      substituteInPlace "hibernate.sh" --replace \
+        'SWSUSP_D="/etc/hibernate"' "SWSUSP_D=\"$out/etc/hibernate\""
+
+      # Remove all references to `/bin' and `/sbin'.
+      for i in scriptlets.d/*
+      do
+        substituteInPlace "$i" --replace "/bin/" "" --replace "/sbin/" ""
+      done
+
+      PREFIX="$out" CONFIG_PREFIX="$out" ./install.sh
+
+      ln -s "$out/share/hibernate/scriptlets.d" "$out/etc/hibernate"
+    '';
+
+    meta = {
+      description = "The `hibernate' script for swsusp and Tux-on-Ice";
+      longDescription = ''
+        This package provides the `hibernate' script, a command-line utility
+	that saves the computer's state to disk and switches it off, turning
+	it into "hibernation".  It works both with Linux swsusp and Tux-on-Ice.
+      '';
+
+      license = stdenv.lib.licenses.gpl2Plus;
+      homepage = http://www.tuxonice.net/;
+      platforms = stdenv.lib.platforms.linux;
+    };
+  }
diff --git a/nixpkgs/pkgs/os-specific/linux/hibernate/gen-manpages.patch b/nixpkgs/pkgs/os-specific/linux/hibernate/gen-manpages.patch
new file mode 100644
index 000000000000..cdbacc86bafa
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hibernate/gen-manpages.patch
@@ -0,0 +1,11 @@
+--- hibernate-script-1.98.1/gen-manpages.sh	2008-03-31 09:40:29.000000000 +0200
++++ hibernate-script-1.98.1/gen-manpages.sh	2008-04-01 15:58:11.000000000 +0200
+@@ -254,7 +254,7 @@ BEGIN {
+ }
+ 
+ # Create a copy of hibernate.sh with only the help items
+-TMPF=`mktemp /tmp/tmp.hibernate.XXXXXX`
++TMPF=`mktemp "$TMPDIR/tmp.hibernate.XXXXXX"`
+ awk '{
+     if ((substr($0, 1, 1) != "#") && (match($0, "AddConfigHelp") || match($0, "AddOptionHelp")) && (match($0, "\\(\\)") == 0)) {
+         print $0;
diff --git a/nixpkgs/pkgs/os-specific/linux/hibernate/hibernate.patch b/nixpkgs/pkgs/os-specific/linux/hibernate/hibernate.patch
new file mode 100644
index 000000000000..24de1637d3ce
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hibernate/hibernate.patch
@@ -0,0 +1,37 @@
+--- hibernate-script-1.98.1/hibernate.sh	2008-03-31 09:40:29.000000000 +0200
++++ hibernate-script-1.98.1/hibernate.sh	2008-04-01 18:24:23.000000000 +0200
+@@ -224,7 +224,7 @@ FindXServer() {
+ 
+ 	    xauth="`get_env_var_of_process $xpid XAUTHORITY`"
+ 	    xhome="`get_env_var_of_process $xpid HOME`"
+-	    xuser=`/bin/ls -ld /proc/$xpid/ | awk '{print $3}'`
++	    xuser=`ls -ld /proc/$xpid/ | awk '{print $3}'`
+ 	    [ -z $xauth ] && [ -n $xhome ] && [ -f $xhome/.Xauthority ] && xauth=$xhome/.Xauthority
+ 
+ 	    [ -z $xauth ] && continue
+@@ -273,14 +273,14 @@ UsingSuspendMethod() {
+ # chain.
+ SortSuspendBits() {
+     # explicit path required to be ash compatible.
+-    /bin/echo -ne "$SUSPEND_BITS" | sort -n
++    echo -ne "$SUSPEND_BITS" | sort -n
+ }
+ 
+ # SortResumeBits: Returns a list of functions registered in the correct order
+ # to call for resuming, prefixed by their position number.
+ SortResumeBits() {
+     # explicit path required to be ash compatible.
+-    /bin/echo -ne "$RESUME_BITS" | sort -rn
++    echo -ne "$RESUME_BITS" | sort -rn
+ }
+ 
+ # WrapHelpText: takes text from stdin, wraps it with an indent of 5 and width
+@@ -557,7 +557,7 @@ LoadScriptlets() {
+     CURRENT_SOURCED_SCRIPTLET=""
+     for scriptlet_dir in $SCRIPTLET_PATH ; do
+ 	[ -d "$scriptlet_dir" ] || continue
+-	[ -z "`/bin/ls -1 $scriptlet_dir`" ] && continue
++	[ -z "`ls -1 $scriptlet_dir`" ] && continue
+ 	for scriptlet in $scriptlet_dir/* ; do
+ 	    # Avoid editor backup files.
+ 	    case "$scriptlet" in *~|*.bak) continue ;; esac
diff --git a/nixpkgs/pkgs/os-specific/linux/hibernate/install.patch b/nixpkgs/pkgs/os-specific/linux/hibernate/install.patch
new file mode 100644
index 000000000000..ae296b955ac8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hibernate/install.patch
@@ -0,0 +1,11 @@
+--- hibernate-script-1.98.1/install.sh	2008-03-31 09:40:29.000000000 +0200
++++ hibernate-script-1.98.1/install.sh	2008-04-01 15:50:46.000000000 +0200
+@@ -63,7 +63,7 @@ fi
+ cp -a blacklisted-modules $BLACKLIST
+ 
+ # Test if they have anything in there, and warn them
+-if /bin/ls $OLD_SCRIPTLET_DIR/* > /dev/null 2>&1 ; then
++if ls $OLD_SCRIPTLET_DIR/* > /dev/null 2>&1 ; then
+     echo "  **"
+     echo "  ** You have scriptlets already installed in $OLD_SCRIPTLET_DIR"
+     echo "  ** Since version 0.95, these have moved to $SCRIPTLET_DIR."
diff --git a/nixpkgs/pkgs/os-specific/linux/hostapd/default.nix b/nixpkgs/pkgs/os-specific/linux/hostapd/default.nix
new file mode 100644
index 000000000000..b1b5401b88db
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hostapd/default.nix
@@ -0,0 +1,72 @@
+{ stdenv, fetchurl, pkgconfig, libnl, openssl, sqlite ? null }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+  name = "hostapd-${version}";
+  version = "2.7";
+
+  src = fetchurl {
+    url = "https://w1.fi/releases/${name}.tar.gz";
+    sha256 = "0hd181sghdk944hxd7d41s7zhqd4dmsbkxipjj27bgisrjixvc11";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libnl openssl sqlite ];
+
+  outputs = [ "out" "man" ];
+
+  extraConfig = ''
+    CONFIG_DRIVER_WIRED=y
+    CONFIG_LIBNL32=y
+    CONFIG_EAP_SIM=y
+    CONFIG_EAP_AKA=y
+    CONFIG_EAP_AKA_PRIME=y
+    CONFIG_EAP_PAX=y
+    CONFIG_EAP_PWD=y
+    CONFIG_EAP_SAKE=y
+    CONFIG_EAP_GPSK=y
+    CONFIG_EAP_GPSK_SHA256=y
+    CONFIG_EAP_FAST=y
+    CONFIG_EAP_IKEV2=y
+    CONFIG_EAP_TNC=y
+    CONFIG_EAP_EKE=y
+    CONFIG_RADIUS_SERVER=y
+    CONFIG_IEEE80211R=y
+    CONFIG_IEEE80211N=y
+    CONFIG_IEEE80211AC=y
+    CONFIG_FULL_DYNAMIC_VLAN=y
+    CONFIG_VLAN_NETLINK=y
+    CONFIG_TLS=openssl
+    CONFIG_TLSV11=y
+    CONFIG_TLSV12=y
+    CONFIG_INTERNETWORKING=y
+    CONFIG_HS20=y
+    CONFIG_ACS=y
+  '' + optionalString (sqlite != null) ''
+    CONFIG_SQLITE=y
+  '';
+
+  configurePhase = ''
+    cd hostapd
+    cp -v defconfig .config
+    echo "$extraConfig" >> .config
+    cat -n .config
+    substituteInPlace Makefile --replace /usr/local $out
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE $(pkg-config --cflags libnl-3.0)"
+  '';
+
+  preInstall = "mkdir -p $out/bin";
+  postInstall = ''
+    install -vD hostapd.8 -t $man/share/man/man8
+    install -vD hostapd_cli.1 -t $man/share/man/man1
+  '';
+
+  meta = {
+    homepage = http://hostap.epitest.fi;
+    repositories.git = git://w1.fi/hostap.git;
+    description = "A user space daemon for access point and authentication servers";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ phreedom ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/hwdata/default.nix b/nixpkgs/pkgs/os-specific/linux/hwdata/default.nix
new file mode 100644
index 000000000000..dfca87e27165
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hwdata/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "hwdata-${version}";
+  version = "0.316";
+
+  src = fetchFromGitHub {
+    owner = "vcrhonek";
+    repo = "hwdata";
+    rev = "v${version}";
+    sha256 = "0k3fypykbq9943cnxlmmpk0xp9nhhf46pfdhkgm99iaa27b8s1gb";
+  };
+
+  preConfigure = "patchShebangs ./configure";
+
+  configureFlags = [ "--datadir=${placeholder "out"}/share" ];
+
+  doCheck = false; # this does build machine-specific checks (e.g. enumerates PCI bus)
+
+  outputHashMode = "recursive";
+  outputHashAlgo = "sha256";
+  outputHash = "0g2w4jr4p1hykracp2za7jb0rcr51kks1m43pzcaf7g99x8669ww";
+
+  meta = {
+    homepage = https://github.com/vcrhonek/hwdata;
+    description = "Hardware Database, including Monitors, pci.ids, usb.ids, and video cards";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/hyperv-daemons/default.nix b/nixpkgs/pkgs/os-specific/linux/hyperv-daemons/default.nix
new file mode 100644
index 000000000000..f89747dc200d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/hyperv-daemons/default.nix
@@ -0,0 +1,109 @@
+{ stdenv, lib, python, kernel, makeWrapper, writeText }:
+
+let
+  daemons = stdenv.mkDerivation rec {
+    name = "hyperv-daemons-bin-${version}";
+    inherit (kernel) src version;
+
+    nativeBuildInputs = [ makeWrapper ];
+
+    # as of 4.9 compilation will fail due to -Werror=format-security
+    hardeningDisable = [ "format" ];
+
+    preConfigure = ''
+      cd tools/hv
+    '';
+
+    installPhase = ''
+      runHook preInstall
+
+      for f in fcopy kvp vss ; do
+        install -Dm755 hv_''${f}_daemon -t $out/bin
+      done
+
+      install -Dm755 hv_get_dns_info.sh lsvmbus -t $out/bin
+
+      # I don't know why this isn't being handled automatically by fixupPhase
+      substituteInPlace $out/bin/lsvmbus \
+        --replace '/usr/bin/env python' ${python.interpreter}
+
+      runHook postInstall
+    '';
+
+    postFixup = ''
+      # kvp needs to be able to find the script(s)
+      wrapProgram $out/bin/hv_kvp_daemon --prefix PATH : $out/bin
+    '';
+  };
+
+  service = bin: title: check:
+    writeText "hv-${bin}.service" ''
+      [Unit]
+      Description=Hyper-V ${title} daemon
+      ConditionVirtualization=microsoft
+      ${lib.optionalString (check != "") ''
+        ConditionPathExists=/dev/vmbus/${check}
+      ''}
+      [Service]
+      ExecStart=@out@/hv_${bin}_daemon -n
+      Restart=on-failure
+      PrivateTmp=true
+      Slice=hyperv.slice
+
+      [Install]
+      WantedBy=hyperv-daemons.target
+    '';
+
+in stdenv.mkDerivation rec {
+  name    = "hyperv-daemons-${version}";
+
+  inherit (kernel) version;
+
+  # we just stick the bins into out as well as it requires "out"
+  outputs = [ "bin" "lib" "out" ];
+
+  phases = [ "installPhase" ];
+
+  buildInputs = [ daemons ];
+
+  installPhase = ''
+    system=$lib/lib/systemd/system
+
+    mkdir -p $system
+
+    cp ${service "fcopy" "file copy (FCOPY)" "hv_fcopy" } $system/hv-fcopy.service
+    cp ${service "kvp"   "key-value pair (KVP)"     ""  } $system/hv-kvp.service
+    cp ${service "vss"   "volume shadow copy (VSS)" ""  } $system/hv-vss.service
+
+    cat > $system/hyperv-daemons.target <<EOF
+    [Unit]
+    Description=Hyper-V Daemons
+    Wants=hv-fcopy.service hv-kvp.service hv-vss.service
+    EOF
+
+    for f in $lib/lib/systemd/system/* ; do
+      substituteInPlace $f --replace @out@ ${daemons}/bin
+    done
+
+    # we need to do both $out and $bin as $out is required
+    for d in $out/bin $bin/bin ; do
+      # make user binaries available
+      mkdir -p $d
+      ln -s ${daemons}/bin/lsvmbus $d/lsvmbus
+    done
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Integration Services for running NixOS under HyperV";
+    longDescription = ''
+      This packages contains the daemons that are used by the Hyper-V hypervisor
+      on the host.
+
+      Microsoft calls their guest agents "Integration Services" which is why
+      we use that name here.
+    '';
+    homepage = https://kernel.org;
+    maintainers = with maintainers; [ peterhoeg ];
+    platforms = kernel.meta.platforms;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/i2c-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/i2c-tools/default.nix
new file mode 100644
index 000000000000..5b061183356c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/i2c-tools/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, fetchurl, perl, read-edid }:
+
+stdenv.mkDerivation rec {
+  name = "i2c-tools-${version}";
+  version = "4.1";
+
+  src = fetchurl {
+    url = "https://www.kernel.org/pub/software/utils/i2c-tools/${name}.tar.xz";
+    sha256 = "1m97hpwqfaqjl9xvr4pvz2vdrsdvxbcn0nnx8pamnyc3s7pikcjp";
+  };
+
+  buildInputs = [ perl ];
+
+  postPatch = ''
+    substituteInPlace eeprom/decode-edid --replace "/usr/sbin/parse-edid" "${read-edid}/bin/parse-edid"
+    substituteInPlace stub/i2c-stub-from-dump --replace "/sbin/" ""
+  '';
+
+  makeFlags = [ "PREFIX=${placeholder "out"}" ];
+
+  postInstall = ''
+    rm -rf $out/include # Installs include/linux/i2c-dev.h that conflics with kernel headers
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Set of I2C tools for Linux";
+    homepage = https://i2c.wiki.kernel.org/index.php/I2C_Tools;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.dezgeg ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/i7z/default.nix b/nixpkgs/pkgs/os-specific/linux/i7z/default.nix
new file mode 100644
index 000000000000..ac5f9fc5ba30
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/i7z/default.nix
@@ -0,0 +1,58 @@
+{ stdenv, lib, fetchFromGitHub, fetchpatch, ncurses
+, withGui ? false, qtbase }:
+
+stdenv.mkDerivation rec {
+  name = "i7z-${version}";
+  version = "0.27.3";
+
+  src = fetchFromGitHub {
+    owner = "DimitryAndric";
+    repo = "i7z";
+    rev = "v${version}";
+    sha256 = "0l8wz0ffb27nkwchc606js652spk8masy3kjmzh7ygipwsary5ds";
+  };
+
+  buildInputs = [ ncurses ] ++ lib.optional withGui qtbase;
+
+  patches = [
+    (fetchpatch {
+      url = "https://salsa.debian.org/debian/i7z/raw/ad1359764ee7a860a02e0c972f40339058fa9369/debian/patches/fix-insecure-tempfile.patch";
+      sha256 = "0ifg06xjw14y4fnzzgkhqm4sv9mcdzgi8m2wffq9z8b1r0znya3s";
+    })
+    (fetchpatch {
+      url = "https://salsa.debian.org/debian/i7z/raw/ad1359764ee7a860a02e0c972f40339058fa9369/debian/patches/nehalem.patch";
+      sha256 = "1ys6sgm01jkqb6d4y7qc3h89dzph8jjjcfya5c5jcm7dkxlzjq8a";
+    })
+    (fetchpatch {
+      url = "https://salsa.debian.org/debian/i7z/raw/ad1359764ee7a860a02e0c972f40339058fa9369/debian/patches/hyphen-used-as-minus-sign.patch";
+      sha256 = "1ji2qvdyq0594cpqz0dlsfggvw3rm63sygh0jxvwjgxpnhykhg1p";
+    })
+    ./qt5.patch
+  ];
+
+  enableParallelBuilding = true;
+
+  postBuild = lib.optionalString withGui ''
+      cd GUI
+      qmake
+      make clean
+      make
+      cd ..
+  '';
+
+  makeFlags = [ "prefix=${placeholder "out"}" ];
+
+  postInstall = lib.optionalString withGui ''
+    install -Dm755 GUI/i7z_GUI $out/bin/i7z-gui
+  '';
+
+  meta = with lib; {
+    description = "A better i7 (and now i3, i5) reporting tool for Linux";
+    homepage = https://github.com/DimitryAndric/i7z;
+    repositories.git = https://github.com/DimitryAndric/i7z.git;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ bluescreen303 ];
+    # broken on ARM
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/i7z/qt5.patch b/nixpkgs/pkgs/os-specific/linux/i7z/qt5.patch
new file mode 100644
index 000000000000..9e9b162d9e85
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/i7z/qt5.patch
@@ -0,0 +1,13 @@
+diff -Naur a/GUI/i7z_GUI.pro b/GUI/i7z_GUI.pro
+--- a/GUI/i7z_GUI.pro	2013-10-12 21:59:19.000000000 +0100
++++ b/GUI/i7z_GUI.pro	2016-11-05 13:54:30.118655672 +0000
+@@ -3,7 +3,8 @@
+ ######################################################################
+ 
+ TEMPLATE = app
+-TARGET = 
++TARGET = i7z_GUI
++QT += widgets
+ DEPENDPATH += .
+ INCLUDEPATH += .
+ CONFIG += debug
diff --git a/nixpkgs/pkgs/os-specific/linux/i810switch/default.nix b/nixpkgs/pkgs/os-specific/linux/i810switch/default.nix
new file mode 100644
index 000000000000..2f4511bcbc47
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/i810switch/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, fetchurl, pciutils }:
+
+stdenv.mkDerivation {
+  name = "i810switch-0.6.5";
+
+  phases = "unpackPhase installPhase";
+
+  installPhase = "
+    sed -i -e 's+/usr++' Makefile
+    sed -i -e 's+^\\(.*putenv(\"PATH=\\).*$+\\1${pciutils}/sbin\");+' i810switch.c
+    make clean
+    make install DESTDIR=\${out}
+  ";
+
+  src = fetchurl {
+    url = http://www16.plala.or.jp/mano-a-mano/i810switch/i810switch-0.6.5.tar.gz;
+    sha256 = "d714840e3b14e1fa9c432c4be0044b7c008d904dece0d611554655b979cad4c3";
+  };
+
+  meta = {
+    description = "A utility for switching between the LCD and external VGA display on Intel graphics cards";
+    homepage = http://www16.plala.or.jp/mano-a-mano/i810switch.html;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ifenslave/default.nix b/nixpkgs/pkgs/os-specific/linux/ifenslave/default.nix
new file mode 100644
index 000000000000..b9390d1d5893
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ifenslave/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "ifenslave-${version}";
+  version = "1.1.0";
+
+  src = fetchurl {
+    url = "mirror://debian/pool/main/i/ifenslave-2.6/ifenslave-2.6_${version}.orig.tar.gz";
+    sha256 = "0h9hrmy19zdksl7ys250r158b943ihbgkb95n8p4k8l0vqsby5vr";
+  };
+
+  buildPhase = ''
+    gcc -o ifenslave ifenslave.c
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp -a ifenslave $out/bin
+  '';
+
+  hardeningDisable = [ "format" ];
+
+  meta = {
+    description = "Utility for enslaving networking interfaces under a bond";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iio-sensor-proxy/default.nix b/nixpkgs/pkgs/os-specific/linux/iio-sensor-proxy/default.nix
new file mode 100644
index 000000000000..dcd5b4763ff1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iio-sensor-proxy/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, fetchFromGitHub, autoconf-archive, gettext, libtool, intltool, autoconf, automake
+, glib, gtk3, gtk-doc, libgudev, pkgconfig, systemd }:
+
+stdenv.mkDerivation rec {
+  name = "iio-sensor-proxy-${version}";
+  version = "2.5";
+
+  src = fetchFromGitHub {
+    owner  = "hadess";
+    repo   = "iio-sensor-proxy";
+    rev    = version;
+    sha256 = "06x1vvslsa44bgw8s5rr17q9i2ssbw0x04l75zsy3rql9r3y2jzg";
+  };
+
+  configurePhase = ''
+    runHook preConfigure
+
+    ./autogen.sh --prefix=$out \
+      --with-udevrulesdir=$out/lib/udev/rules.d \
+      --with-systemdsystemunitdir=$out/lib/systemd/system
+
+    runHook postConfigure
+  '';
+
+  buildInputs = [
+    glib
+    gtk3
+    gtk-doc
+    libgudev
+    systemd
+  ];
+
+  nativeBuildInputs = [
+    autoconf
+    autoconf-archive
+    automake
+    gettext
+    intltool
+    libtool
+    pkgconfig
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Proxy for sending IIO sensor data to D-Bus";
+    homepage = https://github.com/hadess/iio-sensor-proxy;
+    license = licenses.gpl3 ;
+    maintainers = with maintainers; [ peterhoeg ];
+    platforms = platforms.linux;
+    inherit version;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ima-evm-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/ima-evm-utils/default.nix
new file mode 100644
index 000000000000..6de3b19afd7e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ima-evm-utils/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchgit, autoreconfHook, pkgconfig, openssl, attr, keyutils, asciidoc, libxslt, docbook_xsl }:
+
+stdenv.mkDerivation rec {
+  name = "ima-evm-utils-${version}";
+  version = "1.1";
+
+  src = fetchgit {
+    url = "git://git.code.sf.net/p/linux-ima/ima-evm-utils";
+    rev = "v${version}";
+    sha256 = "1dhfw6d9z4dv82q9zg2g025hgr179kamz9chy7v5w9b71aam8jf8";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ openssl attr keyutils asciidoc libxslt ];
+
+  patches = [ ./xattr.patch ];
+
+  buildPhase = "make prefix=$out MANPAGE_DOCBOOK_XSL=${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl";
+
+  meta = {
+    description = "evmctl utility to manage digital signatures of the Linux kernel integrity subsystem (IMA/EVM)";
+    homepage = https://sourceforge.net/projects/linux-ima/;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [ tstrobel ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ima-evm-utils/xattr.patch b/nixpkgs/pkgs/os-specific/linux/ima-evm-utils/xattr.patch
new file mode 100644
index 000000000000..2d27570a5786
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ima-evm-utils/xattr.patch
@@ -0,0 +1,73 @@
+commit 6aea54d2ad2287b3e8894c262ee895f3d4a60516
+Author: André Draszik <git@andred.net>
+Date:   Mon Oct 17 12:45:32 2016 +0100
+
+    evmctl: use correct include for xattr.h
+    
+    The xattr API/ABI is provided by both the c-library, as well as by the
+    libattr package. The c-library's header file is sys/xattr.h, whereas
+    libattr's header file can be found in attr/xattr.h.
+    
+    Given none of the code here *links* against the libattr.so shared library, it
+    is wrong to *compile* against libattr's API (header file).
+    
+    Doing so avoids confusion as to which xattr.h is used as the least problem,
+    and potential ABI differences as the worst problem due the mismatching header
+    file used.
+    
+    So make sure we compile and link against the same thing, the c-library in
+    both cases.
+    
+    Signed-off-by: André Draszik <git@andred.net>
+    Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
+
+diff --git a/configure.ac b/configure.ac
+index 0497eb7..a5b4288 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -30,7 +30,7 @@ AC_SUBST(OPENSSL_LIBS)
+ AC_CHECK_HEADER(unistd.h)
+ AC_CHECK_HEADERS(openssl/conf.h)
+ 
+-AC_CHECK_HEADERS(attr/xattr.h, , [AC_MSG_ERROR([attr/xattr.h header not found. You need the libattr development package.])])
++AC_CHECK_HEADERS(sys/xattr.h, , [AC_MSG_ERROR([sys/xattr.h header not found. You need the c-library development package.])])
+ AC_CHECK_HEADERS(keyutils.h, , [AC_MSG_ERROR([keyutils.h header not found. You need the libkeyutils development package.])])
+ 
+ #debug support - yes for a while
+diff --git a/packaging/ima-evm-utils.spec b/packaging/ima-evm-utils.spec
+index a11a27a..63388d2 100644
+--- a/packaging/ima-evm-utils.spec
++++ b/packaging/ima-evm-utils.spec
+@@ -11,7 +11,6 @@ BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root
+ BuildRequires:    autoconf
+ BuildRequires:    automake
+ BuildRequires:    openssl-devel
+-BuildRequires:    libattr-devel
+ BuildRequires:    keyutils-libs-devel
+ 
+ %description
+diff --git a/packaging/ima-evm-utils.spec.in b/packaging/ima-evm-utils.spec.in
+index 7ca6c6f..65c32f9 100644
+--- a/packaging/ima-evm-utils.spec.in
++++ b/packaging/ima-evm-utils.spec.in
+@@ -11,7 +11,6 @@ BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root
+ BuildRequires:    autoconf
+ BuildRequires:    automake
+ BuildRequires:    openssl-devel
+-BuildRequires:    libattr-devel
+ BuildRequires:    keyutils-libs-devel
+ 
+ %description
+diff --git a/src/evmctl.c b/src/evmctl.c
+index 2ffee78..3fbcd33 100644
+--- a/src/evmctl.c
++++ b/src/evmctl.c
+@@ -49,7 +49,7 @@
+ #include <stdint.h>
+ #include <string.h>
+ #include <dirent.h>
+-#include <attr/xattr.h>
++#include <sys/xattr.h>
+ #include <linux/xattr.h>
+ #include <getopt.h>
+ #include <keyutils.h>
diff --git a/nixpkgs/pkgs/os-specific/linux/input-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/input-utils/default.nix
new file mode 100644
index 000000000000..cd0fc01384bc
--- /dev/null
+++ b/nixpkgs/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/nixpkgs/pkgs/os-specific/linux/intel-ocl/default.nix b/nixpkgs/pkgs/os-specific/linux/intel-ocl/default.nix
new file mode 100644
index 000000000000..d604c9ef6b79
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/intel-ocl/default.nix
@@ -0,0 +1,73 @@
+{ stdenv, fetchzip, rpmextract, ncurses5, numactl, zlib }:
+
+stdenv.mkDerivation rec {
+  name = "intel-ocl-${version}";
+  version = "5.0-63503";
+
+  src = fetchzip {
+    url = "http://registrationcenter-download.intel.com/akdlm/irc_nas/11396/SRB5.0_linux64.zip";
+    sha256 = "0qbp63l74s0i80ysh9ya8x7r79xkddbbz4378nms9i7a0kprg9p2";
+    stripRoot = false;
+  };
+
+  buildInputs = [ rpmextract ];
+
+  sourceRoot = ".";
+
+  libPath = stdenv.lib.makeLibraryPath [
+    stdenv.cc.cc.lib
+    ncurses5
+    numactl
+    zlib
+  ];
+
+  postUnpack = ''
+    # Extract the RPMs contained within the source ZIP.
+    rpmextract source/intel-opencl-r${version}.x86_64.rpm
+    rpmextract source/intel-opencl-cpu-r${version}.x86_64.rpm
+  '';
+
+  patchPhase = ''
+    runHook prePatch
+
+    # Remove libOpenCL.so, since we use ocl-icd's libOpenCL.so instead and this would cause a clash.
+    rm opt/intel/opencl/libOpenCL.so*
+
+    # Patch shared libraries.
+    for lib in opt/intel/opencl/*.so; do
+      patchelf --set-rpath "${libPath}:$out/lib/intel-ocl" $lib || true
+    done
+
+    runHook postPatch
+  '';
+
+  buildPhase = ''
+    runHook preBuild
+
+    # Create ICD file, which just contains the path of the corresponding shared library.
+    echo "$out/lib/intel-ocl/libintelocl.so" > intel.icd
+
+    runHook postBuild
+  '';
+
+  installPhase = ''
+    runHook preInstall
+
+    install -D -m 0755 opt/intel/opencl/*.so* -t $out/lib/intel-ocl
+    install -D -m 0644 opt/intel/opencl/*.{o,rtl,bin} -t $out/lib/intel-ocl
+    install -D -m 0644 opt/intel/opencl/{LICENSE,NOTICES} -t $out/share/doc/intel-ocl
+    install -D -m 0644 intel.icd -t $out/etc/OpenCL/vendors
+
+    runHook postInstall
+  '';
+
+  dontStrip = true;
+
+  meta = {
+    description = "Official OpenCL runtime for Intel CPUs";
+    homepage    = https://software.intel.com/en-us/articles/opencl-drivers;
+    license     = stdenv.lib.licenses.unfree;
+    platforms   = [ "x86_64-linux" ];
+    maintainers = [ stdenv.lib.maintainers.kierdavis ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iomelt/default.nix b/nixpkgs/pkgs/os-specific/linux/iomelt/default.nix
new file mode 100644
index 000000000000..932b81438982
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iomelt/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, lib, fetchurl }:
+
+let version = "0.7";
+in stdenv.mkDerivation {
+  name = "iomelt-${version}";
+  src = fetchurl {
+    url = "http://iomelt.com/s/iomelt-${version}.tar.gz";
+    sha256 = "1jhrdm5b7f1bcbrdwcc4yzg26790jxl4d2ndqiwd9brl2g5537im";
+  };
+
+  preBuild = ''
+    mkdir -p $out/bin
+    mkdir -p $out/share/man/man1
+
+    substituteInPlace Makefile \
+      --replace /usr $out
+  '';
+
+  meta = with lib; {
+    description = "A simple yet effective way to benchmark disk IO in Linux systems";
+    homepage    = http://www.iomelt.com;
+    maintainers = with maintainers; [ cstrahan ];
+    license = licenses.artistic2;
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ioport/default.nix b/nixpkgs/pkgs/os-specific/linux/ioport/default.nix
new file mode 100644
index 000000000000..c14d9f146eb0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ioport/default.nix
@@ -0,0 +1,17 @@
+{ stdenv, perl, fetchurl }:
+
+stdenv.mkDerivation {
+  name = "ioport-1.2";
+  src = fetchurl {
+    url = "https://people.redhat.com/rjones/ioport/files/ioport-1.2.tar.gz";
+    sha256 = "1h4d5g78y7kla0zl25jgyrk43wy3m3bygqg0blki357bc55irb3z";
+  };
+  buildInputs = [ perl ];
+  meta = with stdenv.lib; {
+    description = "Direct access to I/O ports from the command line";
+    homepage = https://people.redhat.com/rjones/ioport/;
+    license = licenses.gpl2Plus;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = [ maintainers.cleverca22 ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iotop/default.nix b/nixpkgs/pkgs/os-specific/linux/iotop/default.nix
new file mode 100644
index 000000000000..e2ded7a8fd0c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iotop/default.nix
@@ -0,0 +1,20 @@
+{ stdenv, fetchurl, python2Packages }:
+
+python2Packages.buildPythonApplication rec {
+  name = "iotop-0.6";
+
+  src = fetchurl {
+    url = "http://guichaz.free.fr/iotop/files/${name}.tar.bz2";
+    sha256 = "0nzprs6zqax0cwq8h7hnszdl3d2m4c2d4vjfxfxbnjfs9sia5pis";
+  };
+
+  doCheck = false;
+
+  meta = with stdenv.lib; {
+    description = "A tool to find out the processes doing the most IO";
+    homepage = http://guichaz.free.fr/iotop;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.raskin ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iproute/default.nix b/nixpkgs/pkgs/os-specific/linux/iproute/default.nix
new file mode 100644
index 000000000000..4d8591a845c8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iproute/default.nix
@@ -0,0 +1,55 @@
+{ fetchurl, stdenv, flex, bash, bison, db, iptables, pkgconfig, libelf }:
+
+stdenv.mkDerivation rec {
+  name = "iproute2-${version}";
+  version = "4.20.0";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/net/iproute2/${name}.tar.xz";
+    sha256 = "1a7xyvqjxfnm7rk21amm0xgxa38clg7q7cmc4dmlg27q81mambf8";
+  };
+
+  preConfigure = ''
+    patchShebangs ./configure
+    sed -e '/ARPDDIR/d' -i Makefile
+    # Don't build netem tools--they're not installed and require HOSTCC
+    substituteInPlace Makefile --replace " netem " " "
+  '';
+
+  outputs = [ "out" "dev"];
+
+  makeFlags = [
+    "DESTDIR="
+    "LIBDIR=$(out)/lib"
+    "SBINDIR=$(out)/sbin"
+    "MANDIR=$(out)/share/man"
+    "BASH_COMPDIR=$(out)/share/bash-completion/completions"
+    "DOCDIR=$(TMPDIR)/share/doc/${name}" # Don't install docs
+    "HDRDIR=$(dev)/include/iproute2"
+  ];
+
+  buildFlags = [
+    "CONFDIR=/etc/iproute2"
+  ];
+
+  installFlags = [
+    "CONFDIR=$(out)/etc/iproute2"
+  ];
+
+  buildInputs = [ db iptables libelf ];
+  nativeBuildInputs = [ bison flex pkgconfig ];
+
+  enableParallelBuilding = true;
+
+  postInstall = ''
+    PATH=${bash}/bin:$PATH patchShebangs $out/sbin
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://wiki.linuxfoundation.org/networking/iproute2;
+    description = "A collection of utilities for controlling TCP/IP networking and traffic control in Linux";
+    platforms = platforms.linux;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ eelco fpletz ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ipsec-tools/CVE-2015-4047.patch b/nixpkgs/pkgs/os-specific/linux/ipsec-tools/CVE-2015-4047.patch
new file mode 100644
index 000000000000..00c23c6cac14
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ipsec-tools/CVE-2015-4047.patch
@@ -0,0 +1,16 @@
+Index: pkg-ipsec-tools/src/racoon/gssapi.c
+===================================================================
+--- pkg-ipsec-tools.orig/src/racoon/gssapi.c
++++ pkg-ipsec-tools/src/racoon/gssapi.c
+@@ -192,6 +192,11 @@ gssapi_init(struct ph1handle *iph1)
+	gss_name_t princ, canon_princ;
+	OM_uint32 maj_stat, min_stat;
+
++	if (iph1->rmconf == NULL) {
++		plog(LLV_ERROR, LOCATION, NULL, "no remote config\n");
++		return -1;
++	}
++
+	gps = racoon_calloc(1, sizeof (struct gssapi_ph1_state));
+	if (gps == NULL) {
+		plog(LLV_ERROR, LOCATION, NULL, "racoon_calloc failed\n");
diff --git a/nixpkgs/pkgs/os-specific/linux/ipsec-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/ipsec-tools/default.nix
new file mode 100644
index 000000000000..0aa074b4df8f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ipsec-tools/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, fetchurl, fetchpatch, linuxHeaders, readline, openssl, flex, kerberos, pam }:
+
+# TODO: These tools are supposed to work under NetBSD and FreeBSD as
+# well, so I guess it's not appropriate to place this expression in
+# "os-specific/linux/ipsec-tools". Since I cannot verify that the
+# expression actually builds on those platforms, I'll leave it here for
+# the time being.
+
+stdenv.mkDerivation rec {
+  name = "ipsec-tools-0.8.2";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/ipsec-tools/${name}.tar.bz2";
+    sha256 = "0b9gfbz78k2nj0k7jdlm5kajig628ja9qm0z5yksiwz22s3v7dlf";
+  };
+
+  buildInputs = [ readline openssl flex kerberos pam ];
+
+  patches = [
+    ./dont-create-localstatedir-during-install.patch
+    ./CVE-2015-4047.patch
+    (fetchpatch {
+      url = "https://anonscm.debian.org/cgit/pkg-ipsec-tools/pkg-ipsec-tools.git/plain/debian/patches/CVE-2016-10396.patch?id=62ac12648a4eb7c5ba5dba0f81998d1acf310d8b";
+      sha256 = "1kf7j2pf1blni52z7q41n0yisqb7gvk01lvldr319zaxxg7rm84a";
+    })
+  ];
+
+  # fix build with newer gcc versions
+  preConfigure = ''substituteInPlace configure --replace "-Werror" "" '';
+
+  configureFlags = [
+    "--sysconfdir=/etc --localstatedir=/var"
+    "--with-kernel-headers=${linuxHeaders}/include"
+    "--disable-security-context"
+    "--enable-adminport"
+    "--enable-dpd"
+    "--enable-frag"
+    "--enable-gssapi"
+    "--enable-hybrid"
+    "--enable-natt"
+    "--enable-shared"
+    "--enable-stats"
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = http://ipsec-tools.sourceforge.net/;
+    description = "Port of KAME's IPsec utilities to the Linux-2.6 IPsec implementation";
+    license = licenses.bsd3;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ipsec-tools/dont-create-localstatedir-during-install.patch b/nixpkgs/pkgs/os-specific/linux/ipsec-tools/dont-create-localstatedir-during-install.patch
new file mode 100644
index 000000000000..16b80c36d6a5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ipsec-tools/dont-create-localstatedir-during-install.patch
@@ -0,0 +1,13 @@
+diff -ubr ipsec-tools-0.8.0-orig/src/racoon/Makefile.in ipsec-tools-0.8.0/src/racoon/Makefile.in
+--- ipsec-tools-0.8.0-orig/src/racoon/Makefile.in	2012-10-20 13:01:07.700903316 +0200
++++ ipsec-tools-0.8.0/src/racoon/Makefile.in	2012-10-20 13:01:13.177832616 +0200
+@@ -1085,9 +1085,6 @@
+ 	uninstall-sbinPROGRAMS
+ 
+ 
+-install-exec-local:
+-	${mkinstalldirs} $(DESTDIR)${adminsockdir}
+-
+ # special object rules
+ crypto_openssl_test.o: crypto_openssl.c
+ 	$(COMPILE) -DEAYDEBUG -o crypto_openssl_test.o -c $(srcdir)/crypto_openssl.c
diff --git a/nixpkgs/pkgs/os-specific/linux/ipset/default.nix b/nixpkgs/pkgs/os-specific/linux/ipset/default.nix
new file mode 100644
index 000000000000..0ae971b6a690
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ipset/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, fetchurl, pkgconfig, libmnl }:
+
+stdenv.mkDerivation rec {
+  name = "ipset-7.1";
+
+  src = fetchurl {
+    url = "http://ipset.netfilter.org/${name}.tar.bz2";
+    sha256 = "1i5d2v732jnx543w1h57g6zi9ckvbxp8pz7377f0rhh56awv6pkv";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libmnl ];
+
+  configureFlags = [ "--with-kmod=no" ];
+
+  meta = with stdenv.lib; {
+    homepage = http://ipset.netfilter.org/;
+    description = "Administration tool for IP sets";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iptables/default.nix b/nixpkgs/pkgs/os-specific/linux/iptables/default.nix
new file mode 100644
index 000000000000..ff6ce3b4889d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iptables/default.nix
@@ -0,0 +1,67 @@
+{ stdenv, fetchurl, fetchpatch, bison, flex, pkgconfig, pruneLibtoolFiles
+, libnetfilter_conntrack, libnftnl, libmnl, libpcap }:
+
+stdenv.mkDerivation rec {
+  name = "iptables-${version}";
+  version = "1.8.2";
+
+  src = fetchurl {
+    url = "https://www.netfilter.org/projects/iptables/files/${name}.tar.bz2";
+    sha256 = "1bqj9hf3szy9r0w14iy23w00ir8448nfhpcprbwmcchsxm88nxx3";
+  };
+
+  patches = [
+    # Adds missing bits to extensions' libipt_icmp.c and libip6t_icmp6.c that were causing build to fail
+    (fetchpatch {
+      url = "https://git.netfilter.org/iptables/patch/?id=907e429d7548157016cd51aba4adc5d0c7d9f816";
+      sha256 = "0vc7ljcglz5152lc3jx4p44vjfi6ipvxdrgkdb5dmkhlb5v93i2h";
+    })
+    # Build with musl libc fails because of conflicting struct ethhdr definitions
+    (fetchpatch {
+      url = "https://git.netfilter.org/iptables/patch/?id=51d374ba41ae4f1bb851228c06b030b83dd2092f";
+      sha256 = "05fwrq03f9sm0v2bfwshbrg7pi2p978w1460arnmpay3135gj266";
+    })
+    # Extensions: libip6t_mh: fix bogus translation error
+    (fetchpatch {
+      url = "https://git.netfilter.org/iptables/patch/?id=5839d7fe62ff667af7132fc7d589b386951f27b3";
+      sha256 = "0578jn1ip710z9kijwg9g2vjq2kfrbafl03m1rgi4fasz215gvkf";
+    })
+    # Prevent headers collisions between linux and netfilter (in.h and in6.h)
+    # Fixed upstream with two commits
+    (fetchpatch {
+      url = "https://git.netfilter.org/iptables/patch/?id=8d9d7e4b9ef4c6e6abab2cf35c747d7ca36824bd";
+      sha256 = "0q3wcspiqym1r6dg1jhg7h8hpvsjzx1k7cs39z36mzlbmj9lm0zb";
+    })
+    (fetchpatch {
+      url = "https://git.netfilter.org/iptables/patch/?id=2908eda10bf9fc81119d4f3ad672c67918ab5955";
+      sha256 = "1dci4c8b7gcdrf77l2aicrcwlbp320xjz76fhavams0b4kgs6yr3";
+    })
+  ];
+
+  nativeBuildInputs = [ bison flex pkgconfig pruneLibtoolFiles ];
+
+  buildInputs = [ libnetfilter_conntrack libnftnl libmnl libpcap ];
+
+  preConfigure = ''
+    export NIX_LDFLAGS="$NIX_LDFLAGS -lmnl -lnftnl"
+  '';
+
+  configureFlags = [
+    "--enable-devel"
+    "--enable-shared"
+    "--enable-bpf-compiler"
+  ];
+
+  outputs = [ "out" "dev" ];
+
+  meta = with stdenv.lib; {
+    description = "A program to configure the Linux IP packet filtering ruleset";
+    homepage = https://www.netfilter.org/projects/iptables/index.html;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ fpletz ];
+    license = licenses.gpl2;
+    downloadPage = "https://www.netfilter.org/projects/iptables/files/";
+    updateWalker = true;
+    inherit version;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iptstate/default.nix b/nixpkgs/pkgs/os-specific/linux/iptstate/default.nix
new file mode 100644
index 000000000000..a9be26a20262
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iptstate/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, fetchurl, libnetfilter_conntrack, ncurses }:
+
+stdenv.mkDerivation rec {
+  name = "iptstate-${version}";
+  version = "2.2.6";
+
+  src = fetchurl {
+    url = "https://github.com/jaymzh/iptstate/releases/download/v${version}/${name}.tar.bz2";
+    sha256 = "bef8eb67a4533e53079f397b71e91dd34da23f8cbd65cb2d5b67cb907b00c068";
+  };
+
+  buildInputs = [ libnetfilter_conntrack ncurses ];
+
+  meta = with stdenv.lib; {
+    description = "Conntrack top like tool";
+    homepage = https://github.com/jaymzh/iptstate;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ trevorj ];
+    downloadPage = "https://github.com/jaymzh/iptstate/releases";
+  };
+
+  installPhase = ''
+    install -m755 -D iptstate $out/bin/iptstate
+  '';
+}
+
diff --git a/nixpkgs/pkgs/os-specific/linux/iputils/build-ninfod-with-openssl.patch b/nixpkgs/pkgs/os-specific/linux/iputils/build-ninfod-with-openssl.patch
new file mode 100644
index 000000000000..7ce1b4f527ec
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iputils/build-ninfod-with-openssl.patch
@@ -0,0 +1,13 @@
+diff --git a/ninfod/meson.build b/ninfod/meson.build
+index ea7ec1b..fada05b 100644
+--- a/ninfod/meson.build
++++ b/ninfod/meson.build
+@@ -10,7 +10,7 @@ ninfod_sources = files('''
+ 	ninfod_name.c
+ '''.split())
+ executable('ninfod', [ninfod_sources, git_version_h],
+-	dependencies : [cap_dep, crypto_dep, rt_dep, threads],
++	dependencies : [cap_dep, dependency('openssl'), rt_dep, threads],
+ 	link_with : [libcommon],
+ 	include_directories : inc,
+ 	install: true,
diff --git a/nixpkgs/pkgs/os-specific/linux/iputils/default.nix b/nixpkgs/pkgs/os-specific/linux/iputils/default.nix
new file mode 100644
index 000000000000..223d5c4fe0fb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iputils/default.nix
@@ -0,0 +1,62 @@
+{ stdenv, fetchFromGitHub, fetchpatch
+, meson, ninja, pkgconfig, gettext, libxslt, docbook_xsl_ns
+, libcap, nettle, libidn2, openssl, systemd
+}:
+
+with stdenv.lib;
+
+let
+  time = "20190324";
+  # ninfod probably could build on cross, but the Makefile doesn't pass --host
+  # etc to the sub configure...
+  withNinfod = stdenv.hostPlatform == stdenv.buildPlatform;
+  sunAsIsLicense = {
+    fullName = "AS-IS, SUN MICROSYSTEMS license";
+    url = "https://github.com/iputils/iputils/blob/s${time}/rdisc.c";
+  };
+in stdenv.mkDerivation {
+  name = "iputils-${time}";
+
+  src = fetchFromGitHub {
+    owner = "iputils";
+    repo = "iputils";
+    rev = "s${time}";
+    sha256 = "0b755gv3370c0rrphx14mrsqjb396zqnsm9lsws842a4k4zrqmvi";
+  };
+
+  # ninfod cannot be build with nettle yet:
+  patches =
+    [ ./build-ninfod-with-openssl.patch
+      (fetchpatch { # tracepath: fix musl build, again
+        url = "https://github.com/iputils/iputils/commit/c9aca1b53324bcd1b5a2de5c645813f80eccd016.patch";
+        sha256 = "0faqgkqbi57cyx1zgzzy6xgd24xr0iawix7mjs47j92ra9gw90cz";
+      })
+      (fetchpatch { # doc: Use namespace correctly
+        url = "https://github.com/iputils/iputils/commit/c503834519d21973323980850431101f90e663ef.patch";
+        sha256 = "1yp6b6403ddccbhfzsb36cscxd36d4xb8syc1g02a18xkswiwf09";
+      })
+    ];
+
+  mesonFlags =
+    [ "-DUSE_CRYPTO=nettle"
+      "-DBUILD_RARPD=true"
+      "-DBUILD_TRACEROUTE6=true"
+      "-Dsystemdunitdir=etc/systemd/system"
+    ]
+    ++ optional (!withNinfod) "-DBUILD_NINFOD=false"
+    # Disable idn usage w/musl (https://github.com/iputils/iputils/pull/111):
+    ++ optional stdenv.hostPlatform.isMusl "-DUSE_IDN=false";
+
+  nativeBuildInputs = [ meson ninja pkgconfig gettext libxslt.bin docbook_xsl_ns libcap ];
+  buildInputs = [ libcap nettle systemd ]
+    ++ optional (!stdenv.hostPlatform.isMusl) libidn2
+    ++ optional withNinfod openssl; # TODO: Build with nettle
+
+  meta = {
+    homepage = https://github.com/iputils/iputils;
+    description = "A set of small useful utilities for Linux networking";
+    license = with licenses; [ gpl2Plus bsd3 sunAsIsLicense ];
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ primeos lheckemann ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ipvsadm/default.nix b/nixpkgs/pkgs/os-specific/linux/ipvsadm/default.nix
new file mode 100644
index 000000000000..0e99dd976c72
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ipvsadm/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl, pkgconfig, libnl, popt, gnugrep }:
+
+stdenv.mkDerivation rec {
+  name = "ipvsadm-${version}";
+  version = "1.29";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/kernel/ipvsadm/${name}.tar.xz";
+    sha256 = "c3de4a21d90a02c621f0c72ee36a7aa27374b6f29fd4178f33fbf71b4c66c149";
+  };
+
+  postPatch = ''
+    substituteInPlace Makefile --replace "-lnl" "$(pkg-config --libs libnl-genl-3.0)"
+  '';
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libnl popt ];
+
+  preBuild = ''
+    makeFlagsArray+=(
+      INCLUDE=$(pkg-config --cflags libnl-genl-3.0)
+      BUILD_ROOT=$out
+      MANDIR=share/man
+    )
+  '';
+
+  postInstall = ''
+    sed -i -e "s|^PATH=.*|PATH=$out/bin:${gnugrep}/bin|" $out/sbin/ipvsadm-{restore,save}
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Linux Virtual Server support programs";
+    homepage = http://www.linuxvirtualserver.org/software/ipvs.html;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/irqbalance/default.nix b/nixpkgs/pkgs/os-specific/linux/irqbalance/default.nix
new file mode 100644
index 000000000000..c4a29d2d601d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/irqbalance/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, pkgconfig, glib, ncurses, libcap_ng }:
+
+stdenv.mkDerivation rec {
+  name = "irqbalance-${version}";
+  version = "1.5.0";
+
+  src = fetchFromGitHub {
+    owner = "irqbalance";
+    repo = "irqbalance";
+    rev = "v${version}";
+    sha256 = "1wdwch4nb479xhinin4yqvcjah6h09i4nh8fhnsfbn1mzl0hiv09";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ glib ncurses libcap_ng ];
+
+  LDFLAGS = "-lncurses";
+
+  meta = {
+    homepage = https://github.com/Irqbalance/irqbalance;
+    description = "A daemon to help balance the cpu load generated by interrupts across all of a systems cpus";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/it87/default.nix b/nixpkgs/pkgs/os-specific/linux/it87/default.nix
new file mode 100644
index 000000000000..c115eab1503e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/it87/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+stdenv.mkDerivation rec {
+  name = "it87-${version}-${kernel.version}";
+  version = "2018-08-14";
+
+  # The original was deleted from github, but this seems to be an active fork
+  src = fetchFromGitHub {
+    owner = "hannesha";
+    repo = "it87";
+    rev = "5515f5b78838cb6be551943ffef5d1792012724c";
+    sha256 = "1ygi4mwds4q7byhg8gqnh3syamdj5rpjy3jj012k7vl54gdgrmgm";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  preConfigure = ''
+    sed -i 's|depmod|#depmod|' Makefile
+  '';
+
+  makeFlags = [
+    "TARGET=${kernel.modDirVersion}"
+    "KERNEL_MODULES=${kernel.dev}/lib/modules/${kernel.modDirVersion}"
+    "MODDESTDIR=$(out)/lib/modules/${kernel.modDirVersion}/kernel/drivers/hwmon"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Patched module for IT87xx superio chip sensors support";
+    homepage = https://github.com/hannesha/it87;
+    license = licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = with maintainers; [ yorickvp ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iw/default.nix b/nixpkgs/pkgs/os-specific/linux/iw/default.nix
new file mode 100644
index 000000000000..387792b86313
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iw/default.nix
@@ -0,0 +1,24 @@
+{stdenv, fetchurl, libnl, pkgconfig}:
+
+stdenv.mkDerivation rec {
+  pname = "iw";
+  version = "5.0.1";
+
+  src = fetchurl {
+    url = "https://www.kernel.org/pub/software/network/${pname}/${pname}-${version}.tar.xz";
+    sha256 = "03awbfrr9i78vgwsa6z2c8g14mia9z8qzrvzxar2ad9299wylf0y";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libnl ];
+
+  makeFlags = [ "PREFIX=${placeholder "out"}" ];
+
+  meta = {
+    description = "Tool to use nl80211";
+    homepage = http://wireless.kernel.org/en/users/Documentation/iw;
+    license = stdenv.lib.licenses.isc;
+    maintainers = with stdenv.lib.maintainers; [viric];
+    platforms = with stdenv.lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/iwd/default.nix b/nixpkgs/pkgs/os-specific/linux/iwd/default.nix
new file mode 100644
index 000000000000..fc7eda0af88c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/iwd/default.nix
@@ -0,0 +1,73 @@
+{ stdenv, fetchgit, autoreconfHook, pkgconfig, coreutils, readline, python3Packages }:
+
+let
+  ell = fetchgit {
+     url = https://git.kernel.org/pub/scm/libs/ell/ell.git;
+     rev = "0.17";
+     sha256 = "0yk1qmvpy61qp82bb0w55n062jqzlkzbz0b1v5k763j98czz9rvz";
+  };
+in stdenv.mkDerivation rec {
+  name = "iwd-${version}";
+  version = "0.14";
+
+  src = fetchgit {
+    url = https://git.kernel.org/pub/scm/network/wireless/iwd.git;
+    rev = version;
+    sha256 = "08ijlnwvj1w354gbv3hdnm3l4iy24qzq4bq5a9z0wynysasw09lv";
+  };
+
+  nativeBuildInputs = [
+    autoreconfHook
+    pkgconfig
+    python3Packages.wrapPython
+  ];
+
+  buildInputs = [
+    readline
+    python3Packages.python
+  ];
+
+  pythonPath = [
+    python3Packages.dbus-python
+    python3Packages.pygobject3
+  ];
+
+  configureFlags = [
+    "--with-dbus-datadir=${placeholder "out"}/etc/"
+    "--with-dbus-busdir=${placeholder "out"}/share/dbus-1/system-services/"
+    "--with-systemd-unitdir=${placeholder "out"}/lib/systemd/system/"
+    "--localstatedir=/var/"
+    "--enable-wired"
+  ];
+
+  postUnpack = ''
+    ln -s ${ell} ell
+    patchShebangs .
+  '';
+
+  postInstall = ''
+    cp -a test/* $out/bin/
+    mkdir -p $out/share
+    cp -a doc $out/share/
+    cp -a README AUTHORS TODO $out/share/doc/
+  '';
+
+  preFixup = ''
+    wrapPythonPrograms
+  '';
+
+  postFixup = ''
+    substituteInPlace $out/share/dbus-1/system-services/net.connman.ead.service \
+                      --replace /bin/false ${coreutils}/bin/false
+    substituteInPlace $out/share/dbus-1/system-services/net.connman.iwd.service \
+                      --replace /bin/false ${coreutils}/bin/false
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://git.kernel.org/pub/scm/network/wireless/iwd.git;
+    description = "Wireless daemon for Linux";
+    license = licenses.lgpl21;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.mic92 ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ixgbevf/default.nix b/nixpkgs/pkgs/os-specific/linux/ixgbevf/default.nix
new file mode 100644
index 000000000000..6bcc548ba521
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ixgbevf/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchurl, kernel, kmod }:
+
+stdenv.mkDerivation rec {
+  name = "ixgbevf-${version}-${kernel.version}";
+  version = "4.3.4";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/e1000/ixgbevf-${version}.tar.gz";
+    sha256 = "122zn9nd8f95bpidiiinc8xaizypkirqs8vlmsdy2iv3w65md9k3";
+  };
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  configurePhase = ''
+    cd src
+    makeFlagsArray+=(KSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build INSTALL_MOD_PATH=$out MANDIR=/share/man)
+    substituteInPlace common.mk --replace /sbin/depmod ${kmod}/bin/depmod
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = {
+    description = "Intel 82599 Virtual Function Driver";
+    homepage = https://sourceforge.net/projects/e1000/files/ixgbevf%20stable/;
+    license = stdenv.lib.licenses.gpl2;
+    priority = 20;
+    broken = (stdenv.lib.versionOlder kernel.version "4.9");
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/jfbview/default.nix b/nixpkgs/pkgs/os-specific/linux/jfbview/default.nix
new file mode 100644
index 000000000000..e037ad98226d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/jfbview/default.nix
@@ -0,0 +1,68 @@
+{ stdenv, fetchFromGitHub
+, freetype, harfbuzz, jbig2dec, libjpeg, libX11, mupdf, ncurses, openjpeg
+, openssl
+
+, imageSupport ? true, imlib2 ? null }:
+
+let
+  package = if imageSupport
+    then "jfbview"
+    else "jfbpdf";
+  binaries = if imageSupport
+    then [ "jfbview" "jpdfcat" "jpdfgrep" ] # all require imlib2
+    else [ "jfbpdf" ]; # does not
+in
+
+stdenv.mkDerivation rec {
+  name = "${package}-${version}";
+  version = "0.5.6";
+
+  src = fetchFromGitHub {
+    repo = "JFBView";
+    owner = "jichu4n";
+    rev = version;
+    sha256 = "09rcmlf04aka0yzr25imadi0fl4nlbsxcahs7fhvzx4nql4halqw";
+  };
+
+  hardeningDisable = [ "format" ];
+
+  buildInputs = [
+    freetype harfbuzz jbig2dec libjpeg libX11 mupdf ncurses openjpeg
+    openssl
+  ] ++ stdenv.lib.optionals imageSupport [
+    imlib2
+  ];
+
+  configurePhase = ''
+    # Hack. Probing (`ldconfig -p`) fails with ‘cannot execute binary file’.
+    # Overriding `OPENJP2 =` later works, but makes build output misleading:
+    substituteInPlace Makefile --replace "ldconfig -p" "echo libopenjp2"
+
+    make config.mk
+  '';
+
+  buildFlags = binaries;
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    mkdir -p $out/bin
+    install ${toString binaries} $out/bin
+  '';
+
+  meta = with stdenv.lib; {
+    description = "PDF and image viewer for the Linux framebuffer";
+    longDescription = ''
+      A very fast PDF and image viewer for the Linux framebuffer with some
+      advanced and unique features, including:
+      - Reads PDFs (MuPDF) and common image formats (Imlib2)
+      - Supports arbitrary zoom (10% - 1000%) and rotation
+      - Table of Contents (TOC) viewer for PDF documents
+      - Multi-threaded rendering on multi-core machines
+      - Asynchronous background rendering of the next page
+      - Customizable multi-threaded caching
+    '';
+    homepage = https://seasonofcode.com/pages/jfbview.html;
+    license = licenses.asl20;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/jool/cli.nix b/nixpkgs/pkgs/os-specific/linux/jool/cli.nix
new file mode 100644
index 000000000000..d851a47924d6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/jool/cli.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, pkgconfig, libnl }:
+
+let
+  sourceAttrs = (import ./source.nix) { inherit fetchFromGitHub; };
+in
+
+stdenv.mkDerivation {
+  name = "jool-cli-${sourceAttrs.version}";
+
+  src = sourceAttrs.src;
+
+  setSourceRoot = ''
+    sourceRoot=$(echo */usr)
+  '';
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ libnl ];
+
+  postPatch = ''
+    chmod u+w -R ../common
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://www.jool.mx/;
+    description = "Fairly compliant SIIT and Stateful NAT64 for Linux - CLI tools";
+    platforms = platforms.linux;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ fpletz ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/jool/default.nix b/nixpkgs/pkgs/os-specific/linux/jool/default.nix
new file mode 100644
index 000000000000..d65be175fc1d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/jool/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+assert stdenv.lib.versionOlder kernel.version "4.18";
+
+let
+  sourceAttrs = (import ./source.nix) { inherit fetchFromGitHub; };
+in
+
+stdenv.mkDerivation {
+  name = "jool-${sourceAttrs.version}-${kernel.version}";
+
+  src = sourceAttrs.src;
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+  hardeningDisable = [ "pic" ];
+
+  prePatch = ''
+    sed -e 's@/lib/modules/\$(.*)@${kernel.dev}/lib/modules/${kernel.modDirVersion}@' -i mod/*/Makefile
+  '';
+
+  buildPhase = ''
+    make -C mod
+  '';
+
+  installPhase = ''
+    make -C mod modules_install INSTALL_MOD_PATH=$out
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://www.jool.mx/;
+    description = "Fairly compliant SIIT and Stateful NAT64 for Linux - kernel modules";
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ fpletz ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/jool/source.nix b/nixpkgs/pkgs/os-specific/linux/jool/source.nix
new file mode 100644
index 000000000000..24134b8b8182
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/jool/source.nix
@@ -0,0 +1,11 @@
+{ fetchFromGitHub }:
+
+rec {
+  version = "unstable-20180706";
+  src = fetchFromGitHub {
+    owner = "NICMx";
+    repo = "Jool";
+    rev = "de791931d94e972c36bb3c102a9cadab5230c285";
+    sha256 = "09mr7lc9k17znpslsfmndx4vgl240llcgblxm92fizmwz23y1d6c";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/jujuutils/default.nix b/nixpkgs/pkgs/os-specific/linux/jujuutils/default.nix
new file mode 100644
index 000000000000..617dad8bdddc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/jujuutils/default.nix
@@ -0,0 +1,19 @@
+{ stdenv, fetchurl, linuxHeaders }:
+
+stdenv.mkDerivation {
+  name = "jujuutils-0.2";
+
+  src = fetchurl {
+    url = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jujuutils/jujuutils-0.2.tar.gz";
+    sha256 = "1r74m7s7rs9d6y7cffi7mdap3jf96qwm1v6jcw53x5cikgmfxn4x";
+  };
+
+  buildInputs = [ linuxHeaders ];
+
+  meta = {
+    homepage = https://github.com/cladisch/linux-firewire-utils;
+    description = "Utilities around FireWire devices connected to a Linux computer";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kbd/default.nix b/nixpkgs/pkgs/os-specific/linux/kbd/default.nix
new file mode 100644
index 000000000000..a37e65f8cb50
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kbd/default.nix
@@ -0,0 +1,72 @@
+{ stdenv, fetchurl, autoreconfHook,
+  gzip, bzip2, pkgconfig, flex, check,
+  pam, coreutils
+}:
+
+stdenv.mkDerivation rec {
+  name = "kbd-${version}";
+  version = "2.0.4";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/kbd/${name}.tar.xz";
+    sha256 = "124swm93dm4ca0pifgkrand3r9gvj3019d4zkfxsj9djpvv0mnaz";
+  };
+
+  configureFlags = [
+    "--enable-optional-progs"
+    "--enable-libkeymap"
+    "--disable-nls"
+  ];
+
+  patches = [ ./search-paths.patch ];
+
+  postPatch =
+    ''
+      # Add Neo keymap subdirectory
+      sed -i -e 's,^KEYMAPSUBDIRS *= *,&i386/neo ,' data/Makefile.am
+
+      # Renaming keymaps with name clashes, because loadkeys just picks
+      # the first keymap it sees. The clashing names lead to e.g.
+      # "loadkeys no" defaulting to a norwegian dvorak map instead of
+      # the much more common qwerty one.
+      pushd data/keymaps/i386
+      mv qwertz/cz{,-qwertz}.map
+      mv olpc/es{,-olpc}.map
+      mv olpc/pt{,-olpc}.map
+      mv dvorak/{no.map,dvorak-no.map}
+      mv fgGIod/trf{,-fgGIod}.map
+      mv colemak/{en-latin9,colemak}.map
+      popd
+
+      # Fix the path to gzip/bzip2.
+      substituteInPlace src/libkeymap/findfile.c \
+        --replace gzip ${gzip}/bin/gzip \
+        --replace bzip2 ${bzip2.bin}/bin/bzip2 \
+
+      # We get a warning in armv5tel-linux and the fuloong2f, so we
+      # disable -Werror in it.
+      ${stdenv.lib.optionalString (stdenv.isAarch32 || stdenv.hostPlatform.isMips) ''
+        sed -i s/-Werror// src/Makefile.am
+      ''}
+    '';
+
+  postInstall = ''
+    for i in $out/bin/unicode_{start,stop}; do
+      substituteInPlace "$i" \
+        --replace /usr/bin/tty ${coreutils}/bin/tty
+    done
+  '';
+
+
+  buildInputs = [ check pam ];
+  nativeBuildInputs = [ autoreconfHook pkgconfig flex ];
+
+  makeFlags = [ "setowner=" ];
+
+  meta = with stdenv.lib; {
+    homepage = ftp://ftp.altlinux.org/pub/people/legion/kbd/;
+    description = "Linux keyboard utilities and keyboard maps";
+    platforms = platforms.linux;
+    license = licenses.gpl2Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kbd/keymaps.nix b/nixpkgs/pkgs/os-specific/linux/kbd/keymaps.nix
new file mode 100644
index 000000000000..ecb7045ed278
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kbd/keymaps.nix
@@ -0,0 +1,35 @@
+{ stdenv, lib, fetchurl, gzip }:
+
+{
+  dvp = stdenv.mkDerivation rec {
+    name = "dvp-${version}";
+    version = "1.2.1";
+
+    src = fetchurl {
+      url = "http://kaufmann.no/downloads/linux/dvp-${lib.replaceStrings ["."] ["_"] version}.map.gz";
+      sha256 = "0e859211cfe16a18a3b9cbf2ca3e280a23a79b4e40b60d8d01d0fde7336b6d50";
+    };
+
+    nativeBuildInputs = [ gzip ];
+
+    buildCommand = ''
+      mkdir -p $out/share/keymaps/i386/dvorak
+      gzip -c -d $src > $out/share/keymaps/i386/dvorak/dvp.map
+    '';
+  };
+
+  neo = stdenv.mkDerivation rec {
+    name = "neo-${version}";
+    version = "2476";
+
+    src = fetchurl {
+      name = "neo.map";
+      url = "https://svn.neo-layout.org/linux/console/neo.map?r=${version}";
+      sha256 = "19mfrd31vzpsjiwc7pshxm0b0sz5dd17xrz6k079cy4im1vf0r4g";
+    };
+
+    buildCommand = ''
+      install -D $src $out/share/keymaps/i386/neo/neo.map
+    '';
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kbd/search-paths.patch b/nixpkgs/pkgs/os-specific/linux/kbd/search-paths.patch
new file mode 100644
index 000000000000..c9405a56721d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kbd/search-paths.patch
@@ -0,0 +1,71 @@
+--- a/src/libkeymap/analyze.l
++++ b/src/libkeymap/analyze.l
+@@ -101,6 +101,9 @@ stack_pop(struct lk_ctx *ctx, void *scan
+ static const char *const include_dirpath0[] = { "", 0 };
+ static const char *const include_dirpath1[] = { "", "../include/", "../../include/", 0 };
+ static const char *const include_dirpath3[] = {
++ 	"/etc/kbd/" KEYMAPDIR "/include/",
++ 	"/etc/kbd/" KEYMAPDIR "/i386/include/",
++ 	"/etc/kbd/" KEYMAPDIR "/mac/include/",
+ 	DATADIR "/" KEYMAPDIR "/include/",
+ 	DATADIR "/" KEYMAPDIR "/i386/include/",
+ 	DATADIR "/" KEYMAPDIR "/mac/include/", 0
+--- a/src/loadkeys.c
++++ b/src/loadkeys.c
+@@ -27,7 +27,7 @@
+ #include "keymap.h"
+ 
+ static const char *progname         = NULL;
+-static const char *const dirpath1[] = { "", DATADIR "/" KEYMAPDIR "/**", KERNDIR "/", 0 };
++static const char *const dirpath1[] = { "", "/etc/kbd/" KEYMAPDIR "/**", DATADIR "/" KEYMAPDIR "/**", 0 };
+ static const char *const suffixes[] = { "", ".kmap", ".map", 0 };
+ 
+ static void __attribute__((noreturn))
+--- a/src/loadunimap.c
++++ b/src/loadunimap.c
+@@ -30,7 +30,7 @@
+ extern char *progname;
+ extern int force;
+ 
+-static const char *const unidirpath[]  = { "", DATADIR "/" UNIMAPDIR "/", 0 };
++static const char *const unidirpath[]  = { "", "/etc/kbd/" UNIMAPDIR "/", DATADIR "/" UNIMAPDIR "/", 0 };
+ static const char *const unisuffixes[] = { "", ".uni", ".sfm", 0 };
+ 
+ #ifdef MAIN
+--- a/src/mapscrn.c
++++ b/src/mapscrn.c
+@@ -27,7 +27,7 @@ void loadnewmap(int fd, char *mfil);
+ static int ctoi(char *);
+ 
+ /* search for the map file in these directories (with trailing /) */
+-static const char *const mapdirpath[]  = { "", DATADIR "/" TRANSDIR "/", 0 };
++static const char *const mapdirpath[]  = { "", "/etc/kbd/" TRANSDIR "/", DATADIR "/" TRANSDIR "/", 0 };
+ static const char *const mapsuffixes[] = { "", ".trans", "_to_uni.trans", ".acm", 0 };
+ 
+ #ifdef MAIN
+--- a/src/resizecons.c
++++ b/src/resizecons.c
+@@ -101,7 +101,7 @@ static int vga_get_fontheight(void);
+ static void vga_set_cursor(int, int);
+ static void vga_set_verticaldisplayend_lowbyte(int);
+ 
+-const char *const dirpath[]  = { "", DATADIR "/" VIDEOMODEDIR "/", 0 };
++const char *const dirpath[]  = { "", "/etc/kbd/" VIDEOMODEDIR "/", DATADIR "/" VIDEOMODEDIR "/", 0};
+ const char *const suffixes[] = { "", 0 };
+ 
+ int main(int argc, char **argv)
+--- a/src/setfont.c
++++ b/src/setfont.c
+@@ -53,10 +53,10 @@ int force   = 0;
+ int debug   = 0;
+ 
+ /* search for the font in these directories (with trailing /) */
+-const char *const fontdirpath[]  = { "", DATADIR "/" FONTDIR "/", 0 };
++const char *const fontdirpath[]  = { "", "/etc/kbd/" FONTDIR "/", DATADIR "/" FONTDIR "/", 0 };
+ const char *const fontsuffixes[] = { "", ".psfu", ".psf", ".cp", ".fnt", 0 };
+ /* hide partial fonts a bit - loading a single one is a bad idea */
+-const char *const partfontdirpath[]  = { "", DATADIR "/" FONTDIR "/" PARTIALDIR "/", 0 };
++const char *const partfontdirpath[]  = { "", "/etc/kbd/" FONTDIR "/" PARTIALDIR "/", DATADIR "/" FONTDIR "/" PARTIALDIR "/", 0 };
+ const char *const partfontsuffixes[] = { "", 0 };
+ 
+ static inline int
diff --git a/nixpkgs/pkgs/os-specific/linux/kbdlight/default.nix b/nixpkgs/pkgs/os-specific/linux/kbdlight/default.nix
new file mode 100644
index 000000000000..44a63c9f1ece
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kbdlight/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "kbdlight-${version}";
+  version = "1.3";
+
+  src = fetchFromGitHub {
+    owner = "hobarrera";
+    repo = "kbdlight";
+    rev = "v${version}";
+    sha256 = "1f08aid1xrbl4sb5447gkip9lnvkia1c4ap0v8zih5s9w8v72bny";
+  };
+
+  preConfigure = ''
+    substituteInPlace Makefile \
+      --replace /usr/local $out \
+      --replace 4755 0755
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/hobarrera/kbdlight;
+    description = "A very simple application that changes MacBooks' keyboard backlight level";
+    license = licenses.isc;
+    maintainers = [ maintainers.womfoo ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix b/nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix
new file mode 100644
index 000000000000..c00fc1761d59
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel-headers/default.nix
@@ -0,0 +1,85 @@
+{ stdenvNoCC, lib, buildPackages
+, fetchurl, fetchpatch, perl
+, elf-header
+}:
+
+let
+  common = { version, sha256, patches ? [] }: stdenvNoCC.mkDerivation {
+    name = "linux-headers-${version}";
+
+    src = fetchurl {
+      url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
+      inherit sha256;
+    };
+
+    ARCH = stdenvNoCC.hostPlatform.platform.kernelArch or (throw "missing kernelArch");
+
+    # It may look odd that we use `stdenvNoCC`, and yet explicit depend on a cc.
+    # We do this so we have a build->build, not build->host, C compiler.
+    depsBuildBuild = [ buildPackages.stdenv.cc ];
+    # `elf-header` is null when libc provides `elf.h`.
+    nativeBuildInputs = [ perl elf-header ];
+
+    extraIncludeDirs = lib.optional stdenvNoCC.hostPlatform.isPowerPC ["ppc"];
+
+    inherit patches;
+
+    hardeningDisable = lib.optional stdenvNoCC.buildPlatform.isDarwin "format";
+
+    makeFlags = [
+      "SHELL=bash"
+      # Avoid use of runtime build->host compilers for checks. These
+      # checks only cared to work around bugs in very old compilers, so
+      # these changes should be safe.
+      "cc-version:=9999"
+      "cc-fullversion:=999999"
+      # `$(..)` expanded by make alone
+      "HOSTCC:=$(BUILD_CC)"
+      "HOSTCXX:=$(BUILD_CXX)"
+    ];
+
+    # Skip clean on darwin, case-sensitivity issues.
+    buildPhase = lib.optionalString (!stdenvNoCC.buildPlatform.isDarwin) ''
+      make mrproper $makeFlags
+    ''
+    # For some reason, doing `make install_headers` twice, first without
+    # INSTALL_HDR_PATH=$out then with, is neccessary to get this to work
+    # for darwin cross. @Ericson2314 has no idea why.
+    + ''
+      make headers_install $makeFlags
+    '';
+
+    checkPhase = ''
+      make headers_check $makeFlags
+    '';
+
+    installPhase = ''
+      make headers_install INSTALL_HDR_PATH=$out $makeFlags
+    ''
+    # Some builds (e.g. KVM) want a kernel.release.
+    + '' mkdir -p $out/include/config
+      echo "${version}-default" > $out/include/config/kernel.release
+    ''
+    # These oddly named file records teh `SHELL` passed, which causes bootstrap
+    # tools run-time dependency.
+    + ''
+      find "$out" -name '..install.cmd' -print0 | xargs -0 rm
+    '';
+
+    meta = with lib; {
+      description = "Header files and scripts for Linux kernel";
+      license = licenses.gpl2;
+      platforms = platforms.linux;
+    };
+  };
+in {
+
+  linuxHeaders = common {
+    version = "4.19.16";
+    sha256 = "1pqvn6dsh0xhdpawz4ag27vkw1abvb6sn3869i4fbrz33ww8i86q";
+    patches = [
+       ./no-relocs.patch # for building x86 kernel headers on non-ELF platforms
+       ./no-dynamic-cc-version-check.patch # so we can use `stdenvNoCC`, see `makeFlags` above
+    ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch
new file mode 100644
index 000000000000..9b582cac7153
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-dynamic-cc-version-check.patch
@@ -0,0 +1,32 @@
+diff --git a/Makefile b/Makefile
+index 863f58503bee..b778d5023208 100644
+--- a/Makefile
++++ b/Makefile
+@@ -501,11 +501,9 @@ KBUILD_CFLAGS      += $(call cc-option,-fno-PIE)
+ KBUILD_AFLAGS  += $(call cc-option,-fno-PIE)
+ 
+ # check for 'asm goto'
+-ifeq ($(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-goto.sh $(CC) $(KBUILD_CFLAGS)), y)
+   CC_HAVE_ASM_GOTO := 1
+   KBUILD_CFLAGS += -DCC_HAVE_ASM_GOTO
+   KBUILD_AFLAGS += -DCC_HAVE_ASM_GOTO
+-endif
+ 
+ # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
+ # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
+diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
+index 065324a8046f..d09c67194549 100644
+--- a/scripts/Kbuild.include
++++ b/scripts/Kbuild.include
+@@ -216,11 +216,8 @@ cc-disable-warning = $(call try-run-cached,\
+ cc-name = $(call shell-cached,$(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
+ 
+ # cc-version
+-cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
+ 
+ # cc-fullversion
+-cc-fullversion = $(shell $(CONFIG_SHELL) \
+-	$(srctree)/scripts/gcc-version.sh -p $(CC))
+ 
+ # cc-ifversion
+ # Usage:  EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1)
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch
new file mode 100644
index 000000000000..67e8b19e23bd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel-headers/no-relocs.patch
@@ -0,0 +1,13 @@
+diff --git a/arch/x86/Makefile b/arch/x86/Makefile
+index fad55160dcb9..a48c8331cbb2 100644
+--- a/arch/x86/Makefile
++++ b/arch/x86/Makefile
+@@ -239,7 +239,7 @@ ifdef CONFIG_RETPOLINE
+ endif
+ 
+ archscripts: scripts_basic
+-	$(Q)$(MAKE) $(build)=arch/x86/tools relocs
++	$(Q)$(MAKE) $(build)=arch/x86/tools
+ 
+ ###
+ # Syscall table generation
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/bridge-stp-helper.patch b/nixpkgs/pkgs/os-specific/linux/kernel/bridge-stp-helper.patch
new file mode 100644
index 000000000000..70d0f944c2a0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/bridge-stp-helper.patch
@@ -0,0 +1,13 @@
+diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
+index aea3d13..8fcbf81 100644
+--- a/net/bridge/br_private.h
++++ b/net/bridge/br_private.h
+@@ -39,7 +39,7 @@
+ #define BR_GROUPFWD_8021AD	0xB801u
+ 
+ /* Path to usermode spanning tree program */
+-#define BR_STP_PROG	"/sbin/bridge-stp"
++#define BR_STP_PROG	"/run/current-system/sw/bin/bridge-stp"
+ 
+ typedef struct bridge_id bridge_id;
+ typedef struct mac_addr mac_addr;
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/common-config.nix b/nixpkgs/pkgs/os-specific/linux/kernel/common-config.nix
new file mode 100644
index 000000000000..5711e019f95b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/common-config.nix
@@ -0,0 +1,702 @@
+# WARNING/NOTE: whenever you want to add an option here you need to either
+# * mark it as an optional one with `option`,
+# * or make sure it works for all the versions in nixpkgs,
+# * or check for which kernel versions it will work (using kernel
+#   changelog, google or whatever) and mark it with `whenOlder` or
+#   `whenAtLeast`.
+# Then do test your change by building all the kernels (or at least
+# their configs) in Nixpkgs or else you will guarantee lots and lots
+# of pain to users trying to switch to an older kernel because of some
+# hardware problems with a new one.
+
+# Configuration
+{ stdenv, version
+
+, features ? { grsecurity = false; xen_dom0 = false; }
+}:
+
+with stdenv.lib;
+
+  with import ../../../../lib/kernel.nix { inherit (stdenv) lib; inherit version; };
+
+let
+
+  # configuration items have to be part of a subattrs
+  flattenKConf =  nested: mapAttrs (_: head) (zipAttrs (attrValues nested));
+
+  options = {
+
+    debug = {
+      DEBUG_INFO                = if (features.debug or false) then yes else no;
+      DEBUG_KERNEL              = yes;
+      DEBUG_DEVRES              = no;
+      DYNAMIC_DEBUG             = yes;
+      TIMER_STATS               = whenOlder "4.11" yes;
+      DEBUG_NX_TEST             = whenOlder "4.11" no;
+      CPU_NOTIFIER_ERROR_INJECT = whenOlder "4.4" (option no);
+      DEBUG_STACK_USAGE         = no;
+      DEBUG_STACKOVERFLOW       = mkIf (!features.grsecurity) no;
+      RCU_TORTURE_TEST          = no;
+      SCHEDSTATS                = no;
+      DETECT_HUNG_TASK          = yes;
+      CRASH_DUMP                = option no;
+      # Easier debugging of NFS issues.
+      SUNRPC_DEBUG              = yes;
+    };
+
+    power-management = {
+      PM_ADVANCED_DEBUG                = yes;
+      X86_INTEL_LPSS                   = yes;
+      X86_INTEL_PSTATE                 = yes;
+      INTEL_IDLE                       = yes;
+      CPU_FREQ_DEFAULT_GOV_PERFORMANCE = yes;
+      CPU_FREQ_GOV_SCHEDUTIL           = whenAtLeast "4.9" yes;
+      PM_WAKELOCKS                     = yes;
+    };
+
+    external-firmware = {
+      # Support drivers that need external firmware.
+      STANDALONE = no;
+    };
+
+    proc-config-gz = {
+      # Make /proc/config.gz available
+      IKCONFIG      = yes;
+      IKCONFIG_PROC = yes;
+    };
+
+    optimization = {
+      # Optimize with -O2, not -Os
+      CC_OPTIMIZE_FOR_SIZE = no;
+    };
+
+    memtest = {
+      MEMTEST = yes;
+    };
+
+    # Include the CFQ I/O scheduler in the kernel, rather than as a
+    # module, so that the initrd gets a good I/O scheduler.
+    scheduler = {
+      IOSCHED_CFQ = whenOlder "5.0" yes; # Removed in 5.0-RC1
+      BLK_CGROUP  = yes; # required by CFQ"
+      IOSCHED_DEADLINE = whenOlder "5.0" yes; # Removed in 5.0-RC1
+      MQ_IOSCHED_DEADLINE = whenAtLeast "4.11" yes;
+      BFQ_GROUP_IOSCHED = whenAtLeast "4.12" yes;
+      MQ_IOSCHED_KYBER = whenAtLeast "4.12" yes;
+      IOSCHED_BFQ = whenAtLeast "4.12" module;
+    };
+
+    # Enable NUMA.
+    numa = {
+      NUMA  = option yes;
+    };
+
+    networking = {
+      NET                = yes;
+      IP_PNP             = no;
+      NETFILTER          = yes;
+      NETFILTER_ADVANCED = yes;
+      IP_VS_PROTO_TCP    = yes;
+      IP_VS_PROTO_UDP    = yes;
+      IP_VS_PROTO_ESP    = yes;
+      IP_VS_PROTO_AH     = yes;
+      IP_DCCP_CCID3      = no; # experimental
+      CLS_U32_PERF       = yes;
+      CLS_U32_MARK       = yes;
+      BPF_JIT            = mkIf (stdenv.hostPlatform.system == "x86_64-linux") yes;
+      WAN                = yes;
+      # Required by systemd per-cgroup firewalling
+      CGROUP_BPF                  = option yes;
+      CGROUP_NET_PRIO             = yes; # Required by systemd
+      IP_ROUTE_VERBOSE            = yes;
+      IP_MROUTE_MULTIPLE_TABLES   = yes;
+      IP_MULTICAST                = yes;
+      IPV6_ROUTER_PREF            = yes;
+      IPV6_ROUTE_INFO             = yes;
+      IPV6_OPTIMISTIC_DAD         = yes;
+      IPV6_MULTIPLE_TABLES        = yes;
+      IPV6_SUBTREES               = yes;
+      IPV6_MROUTE                 = yes;
+      IPV6_MROUTE_MULTIPLE_TABLES = yes;
+      IPV6_PIMSM_V2               = yes;
+      IPV6_FOU_TUNNEL             = whenAtLeast "4.7" module;
+      NET_CLS_BPF                 = whenAtLeast "4.4" module;
+      NET_ACT_BPF                 = whenAtLeast "4.4" module;
+      L2TP_V3                     = yes;
+      L2TP_IP                     = module;
+      L2TP_ETH                    = module;
+      BRIDGE_VLAN_FILTERING       = yes;
+      BONDING                     = module;
+      NET_L3_MASTER_DEV           = option yes;
+      NET_FOU_IP_TUNNELS          = option yes;
+      IP_NF_TARGET_REDIRECT       = module;
+
+      PPP_MULTILINK = yes; # PPP multilink support
+      PPP_FILTER    = yes;
+
+      # needed for iwd WPS support (wpa_supplicant replacement)
+      KEY_DH_OPERATIONS = whenAtLeast "4.7" yes;
+
+      # needed for nftables
+      NF_TABLES_INET              = whenAtLeast "4.17" yes;
+      NF_TABLES_NETDEV            = whenAtLeast "4.17" yes;
+      NF_TABLES_IPV4              = whenAtLeast "4.17" yes;
+      NF_TABLES_ARP               = whenAtLeast "4.17" yes;
+      NF_TABLES_IPV6              = whenAtLeast "4.17" yes;
+      NF_TABLES_BRIDGE            = whenAtLeast "4.17" yes;
+    };
+
+    wireless = {
+      CFG80211_WEXT         = option yes; # Without it, ipw2200 drivers don't build
+      IPW2100_MONITOR       = option yes; # support promiscuous mode
+      IPW2200_MONITOR       = option yes; # support promiscuous mode
+      HOSTAP_FIRMWARE       = option yes; # Support downloading firmware images with Host AP driver
+      HOSTAP_FIRMWARE_NVRAM = option yes;
+      ATH9K_PCI             = option yes; # Detect Atheros AR9xxx cards on PCI(e) bus
+      ATH9K_AHB             = option yes; # Ditto, AHB bus
+      B43_PHY_HT            = option yes;
+      BCMA_HOST_PCI         = option yes;
+    };
+
+    fb = {
+      FB                  = yes;
+      FB_EFI              = yes;
+      FB_NVIDIA_I2C       = yes; # Enable DDC Support
+      FB_RIVA_I2C         = yes;
+      FB_ATY_CT           = yes; # Mach64 CT/VT/GT/LT (incl. 3D RAGE) support
+      FB_ATY_GX           = yes; # Mach64 GX support
+      FB_SAVAGE_I2C       = yes;
+      FB_SAVAGE_ACCEL     = yes;
+      FB_SIS_300          = yes;
+      FB_SIS_315          = yes;
+      FB_3DFX_ACCEL       = yes;
+      FB_VESA             = yes;
+      FRAMEBUFFER_CONSOLE = yes;
+      FRAMEBUFFER_CONSOLE_ROTATION = yes;
+      FB_GEODE            = mkIf (stdenv.hostPlatform.system == "i686-linux") yes;
+    };
+
+    video = {
+      # Enable KMS for devices whose X.org driver supports it
+      DRM_I915_KMS           = whenOlder "4.3" yes;
+      # Allow specifying custom EDID on the kernel command line
+      DRM_LOAD_EDID_FIRMWARE = yes;
+      VGA_SWITCHEROO         = yes; # Hybrid graphics support
+      DRM_GMA600             = yes;
+      DRM_GMA3600            = yes;
+      # necessary for amdgpu polaris support
+      DRM_AMD_POWERPLAY = whenBetween "4.5" "4.9" yes;
+      # (experimental) amdgpu support for verde and newer chipsets
+      DRM_AMDGPU_SI = whenAtLeast "4.9" yes;
+      # (stable) amdgpu support for bonaire and newer chipsets
+      DRM_AMDGPU_CIK = whenAtLeast "4.9" yes;
+    } // optionalAttrs (stdenv.hostPlatform.system == "x86_64-linux") {
+      # Intel GVT-g graphics virtualization supports 64-bit only
+      DRM_I915_GVT = whenAtLeast "4.16" yes;
+      DRM_I915_GVT_KVMGT = whenAtLeast "4.16" module;
+    };
+
+    sound = {
+      SND_DYNAMIC_MINORS  = yes;
+      SND_AC97_POWER_SAVE = yes; # AC97 Power-Saving Mode
+      SND_HDA_INPUT_BEEP  = yes; # Support digital beep via input layer
+      SND_HDA_RECONFIG    = yes; # Support reconfiguration of jack functions
+      # Support configuring jack functions via fw mechanism at boot
+      SND_HDA_PATCH_LOADER = yes;
+      SND_OSSEMUL         = yes;
+      SND_USB_CAIAQ_INPUT = yes;
+      # Enable PSS mixer (Beethoven ADSP-16 and other compatible)
+      PSS_MIXER           = whenOlder "4.12" yes;
+    };
+
+    usb-serial = {
+      USB_SERIAL_GENERIC          = yes; # USB Generic Serial Driver
+    } // optionalAttrs (versionOlder version "4.16") {
+      # Include firmware for various USB serial devices.
+      # Only applicable for kernels below 4.16, after that no firmware is shipped in the kernel tree.
+      USB_SERIAL_KEYSPAN_MPR      = yes;
+      USB_SERIAL_KEYSPAN_USA28    = yes;
+      USB_SERIAL_KEYSPAN_USA28X   = yes;
+      USB_SERIAL_KEYSPAN_USA28XA  = yes;
+      USB_SERIAL_KEYSPAN_USA28XB  = yes;
+      USB_SERIAL_KEYSPAN_USA19    = yes;
+      USB_SERIAL_KEYSPAN_USA18X   = yes;
+      USB_SERIAL_KEYSPAN_USA19W   = yes;
+      USB_SERIAL_KEYSPAN_USA19QW  = yes;
+      USB_SERIAL_KEYSPAN_USA19QI  = yes;
+      USB_SERIAL_KEYSPAN_USA49W   = yes;
+      USB_SERIAL_KEYSPAN_USA49WLC = yes;
+    };
+
+    usb = {
+      USB_DEBUG = { optional = true; tristate = whenOlder "4.18" "n";};
+      USB_EHCI_ROOT_HUB_TT = yes; # Root Hub Transaction Translators
+      USB_EHCI_TT_NEWSCHED = yes; # Improved transaction translator scheduling
+    };
+
+    # Filesystem options - in particular, enable extended attributes and
+    # ACLs for all filesystems that support them.
+    filesystem = {
+      FANOTIFY        = yes;
+      TMPFS           = yes;
+      TMPFS_POSIX_ACL = yes;
+      FS_ENCRYPTION   = if (versionAtLeast version "5.1") then yes else whenAtLeast "4.9" (option module);
+
+      EXT2_FS_XATTR     = yes;
+      EXT2_FS_POSIX_ACL = yes;
+      EXT2_FS_SECURITY  = yes;
+      EXT2_FS_XIP       = whenOlder "4.0" yes; # Ext2 execute in place support
+
+      EXT3_FS_POSIX_ACL = yes;
+      EXT3_FS_SECURITY  = yes;
+
+      EXT4_FS_POSIX_ACL = yes;
+      EXT4_FS_SECURITY  = yes;
+      EXT4_ENCRYPTION   = { optional = true; tristate = if (versionOlder version "4.8") then "m" else "y"; };
+
+      REISERFS_FS_XATTR     = option yes;
+      REISERFS_FS_POSIX_ACL = option yes;
+      REISERFS_FS_SECURITY  = option yes;
+
+      JFS_POSIX_ACL = option yes;
+      JFS_SECURITY  = option yes;
+
+      XFS_QUOTA     = option yes;
+      XFS_POSIX_ACL = option yes;
+      XFS_RT        = option yes; # XFS Realtime subvolume support
+
+      OCFS2_DEBUG_MASKLOG = option no;
+
+      BTRFS_FS_POSIX_ACL = yes;
+
+      UBIFS_FS_ADVANCED_COMPR = option yes;
+
+      F2FS_FS             = module;
+      F2FS_FS_SECURITY    = option yes;
+      F2FS_FS_ENCRYPTION  = option yes;
+      UDF_FS              = module;
+
+      NFSD_PNFS              = whenBetween "4.0" "4.6" yes;
+      NFSD_V2_ACL            = yes;
+      NFSD_V3                = yes;
+      NFSD_V3_ACL            = yes;
+      NFSD_V4                = yes;
+      NFSD_V4_SECURITY_LABEL = yes;
+
+      NFS_FSCACHE           = yes;
+      NFS_SWAP              = yes;
+      NFS_V3_ACL            = yes;
+      NFS_V4_1              = yes;  # NFSv4.1 client support
+      NFS_V4_2              = yes;
+      NFS_V4_SECURITY_LABEL = yes;
+
+      CIFS_XATTR        = yes;
+      CIFS_POSIX        = option yes;
+      CIFS_FSCACHE      = yes;
+      CIFS_STATS        = whenOlder "4.19" yes;
+      CIFS_WEAK_PW_HASH = yes;
+      CIFS_UPCALL       = yes;
+      CIFS_ACL          = yes;
+      CIFS_DFS_UPCALL   = yes;
+      CIFS_SMB2         = whenOlder "4.13" yes;
+
+      CEPH_FSCACHE      = yes;
+      CEPH_FS_POSIX_ACL = yes;
+
+      SQUASHFS_FILE_DIRECT         = yes;
+      SQUASHFS_DECOMP_MULTI_PERCPU = yes;
+      SQUASHFS_XATTR               = yes;
+      SQUASHFS_ZLIB                = yes;
+      SQUASHFS_LZO                 = yes;
+      SQUASHFS_XZ                  = yes;
+      SQUASHFS_LZ4                 = yes;
+      SQUASHFS_ZSTD                = whenAtLeast "4.14" yes;
+
+      # Native Language Support modules, needed by some filesystems
+      NLS              = yes;
+      NLS_DEFAULT      = freeform "utf8";
+      NLS_UTF8         = module;
+      NLS_CODEPAGE_437 = module; # VFAT default for the codepage= mount option
+      NLS_ISO8859_1    = module; # VFAT default for the iocharset= mount option
+
+      DEVTMPFS = yes;
+    };
+
+    security = {
+      # Detect writes to read-only module pages
+      DEBUG_SET_MODULE_RONX            = { optional = true; tristate = whenOlder "4.11" "y"; };
+      RANDOMIZE_BASE                   = option yes;
+      STRICT_DEVMEM                    = option yes; # Filter access to /dev/mem
+      SECURITY_SELINUX_BOOTPARAM_VALUE = freeform "0"; # Disable SELinux by default
+      # Prevent processes from ptracing non-children processes
+      SECURITY_YAMA                    = option yes;
+      DEVKMEM                          = mkIf (!features.grsecurity) no; # Disable /dev/kmem
+
+      USER_NS                          = yes; # Support for user namespaces
+
+      SECURITY_APPARMOR                = yes;
+      DEFAULT_SECURITY_APPARMOR        = yes;
+
+    } // optionalAttrs (!stdenv.hostPlatform.isAarch32) {
+
+      # Detect buffer overflows on the stack
+      CC_STACKPROTECTOR_REGULAR = {optional = true; tristate = whenOlder "4.18" "y";};
+    };
+
+    microcode = {
+      MICROCODE       = yes;
+      MICROCODE_INTEL = yes;
+      MICROCODE_AMD   = yes;
+
+      MICROCODE_EARLY       = whenOlder "4.4" yes;
+      MICROCODE_INTEL_EARLY = whenOlder "4.4" yes;
+      MICROCODE_AMD_EARLY   = whenOlder "4.4" yes;
+    } // optionalAttrs (versionAtLeast version "4.10") {
+      # Write Back Throttling
+      # https://lwn.net/Articles/682582/
+      # https://bugzilla.kernel.org/show_bug.cgi?id=12309#c655
+      BLK_WBT    = yes;
+      BLK_WBT_SQ = whenOlder "5.0" yes; # Removed in 5.0-RC1
+      BLK_WBT_MQ = yes;
+    };
+
+    container = {
+      NAMESPACES     = yes; #  Required by 'unshare' used by 'nixos-install'
+      RT_GROUP_SCHED = no;
+      CGROUP_DEVICE  = yes;
+      CGROUP_HUGETLB = yes;
+      CGROUP_PERF    = yes;
+      CGROUP_RDMA    = whenAtLeast "4.11" yes;
+
+      MEMCG                    = yes;
+      MEMCG_SWAP               = yes;
+
+      DEVPTS_MULTIPLE_INSTANCES = whenOlder "4.7" yes;
+      BLK_DEV_THROTTLING        = yes;
+      CFQ_GROUP_IOSCHED         = whenOlder "5.0" yes; # Removed in 5.0-RC1
+      CGROUP_PIDS               = whenAtLeast "4.3" yes;
+    };
+
+    staging = {
+      # Enable staging drivers.  These are somewhat experimental, but
+      # they generally don't hurt.
+      STAGING = yes;
+    };
+
+    proc-events = {
+      # PROC_EVENTS requires that the netlink connector is not built
+      # as a module.  This is required by libcgroup's cgrulesengd.
+      CONNECTOR   = yes;
+      PROC_EVENTS = yes;
+    };
+
+    tracing = {
+      FTRACE                = yes;
+      KPROBES               = yes;
+      FUNCTION_TRACER       = yes;
+      FTRACE_SYSCALLS       = yes;
+      SCHED_TRACER          = yes;
+      STACK_TRACER          = yes;
+      UPROBE_EVENT          = { optional = true; tristate = whenOlder "4.11" "y";};
+      UPROBE_EVENTS         = { optional = true; tristate = whenAtLeast "4.11" "y";};
+      BPF_SYSCALL           = whenAtLeast "4.4" yes;
+      BPF_EVENTS            = whenAtLeast "4.4" yes;
+      FUNCTION_PROFILER     = yes;
+      RING_BUFFER_BENCHMARK = no;
+    };
+
+    virtualisation = {
+      PARAVIRT = option yes;
+
+      HYPERVISOR_GUEST = mkIf (!features.grsecurity) yes;
+      PARAVIRT_SPINLOCKS  = option yes;
+
+      KVM_APIC_ARCHITECTURE             = whenOlder "4.8" yes;
+      KVM_ASYNC_PF                      = yes;
+      KVM_COMPAT = { optional = true; tristate = whenBetween "4.0" "4.12" "y"; };
+      KVM_DEVICE_ASSIGNMENT  = { optional = true; tristate = whenBetween "3.10" "4.12" "y"; };
+      KVM_GENERIC_DIRTYLOG_READ_PROTECT = whenAtLeast "4.0"  yes;
+      KVM_GUEST                         = mkIf (!features.grsecurity) yes;
+      KVM_MMIO                          = yes;
+      KVM_VFIO                          = yes;
+      KSM = yes;
+      VIRT_DRIVERS = yes;
+      # We nneed 64 GB (PAE) support for Xen guest support
+      HIGHMEM64G = { optional = true; tristate = mkIf (!stdenv.is64bit) "y";};
+
+      VFIO_PCI_VGA = mkIf stdenv.is64bit yes;
+
+    } // optionalAttrs (stdenv.isx86_64 || stdenv.isi686) ({
+      XEN = option yes;
+
+      # XXX: why isn't this in the xen-dom0 conditional section below?
+      XEN_DOM0 = option yes;
+
+    } // optionalAttrs features.xen_dom0 {
+      PCI_XEN                     = option yes;
+      HVC_XEN                     = option yes;
+      HVC_XEN_FRONTEND            = option yes;
+      XEN_SYS_HYPERVISOR          = option yes;
+      SWIOTLB_XEN                 = option yes;
+      XEN_BACKEND                 = option yes;
+      XEN_BALLOON                 = option yes;
+      XEN_BALLOON_MEMORY_HOTPLUG  = option yes;
+      XEN_EFI                     = option yes;
+      XEN_HAVE_PVMMU              = option yes;
+      XEN_MCE_LOG                 = option yes;
+      XEN_PVH                     = option yes;
+      XEN_PVHVM                   = option yes;
+      XEN_SAVE_RESTORE            = option yes;
+      XEN_SCRUB_PAGES             = option yes;
+      XEN_SELFBALLOONING          = option yes;
+      XEN_STUB                    = option yes;
+      XEN_TMEM                    = option yes;
+    });
+
+    media = {
+      MEDIA_DIGITAL_TV_SUPPORT = yes;
+      MEDIA_CAMERA_SUPPORT     = yes;
+      MEDIA_RC_SUPPORT         = whenOlder "4.14" yes;
+      MEDIA_CONTROLLER         = yes;
+      MEDIA_PCI_SUPPORT        = yes;
+      MEDIA_USB_SUPPORT        = yes;
+      MEDIA_ANALOG_TV_SUPPORT  = yes;
+      VIDEO_STK1160_COMMON     = module;
+      VIDEO_STK1160_AC97       = whenOlder "4.11" yes;
+    };
+
+    "9p" = {
+      # Enable the 9P cache to speed up NixOS VM tests.
+      "9P_FSCACHE"      = option yes;
+      "9P_FS_POSIX_ACL" = option yes;
+    };
+
+    huge-page = {
+      TRANSPARENT_HUGEPAGE         = option yes;
+      TRANSPARENT_HUGEPAGE_ALWAYS  = option no;
+      TRANSPARENT_HUGEPAGE_MADVISE = option yes;
+    };
+
+    zram = {
+      ZRAM     = module;
+      ZSWAP    = option yes;
+      ZBUD     = option yes;
+      ZSMALLOC = module;
+    };
+
+    brcmfmac = {
+      # Enable PCIe and USB for the brcmfmac driver
+      BRCMFMAC_USB  = option yes;
+      BRCMFMAC_PCIE = option yes;
+    };
+
+    # Support x2APIC (which requires IRQ remapping)
+    x2apic = optionalAttrs (stdenv.hostPlatform.system == "x86_64-linux") {
+      X86_X2APIC = yes;
+      IRQ_REMAP  = yes;
+    };
+
+    # Disable various self-test modules that have no use in a production system
+    tests = {
+      # This menu disables all/most of them on >= 4.16
+      RUNTIME_TESTING_MENU = option no;
+    } // optionalAttrs (versionOlder version "4.16") {
+      # For older kernels, painstakingly disable each symbol.
+      ARM_KPROBES_TEST    = option no;
+      ASYNC_RAID6_TEST    = option no;
+      ATOMIC64_SELFTEST   = option no;
+      BACKTRACE_SELF_TEST = option no;
+      INTERVAL_TREE_TEST  = option no;
+      PERCPU_TEST         = option no;
+      RBTREE_TEST         = option no;
+      TEST_BITMAP         = option no;
+      TEST_BPF            = option no;
+      TEST_FIRMWARE       = option no;
+      TEST_HASH           = option no;
+      TEST_HEXDUMP        = option no;
+      TEST_KMOD           = option no;
+      TEST_KSTRTOX        = option no;
+      TEST_LIST_SORT      = option no;
+      TEST_LKM            = option no;
+      TEST_PARMAN         = option no;
+      TEST_PRINTF         = option no;
+      TEST_RHASHTABLE     = option no;
+      TEST_SORT           = option no;
+      TEST_STATIC_KEYS    = option no;
+      TEST_STRING_HELPERS = option no;
+      TEST_UDELAY         = option no;
+      TEST_USER_COPY      = option no;
+      TEST_UUID           = option no;
+    } // {
+      CRC32_SELFTEST           = option no;
+      CRYPTO_TEST              = option no;
+      EFI_TEST                 = option no;
+      GLOB_SELFTEST            = option no;
+      DRM_DEBUG_MM_SELFTEST    = { optional = true; tristate = whenOlder "4.18" "n";};
+      LNET_SELFTEST            = { optional = true; tristate = whenOlder "4.18" "n";};
+      LOCK_TORTURE_TEST        = option no;
+      MTD_TESTS                = option no;
+      NOTIFIER_ERROR_INJECTION = option no;
+      RCU_PERF_TEST            = option no;
+      RCU_TORTURE_TEST         = option no;
+      TEST_ASYNC_DRIVER_PROBE  = option no;
+      WW_MUTEX_SELFTEST        = option no;
+      XZ_DEC_TEST              = option no;
+    } // optionalAttrs (features.criu or false) ({
+      EXPERT              = yes;
+      CHECKPOINT_RESTORE  = yes;
+    } // optionalAttrs (features.criu_revert_expert or true) {
+      RFKILL_INPUT          = option yes;
+      HID_PICOLCD_FB        = option yes;
+      HID_PICOLCD_BACKLIGHT = option yes;
+      HID_PICOLCD_LCD       = option yes;
+      HID_PICOLCD_LEDS      = option yes;
+      HID_PICOLCD_CIR       = option yes;
+      DEBUG_MEMORY_INIT     = option yes;
+    });
+
+    misc = {
+      MODULE_COMPRESS    = yes;
+      MODULE_COMPRESS_XZ = yes;
+      KERNEL_XZ          = yes;
+
+      UNIX               = yes;  # Unix domain sockets.
+
+      MD                 = yes;     # Device mapper (RAID, LVM, etc.)
+
+      # Enable initrd support.
+      BLK_DEV_RAM       = yes;
+      BLK_DEV_INITRD    = yes;
+
+      PM_TRACE_RTC         = no; # Disable some expensive (?) features.
+      ACCESSIBILITY        = yes; # Accessibility support
+      AUXDISPLAY           = yes; # Auxiliary Display support
+      DONGLE               = whenOlder "4.17" yes; # Serial dongle support
+      HIPPI                = yes;
+      MTD_COMPLEX_MAPPINGS = yes; # needed for many devices
+
+      SCSI_LOWLEVEL        = yes; # enable lots of SCSI devices
+      SCSI_LOWLEVEL_PCMCIA = yes;
+      SCSI_SAS_ATA         = yes; # added to enable detection of hard drive
+
+      SPI        = yes; # needed for many devices
+      SPI_MASTER = yes;
+
+      "8139TOO_8129" = yes;
+      "8139TOO_PIO"  = no; # PIO is slower
+
+      AIC79XX_DEBUG_ENABLE = no;
+      AIC7XXX_DEBUG_ENABLE = no;
+      AIC94XX_DEBUG = no;
+      B43_PCMCIA = { optional=true; tristate = whenOlder "4.4" "y";};
+
+      BLK_DEV_INTEGRITY       = yes;
+
+      BLK_SED_OPAL = whenAtLeast "4.14" yes;
+
+      BSD_PROCESS_ACCT_V3 = yes;
+
+      BT_HCIUART_BCSP = option yes;
+      BT_HCIUART_H4   = option yes; # UART (H4) protocol support
+      BT_HCIUART_LL   = option yes;
+      BT_RFCOMM_TTY   = option yes; # RFCOMM TTY support
+
+      CLEANCACHE = option yes;
+      CRASH_DUMP = option no;
+
+      DVB_DYNAMIC_MINORS = option yes; # we use udev
+
+      EFI_STUB            = yes; # EFI bootloader in the bzImage itself
+      CGROUPS             = yes; # used by systemd
+      FHANDLE             = yes; # used by systemd
+      SECCOMP             = yes; # used by systemd >= 231
+      SECCOMP_FILTER      = yes; # ditto
+      POSIX_MQUEUE        = yes;
+      FRONTSWAP           = yes;
+      FUSION              = yes; # Fusion MPT device support
+      IDE                 = no; # deprecated IDE support
+      IDLE_PAGE_TRACKING  = yes;
+      IRDA_ULTRA          = whenOlder "4.17" yes; # Ultra (connectionless) protocol
+
+      JOYSTICK_IFORCE_232 = option yes; # I-Force Serial joysticks and wheels
+      JOYSTICK_IFORCE_USB = option yes; # I-Force USB joysticks and wheels
+      JOYSTICK_XPAD_FF    = option yes; # X-Box gamepad rumble support
+      JOYSTICK_XPAD_LEDS  = option yes; # LED Support for Xbox360 controller 'BigX' LED
+
+      KEXEC_FILE      = option yes;
+      KEXEC_JUMP      = option yes;
+
+      # Windows Logical Disk Manager (Dynamic Disk) support
+      LDM_PARTITION         = yes;
+      LOGIRUMBLEPAD2_FF     = yes; # Logitech Rumblepad 2 force feedback
+      LOGO                  = no; # not needed
+      MEDIA_ATTACH          = yes;
+      MEGARAID_NEWGEN       = yes;
+
+      MLX4_EN_VXLAN = whenOlder "4.8" yes;
+      MLX5_CORE_EN       = option yes;
+
+      PSI = whenAtLeast "4.20" yes;
+
+      MODVERSIONS        = whenOlder "4.9" yes;
+      MOUSE_PS2_ELANTECH = yes; # Elantech PS/2 protocol extension
+      MTRR_SANITIZER     = yes;
+      NET_FC             = yes; # Fibre Channel driver support
+      # GPIO on Intel Bay Trail, for some Chromebook internal eMMC disks
+      PINCTRL_BAYTRAIL   = yes;
+      # 8 is default. Modern gpt tables on eMMC may go far beyond 8.
+      MMC_BLOCK_MINORS   = freeform "32";
+
+      REGULATOR  = yes; # Voltage and Current Regulator Support
+      RC_DEVICES = option yes; # Enable IR devices
+
+      RT2800USB_RT53XX = yes;
+      RT2800USB_RT55XX = yes;
+
+      SCHED_AUTOGROUP  = yes;
+      CFS_BANDWIDTH    = yes;
+
+      SCSI_LOGGING = yes; # SCSI logging facility
+      SERIAL_8250  = yes; # 8250/16550 and compatible serial support
+
+      SLIP_COMPRESSED = yes; # CSLIP compressed headers
+      SLIP_SMART      = yes;
+
+      HWMON         = yes;
+      THERMAL_HWMON = yes; # Hardware monitoring support
+      UEVENT_HELPER = no;
+
+      USERFAULTFD   = yes;
+      X86_CHECK_BIOS_CORRUPTION = yes;
+      X86_MCE                   = yes;
+
+      # Our initrd init uses shebang scripts, so can't be modular.
+      BINFMT_SCRIPT = yes;
+      # For systemd-binfmt
+      BINFMT_MISC   = option yes;
+
+      # Disable the firmware helper fallback, udev doesn't implement it any more
+      FW_LOADER_USER_HELPER_FALLBACK = option no;
+
+      HOTPLUG_PCI_ACPI = yes; # PCI hotplug using ACPI
+      HOTPLUG_PCI_PCIE = yes; # PCI-Expresscard hotplug support
+
+      # Enable AMD's ROCm GPU compute stack
+      HSA_AMD = whenAtLeast "4.20" yes;
+
+    } // optionalAttrs (stdenv.hostPlatform.system == "x86_64-linux" || stdenv.hostPlatform.system == "aarch64-linux") {
+      # Enable memory hotplug support
+      # Allows you to dynamically add & remove memory to a VM client running NixOS without requiring a reboot
+      ACPI_HOTPLUG_MEMORY = yes;
+      MEMORY_HOTPLUG = yes;
+      MEMORY_HOTREMOVE = yes;
+      MIGRATION = yes;
+      SPARSEMEM = yes;
+
+      # Bump the maximum number of CPUs to support systems like EC2 x1.*
+      # instances and Xeon Phi.
+      NR_CPUS = freeform "384";
+    };
+  };
+in
+  flattenKConf options
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.11.patch b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.11.patch
new file mode 100644
index 000000000000..38cc0532ba97
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.11.patch
@@ -0,0 +1,784 @@
+commit 827b86ad1dd21feed4c0b99faf6059f245f7dadb
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Mar 11 07:31:23 2016 -0500
+
+    sched: Misc preps for cgroup unified hierarchy interface
+    
+    Make the following changes in preparation for the cpu controller
+    interface implementation for the unified hierarchy.  This patch
+    doesn't cause any functional differences.
+    
+    * s/cpu_stats_show()/cpu_cfs_stats_show()/
+    
+    * s/cpu_files/cpu_legacy_files/
+    
+    * Separate out cpuacct_stats_read() from cpuacct_stats_show().  While
+      at it, make the @val array u64 for consistency.
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+    Cc: Ingo Molnar <mingo@redhat.com>
+    Cc: Peter Zijlstra <peterz@infradead.org>
+    Cc: Li Zefan <lizefan@huawei.com>
+    Cc: Johannes Weiner <hannes@cmpxchg.org>
+
+diff --git a/kernel/sched/core.c b/kernel/sched/core.c
+index 3b31fc05a0f1..a1b95e83fa87 100644
+--- a/kernel/sched/core.c
++++ b/kernel/sched/core.c
+@@ -7174,7 +7174,7 @@ static int __cfs_schedulable(struct task_group *tg, u64 period, u64 quota)
+ 	return ret;
+ }
+ 
+-static int cpu_stats_show(struct seq_file *sf, void *v)
++static int cpu_cfs_stats_show(struct seq_file *sf, void *v)
+ {
+ 	struct task_group *tg = css_tg(seq_css(sf));
+ 	struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
+@@ -7214,7 +7214,7 @@ static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css,
+ }
+ #endif /* CONFIG_RT_GROUP_SCHED */
+ 
+-static struct cftype cpu_files[] = {
++static struct cftype cpu_legacy_files[] = {
+ #ifdef CONFIG_FAIR_GROUP_SCHED
+ 	{
+ 		.name = "shares",
+@@ -7235,7 +7235,7 @@ static struct cftype cpu_files[] = {
+ 	},
+ 	{
+ 		.name = "stat",
+-		.seq_show = cpu_stats_show,
++		.seq_show = cpu_cfs_stats_show,
+ 	},
+ #endif
+ #ifdef CONFIG_RT_GROUP_SCHED
+@@ -7261,7 +7261,7 @@ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.fork		= cpu_cgroup_fork,
+ 	.can_attach	= cpu_cgroup_can_attach,
+ 	.attach		= cpu_cgroup_attach,
+-	.legacy_cftypes	= cpu_files,
++	.legacy_cftypes	= cpu_legacy_files,
+ 	.early_init	= true,
+ };
+ 
+diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
+index f95ab29a45d0..6151c23f722f 100644
+--- a/kernel/sched/cpuacct.c
++++ b/kernel/sched/cpuacct.c
+@@ -276,26 +276,33 @@ static int cpuacct_all_seq_show(struct seq_file *m, void *V)
+ 	return 0;
+ }
+ 
+-static int cpuacct_stats_show(struct seq_file *sf, void *v)
++static void cpuacct_stats_read(struct cpuacct *ca,
++			       u64 (*val)[CPUACCT_STAT_NSTATS])
+ {
+-	struct cpuacct *ca = css_ca(seq_css(sf));
+-	s64 val[CPUACCT_STAT_NSTATS];
+ 	int cpu;
+-	int stat;
+ 
+-	memset(val, 0, sizeof(val));
++	memset(val, 0, sizeof(*val));
++
+ 	for_each_possible_cpu(cpu) {
+ 		u64 *cpustat = per_cpu_ptr(ca->cpustat, cpu)->cpustat;
+ 
+-		val[CPUACCT_STAT_USER]   += cpustat[CPUTIME_USER];
+-		val[CPUACCT_STAT_USER]   += cpustat[CPUTIME_NICE];
+-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SYSTEM];
+-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_IRQ];
+-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SOFTIRQ];
++		(*val)[CPUACCT_STAT_USER]   += cpustat[CPUTIME_USER];
++		(*val)[CPUACCT_STAT_USER]   += cpustat[CPUTIME_NICE];
++		(*val)[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SYSTEM];
++		(*val)[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_IRQ];
++		(*val)[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SOFTIRQ];
+ 	}
++}
++
++static int cpuacct_stats_show(struct seq_file *sf, void *v)
++{
++	u64 val[CPUACCT_STAT_NSTATS];
++	int stat;
++
++	cpuacct_stats_read(css_ca(seq_css(sf)), &val);
+ 
+ 	for (stat = 0; stat < CPUACCT_STAT_NSTATS; stat++) {
+-		seq_printf(sf, "%s %lld\n",
++		seq_printf(sf, "%s %llu\n",
+ 			   cpuacct_stat_desc[stat],
+ 			   (long long)nsec_to_clock_t(val[stat]));
+ 	}
+
+commit fdb64d002b3a223ce4bb11aa4448a42050470052
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Mar 11 07:31:23 2016 -0500
+
+    sched: Implement interface for cgroup unified hierarchy
+    
+    While the cpu controller doesn't have any functional problems, there
+    are a couple interface issues which can be addressed in the v2
+    interface.
+    
+    * cpuacct being a separate controller.  This separation is artificial
+      and rather pointless as demonstrated by most use cases co-mounting
+      the two controllers.  It also forces certain information to be
+      accounted twice.
+    
+    * Use of different time units.  Writable control knobs use
+      microseconds, some stat fields use nanoseconds while other cpuacct
+      stat fields use centiseconds.
+    
+    * Control knobs which can't be used in the root cgroup still show up
+      in the root.
+    
+    * Control knob names and semantics aren't consistent with other
+      controllers.
+    
+    This patchset implements cpu controller's interface on the unified
+    hierarchy which adheres to the controller file conventions described
+    in Documentation/cgroups/unified-hierarchy.txt.  Overall, the
+    following changes are made.
+    
+    * cpuacct is implictly enabled and disabled by cpu and its information
+      is reported through "cpu.stat" which now uses microseconds for all
+      time durations.  All time duration fields now have "_usec" appended
+      to them for clarity.  While this doesn't solve the double accounting
+      immediately, once majority of users switch to v2, cpu can directly
+      account and report the relevant stats and cpuacct can be disabled on
+      the unified hierarchy.
+    
+      Note that cpuacct.usage_percpu is currently not included in
+      "cpu.stat".  If this information is actually called for, it can be
+      added later.
+    
+    * "cpu.shares" is replaced with "cpu.weight" and operates on the
+      standard scale defined by CGROUP_WEIGHT_MIN/DFL/MAX (1, 100, 10000).
+      The weight is scaled to scheduler weight so that 100 maps to 1024
+      and the ratio relationship is preserved - if weight is W and its
+      scaled value is S, W / 100 == S / 1024.  While the mapped range is a
+      bit smaller than the orignal scheduler weight range, the dead zones
+      on both sides are relatively small and covers wider range than the
+      nice value mappings.  This file doesn't make sense in the root
+      cgroup and isn't create on root.
+    
+    * "cpu.cfs_quota_us" and "cpu.cfs_period_us" are replaced by "cpu.max"
+      which contains both quota and period.
+    
+    * "cpu.rt_runtime_us" and "cpu.rt_period_us" are replaced by
+      "cpu.rt.max" which contains both runtime and period.
+    
+    v2: cpu_stats_show() was incorrectly using CONFIG_FAIR_GROUP_SCHED for
+        CFS bandwidth stats and also using raw division for u64.  Use
+        CONFIG_CFS_BANDWITH and do_div() instead.
+    
+        The semantics of "cpu.rt.max" is not fully decided yet.  Dropped
+        for now.
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+    Cc: Ingo Molnar <mingo@redhat.com>
+    Cc: Peter Zijlstra <peterz@infradead.org>
+    Cc: Li Zefan <lizefan@huawei.com>
+    Cc: Johannes Weiner <hannes@cmpxchg.org>
+
+diff --git a/kernel/sched/core.c b/kernel/sched/core.c
+index a1b95e83fa87..f01d56e58a1b 100644
+--- a/kernel/sched/core.c
++++ b/kernel/sched/core.c
+@@ -7253,6 +7253,139 @@ static struct cftype cpu_legacy_files[] = {
+ 	{ }	/* Terminate */
+ };
+ 
++static int cpu_stats_show(struct seq_file *sf, void *v)
++{
++	cpuacct_cpu_stats_show(sf);
++
++#ifdef CONFIG_CFS_BANDWIDTH
++	{
++		struct task_group *tg = css_tg(seq_css(sf));
++		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
++		u64 throttled_usec;
++
++		throttled_usec = cfs_b->throttled_time;
++		do_div(throttled_usec, NSEC_PER_USEC);
++
++		seq_printf(sf, "nr_periods %d\n"
++			   "nr_throttled %d\n"
++			   "throttled_usec %llu\n",
++			   cfs_b->nr_periods, cfs_b->nr_throttled,
++			   throttled_usec);
++	}
++#endif
++	return 0;
++}
++
++#ifdef CONFIG_FAIR_GROUP_SCHED
++static u64 cpu_weight_read_u64(struct cgroup_subsys_state *css,
++			       struct cftype *cft)
++{
++	struct task_group *tg = css_tg(css);
++	u64 weight = scale_load_down(tg->shares);
++
++	return DIV_ROUND_CLOSEST_ULL(weight * CGROUP_WEIGHT_DFL, 1024);
++}
++
++static int cpu_weight_write_u64(struct cgroup_subsys_state *css,
++				struct cftype *cftype, u64 weight)
++{
++	/*
++	 * cgroup weight knobs should use the common MIN, DFL and MAX
++	 * values which are 1, 100 and 10000 respectively.  While it loses
++	 * a bit of range on both ends, it maps pretty well onto the shares
++	 * value used by scheduler and the round-trip conversions preserve
++	 * the original value over the entire range.
++	 */
++	if (weight < CGROUP_WEIGHT_MIN || weight > CGROUP_WEIGHT_MAX)
++		return -ERANGE;
++
++	weight = DIV_ROUND_CLOSEST_ULL(weight * 1024, CGROUP_WEIGHT_DFL);
++
++	return sched_group_set_shares(css_tg(css), scale_load(weight));
++}
++#endif
++
++static void __maybe_unused cpu_period_quota_print(struct seq_file *sf,
++						  long period, long quota)
++{
++	if (quota < 0)
++		seq_puts(sf, "max");
++	else
++		seq_printf(sf, "%ld", quota);
++
++	seq_printf(sf, " %ld\n", period);
++}
++
++/* caller should put the current value in *@periodp before calling */
++static int __maybe_unused cpu_period_quota_parse(char *buf,
++						 u64 *periodp, u64 *quotap)
++{
++	char tok[21];	/* U64_MAX */
++
++	if (!sscanf(buf, "%s %llu", tok, periodp))
++		return -EINVAL;
++
++	*periodp *= NSEC_PER_USEC;
++
++	if (sscanf(tok, "%llu", quotap))
++		*quotap *= NSEC_PER_USEC;
++	else if (!strcmp(tok, "max"))
++		*quotap = RUNTIME_INF;
++	else
++		return -EINVAL;
++
++	return 0;
++}
++
++#ifdef CONFIG_CFS_BANDWIDTH
++static int cpu_max_show(struct seq_file *sf, void *v)
++{
++	struct task_group *tg = css_tg(seq_css(sf));
++
++	cpu_period_quota_print(sf, tg_get_cfs_period(tg), tg_get_cfs_quota(tg));
++	return 0;
++}
++
++static ssize_t cpu_max_write(struct kernfs_open_file *of,
++			     char *buf, size_t nbytes, loff_t off)
++{
++	struct task_group *tg = css_tg(of_css(of));
++	u64 period = tg_get_cfs_period(tg);
++	u64 quota;
++	int ret;
++
++	ret = cpu_period_quota_parse(buf, &period, &quota);
++	if (!ret)
++		ret = tg_set_cfs_bandwidth(tg, period, quota);
++	return ret ?: nbytes;
++}
++#endif
++
++static struct cftype cpu_files[] = {
++	{
++		.name = "stat",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.seq_show = cpu_stats_show,
++	},
++#ifdef CONFIG_FAIR_GROUP_SCHED
++	{
++		.name = "weight",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.read_u64 = cpu_weight_read_u64,
++		.write_u64 = cpu_weight_write_u64,
++	},
++#endif
++#ifdef CONFIG_CFS_BANDWIDTH
++	{
++		.name = "max",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.seq_show = cpu_max_show,
++		.write = cpu_max_write,
++	},
++#endif
++	{ }	/* terminate */
++};
++
+ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.css_alloc	= cpu_cgroup_css_alloc,
+ 	.css_online	= cpu_cgroup_css_online,
+@@ -7262,7 +7395,15 @@ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.can_attach	= cpu_cgroup_can_attach,
+ 	.attach		= cpu_cgroup_attach,
+ 	.legacy_cftypes	= cpu_legacy_files,
++	.dfl_cftypes	= cpu_files,
+ 	.early_init	= true,
++#ifdef CONFIG_CGROUP_CPUACCT
++	/*
++	 * cpuacct is enabled together with cpu on the unified hierarchy
++	 * and its stats are reported through "cpu.stat".
++	 */
++	.depends_on	= 1 << cpuacct_cgrp_id,
++#endif
+ };
+ 
+ #endif	/* CONFIG_CGROUP_SCHED */
+diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
+index 6151c23f722f..fc1cf13c3af1 100644
+--- a/kernel/sched/cpuacct.c
++++ b/kernel/sched/cpuacct.c
+@@ -347,6 +347,31 @@ static struct cftype files[] = {
+ 	{ }	/* terminate */
+ };
+ 
++/* used to print cpuacct stats in cpu.stat on the unified hierarchy */
++void cpuacct_cpu_stats_show(struct seq_file *sf)
++{
++	struct cgroup_subsys_state *css;
++	u64 usage, val[CPUACCT_STAT_NSTATS];
++
++	css = cgroup_get_e_css(seq_css(sf)->cgroup, &cpuacct_cgrp_subsys);
++
++	usage = cpuusage_read(css, seq_cft(sf));
++	cpuacct_stats_read(css_ca(css), &val);
++
++	val[CPUACCT_STAT_USER] *= TICK_NSEC;
++	val[CPUACCT_STAT_SYSTEM] *= TICK_NSEC;
++	do_div(usage, NSEC_PER_USEC);
++	do_div(val[CPUACCT_STAT_USER], NSEC_PER_USEC);
++	do_div(val[CPUACCT_STAT_SYSTEM], NSEC_PER_USEC);
++
++	seq_printf(sf, "usage_usec %llu\n"
++		   "user_usec %llu\n"
++		   "system_usec %llu\n",
++		   usage, val[CPUACCT_STAT_USER], val[CPUACCT_STAT_SYSTEM]);
++
++	css_put(css);
++}
++
+ /*
+  * charge this task's execution time to its accounting group.
+  *
+diff --git a/kernel/sched/cpuacct.h b/kernel/sched/cpuacct.h
+index ba72807c73d4..ddf7af466d35 100644
+--- a/kernel/sched/cpuacct.h
++++ b/kernel/sched/cpuacct.h
+@@ -2,6 +2,7 @@
+ 
+ extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
+ extern void cpuacct_account_field(struct task_struct *tsk, int index, u64 val);
++extern void cpuacct_cpu_stats_show(struct seq_file *sf);
+ 
+ #else
+ 
+@@ -14,4 +15,8 @@ cpuacct_account_field(struct task_struct *tsk, int index, u64 val)
+ {
+ }
+ 
++static inline void cpuacct_cpu_stats_show(struct seq_file *sf)
++{
++}
++
+ #endif
+
+commit 8dde150866b8c433216105c50b7e889d5242d583
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Aug 5 12:41:01 2016 -0400
+
+    cgroup: add documentation regarding CPU controller cgroup v2 support
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+
+diff --git a/Documentation/cgroup-v2-cpu.txt b/Documentation/cgroup-v2-cpu.txt
+new file mode 100644
+index 000000000000..1ed7032d4472
+--- /dev/null
++++ b/Documentation/cgroup-v2-cpu.txt
+@@ -0,0 +1,368 @@
++
++
++CPU Controller on Control Group v2
++
++August, 2016		Tejun Heo <tj@kernel.org>
++
++
++While most controllers have support for cgroup v2 now, the CPU
++controller support is not upstream yet due to objections from the
++scheduler maintainers on the basic designs of cgroup v2.  This
++document explains the current situation as well as an interim
++solution, and details the disagreements and arguments.  The latest
++version of this document can be found at the following URL.
++
++ https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup-v2-cpu.txt?h=cgroup-v2-cpu
++
++This document was posted to the linux-kernel and cgroup mailing lists.
++Unfortunately, no consensus was reached as of Oct, 2016.  The thread
++can be found at the following URL.
++
++ http://lkml.kernel.org/r/20160805170752.GK2542@mtj.duckdns.org
++
++
++CONTENTS
++
++1. Current Situation and Interim Solution
++2. Disagreements and Arguments
++  2-1. Contentious Restrictions
++    2-1-1. Process Granularity
++    2-1-2. No Internal Process Constraint
++  2-2. Impact on CPU Controller
++    2-2-1. Impact of Process Granularity
++    2-2-2. Impact of No Internal Process Constraint
++  2-3. Arguments for cgroup v2
++3. Way Forward
++4. References
++
++
++1. Current Situation and Interim Solution
++
++All objections from the scheduler maintainers apply to cgroup v2 core
++design, and there are no known objections to the specifics of the CPU
++controller cgroup v2 interface.  The only blocked part is changes to
++expose the CPU controller interface on cgroup v2, which comprises the
++following two patches:
++
++ [1] sched: Misc preps for cgroup unified hierarchy interface
++ [2] sched: Implement interface for cgroup unified hierarchy
++
++The necessary changes are superficial and implement the interface
++files on cgroup v2.  The combined diffstat is as follows.
++
++ kernel/sched/core.c    |  149 +++++++++++++++++++++++++++++++++++++++++++++++--
++ kernel/sched/cpuacct.c |   57 ++++++++++++------
++ kernel/sched/cpuacct.h |    5 +
++ 3 files changed, 189 insertions(+), 22 deletions(-)
++
++The patches are easy to apply and forward-port.  The following git
++branch will always carry the two patches on top of the latest release
++of the upstream kernel.
++
++ git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git/cgroup-v2-cpu
++
++There also are versioned branches going back to v4.4.
++
++ git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git/cgroup-v2-cpu-$KERNEL_VER
++
++While it's difficult to tell whether the CPU controller support will
++be merged, there are crucial resource control features in cgroup v2
++that are only possible due to the design choices that are being
++objected to, and every effort will be made to ease enabling the CPU
++controller cgroup v2 support out-of-tree for parties which choose to.
++
++
++2. Disagreements and Arguments
++
++There have been several lengthy discussion threads [3][4] on LKML
++around the structural constraints of cgroup v2.  The two that affect
++the CPU controller are process granularity and no internal process
++constraint.  Both arise primarily from the need for common resource
++domain definition across different resources.
++
++The common resource domain is a powerful concept in cgroup v2 that
++allows controllers to make basic assumptions about the structural
++organization of processes and controllers inside the cgroup hierarchy,
++and thus solve problems spanning multiple types of resources.  The
++prime example for this is page cache writeback: dirty page cache is
++regulated through throttling buffered writers based on memory
++availability, and initiating batched write outs to the disk based on
++IO capacity.  Tracking and controlling writeback inside a cgroup thus
++requires the direct cooperation of the memory and the IO controller.
++
++This easily extends to other areas, such as CPU cycles consumed while
++performing memory reclaim or IO encryption.
++
++
++2-1. Contentious Restrictions
++
++For controllers of different resources to work together, they must
++agree on a common organization.  This uniform model across controllers
++imposes two contentious restrictions on the CPU controller: process
++granularity and the no-internal-process constraint.
++
++
++  2-1-1. Process Granularity
++
++  For memory, because an address space is shared between all threads
++  of a process, the terminal consumer is a process, not a thread.
++  Separating the threads of a single process into different memory
++  control domains doesn't make semantical sense.  cgroup v2 ensures
++  that all controller can agree on the same organization by requiring
++  that threads of the same process belong to the same cgroup.
++
++  There are other reasons to enforce process granularity.  One
++  important one is isolating system-level management operations from
++  in-process application operations.  The cgroup interface, being a
++  virtual filesystem, is very unfit for multiple independent
++  operations taking place at the same time as most operations have to
++  be multi-step and there is no way to synchronize multiple accessors.
++  See also [5] Documentation/cgroup-v2.txt, "R-2. Thread Granularity"
++
++
++  2-1-2. No Internal Process Constraint
++
++  cgroup v2 does not allow processes to belong to any cgroup which has
++  child cgroups when resource controllers are enabled on it (the
++  notable exception being the root cgroup itself).  This is because,
++  for some resources, a resource domain (cgroup) is not directly
++  comparable to the terminal consumer (process/task) of said resource,
++  and so putting the two into a sibling relationship isn't meaningful.
++
++  - Differing Control Parameters and Capabilities
++
++    A cgroup controller has different resource control parameters and
++    capabilities from a terminal consumer, be that a task or process.
++    There are a couple cases where a cgroup control knob can be mapped
++    to a per-task or per-process API but they are exceptions and the
++    mappings aren't obvious even in those cases.
++
++    For example, task priorities (also known as nice values) set
++    through setpriority(2) are mapped to the CPU controller
++    "cpu.shares" values.  However, how exactly the two ranges map and
++    even the fact that they map to each other at all are not obvious.
++
++    The situation gets further muddled when considering other resource
++    types and control knobs.  IO priorities set through ioprio_set(2)
++    cannot be mapped to IO controller weights and most cgroup resource
++    control knobs including the bandwidth control knobs of the CPU
++    controller don't have counterparts in the terminal consumers.
++
++  - Anonymous Resource Consumption
++
++    For CPU, every time slice consumed from inside a cgroup, which
++    comprises most but not all of consumed CPU time for the cgroup,
++    can be clearly attributed to a specific task or process.  Because
++    these two types of entities are directly comparable as consumers
++    of CPU time, it's theoretically possible to mix tasks and cgroups
++    on the same tree levels and let them directly compete for the time
++    quota available to their common ancestor.
++
++    However, the same can't be said for resource types like memory or
++    IO: the memory consumed by the page cache, for example, can be
++    tracked on a per-cgroup level, but due to mismatches in lifetimes
++    of involved objects (page cache can persist long after processes
++    are gone), shared usages and the implementation overhead of
++    tracking persistent state, it can no longer be attributed to
++    individual processes after instantiation.  Consequently, any IO
++    incurred by page cache writeback can be attributed to a cgroup,
++    but not to the individual consumers inside the cgroup.
++
++  For memory and IO, this makes a resource domain (cgroup) an object
++  of a fundamentally different type than a terminal consumer
++  (process).  A process can't be a first class object in the resource
++  distribution graph as its total resource consumption can't be
++  described without the containing resource domain.
++
++  Disallowing processes in internal cgroups avoids competition between
++  cgroups and processes which cannot be meaningfully defined for these
++  resources.  All resource control takes place among cgroups and a
++  terminal consumer interacts with the containing cgroup the same way
++  it would with the system without cgroup.
++
++  Root cgroup is exempt from this constraint, which is in line with
++  how root cgroup is handled in general - it's excluded from cgroup
++  resource accounting and control.
++
++
++Enforcing process granularity and no internal process constraint
++allows all controllers to be on the same footing in terms of resource
++distribution hierarchy.
++
++
++2-2. Impact on CPU Controller
++
++As indicated earlier, the CPU controller's resource distribution graph
++is the simplest.  Every schedulable resource consumption can be
++attributed to a specific task.  In addition, for weight based control,
++the per-task priority set through setpriority(2) can be translated to
++and from a per-cgroup weight.  As such, the CPU controller can treat a
++task and a cgroup symmetrically, allowing support for any tree layout
++of cgroups and tasks.  Both process granularity and the no internal
++process constraint restrict how the CPU controller can be used.
++
++
++  2-2-1. Impact of Process Granularity
++
++  Process granularity prevents tasks belonging to the same process to
++  be assigned to different cgroups.  It was pointed out [6] that this
++  excludes the valid use case of hierarchical CPU distribution within
++  processes.
++
++  To address this issue, the rgroup (resource group) [7][8][9]
++  interface, an extension of the existing setpriority(2) API, was
++  proposed, which is in line with other programmable priority
++  mechanisms and eliminates the risk of in-application configuration
++  and system configuration stepping on each other's toes.
++  Unfortunately, the proposal quickly turned into discussions around
++  cgroup v2 design decisions [4] and no consensus could be reached.
++
++
++  2-2-2. Impact of No Internal Process Constraint
++
++  The no internal process constraint disallows tasks from competing
++  directly against cgroups.  Here is an excerpt from Peter Zijlstra
++  pointing out the issue [10] - R, L and A are cgroups; t1, t2, t3 and
++  t4 are tasks:
++
++
++          R
++        / | \
++       t1 t2 A
++           /   \
++          t3   t4
++
++
++    Is fundamentally different from:
++
++
++               R
++             /   \
++           L       A
++         /   \   /   \
++        t1  t2  t3   t4
++
++
++    Because if in the first hierarchy you add a task (t5) to R, all of
++    its A will run at 1/4th of total bandwidth where before it had
++    1/3rd, whereas with the second example, if you add our t5 to L, A
++    doesn't get any less bandwidth.
++
++
++  It is true that the trees are semantically different from each other
++  and the symmetric handling of tasks and cgroups is aesthetically
++  pleasing.  However, it isn't clear what the practical usefulness of
++  a layout with direct competition between tasks and cgroups would be,
++  considering that number and behavior of tasks are controlled by each
++  application, and cgroups primarily deal with system level resource
++  distribution; changes in the number of active threads would directly
++  impact resource distribution.  Real world use cases of such layouts
++  could not be established during the discussions.
++
++
++2-3. Arguments for cgroup v2
++
++There are strong demands for comprehensive hierarchical resource
++control across all major resources, and establishing a common resource
++hierarchy is an essential step.  As with most engineering decisions,
++common resource hierarchy definition comes with its trade-offs.  With
++cgroup v2, the trade-offs are in the form of structural constraints
++which, among others, restrict the CPU controller's space of possible
++configurations.
++
++However, even with the restrictions, cgroup v2, in combination with
++rgroup, covers most of identified real world use cases while enabling
++new important use cases of resource control across multiple resource
++types that were fundamentally broken previously.
++
++Furthermore, for resource control, treating resource domains as
++objects of a different type from terminal consumers has important
++advantages - it can account for resource consumptions which are not
++tied to any specific terminal consumer, be that a task or process, and
++allows decoupling resource distribution controls from in-application
++APIs.  Even the CPU controller may benefit from it as the kernel can
++consume significant amount of CPU cycles in interrupt context or tasks
++shared across multiple resource domains (e.g. softirq).
++
++Finally, it's important to note that enabling cgroup v2 support for
++the CPU controller doesn't block use cases which require the features
++which are not available on cgroup v2.  Unlikely, but should anybody
++actually rely on the CPU controller's symmetric handling of tasks and
++cgroups, backward compatibility is and will be maintained by being
++able to disconnect the controller from the cgroup v2 hierarchy and use
++it standalone.  This also holds for cpuset which is often used in
++highly customized configurations which might be a poor fit for common
++resource domains.
++
++The required changes are minimal, the benefits for the target use
++cases are critical and obvious, and use cases which have to use v1 can
++continue to do so.
++
++
++3. Way Forward
++
++cgroup v2 primarily aims to solve the problem of comprehensive
++hierarchical resource control across all major computing resources,
++which is one of the core problems of modern server infrastructure
++engineering.  The trade-offs that cgroup v2 took are results of
++pursuing that goal and gaining a better understanding of the nature of
++resource control in the process.
++
++I believe that real world usages will prove cgroup v2's model right,
++considering the crucial pieces of comprehensive resource control that
++cannot be implemented without common resource domains.  This is not to
++say that cgroup v2 is fixed in stone and can't be updated; if there is
++an approach which better serves both comprehensive resource control
++and the CPU controller's flexibility, we will surely move towards
++that.  It goes without saying that discussions around such approach
++should consider practical aspects of resource control as a whole
++rather than absolutely focusing on a particular controller.
++
++Until such consensus can be reached, the CPU controller cgroup v2
++support will be maintained out of the mainline kernel in an easily
++accessible form.  If there is anything cgroup developers can do to
++ease the pain, please feel free to contact us on the cgroup mailing
++list at cgroups@vger.kernel.org.
++
++
++4. References
++
++[1]  http://lkml.kernel.org/r/20160105164834.GE5995@mtj.duckdns.org
++     [PATCH 1/2] sched: Misc preps for cgroup unified hierarchy interface
++     Tejun Heo <tj@kernel.org>
++
++[2]  http://lkml.kernel.org/r/20160105164852.GF5995@mtj.duckdns.org
++     [PATCH 2/2] sched: Implement interface for cgroup unified hierarchy
++     Tejun Heo <tj@kernel.org>
++
++[3]  http://lkml.kernel.org/r/1438641689-14655-4-git-send-email-tj@kernel.org
++     [PATCH 3/3] sched: Implement interface for cgroup unified hierarchy
++     Tejun Heo <tj@kernel.org>
++
++[4]  http://lkml.kernel.org/r/20160407064549.GH3430@twins.programming.kicks-ass.net
++     Re: [PATCHSET RFC cgroup/for-4.6] cgroup, sched: implement resource group and PRIO_RGRP
++     Peter Zijlstra <peterz@infradead.org>
++
++[5]  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/cgroup-v2.txt
++     Control Group v2
++     Tejun Heo <tj@kernel.org>
++
++[6]  http://lkml.kernel.org/r/CAPM31RJNy3jgG=DYe6GO=wyL4BPPxwUm1f2S6YXacQmo7viFZA@mail.gmail.com
++     Re: [PATCH 3/3] sched: Implement interface for cgroup unified hierarchy
++     Paul Turner <pjt@google.com>
++
++[7]  http://lkml.kernel.org/r/20160105154503.GC5995@mtj.duckdns.org
++     [RFD] cgroup: thread granularity support for cpu controller
++     Tejun Heo <tj@kernel.org>
++
++[8]  http://lkml.kernel.org/r/1457710888-31182-1-git-send-email-tj@kernel.org
++     [PATCHSET RFC cgroup/for-4.6] cgroup, sched: implement resource group and PRIO_RGRP
++     Tejun Heo <tj@kernel.org>
++
++[9]  http://lkml.kernel.org/r/20160311160522.GA24046@htj.duckdns.org
++     Example program for PRIO_RGRP
++     Tejun Heo <tj@kernel.org>
++
++[10] http://lkml.kernel.org/r/20160407082810.GN3430@twins.programming.kicks-ass.net
++     Re: [PATCHSET RFC cgroup/for-4.6] cgroup, sched: implement resource
++     Peter Zijlstra <peterz@infradead.org>
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.4.patch b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.4.patch
new file mode 100644
index 000000000000..8f2418c9efce
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.4.patch
@@ -0,0 +1,407 @@
+commit e7cae741f6d645ac68fe8823ca6ef45dbbf6891b
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Mar 11 07:31:23 2016 -0500
+
+    sched: Misc preps for cgroup unified hierarchy interface
+    
+    Make the following changes in preparation for the cpu controller
+    interface implementation for the unified hierarchy.  This patch
+    doesn't cause any functional differences.
+    
+    * s/cpu_stats_show()/cpu_cfs_stats_show()/
+    
+    * s/cpu_files/cpu_legacy_files/
+    
+    * Separate out cpuacct_stats_read() from cpuacct_stats_show().  While
+      at it, remove pointless cpuacct_stat_desc[] array.
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+    Cc: Ingo Molnar <mingo@redhat.com>
+    Cc: Peter Zijlstra <peterz@infradead.org>
+    Cc: Li Zefan <lizefan@huawei.com>
+    Cc: Johannes Weiner <hannes@cmpxchg.org>
+
+diff --git a/kernel/sched/core.c b/kernel/sched/core.c
+index 732e993..77f3ddd 100644
+--- a/kernel/sched/core.c
++++ b/kernel/sched/core.c
+@@ -8512,7 +8512,7 @@ static int __cfs_schedulable(struct task_group *tg, u64 period, u64 quota)
+ 	return ret;
+ }
+ 
+-static int cpu_stats_show(struct seq_file *sf, void *v)
++static int cpu_cfs_stats_show(struct seq_file *sf, void *v)
+ {
+ 	struct task_group *tg = css_tg(seq_css(sf));
+ 	struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
+@@ -8552,7 +8552,7 @@ static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css,
+ }
+ #endif /* CONFIG_RT_GROUP_SCHED */
+ 
+-static struct cftype cpu_files[] = {
++static struct cftype cpu_legacy_files[] = {
+ #ifdef CONFIG_FAIR_GROUP_SCHED
+ 	{
+ 		.name = "shares",
+@@ -8573,7 +8573,7 @@ static struct cftype cpu_files[] = {
+ 	},
+ 	{
+ 		.name = "stat",
+-		.seq_show = cpu_stats_show,
++		.seq_show = cpu_cfs_stats_show,
+ 	},
+ #endif
+ #ifdef CONFIG_RT_GROUP_SCHED
+@@ -8599,7 +8599,7 @@ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.fork		= cpu_cgroup_fork,
+ 	.can_attach	= cpu_cgroup_can_attach,
+ 	.attach		= cpu_cgroup_attach,
+-	.legacy_cftypes	= cpu_files,
++	.legacy_cftypes	= cpu_legacy_files,
+ 	.early_init	= 1,
+ };
+ 
+diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
+index dd7cbb5..42b2dd5 100644
+--- a/kernel/sched/cpuacct.c
++++ b/kernel/sched/cpuacct.c
+@@ -177,36 +177,33 @@ static int cpuacct_percpu_seq_show(struct seq_file *m, void *V)
+ 	return 0;
+ }
+ 
+-static const char * const cpuacct_stat_desc[] = {
+-	[CPUACCT_STAT_USER] = "user",
+-	[CPUACCT_STAT_SYSTEM] = "system",
+-};
+-
+-static int cpuacct_stats_show(struct seq_file *sf, void *v)
++static void cpuacct_stats_read(struct cpuacct *ca, u64 *userp, u64 *sysp)
+ {
+-	struct cpuacct *ca = css_ca(seq_css(sf));
+ 	int cpu;
+-	s64 val = 0;
+ 
++	*userp = 0;
+ 	for_each_online_cpu(cpu) {
+ 		struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat, cpu);
+-		val += kcpustat->cpustat[CPUTIME_USER];
+-		val += kcpustat->cpustat[CPUTIME_NICE];
++		*userp += kcpustat->cpustat[CPUTIME_USER];
++		*userp += kcpustat->cpustat[CPUTIME_NICE];
+ 	}
+-	val = cputime64_to_clock_t(val);
+-	seq_printf(sf, "%s %lld\n", cpuacct_stat_desc[CPUACCT_STAT_USER], val);
+ 
+-	val = 0;
++	*sysp = 0;
+ 	for_each_online_cpu(cpu) {
+ 		struct kernel_cpustat *kcpustat = per_cpu_ptr(ca->cpustat, cpu);
+-		val += kcpustat->cpustat[CPUTIME_SYSTEM];
+-		val += kcpustat->cpustat[CPUTIME_IRQ];
+-		val += kcpustat->cpustat[CPUTIME_SOFTIRQ];
++		*sysp += kcpustat->cpustat[CPUTIME_SYSTEM];
++		*sysp += kcpustat->cpustat[CPUTIME_IRQ];
++		*sysp += kcpustat->cpustat[CPUTIME_SOFTIRQ];
+ 	}
++}
+ 
+-	val = cputime64_to_clock_t(val);
+-	seq_printf(sf, "%s %lld\n", cpuacct_stat_desc[CPUACCT_STAT_SYSTEM], val);
++static int cpuacct_stats_show(struct seq_file *sf, void *v)
++{
++	cputime64_t user, sys;
+ 
++	cpuacct_stats_read(css_ca(seq_css(sf)), &user, &sys);
++	seq_printf(sf, "user %lld\n", cputime64_to_clock_t(user));
++	seq_printf(sf, "system %lld\n", cputime64_to_clock_t(sys));
+ 	return 0;
+ }
+ 
+
+commit 1bb33e8a69f089f2d3f58a0e681d4ff352e11c97
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Mar 11 07:31:23 2016 -0500
+
+    sched: Implement interface for cgroup unified hierarchy
+    
+    While the cpu controller doesn't have any functional problems, there
+    are a couple interface issues which can be addressed in the v2
+    interface.
+    
+    * cpuacct being a separate controller.  This separation is artificial
+      and rather pointless as demonstrated by most use cases co-mounting
+      the two controllers.  It also forces certain information to be
+      accounted twice.
+    
+    * Use of different time units.  Writable control knobs use
+      microseconds, some stat fields use nanoseconds while other cpuacct
+      stat fields use centiseconds.
+    
+    * Control knobs which can't be used in the root cgroup still show up
+      in the root.
+    
+    * Control knob names and semantics aren't consistent with other
+      controllers.
+    
+    This patchset implements cpu controller's interface on the unified
+    hierarchy which adheres to the controller file conventions described
+    in Documentation/cgroups/unified-hierarchy.txt.  Overall, the
+    following changes are made.
+    
+    * cpuacct is implictly enabled and disabled by cpu and its information
+      is reported through "cpu.stat" which now uses microseconds for all
+      time durations.  All time duration fields now have "_usec" appended
+      to them for clarity.  While this doesn't solve the double accounting
+      immediately, once majority of users switch to v2, cpu can directly
+      account and report the relevant stats and cpuacct can be disabled on
+      the unified hierarchy.
+    
+      Note that cpuacct.usage_percpu is currently not included in
+      "cpu.stat".  If this information is actually called for, it can be
+      added later.
+    
+    * "cpu.shares" is replaced with "cpu.weight" and operates on the
+      standard scale defined by CGROUP_WEIGHT_MIN/DFL/MAX (1, 100, 10000).
+      The weight is scaled to scheduler weight so that 100 maps to 1024
+      and the ratio relationship is preserved - if weight is W and its
+      scaled value is S, W / 100 == S / 1024.  While the mapped range is a
+      bit smaller than the orignal scheduler weight range, the dead zones
+      on both sides are relatively small and covers wider range than the
+      nice value mappings.  This file doesn't make sense in the root
+      cgroup and isn't create on root.
+    
+    * "cpu.cfs_quota_us" and "cpu.cfs_period_us" are replaced by "cpu.max"
+      which contains both quota and period.
+    
+    * "cpu.rt_runtime_us" and "cpu.rt_period_us" are replaced by
+      "cpu.rt.max" which contains both runtime and period.
+    
+    v2: cpu_stats_show() was incorrectly using CONFIG_FAIR_GROUP_SCHED for
+        CFS bandwidth stats and also using raw division for u64.  Use
+        CONFIG_CFS_BANDWITH and do_div() instead.
+    
+        The semantics of "cpu.rt.max" is not fully decided yet.  Dropped
+        for now.
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+    Cc: Ingo Molnar <mingo@redhat.com>
+    Cc: Peter Zijlstra <peterz@infradead.org>
+    Cc: Li Zefan <lizefan@huawei.com>
+    Cc: Johannes Weiner <hannes@cmpxchg.org>
+
+diff --git a/kernel/sched/core.c b/kernel/sched/core.c
+index 77f3ddd..7aafe63 100644
+--- a/kernel/sched/core.c
++++ b/kernel/sched/core.c
+@@ -8591,6 +8591,139 @@ static struct cftype cpu_legacy_files[] = {
+ 	{ }	/* terminate */
+ };
+ 
++static int cpu_stats_show(struct seq_file *sf, void *v)
++{
++	cpuacct_cpu_stats_show(sf);
++
++#ifdef CONFIG_CFS_BANDWIDTH
++	{
++		struct task_group *tg = css_tg(seq_css(sf));
++		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
++		u64 throttled_usec;
++
++		throttled_usec = cfs_b->throttled_time;
++		do_div(throttled_usec, NSEC_PER_USEC);
++
++		seq_printf(sf, "nr_periods %d\n"
++			   "nr_throttled %d\n"
++			   "throttled_usec %llu\n",
++			   cfs_b->nr_periods, cfs_b->nr_throttled,
++			   throttled_usec);
++	}
++#endif
++	return 0;
++}
++
++#ifdef CONFIG_FAIR_GROUP_SCHED
++static u64 cpu_weight_read_u64(struct cgroup_subsys_state *css,
++			       struct cftype *cft)
++{
++	struct task_group *tg = css_tg(css);
++	u64 weight = scale_load_down(tg->shares);
++
++	return DIV_ROUND_CLOSEST_ULL(weight * CGROUP_WEIGHT_DFL, 1024);
++}
++
++static int cpu_weight_write_u64(struct cgroup_subsys_state *css,
++				struct cftype *cftype, u64 weight)
++{
++	/*
++	 * cgroup weight knobs should use the common MIN, DFL and MAX
++	 * values which are 1, 100 and 10000 respectively.  While it loses
++	 * a bit of range on both ends, it maps pretty well onto the shares
++	 * value used by scheduler and the round-trip conversions preserve
++	 * the original value over the entire range.
++	 */
++	if (weight < CGROUP_WEIGHT_MIN || weight > CGROUP_WEIGHT_MAX)
++		return -ERANGE;
++
++	weight = DIV_ROUND_CLOSEST_ULL(weight * 1024, CGROUP_WEIGHT_DFL);
++
++	return sched_group_set_shares(css_tg(css), scale_load(weight));
++}
++#endif
++
++static void __maybe_unused cpu_period_quota_print(struct seq_file *sf,
++						  long period, long quota)
++{
++	if (quota < 0)
++		seq_puts(sf, "max");
++	else
++		seq_printf(sf, "%ld", quota);
++
++	seq_printf(sf, " %ld\n", period);
++}
++
++/* caller should put the current value in *@periodp before calling */
++static int __maybe_unused cpu_period_quota_parse(char *buf,
++						 u64 *periodp, u64 *quotap)
++{
++	char tok[21];	/* U64_MAX */
++
++	if (!sscanf(buf, "%s %llu", tok, periodp))
++		return -EINVAL;
++
++	*periodp *= NSEC_PER_USEC;
++
++	if (sscanf(tok, "%llu", quotap))
++		*quotap *= NSEC_PER_USEC;
++	else if (!strcmp(tok, "max"))
++		*quotap = RUNTIME_INF;
++	else
++		return -EINVAL;
++
++	return 0;
++}
++
++#ifdef CONFIG_CFS_BANDWIDTH
++static int cpu_max_show(struct seq_file *sf, void *v)
++{
++	struct task_group *tg = css_tg(seq_css(sf));
++
++	cpu_period_quota_print(sf, tg_get_cfs_period(tg), tg_get_cfs_quota(tg));
++	return 0;
++}
++
++static ssize_t cpu_max_write(struct kernfs_open_file *of,
++			     char *buf, size_t nbytes, loff_t off)
++{
++	struct task_group *tg = css_tg(of_css(of));
++	u64 period = tg_get_cfs_period(tg);
++	u64 quota;
++	int ret;
++
++	ret = cpu_period_quota_parse(buf, &period, &quota);
++	if (!ret)
++		ret = tg_set_cfs_bandwidth(tg, period, quota);
++	return ret ?: nbytes;
++}
++#endif
++
++static struct cftype cpu_files[] = {
++	{
++		.name = "stat",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.seq_show = cpu_stats_show,
++	},
++#ifdef CONFIG_FAIR_GROUP_SCHED
++	{
++		.name = "weight",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.read_u64 = cpu_weight_read_u64,
++		.write_u64 = cpu_weight_write_u64,
++	},
++#endif
++#ifdef CONFIG_CFS_BANDWIDTH
++	{
++		.name = "max",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.seq_show = cpu_max_show,
++		.write = cpu_max_write,
++	},
++#endif
++	{ }	/* terminate */
++};
++
+ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.css_alloc	= cpu_cgroup_css_alloc,
+ 	.css_free	= cpu_cgroup_css_free,
+@@ -8600,7 +8733,15 @@ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.can_attach	= cpu_cgroup_can_attach,
+ 	.attach		= cpu_cgroup_attach,
+ 	.legacy_cftypes	= cpu_legacy_files,
++	.dfl_cftypes	= cpu_files,
+ 	.early_init	= 1,
++#ifdef CONFIG_CGROUP_CPUACCT
++	/*
++	 * cpuacct is enabled together with cpu on the unified hierarchy
++	 * and its stats are reported through "cpu.stat".
++	 */
++	.depends_on	= 1 << cpuacct_cgrp_id,
++#endif
+ };
+ 
+ #endif	/* CONFIG_CGROUP_SCHED */
+diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
+index 42b2dd5..b4d32a6 100644
+--- a/kernel/sched/cpuacct.c
++++ b/kernel/sched/cpuacct.c
+@@ -224,6 +224,30 @@ static struct cftype files[] = {
+ 	{ }	/* terminate */
+ };
+ 
++/* used to print cpuacct stats in cpu.stat on the unified hierarchy */
++void cpuacct_cpu_stats_show(struct seq_file *sf)
++{
++	struct cgroup_subsys_state *css;
++	u64 usage, user, sys;
++
++	css = cgroup_get_e_css(seq_css(sf)->cgroup, &cpuacct_cgrp_subsys);
++
++	usage = cpuusage_read(css, seq_cft(sf));
++	cpuacct_stats_read(css_ca(css), &user, &sys);
++
++	user *= TICK_NSEC;
++	sys *= TICK_NSEC;
++	do_div(usage, NSEC_PER_USEC);
++	do_div(user, NSEC_PER_USEC);
++	do_div(sys, NSEC_PER_USEC);
++
++	seq_printf(sf, "usage_usec %llu\n"
++		   "user_usec %llu\n"
++		   "system_usec %llu\n", usage, user, sys);
++
++	css_put(css);
++}
++
+ /*
+  * charge this task's execution time to its accounting group.
+  *
+diff --git a/kernel/sched/cpuacct.h b/kernel/sched/cpuacct.h
+index ed60562..44eace9 100644
+--- a/kernel/sched/cpuacct.h
++++ b/kernel/sched/cpuacct.h
+@@ -2,6 +2,7 @@
+ 
+ extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
+ extern void cpuacct_account_field(struct task_struct *p, int index, u64 val);
++extern void cpuacct_cpu_stats_show(struct seq_file *sf);
+ 
+ #else
+ 
+@@ -14,4 +15,8 @@ cpuacct_account_field(struct task_struct *p, int index, u64 val)
+ {
+ }
+ 
++static inline void cpuacct_cpu_stats_show(struct seq_file *sf)
++{
++}
++
+ #endif
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.9.patch b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.9.patch
new file mode 100644
index 000000000000..6f0904cbce99
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/4.9.patch
@@ -0,0 +1,784 @@
+commit 280858b0bb3384b9ec06b455e196b453888bd6b8
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Mar 11 07:31:23 2016 -0500
+
+    sched: Misc preps for cgroup unified hierarchy interface
+    
+    Make the following changes in preparation for the cpu controller
+    interface implementation for the unified hierarchy.  This patch
+    doesn't cause any functional differences.
+    
+    * s/cpu_stats_show()/cpu_cfs_stats_show()/
+    
+    * s/cpu_files/cpu_legacy_files/
+    
+    * Separate out cpuacct_stats_read() from cpuacct_stats_show().  While
+      at it, make the @val array u64 for consistency.
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+    Cc: Ingo Molnar <mingo@redhat.com>
+    Cc: Peter Zijlstra <peterz@infradead.org>
+    Cc: Li Zefan <lizefan@huawei.com>
+    Cc: Johannes Weiner <hannes@cmpxchg.org>
+
+diff --git a/kernel/sched/core.c b/kernel/sched/core.c
+index 154fd689fe02..57472485b79c 100644
+--- a/kernel/sched/core.c
++++ b/kernel/sched/core.c
+@@ -8705,7 +8705,7 @@ static int __cfs_schedulable(struct task_group *tg, u64 period, u64 quota)
+ 	return ret;
+ }
+ 
+-static int cpu_stats_show(struct seq_file *sf, void *v)
++static int cpu_cfs_stats_show(struct seq_file *sf, void *v)
+ {
+ 	struct task_group *tg = css_tg(seq_css(sf));
+ 	struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
+@@ -8745,7 +8745,7 @@ static u64 cpu_rt_period_read_uint(struct cgroup_subsys_state *css,
+ }
+ #endif /* CONFIG_RT_GROUP_SCHED */
+ 
+-static struct cftype cpu_files[] = {
++static struct cftype cpu_legacy_files[] = {
+ #ifdef CONFIG_FAIR_GROUP_SCHED
+ 	{
+ 		.name = "shares",
+@@ -8766,7 +8766,7 @@ static struct cftype cpu_files[] = {
+ 	},
+ 	{
+ 		.name = "stat",
+-		.seq_show = cpu_stats_show,
++		.seq_show = cpu_cfs_stats_show,
+ 	},
+ #endif
+ #ifdef CONFIG_RT_GROUP_SCHED
+@@ -8791,7 +8791,7 @@ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.fork		= cpu_cgroup_fork,
+ 	.can_attach	= cpu_cgroup_can_attach,
+ 	.attach		= cpu_cgroup_attach,
+-	.legacy_cftypes	= cpu_files,
++	.legacy_cftypes	= cpu_legacy_files,
+ 	.early_init	= true,
+ };
+ 
+diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
+index bc0b309c3f19..d1e5dd0b3a64 100644
+--- a/kernel/sched/cpuacct.c
++++ b/kernel/sched/cpuacct.c
+@@ -276,26 +276,33 @@ static int cpuacct_all_seq_show(struct seq_file *m, void *V)
+ 	return 0;
+ }
+ 
+-static int cpuacct_stats_show(struct seq_file *sf, void *v)
++static void cpuacct_stats_read(struct cpuacct *ca,
++			       u64 (*val)[CPUACCT_STAT_NSTATS])
+ {
+-	struct cpuacct *ca = css_ca(seq_css(sf));
+-	s64 val[CPUACCT_STAT_NSTATS];
+ 	int cpu;
+-	int stat;
+ 
+-	memset(val, 0, sizeof(val));
++	memset(val, 0, sizeof(*val));
++
+ 	for_each_possible_cpu(cpu) {
+ 		u64 *cpustat = per_cpu_ptr(ca->cpustat, cpu)->cpustat;
+ 
+-		val[CPUACCT_STAT_USER]   += cpustat[CPUTIME_USER];
+-		val[CPUACCT_STAT_USER]   += cpustat[CPUTIME_NICE];
+-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SYSTEM];
+-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_IRQ];
+-		val[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SOFTIRQ];
++		(*val)[CPUACCT_STAT_USER]   += cpustat[CPUTIME_USER];
++		(*val)[CPUACCT_STAT_USER]   += cpustat[CPUTIME_NICE];
++		(*val)[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SYSTEM];
++		(*val)[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_IRQ];
++		(*val)[CPUACCT_STAT_SYSTEM] += cpustat[CPUTIME_SOFTIRQ];
+ 	}
++}
++
++static int cpuacct_stats_show(struct seq_file *sf, void *v)
++{
++	u64 val[CPUACCT_STAT_NSTATS];
++	int stat;
++
++	cpuacct_stats_read(css_ca(seq_css(sf)), &val);
+ 
+ 	for (stat = 0; stat < CPUACCT_STAT_NSTATS; stat++) {
+-		seq_printf(sf, "%s %lld\n",
++		seq_printf(sf, "%s %llu\n",
+ 			   cpuacct_stat_desc[stat],
+ 			   cputime64_to_clock_t(val[stat]));
+ 	}
+
+commit 015cbdcb90034fd566d00de9d3d405613da3cd26
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Mar 11 07:31:23 2016 -0500
+
+    sched: Implement interface for cgroup unified hierarchy
+    
+    While the cpu controller doesn't have any functional problems, there
+    are a couple interface issues which can be addressed in the v2
+    interface.
+    
+    * cpuacct being a separate controller.  This separation is artificial
+      and rather pointless as demonstrated by most use cases co-mounting
+      the two controllers.  It also forces certain information to be
+      accounted twice.
+    
+    * Use of different time units.  Writable control knobs use
+      microseconds, some stat fields use nanoseconds while other cpuacct
+      stat fields use centiseconds.
+    
+    * Control knobs which can't be used in the root cgroup still show up
+      in the root.
+    
+    * Control knob names and semantics aren't consistent with other
+      controllers.
+    
+    This patchset implements cpu controller's interface on the unified
+    hierarchy which adheres to the controller file conventions described
+    in Documentation/cgroups/unified-hierarchy.txt.  Overall, the
+    following changes are made.
+    
+    * cpuacct is implictly enabled and disabled by cpu and its information
+      is reported through "cpu.stat" which now uses microseconds for all
+      time durations.  All time duration fields now have "_usec" appended
+      to them for clarity.  While this doesn't solve the double accounting
+      immediately, once majority of users switch to v2, cpu can directly
+      account and report the relevant stats and cpuacct can be disabled on
+      the unified hierarchy.
+    
+      Note that cpuacct.usage_percpu is currently not included in
+      "cpu.stat".  If this information is actually called for, it can be
+      added later.
+    
+    * "cpu.shares" is replaced with "cpu.weight" and operates on the
+      standard scale defined by CGROUP_WEIGHT_MIN/DFL/MAX (1, 100, 10000).
+      The weight is scaled to scheduler weight so that 100 maps to 1024
+      and the ratio relationship is preserved - if weight is W and its
+      scaled value is S, W / 100 == S / 1024.  While the mapped range is a
+      bit smaller than the orignal scheduler weight range, the dead zones
+      on both sides are relatively small and covers wider range than the
+      nice value mappings.  This file doesn't make sense in the root
+      cgroup and isn't create on root.
+    
+    * "cpu.cfs_quota_us" and "cpu.cfs_period_us" are replaced by "cpu.max"
+      which contains both quota and period.
+    
+    * "cpu.rt_runtime_us" and "cpu.rt_period_us" are replaced by
+      "cpu.rt.max" which contains both runtime and period.
+    
+    v2: cpu_stats_show() was incorrectly using CONFIG_FAIR_GROUP_SCHED for
+        CFS bandwidth stats and also using raw division for u64.  Use
+        CONFIG_CFS_BANDWITH and do_div() instead.
+    
+        The semantics of "cpu.rt.max" is not fully decided yet.  Dropped
+        for now.
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+    Cc: Ingo Molnar <mingo@redhat.com>
+    Cc: Peter Zijlstra <peterz@infradead.org>
+    Cc: Li Zefan <lizefan@huawei.com>
+    Cc: Johannes Weiner <hannes@cmpxchg.org>
+
+diff --git a/kernel/sched/core.c b/kernel/sched/core.c
+index 57472485b79c..c0ae869f51c4 100644
+--- a/kernel/sched/core.c
++++ b/kernel/sched/core.c
+@@ -8784,6 +8784,139 @@ static struct cftype cpu_legacy_files[] = {
+ 	{ }	/* terminate */
+ };
+ 
++static int cpu_stats_show(struct seq_file *sf, void *v)
++{
++	cpuacct_cpu_stats_show(sf);
++
++#ifdef CONFIG_CFS_BANDWIDTH
++	{
++		struct task_group *tg = css_tg(seq_css(sf));
++		struct cfs_bandwidth *cfs_b = &tg->cfs_bandwidth;
++		u64 throttled_usec;
++
++		throttled_usec = cfs_b->throttled_time;
++		do_div(throttled_usec, NSEC_PER_USEC);
++
++		seq_printf(sf, "nr_periods %d\n"
++			   "nr_throttled %d\n"
++			   "throttled_usec %llu\n",
++			   cfs_b->nr_periods, cfs_b->nr_throttled,
++			   throttled_usec);
++	}
++#endif
++	return 0;
++}
++
++#ifdef CONFIG_FAIR_GROUP_SCHED
++static u64 cpu_weight_read_u64(struct cgroup_subsys_state *css,
++			       struct cftype *cft)
++{
++	struct task_group *tg = css_tg(css);
++	u64 weight = scale_load_down(tg->shares);
++
++	return DIV_ROUND_CLOSEST_ULL(weight * CGROUP_WEIGHT_DFL, 1024);
++}
++
++static int cpu_weight_write_u64(struct cgroup_subsys_state *css,
++				struct cftype *cftype, u64 weight)
++{
++	/*
++	 * cgroup weight knobs should use the common MIN, DFL and MAX
++	 * values which are 1, 100 and 10000 respectively.  While it loses
++	 * a bit of range on both ends, it maps pretty well onto the shares
++	 * value used by scheduler and the round-trip conversions preserve
++	 * the original value over the entire range.
++	 */
++	if (weight < CGROUP_WEIGHT_MIN || weight > CGROUP_WEIGHT_MAX)
++		return -ERANGE;
++
++	weight = DIV_ROUND_CLOSEST_ULL(weight * 1024, CGROUP_WEIGHT_DFL);
++
++	return sched_group_set_shares(css_tg(css), scale_load(weight));
++}
++#endif
++
++static void __maybe_unused cpu_period_quota_print(struct seq_file *sf,
++						  long period, long quota)
++{
++	if (quota < 0)
++		seq_puts(sf, "max");
++	else
++		seq_printf(sf, "%ld", quota);
++
++	seq_printf(sf, " %ld\n", period);
++}
++
++/* caller should put the current value in *@periodp before calling */
++static int __maybe_unused cpu_period_quota_parse(char *buf,
++						 u64 *periodp, u64 *quotap)
++{
++	char tok[21];	/* U64_MAX */
++
++	if (!sscanf(buf, "%s %llu", tok, periodp))
++		return -EINVAL;
++
++	*periodp *= NSEC_PER_USEC;
++
++	if (sscanf(tok, "%llu", quotap))
++		*quotap *= NSEC_PER_USEC;
++	else if (!strcmp(tok, "max"))
++		*quotap = RUNTIME_INF;
++	else
++		return -EINVAL;
++
++	return 0;
++}
++
++#ifdef CONFIG_CFS_BANDWIDTH
++static int cpu_max_show(struct seq_file *sf, void *v)
++{
++	struct task_group *tg = css_tg(seq_css(sf));
++
++	cpu_period_quota_print(sf, tg_get_cfs_period(tg), tg_get_cfs_quota(tg));
++	return 0;
++}
++
++static ssize_t cpu_max_write(struct kernfs_open_file *of,
++			     char *buf, size_t nbytes, loff_t off)
++{
++	struct task_group *tg = css_tg(of_css(of));
++	u64 period = tg_get_cfs_period(tg);
++	u64 quota;
++	int ret;
++
++	ret = cpu_period_quota_parse(buf, &period, &quota);
++	if (!ret)
++		ret = tg_set_cfs_bandwidth(tg, period, quota);
++	return ret ?: nbytes;
++}
++#endif
++
++static struct cftype cpu_files[] = {
++	{
++		.name = "stat",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.seq_show = cpu_stats_show,
++	},
++#ifdef CONFIG_FAIR_GROUP_SCHED
++	{
++		.name = "weight",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.read_u64 = cpu_weight_read_u64,
++		.write_u64 = cpu_weight_write_u64,
++	},
++#endif
++#ifdef CONFIG_CFS_BANDWIDTH
++	{
++		.name = "max",
++		.flags = CFTYPE_NOT_ON_ROOT,
++		.seq_show = cpu_max_show,
++		.write = cpu_max_write,
++	},
++#endif
++	{ }	/* terminate */
++};
++
+ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.css_alloc	= cpu_cgroup_css_alloc,
+ 	.css_released	= cpu_cgroup_css_released,
+@@ -8792,7 +8925,15 @@ struct cgroup_subsys cpu_cgrp_subsys = {
+ 	.can_attach	= cpu_cgroup_can_attach,
+ 	.attach		= cpu_cgroup_attach,
+ 	.legacy_cftypes	= cpu_legacy_files,
++	.dfl_cftypes	= cpu_files,
+ 	.early_init	= true,
++#ifdef CONFIG_CGROUP_CPUACCT
++	/*
++	 * cpuacct is enabled together with cpu on the unified hierarchy
++	 * and its stats are reported through "cpu.stat".
++	 */
++	.depends_on	= 1 << cpuacct_cgrp_id,
++#endif
+ };
+ 
+ #endif	/* CONFIG_CGROUP_SCHED */
+diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c
+index d1e5dd0b3a64..57f390514c39 100644
+--- a/kernel/sched/cpuacct.c
++++ b/kernel/sched/cpuacct.c
+@@ -347,6 +347,31 @@ static struct cftype files[] = {
+ 	{ }	/* terminate */
+ };
+ 
++/* used to print cpuacct stats in cpu.stat on the unified hierarchy */
++void cpuacct_cpu_stats_show(struct seq_file *sf)
++{
++	struct cgroup_subsys_state *css;
++	u64 usage, val[CPUACCT_STAT_NSTATS];
++
++	css = cgroup_get_e_css(seq_css(sf)->cgroup, &cpuacct_cgrp_subsys);
++
++	usage = cpuusage_read(css, seq_cft(sf));
++	cpuacct_stats_read(css_ca(css), &val);
++
++	val[CPUACCT_STAT_USER] *= TICK_NSEC;
++	val[CPUACCT_STAT_SYSTEM] *= TICK_NSEC;
++	do_div(usage, NSEC_PER_USEC);
++	do_div(val[CPUACCT_STAT_USER], NSEC_PER_USEC);
++	do_div(val[CPUACCT_STAT_SYSTEM], NSEC_PER_USEC);
++
++	seq_printf(sf, "usage_usec %llu\n"
++		   "user_usec %llu\n"
++		   "system_usec %llu\n",
++		   usage, val[CPUACCT_STAT_USER], val[CPUACCT_STAT_SYSTEM]);
++
++	css_put(css);
++}
++
+ /*
+  * charge this task's execution time to its accounting group.
+  *
+diff --git a/kernel/sched/cpuacct.h b/kernel/sched/cpuacct.h
+index ba72807c73d4..ddf7af466d35 100644
+--- a/kernel/sched/cpuacct.h
++++ b/kernel/sched/cpuacct.h
+@@ -2,6 +2,7 @@
+ 
+ extern void cpuacct_charge(struct task_struct *tsk, u64 cputime);
+ extern void cpuacct_account_field(struct task_struct *tsk, int index, u64 val);
++extern void cpuacct_cpu_stats_show(struct seq_file *sf);
+ 
+ #else
+ 
+@@ -14,4 +15,8 @@ cpuacct_account_field(struct task_struct *tsk, int index, u64 val)
+ {
+ }
+ 
++static inline void cpuacct_cpu_stats_show(struct seq_file *sf)
++{
++}
++
+ #endif
+
+commit 5019fe3d7ec456b58d451ef06fe1f81d7d9f28a9
+Author: Tejun Heo <tj@kernel.org>
+Date:   Fri Aug 5 12:41:01 2016 -0400
+
+    cgroup: add documentation regarding CPU controller cgroup v2 support
+    
+    Signed-off-by: Tejun Heo <tj@kernel.org>
+
+diff --git a/Documentation/cgroup-v2-cpu.txt b/Documentation/cgroup-v2-cpu.txt
+new file mode 100644
+index 000000000000..1ed7032d4472
+--- /dev/null
++++ b/Documentation/cgroup-v2-cpu.txt
+@@ -0,0 +1,368 @@
++
++
++CPU Controller on Control Group v2
++
++August, 2016		Tejun Heo <tj@kernel.org>
++
++
++While most controllers have support for cgroup v2 now, the CPU
++controller support is not upstream yet due to objections from the
++scheduler maintainers on the basic designs of cgroup v2.  This
++document explains the current situation as well as an interim
++solution, and details the disagreements and arguments.  The latest
++version of this document can be found at the following URL.
++
++ https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup-v2-cpu.txt?h=cgroup-v2-cpu
++
++This document was posted to the linux-kernel and cgroup mailing lists.
++Unfortunately, no consensus was reached as of Oct, 2016.  The thread
++can be found at the following URL.
++
++ http://lkml.kernel.org/r/20160805170752.GK2542@mtj.duckdns.org
++
++
++CONTENTS
++
++1. Current Situation and Interim Solution
++2. Disagreements and Arguments
++  2-1. Contentious Restrictions
++    2-1-1. Process Granularity
++    2-1-2. No Internal Process Constraint
++  2-2. Impact on CPU Controller
++    2-2-1. Impact of Process Granularity
++    2-2-2. Impact of No Internal Process Constraint
++  2-3. Arguments for cgroup v2
++3. Way Forward
++4. References
++
++
++1. Current Situation and Interim Solution
++
++All objections from the scheduler maintainers apply to cgroup v2 core
++design, and there are no known objections to the specifics of the CPU
++controller cgroup v2 interface.  The only blocked part is changes to
++expose the CPU controller interface on cgroup v2, which comprises the
++following two patches:
++
++ [1] sched: Misc preps for cgroup unified hierarchy interface
++ [2] sched: Implement interface for cgroup unified hierarchy
++
++The necessary changes are superficial and implement the interface
++files on cgroup v2.  The combined diffstat is as follows.
++
++ kernel/sched/core.c    |  149 +++++++++++++++++++++++++++++++++++++++++++++++--
++ kernel/sched/cpuacct.c |   57 ++++++++++++------
++ kernel/sched/cpuacct.h |    5 +
++ 3 files changed, 189 insertions(+), 22 deletions(-)
++
++The patches are easy to apply and forward-port.  The following git
++branch will always carry the two patches on top of the latest release
++of the upstream kernel.
++
++ git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git/cgroup-v2-cpu
++
++There also are versioned branches going back to v4.4.
++
++ git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git/cgroup-v2-cpu-$KERNEL_VER
++
++While it's difficult to tell whether the CPU controller support will
++be merged, there are crucial resource control features in cgroup v2
++that are only possible due to the design choices that are being
++objected to, and every effort will be made to ease enabling the CPU
++controller cgroup v2 support out-of-tree for parties which choose to.
++
++
++2. Disagreements and Arguments
++
++There have been several lengthy discussion threads [3][4] on LKML
++around the structural constraints of cgroup v2.  The two that affect
++the CPU controller are process granularity and no internal process
++constraint.  Both arise primarily from the need for common resource
++domain definition across different resources.
++
++The common resource domain is a powerful concept in cgroup v2 that
++allows controllers to make basic assumptions about the structural
++organization of processes and controllers inside the cgroup hierarchy,
++and thus solve problems spanning multiple types of resources.  The
++prime example for this is page cache writeback: dirty page cache is
++regulated through throttling buffered writers based on memory
++availability, and initiating batched write outs to the disk based on
++IO capacity.  Tracking and controlling writeback inside a cgroup thus
++requires the direct cooperation of the memory and the IO controller.
++
++This easily extends to other areas, such as CPU cycles consumed while
++performing memory reclaim or IO encryption.
++
++
++2-1. Contentious Restrictions
++
++For controllers of different resources to work together, they must
++agree on a common organization.  This uniform model across controllers
++imposes two contentious restrictions on the CPU controller: process
++granularity and the no-internal-process constraint.
++
++
++  2-1-1. Process Granularity
++
++  For memory, because an address space is shared between all threads
++  of a process, the terminal consumer is a process, not a thread.
++  Separating the threads of a single process into different memory
++  control domains doesn't make semantical sense.  cgroup v2 ensures
++  that all controller can agree on the same organization by requiring
++  that threads of the same process belong to the same cgroup.
++
++  There are other reasons to enforce process granularity.  One
++  important one is isolating system-level management operations from
++  in-process application operations.  The cgroup interface, being a
++  virtual filesystem, is very unfit for multiple independent
++  operations taking place at the same time as most operations have to
++  be multi-step and there is no way to synchronize multiple accessors.
++  See also [5] Documentation/cgroup-v2.txt, "R-2. Thread Granularity"
++
++
++  2-1-2. No Internal Process Constraint
++
++  cgroup v2 does not allow processes to belong to any cgroup which has
++  child cgroups when resource controllers are enabled on it (the
++  notable exception being the root cgroup itself).  This is because,
++  for some resources, a resource domain (cgroup) is not directly
++  comparable to the terminal consumer (process/task) of said resource,
++  and so putting the two into a sibling relationship isn't meaningful.
++
++  - Differing Control Parameters and Capabilities
++
++    A cgroup controller has different resource control parameters and
++    capabilities from a terminal consumer, be that a task or process.
++    There are a couple cases where a cgroup control knob can be mapped
++    to a per-task or per-process API but they are exceptions and the
++    mappings aren't obvious even in those cases.
++
++    For example, task priorities (also known as nice values) set
++    through setpriority(2) are mapped to the CPU controller
++    "cpu.shares" values.  However, how exactly the two ranges map and
++    even the fact that they map to each other at all are not obvious.
++
++    The situation gets further muddled when considering other resource
++    types and control knobs.  IO priorities set through ioprio_set(2)
++    cannot be mapped to IO controller weights and most cgroup resource
++    control knobs including the bandwidth control knobs of the CPU
++    controller don't have counterparts in the terminal consumers.
++
++  - Anonymous Resource Consumption
++
++    For CPU, every time slice consumed from inside a cgroup, which
++    comprises most but not all of consumed CPU time for the cgroup,
++    can be clearly attributed to a specific task or process.  Because
++    these two types of entities are directly comparable as consumers
++    of CPU time, it's theoretically possible to mix tasks and cgroups
++    on the same tree levels and let them directly compete for the time
++    quota available to their common ancestor.
++
++    However, the same can't be said for resource types like memory or
++    IO: the memory consumed by the page cache, for example, can be
++    tracked on a per-cgroup level, but due to mismatches in lifetimes
++    of involved objects (page cache can persist long after processes
++    are gone), shared usages and the implementation overhead of
++    tracking persistent state, it can no longer be attributed to
++    individual processes after instantiation.  Consequently, any IO
++    incurred by page cache writeback can be attributed to a cgroup,
++    but not to the individual consumers inside the cgroup.
++
++  For memory and IO, this makes a resource domain (cgroup) an object
++  of a fundamentally different type than a terminal consumer
++  (process).  A process can't be a first class object in the resource
++  distribution graph as its total resource consumption can't be
++  described without the containing resource domain.
++
++  Disallowing processes in internal cgroups avoids competition between
++  cgroups and processes which cannot be meaningfully defined for these
++  resources.  All resource control takes place among cgroups and a
++  terminal consumer interacts with the containing cgroup the same way
++  it would with the system without cgroup.
++
++  Root cgroup is exempt from this constraint, which is in line with
++  how root cgroup is handled in general - it's excluded from cgroup
++  resource accounting and control.
++
++
++Enforcing process granularity and no internal process constraint
++allows all controllers to be on the same footing in terms of resource
++distribution hierarchy.
++
++
++2-2. Impact on CPU Controller
++
++As indicated earlier, the CPU controller's resource distribution graph
++is the simplest.  Every schedulable resource consumption can be
++attributed to a specific task.  In addition, for weight based control,
++the per-task priority set through setpriority(2) can be translated to
++and from a per-cgroup weight.  As such, the CPU controller can treat a
++task and a cgroup symmetrically, allowing support for any tree layout
++of cgroups and tasks.  Both process granularity and the no internal
++process constraint restrict how the CPU controller can be used.
++
++
++  2-2-1. Impact of Process Granularity
++
++  Process granularity prevents tasks belonging to the same process to
++  be assigned to different cgroups.  It was pointed out [6] that this
++  excludes the valid use case of hierarchical CPU distribution within
++  processes.
++
++  To address this issue, the rgroup (resource group) [7][8][9]
++  interface, an extension of the existing setpriority(2) API, was
++  proposed, which is in line with other programmable priority
++  mechanisms and eliminates the risk of in-application configuration
++  and system configuration stepping on each other's toes.
++  Unfortunately, the proposal quickly turned into discussions around
++  cgroup v2 design decisions [4] and no consensus could be reached.
++
++
++  2-2-2. Impact of No Internal Process Constraint
++
++  The no internal process constraint disallows tasks from competing
++  directly against cgroups.  Here is an excerpt from Peter Zijlstra
++  pointing out the issue [10] - R, L and A are cgroups; t1, t2, t3 and
++  t4 are tasks:
++
++
++          R
++        / | \
++       t1 t2 A
++           /   \
++          t3   t4
++
++
++    Is fundamentally different from:
++
++
++               R
++             /   \
++           L       A
++         /   \   /   \
++        t1  t2  t3   t4
++
++
++    Because if in the first hierarchy you add a task (t5) to R, all of
++    its A will run at 1/4th of total bandwidth where before it had
++    1/3rd, whereas with the second example, if you add our t5 to L, A
++    doesn't get any less bandwidth.
++
++
++  It is true that the trees are semantically different from each other
++  and the symmetric handling of tasks and cgroups is aesthetically
++  pleasing.  However, it isn't clear what the practical usefulness of
++  a layout with direct competition between tasks and cgroups would be,
++  considering that number and behavior of tasks are controlled by each
++  application, and cgroups primarily deal with system level resource
++  distribution; changes in the number of active threads would directly
++  impact resource distribution.  Real world use cases of such layouts
++  could not be established during the discussions.
++
++
++2-3. Arguments for cgroup v2
++
++There are strong demands for comprehensive hierarchical resource
++control across all major resources, and establishing a common resource
++hierarchy is an essential step.  As with most engineering decisions,
++common resource hierarchy definition comes with its trade-offs.  With
++cgroup v2, the trade-offs are in the form of structural constraints
++which, among others, restrict the CPU controller's space of possible
++configurations.
++
++However, even with the restrictions, cgroup v2, in combination with
++rgroup, covers most of identified real world use cases while enabling
++new important use cases of resource control across multiple resource
++types that were fundamentally broken previously.
++
++Furthermore, for resource control, treating resource domains as
++objects of a different type from terminal consumers has important
++advantages - it can account for resource consumptions which are not
++tied to any specific terminal consumer, be that a task or process, and
++allows decoupling resource distribution controls from in-application
++APIs.  Even the CPU controller may benefit from it as the kernel can
++consume significant amount of CPU cycles in interrupt context or tasks
++shared across multiple resource domains (e.g. softirq).
++
++Finally, it's important to note that enabling cgroup v2 support for
++the CPU controller doesn't block use cases which require the features
++which are not available on cgroup v2.  Unlikely, but should anybody
++actually rely on the CPU controller's symmetric handling of tasks and
++cgroups, backward compatibility is and will be maintained by being
++able to disconnect the controller from the cgroup v2 hierarchy and use
++it standalone.  This also holds for cpuset which is often used in
++highly customized configurations which might be a poor fit for common
++resource domains.
++
++The required changes are minimal, the benefits for the target use
++cases are critical and obvious, and use cases which have to use v1 can
++continue to do so.
++
++
++3. Way Forward
++
++cgroup v2 primarily aims to solve the problem of comprehensive
++hierarchical resource control across all major computing resources,
++which is one of the core problems of modern server infrastructure
++engineering.  The trade-offs that cgroup v2 took are results of
++pursuing that goal and gaining a better understanding of the nature of
++resource control in the process.
++
++I believe that real world usages will prove cgroup v2's model right,
++considering the crucial pieces of comprehensive resource control that
++cannot be implemented without common resource domains.  This is not to
++say that cgroup v2 is fixed in stone and can't be updated; if there is
++an approach which better serves both comprehensive resource control
++and the CPU controller's flexibility, we will surely move towards
++that.  It goes without saying that discussions around such approach
++should consider practical aspects of resource control as a whole
++rather than absolutely focusing on a particular controller.
++
++Until such consensus can be reached, the CPU controller cgroup v2
++support will be maintained out of the mainline kernel in an easily
++accessible form.  If there is anything cgroup developers can do to
++ease the pain, please feel free to contact us on the cgroup mailing
++list at cgroups@vger.kernel.org.
++
++
++4. References
++
++[1]  http://lkml.kernel.org/r/20160105164834.GE5995@mtj.duckdns.org
++     [PATCH 1/2] sched: Misc preps for cgroup unified hierarchy interface
++     Tejun Heo <tj@kernel.org>
++
++[2]  http://lkml.kernel.org/r/20160105164852.GF5995@mtj.duckdns.org
++     [PATCH 2/2] sched: Implement interface for cgroup unified hierarchy
++     Tejun Heo <tj@kernel.org>
++
++[3]  http://lkml.kernel.org/r/1438641689-14655-4-git-send-email-tj@kernel.org
++     [PATCH 3/3] sched: Implement interface for cgroup unified hierarchy
++     Tejun Heo <tj@kernel.org>
++
++[4]  http://lkml.kernel.org/r/20160407064549.GH3430@twins.programming.kicks-ass.net
++     Re: [PATCHSET RFC cgroup/for-4.6] cgroup, sched: implement resource group and PRIO_RGRP
++     Peter Zijlstra <peterz@infradead.org>
++
++[5]  https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/Documentation/cgroup-v2.txt
++     Control Group v2
++     Tejun Heo <tj@kernel.org>
++
++[6]  http://lkml.kernel.org/r/CAPM31RJNy3jgG=DYe6GO=wyL4BPPxwUm1f2S6YXacQmo7viFZA@mail.gmail.com
++     Re: [PATCH 3/3] sched: Implement interface for cgroup unified hierarchy
++     Paul Turner <pjt@google.com>
++
++[7]  http://lkml.kernel.org/r/20160105154503.GC5995@mtj.duckdns.org
++     [RFD] cgroup: thread granularity support for cpu controller
++     Tejun Heo <tj@kernel.org>
++
++[8]  http://lkml.kernel.org/r/1457710888-31182-1-git-send-email-tj@kernel.org
++     [PATCHSET RFC cgroup/for-4.6] cgroup, sched: implement resource group and PRIO_RGRP
++     Tejun Heo <tj@kernel.org>
++
++[9]  http://lkml.kernel.org/r/20160311160522.GA24046@htj.duckdns.org
++     Example program for PRIO_RGRP
++     Tejun Heo <tj@kernel.org>
++
++[10] http://lkml.kernel.org/r/20160407082810.GN3430@twins.programming.kicks-ass.net
++     Re: [PATCHSET RFC cgroup/for-4.6] cgroup, sched: implement resource
++     Peter Zijlstra <peterz@infradead.org>
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/README.md b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/README.md
new file mode 100644
index 000000000000..6d48fde6beef
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/README.md
@@ -0,0 +1,21 @@
+Patches for CPU Controller on Control Group v2
+===============================================
+
+See Tejun Heo's [explanation][1] for why these patches are currently
+out-of-tree.
+
+Generating the patches
+-----------------------
+
+In a linux checkout, with remote tc-cgroup pointing to
+git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup.git, your
+nixpkgs checkout in the same directory as your linux checkout (or
+modify the command accordingly), and setting `ver` to the appropriate
+version:
+
+```shell
+$ ver=4.7
+$ git log --reverse --patch v$ver..remotes/tc-cgroup/cgroup-v2-cpu-v$ver > ../nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/$ver.patch
+```
+
+[1]: https://git.kernel.org/cgit/linux/kernel/git/tj/cgroup.git/tree/Documentation/cgroup-v2-cpu.txt?h=cgroup-v2-cpu
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/default.nix b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/default.nix
new file mode 100644
index 000000000000..5bef5633aa03
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/cpu-cgroup-v2-patches/default.nix
@@ -0,0 +1,11 @@
+let
+  ents = builtins.readDir ./.;
+in builtins.listToAttrs (builtins.filter (x: x != null) (map (name: let
+  match = builtins.match "(.*)\\.patch" name;
+in if match == null then null else {
+  name = builtins.head match;
+  value = {
+    name = "cpu-cgroup-v2-${name}";
+    patch = ./. + "/${name}";
+  };
+}) (builtins.attrNames ents)))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/generate-config.pl b/nixpkgs/pkgs/os-specific/linux/kernel/generate-config.pl
new file mode 100644
index 000000000000..f886fcfdc358
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/generate-config.pl
@@ -0,0 +1,145 @@
+# This script runs `make config' to generate a Linux kernel
+# configuration file.  For each question (i.e. kernel configuration
+# option), unless an override is provided, it answers "m" if possible,
+# and otherwise uses the default answer (as determined by the default
+# config for the architecture).  Overrides are read from the file
+# $KERNEL_CONFIG, which on each line contains an option name and an
+# answer, e.g. "EXT2_FS_POSIX_ACL y".  The script warns about ignored
+# options in $KERNEL_CONFIG, and barfs if `make config' selects
+# another answer for an option than the one provided in
+# $KERNEL_CONFIG.
+
+use strict;
+use IPC::Open2;
+use Cwd;
+
+# exported via nix
+my $debug = $ENV{'DEBUG'};
+my $autoModules = $ENV{'AUTO_MODULES'};
+my $preferBuiltin = $ENV{'PREFER_BUILTIN'};
+my $ignoreConfigErrors = $ENV{'ignoreConfigErrors'};
+my $buildRoot = $ENV{'BUILD_ROOT'};
+$SIG{PIPE} = 'IGNORE';
+
+# Read the answers.
+my %answers;
+my %requiredAnswers;
+open ANSWERS, "<$ENV{KERNEL_CONFIG}" or die "Could not open answer file";
+while (<ANSWERS>) {
+    chomp;
+    s/#.*//;
+    if (/^\s*([A-Za-z0-9_]+)(\?)?\s+(\S+)\s*$/) {
+        $answers{$1} = $3;
+        $requiredAnswers{$1} = !(defined $2);
+    } elsif (!/^\s*$/) {
+        die "invalid config line: $_";
+    }
+}
+close ANSWERS;
+
+sub runConfig {
+
+    # Run `make config'.
+    my $pid = open2(\*IN, \*OUT, "make -C $ENV{SRC} O=$buildRoot config SHELL=bash ARCH=$ENV{ARCH}");
+
+    # Parse the output, look for questions and then send an
+    # appropriate answer.
+    my $line = ""; my $s;
+    my %choices = ();
+
+    my ($prevQuestion, $prevName);
+
+    while (!eof IN) {
+        read IN, $s, 1 or next;
+        $line .= $s;
+
+        #print STDERR "LINE: $line\n";
+
+        if ($s eq "\n") {
+            print STDERR "GOT: $line" if $debug;
+
+            # Remember choice alternatives ("> 1. bla (FOO)" or " 2. bla (BAR) (NEW)").
+            if ($line =~ /^\s*>?\s*(\d+)\.\s+.*?\(([A-Za-z0-9_]+)\)(?:\s+\(NEW\))?\s*$/) {
+                $choices{$2} = $1;
+            }
+
+            $line = "";
+        }
+
+        elsif ($line =~ /###$/) {
+            # The config program is waiting for an answer.
+
+            # Is this a regular question? ("bla bla (OPTION_NAME) [Y/n/m/...] ")
+            if ($line =~ /(.*) \(([A-Za-z0-9_]+)\) \[(.*)\].*###$/) {
+                my $question = $1; my $name = $2; my $alts = $3;
+                my $answer = "";
+                # Build everything as a module if possible.
+                $answer = "m" if $autoModules && $alts =~ /\/m/ && !($preferBuiltin && $alts =~ /Y/);
+                $answer = $answers{$name} if defined $answers{$name};
+                print STDERR "QUESTION: $question, NAME: $name, ALTS: $alts, ANSWER: $answer\n" if $debug;
+                print OUT "$answer\n";
+                die "repeated question: $question" if $prevQuestion && $prevQuestion eq $question && $name eq $prevName;
+                $prevQuestion = $question;
+                $prevName = $name;
+            }
+
+            # Is this a choice? ("choice[1-N]: ")
+            elsif ($line =~ /choice\[(.*)\]: ###$/) {
+                my $answer = "";
+                foreach my $name (keys %choices) {
+                    $answer = $choices{$name} if ($answers{$name} || "") eq "y";
+                }
+                print STDERR "CHOICE: $1, ANSWER: $answer\n" if $debug;
+                print OUT "$answer\n" if $1 =~ /-/;
+            }
+
+            # Some questions lack the option name ("bla bla [Y/n/m/...] ").
+            elsif ($line =~ /(.*) \[(.*)\] ###$/) {
+                print OUT "\n";
+            }
+
+            else {
+                warn "don't know how to answer this question: $line\n";
+                print OUT "\n";
+            }
+
+            $line = "";
+            %choices = ();
+        }
+    }
+
+    close IN;
+    waitpid $pid, 0;
+}
+
+# Run `make config' several times to converge on the desired result.
+# (Some options may only become available after other options are
+# set in a previous run.)
+runConfig;
+runConfig;
+
+# Read the final .config file and check that our answers are in
+# there.  `make config' often overrides answers if later questions
+# cause options to be selected.
+my %config;
+open CONFIG, "<$buildRoot/.config" or die "Could not read .config";
+while (<CONFIG>) {
+    chomp;
+    if (/^CONFIG_([A-Za-z0-9_]+)="(.*)"$/) {
+        # String options have double quotes, e.g. 'CONFIG_NLS_DEFAULT="utf8"' and allow escaping.
+        ($config{$1} = $2) =~ s/\\([\\"])/$1/g;
+    } elsif (/^CONFIG_([A-Za-z0-9_]+)=(.*)$/) {
+        $config{$1} = $2;
+    } elsif (/^# CONFIG_([A-Za-z0-9_]+) is not set$/) {
+        $config{$1} = "n";
+    }
+}
+close CONFIG;
+
+foreach my $name (sort (keys %answers)) {
+    my $f = $requiredAnswers{$name} && $ignoreConfigErrors ne "1"
+        ? sub { die "error: " . $_[0]; } : sub { warn "warning: " . $_[0]; };
+    &$f("unused option: $name\n") unless defined $config{$name};
+    &$f("option not set correctly: $name (wanted '$answers{$name}', got '$config{$name}')\n")
+        if $config{$name} && $config{$name} ne $answers{$name};
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/generic.nix b/nixpkgs/pkgs/os-specific/linux/kernel/generic.nix
new file mode 100644
index 000000000000..df9a628f83da
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/generic.nix
@@ -0,0 +1,176 @@
+{ buildPackages
+, ncurses
+, callPackage
+, perl
+, bison ? null
+, flex ? null
+, gmp ? null
+, libmpc ? null
+, mpfr ? null
+, stdenv
+
+, # The kernel source tarball.
+  src
+
+, # The kernel version.
+  version
+
+, # Allows overriding the default defconfig
+  defconfig ? null
+
+, # Legacy overrides to the intermediate kernel config, as string
+  extraConfig ? ""
+
+, # kernel intermediate config overrides, as a set
+ structuredExtraConfig ? {}
+
+, # The version number used for the module directory
+  modDirVersion ? version
+
+, # An attribute set whose attributes express the availability of
+  # certain features in this kernel.  E.g. `{iwlwifi = true;}'
+  # indicates a kernel that provides Intel wireless support.  Used in
+  # NixOS to implement kernel-specific behaviour.
+  features ? {}
+
+, # A list of patches to apply to the kernel.  Each element of this list
+  # should be an attribute set {name, patch} where `name' is a
+  # symbolic name and `patch' is the actual patch.  The patch may
+  # optionally be compressed with gzip or bzip2.
+  kernelPatches ? []
+, ignoreConfigErrors ? stdenv.hostPlatform.platform.name != "pc" ||
+                       stdenv.hostPlatform != stdenv.buildPlatform
+, extraMeta ? {}
+
+# easy overrides to stdenv.hostPlatform.platform members
+, autoModules ? stdenv.hostPlatform.platform.kernelAutoModules
+, preferBuiltin ? stdenv.hostPlatform.platform.kernelPreferBuiltin or false
+, kernelArch ? stdenv.hostPlatform.platform.kernelArch
+
+, ...
+}:
+
+assert stdenv.isLinux;
+
+let
+
+  lib = stdenv.lib;
+
+  # Combine the `features' attribute sets of all the kernel patches.
+  kernelFeatures = lib.fold (x: y: (x.features or {}) // y) ({
+    iwlwifi = true;
+    efiBootStub = true;
+    needsCifsUtils = true;
+    netfilterRPFilter = true;
+    grsecurity = false;
+    xen_dom0 = false;
+    ia32Emulation = true;
+  } // features) kernelPatches;
+
+  commonStructuredConfig = import ./common-config.nix {
+    inherit stdenv version ;
+
+    features = kernelFeatures; # Ensure we know of all extra patches, etc.
+  };
+
+  intermediateNixConfig = configfile.moduleStructuredConfig.intermediateNixConfig
+    # extra config in legacy string format
+    + extraConfig
+    + lib.optionalString (stdenv.hostPlatform.platform ? kernelExtraConfig) stdenv.hostPlatform.platform.kernelExtraConfig;
+
+  structuredConfigFromPatches =
+        map ({extraStructuredConfig ? {}, ...}: {settings=extraStructuredConfig;}) kernelPatches;
+
+  # appends kernel patches extraConfig
+  kernelConfigFun = baseConfigStr:
+    let
+      configFromPatches =
+        map ({extraConfig ? "", ...}: extraConfig) kernelPatches;
+    in lib.concatStringsSep "\n" ([baseConfigStr] ++ configFromPatches);
+
+  configfile = stdenv.mkDerivation {
+    inherit ignoreConfigErrors autoModules preferBuiltin kernelArch;
+    name = "linux-config-${version}";
+
+    generateConfig = ./generate-config.pl;
+
+    kernelConfig = kernelConfigFun intermediateNixConfig;
+    passAsFile = [ "kernelConfig" ];
+
+    depsBuildBuild = [ buildPackages.stdenv.cc ];
+    nativeBuildInputs = [ perl gmp libmpc mpfr ]
+      ++ lib.optionals (stdenv.lib.versionAtLeast version "4.16") [ bison flex ];
+
+    platformName = stdenv.hostPlatform.platform.name;
+    # e.g. "defconfig"
+    kernelBaseConfig = if defconfig != null then defconfig else stdenv.hostPlatform.platform.kernelBaseConfig;
+    # e.g. "bzImage"
+    kernelTarget = stdenv.hostPlatform.platform.kernelTarget;
+
+    prePatch = kernel.prePatch + ''
+      # Patch kconfig to print "###" after every question so that
+      # generate-config.pl from the generic builder can answer them.
+      sed -e '/fflush(stdout);/i\printf("###");' -i scripts/kconfig/conf.c
+    '';
+
+    preUnpack = kernel.preUnpack or "";
+
+    inherit (kernel) src patches;
+
+    buildPhase = ''
+      export buildRoot="''${buildRoot:-build}"
+
+      # Get a basic config file for later refinement with $generateConfig.
+      make -C .  O="$buildRoot" $kernelBaseConfig \
+          ARCH=$kernelArch \
+          HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc \
+          HOSTCXX=${buildPackages.stdenv.cc.targetPrefix}g++
+
+      # Create the config file.
+      echo "generating kernel configuration..."
+      ln -s "$kernelConfigPath" "$buildRoot/kernel-config"
+      DEBUG=1 ARCH=$kernelArch KERNEL_CONFIG="$buildRoot/kernel-config" AUTO_MODULES=$autoModules \
+           PREFER_BUILTIN=$preferBuiltin BUILD_ROOT="$buildRoot" SRC=. perl -w $generateConfig
+    '';
+
+    installPhase = "mv $buildRoot/.config $out";
+
+    enableParallelBuilding = true;
+
+    passthru = rec {
+
+      module = import ../../../../nixos/modules/system/boot/kernel_config.nix;
+      # used also in apache
+      # { modules = [ { options = res.options; config = svc.config or svc; } ];
+      #   check = false;
+      # The result is a set of two attributes
+      moduleStructuredConfig = (lib.evalModules {
+        modules = [
+          module
+          { settings = commonStructuredConfig; }
+          { settings = structuredExtraConfig; }
+        ]
+        ++  structuredConfigFromPatches
+        ;
+      }).config;
+
+      #
+      structuredConfig = moduleStructuredConfig.settings;
+    };
+
+
+  }; # end of configfile derivation
+
+  kernel = (callPackage ./manual-config.nix {}) {
+    inherit version modDirVersion src kernelPatches stdenv extraMeta configfile;
+
+    config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
+  };
+
+  passthru = {
+    features = kernelFeatures;
+    inherit commonStructuredConfig;
+    passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
+  };
+
+in lib.extendDerivation true passthru kernel
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/genksyms-fix-segfault.patch b/nixpkgs/pkgs/os-specific/linux/kernel/genksyms-fix-segfault.patch
new file mode 100644
index 000000000000..47ae77a5a54d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/genksyms-fix-segfault.patch
@@ -0,0 +1,19 @@
+diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c
+index 88632df..ba6cfa9 100644
+--- a/scripts/genksyms/genksyms.c
++++ b/scripts/genksyms/genksyms.c
+@@ -233,11 +233,11 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
+ 		free_list(last_enum_expr, NULL);
+ 		last_enum_expr = NULL;
+ 		enum_counter = 0;
+-		if (!name)
+-			/* Anonymous enum definition, nothing more to do */
+-			return NULL;
+ 	}
+ 
++	if (!name)
++		return NULL;
++
+ 	h = crc32(name) % HASH_BUCKETS;
+ 	for (sym = symtab[h]; sym; sym = sym->hash_next) {
+ 		if (map_to_ns(sym->type) == map_to_ns(type) &&
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/hardened-config.nix b/nixpkgs/pkgs/os-specific/linux/kernel/hardened-config.nix
new file mode 100644
index 000000000000..f1f18c64130c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/hardened-config.nix
@@ -0,0 +1,120 @@
+# Based on recommendations from:
+# http://kernsec.org/wiki/index.php/Kernel_Self_Protection_Project#Recommended_settings
+# https://wiki.gentoo.org/wiki/Hardened/Hardened_Kernel_Project
+#
+# Dangerous features that can be permanently (for the boot session) disabled at
+# boot via sysctl or kernel cmdline are left enabled here, for improved
+# flexibility.
+#
+# See also <nixos/modules/profiles/hardened.nix>
+
+{ stdenv, version }:
+
+with stdenv.lib;
+with import ../../../../lib/kernel.nix { inherit (stdenv) lib; inherit version; };
+
+assert (versionAtLeast version "4.9");
+
+optionalAttrs (stdenv.hostPlatform.platform.kernelArch == "x86_64") {
+  DEFAULT_MMAP_MIN_ADDR = freeform "65536";  # Prevent allocation of first 64K of memory
+
+  # Reduce attack surface by disabling various emulations
+  IA32_EMULATION     = no;
+  X86_X32            = no;
+  # Note: this config depends on EXPERT y and so will not take effect, hence
+  # it is left "optional" for now.
+  MODIFY_LDT_SYSCALL = option no;
+  VMAP_STACK         = yes; # Catch kernel stack overflows
+
+  # Randomize position of kernel and memory.
+  RANDOMIZE_BASE   = yes;
+  RANDOMIZE_MEMORY = yes;
+
+  # Disable legacy virtual syscalls by default (modern glibc use vDSO instead).
+  #
+  # Note that the vanilla default is to *emulate* the legacy vsyscall mechanism,
+  # which is supposed to be safer than the native variant (wrt. ret2libc), so
+  # disabling it mainly helps reduce surface.
+  LEGACY_VSYSCALL_NONE = yes;
+} // {
+  # Report BUG() conditions and kill the offending process.
+  BUG = yes;
+
+  BUG_ON_DATA_CORRUPTION = whenAtLeast "4.10" yes;
+
+  # Safer page access permissions (wrt. code injection).  Default on >=4.11.
+  DEBUG_RODATA          = whenOlder "4.11" yes;
+  DEBUG_SET_MODULE_RONX = whenOlder "4.11" yes;
+
+  # Mark LSM hooks read-only after init.  SECURITY_WRITABLE_HOOKS n
+  # conflicts with SECURITY_SELINUX_DISABLE y; disabling the latter
+  # implicitly marks LSM hooks read-only after init.
+  #
+  # SELinux can only be disabled at boot via selinux=0
+  #
+  # We set SECURITY_WRITABLE_HOOKS n primarily for documentation purposes; the
+  # config builder fails to detect that it has indeed been unset.
+  SECURITY_SELINUX_DISABLE = whenAtLeast "4.12" no;
+  SECURITY_WRITABLE_HOOKS  = whenAtLeast "4.12" (option no);
+
+  DEBUG_WX = yes; # boot-time warning on RWX mappings
+  STRICT_KERNEL_RWX = whenAtLeast "4.11" yes;
+
+  # Stricter /dev/mem
+  STRICT_DEVMEM    = option yes;
+  IO_STRICT_DEVMEM = option yes;
+
+  # Perform additional validation of commonly targeted structures.
+  DEBUG_CREDENTIALS     = yes;
+  DEBUG_NOTIFIERS       = yes;
+  DEBUG_LIST            = yes;
+  DEBUG_PI_LIST         = yes; # doesn't BUG()
+  DEBUG_SG              = yes;
+  SCHED_STACK_END_CHECK = yes;
+
+  REFCOUNT_FULL = whenAtLeast "4.13" yes;
+
+  # Perform usercopy bounds checking.
+  HARDENED_USERCOPY = yes;
+  HARDENED_USERCOPY_FALLBACK = whenAtLeast "4.16" no; # for full whitelist enforcement
+
+  # Randomize allocator freelists.
+  SLAB_FREELIST_RANDOM = yes;
+
+  SLAB_FREELIST_HARDENED = whenAtLeast "4.14" yes;
+
+  # Allow enabling slub/slab free poisoning with slub_debug=P
+  SLUB_DEBUG = yes;
+
+  # Wipe higher-level memory allocations on free() with page_poison=1
+  PAGE_POISONING           = yes;
+  PAGE_POISONING_NO_SANITY = yes;
+  PAGE_POISONING_ZERO      = yes;
+
+  # Reboot devices immediately if kernel experiences an Oops.
+  PANIC_ON_OOPS = yes;
+  PANIC_TIMEOUT = freeform "-1";
+
+  GCC_PLUGINS = yes; # Enable gcc plugin options
+  # Gather additional entropy at boot time for systems that may = no;ot have appropriate entropy sources.
+  GCC_PLUGIN_LATENT_ENTROPY = yes;
+
+  GCC_PLUGIN_STRUCTLEAK = whenAtLeast "4.11" yes; # A port of the PaX structleak plugin
+  GCC_PLUGIN_STRUCTLEAK_BYREF_ALL = whenAtLeast "4.14" yes; # Also cover structs passed by address
+  GCC_PLUGIN_STACKLEAK = whenAtLeast "4.20" yes; # A port of the PaX stackleak plugin
+  GCC_PLUGIN_RANDSTRUCT = whenAtLeast "4.13" yes; # A port of the PaX randstruct plugin
+  GCC_PLUGIN_RANDSTRUCT_PERFORMANCE = whenAtLeast "4.13" yes;
+
+  # Disable various dangerous settings
+  ACPI_CUSTOM_METHOD = no; # Allows writing directly to physical memory
+  PROC_KCORE         = no; # Exposes kernel text image layout
+  INET_DIAG          = no; # Has been used for heap based attacks in the past
+
+  # Use -fstack-protector-strong (gcc 4.9+) for best stack canary coverage.
+  CC_STACKPROTECTOR_REGULAR = whenOlder "4.18" no;
+  CC_STACKPROTECTOR_STRONG  = whenOlder "4.18" yes;
+
+  # Enable compile/run-time buffer overflow detection ala glibc's _FORTIFY_SOURCE
+  FORTIFY_SOURCE = whenAtLeast "4.13" yes;
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.14.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.14.nix
new file mode 100644
index 000000000000..89639d34a6c3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.14.nix
@@ -0,0 +1,18 @@
+{ stdenv, buildPackages, fetchurl, perl, buildLinux, modDirVersionArg ? null, ... } @ args:
+
+with stdenv.lib;
+
+buildLinux (args // rec {
+  version = "4.14.110";
+
+  # modDirVersion needs to be x.y.z, will automatically add .0 if needed
+  modDirVersion = if (modDirVersionArg == null) then concatStrings (intersperse "." (take 3 (splitString "." "${version}.0"))) else modDirVersionArg;
+
+  # 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 = "0wlysm6j8mmfwcja8pxg6a5c611m3x597591hswpm2nwcja3bslr";
+  };
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.19.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.19.nix
new file mode 100644
index 000000000000..d043a18844b1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.19.nix
@@ -0,0 +1,18 @@
+{ stdenv, buildPackages, fetchurl, perl, buildLinux, modDirVersionArg ? null, ... } @ args:
+
+with stdenv.lib;
+
+buildLinux (args // rec {
+  version = "4.19.33";
+
+  # modDirVersion needs to be x.y.z, will automatically add .0 if needed
+  modDirVersion = if (modDirVersionArg == null) then concatStrings (intersperse "." (take 3 (splitString "." "${version}.0"))) else modDirVersionArg;
+
+  # 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 = "14yk5hli62q1g8vghjjghbxjkpxns8zp0l2wmyhlx0v21bx2v89r";
+  };
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.4.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.4.nix
new file mode 100644
index 000000000000..1698c9d70942
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.4.nix
@@ -0,0 +1,11 @@
+{ stdenv, buildPackages, fetchurl, perl, buildLinux, ... } @ args:
+
+buildLinux (args // rec {
+  version = "4.4.178";
+  extraMeta.branch = "4.4";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
+    sha256 = "0g84g808v7zjnfm1nh7ba0swa4n2bfw8m7h5qgmknjwrnwi8qnf3";
+  };
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.9.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.9.nix
new file mode 100644
index 000000000000..f583ced1a631
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-4.9.nix
@@ -0,0 +1,11 @@
+{ stdenv, buildPackages, fetchurl, perl, buildLinux, ... } @ args:
+
+buildLinux (args // rec {
+  version = "4.9.167";
+  extraMeta.branch = "4.9";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
+    sha256 = "130a7z31sdha84w67vfx0j1sq68v15aksfkcshz219p75y561f52";
+  };
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-5.0.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-5.0.nix
new file mode 100644
index 000000000000..4038a89f6c63
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-5.0.nix
@@ -0,0 +1,18 @@
+{ stdenv, buildPackages, fetchurl, perl, buildLinux, modDirVersionArg ? null, ... } @ args:
+
+with stdenv.lib;
+
+buildLinux (args // rec {
+  version = "5.0.6";
+
+  # modDirVersion needs to be x.y.z, will automatically add .0 if needed
+  modDirVersion = if (modDirVersionArg == null) then concatStrings (intersperse "." (take 3 (splitString "." "${version}.0"))) else modDirVersionArg;
+
+  # branchVersion needs to be x.y
+  extraMeta.branch = concatStrings (intersperse "." (take 2 (splitString "." version)));
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/kernel/v5.x/linux-${version}.tar.xz";
+    sha256 = "04zl3xqgr6rlkc44raz3rz74ag7l5j16wkvkdmlzrdq7ia6rljly";
+  };
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-hardkernel-4.14.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-hardkernel-4.14.nix
new file mode 100644
index 000000000000..3fcb2fcbb24a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-hardkernel-4.14.nix
@@ -0,0 +1,33 @@
+{ stdenv, buildPackages, fetchFromGitHub, perl, buildLinux, libelf, utillinux, ... } @ args:
+
+buildLinux (args // rec {
+  version = "4.14.102-156";
+
+  # modDirVersion needs to be x.y.z.
+  modDirVersion = "4.14.102";
+
+  # branchVersion needs to be x.y.
+  extraMeta.branch = "4.14";
+
+  src = fetchFromGitHub {
+    owner = "hardkernel";
+    repo = "linux";
+    rev = version;
+    sha256 = "12af0n1lg2w2qm9aq1v8w3x8npaka60ks9xp6jwaw0l06j23ryyv";
+  };
+
+  defconfig = "odroidxu4_defconfig";
+
+  # This extraConfig is (only) required because the gator module fails to build as-is.
+  extraConfig = ''
+
+    GATOR n
+
+    # This attempted fix applies correctly but does not fix the build.
+    #GATOR_MALI_MIDGARD_PATH ${src}/drivers/gpu/arm/midgard
+
+  '' + (args.extraConfig or "");
+
+  extraMeta.platforms = [ "armv7l-linux" ];
+
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-libre.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-libre.nix
new file mode 100644
index 000000000000..a3dd17b72892
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-libre.nix
@@ -0,0 +1,41 @@
+{ stdenv, lib, fetchsvn, linux
+, scripts ? fetchsvn {
+    url = "https://www.fsfla.org/svn/fsfla/software/linux-libre/releases/tags/";
+
+    # Update this if linux_latest-libre fails to build.
+    # $ curl https://www.fsfla.org/svn/fsfla/software/linux-libre/releases/tags/ | grep -Eo 'Revision [0-9]+'
+    rev = "16063";
+    sha256 = "0y4icpkysnf15bpkj71g8samhj516913mx6ng5fb2hdxc4009bx2";
+  }
+, ...
+}:
+
+let
+  majorMinor = lib.versions.majorMinor linux.modDirVersion;
+
+  major = lib.versions.major linux.modDirVersion;
+  minor = lib.versions.minor linux.modDirVersion;
+  patch = lib.versions.patch linux.modDirVersion;
+
+in linux.override {
+  argsOverride = {
+    modDirVersion = "${linux.modDirVersion}-gnu";
+
+    src = stdenv.mkDerivation {
+      name = "${linux.name}-libre-src";
+      src = linux.src;
+      buildPhase = ''
+        ${scripts}/${majorMinor}-gnu/deblob-${majorMinor} \
+            ${major} ${minor} ${patch}
+      '';
+      checkPhase = ''
+        ${scripts}/deblob-check
+      '';
+      installPhase = ''
+        cp -r . "$out"
+      '';
+    };
+
+    maintainers = [ lib.maintainers.qyliss ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp-93.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp-93.nix
new file mode 100644
index 000000000000..8be59fbea903
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp-93.nix
@@ -0,0 +1,47 @@
+{ stdenv, buildPackages, fetchFromGitHub, perl, buildLinux, ... } @ args:
+
+buildLinux (rec {
+  mptcpVersion = "0.93";
+  modDirVersion = "4.9.60";
+  version = "${modDirVersion}-mptcp_v${mptcpVersion}";
+
+  extraMeta = {
+    branch = "4.4";
+    maintainers = with stdenv.lib.maintainers; [ teto layus ];
+  };
+
+  src = fetchFromGitHub {
+    owner = "multipath-tcp";
+    repo = "mptcp";
+    rev = "v${mptcpVersion}";
+    sha256 = "1irlppzvcmckrazs2c4vg6y8ji31552izc3wqabf401v57jvxcys";
+  };
+
+  extraConfig = ''
+    IPV6 y
+    MPTCP y
+    IP_MULTIPLE_TABLES y
+
+    # Enable advanced path-managers...
+    MPTCP_PM_ADVANCED y
+    MPTCP_FULLMESH y
+    MPTCP_NDIFFPORTS y
+    # ... but use none by default.
+    # The default is safer if source policy routing is not setup.
+    DEFAULT_DUMMY y
+    DEFAULT_MPTCP_PM default
+
+    # MPTCP scheduler selection.
+    # Disabled as the only non-default is the useless round-robin.
+    MPTCP_SCHED_ADVANCED n
+    DEFAULT_MPTCP_SCHED default
+
+    # Smarter TCP congestion controllers
+    TCP_CONG_LIA m
+    TCP_CONG_OLIA m
+    TCP_CONG_WVEGAS m
+    TCP_CONG_BALIA m
+
+  '' + (args.extraConfig or "");
+} // args)
+
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp.nix
new file mode 100644
index 000000000000..d96853eb7cfc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-mptcp.nix
@@ -0,0 +1,49 @@
+{ stdenv, buildPackages, fetchFromGitHub, perl, buildLinux, structuredExtraConfig ? {}, ... } @ args:
+let
+  mptcpVersion = "0.94.3";
+  modDirVersion = "4.14.105";
+in
+buildLinux ({
+  version = "${modDirVersion}-mptcp_v${mptcpVersion}";
+  inherit modDirVersion;
+
+  extraMeta = {
+    branch = "4.4";
+    maintainers = with stdenv.lib.maintainers; [ teto layus ];
+  };
+
+  src = fetchFromGitHub {
+    owner = "multipath-tcp";
+    repo = "mptcp";
+    rev = "v${mptcpVersion}";
+    sha256 = "1pic86icrlmxajw4hkqyljha8a3k4w9kb5z74xj4yiyapmk9wprm";
+  };
+
+  structuredExtraConfig = with import ../../../../lib/kernel.nix { inherit (stdenv) lib; version = null; };
+    stdenv.lib.mkMerge [ {
+    IPV6               = yes;
+    MPTCP              = yes;
+    IP_MULTIPLE_TABLES = yes;
+
+    # Enable advanced path-managers...
+    MPTCP_PM_ADVANCED = yes;
+    MPTCP_FULLMESH = yes;
+    MPTCP_NDIFFPORTS = yes;
+    # ... but use none by default.
+    # The default is safer if source policy routing is not setup.
+    DEFAULT_DUMMY = yes;
+    DEFAULT_MPTCP_PM.freeform = "default";
+
+    # MPTCP scheduler selection.
+    MPTCP_SCHED_ADVANCED = yes;
+    DEFAULT_MPTCP_SCHED.freeform = "default";
+
+    # Smarter TCP congestion controllers
+    TCP_CONG_LIA = module;
+    TCP_CONG_OLIA = module;
+    TCP_CONG_WVEGAS = module;
+    TCP_CONG_BALIA = module;
+  }
+  structuredExtraConfig
+  ];
+} // args)
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-rpi.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-rpi.nix
new file mode 100644
index 000000000000..7077a70a7ab0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-rpi.nix
@@ -0,0 +1,60 @@
+{ stdenv, lib, buildPackages, fetchFromGitHub, perl, buildLinux, ... } @ args:
+
+let
+  modDirVersion = "4.14.70";
+  tag = "1.20180919";
+in
+lib.overrideDerivation (buildLinux (args // rec {
+  version = "${modDirVersion}-${tag}";
+  inherit modDirVersion;
+
+  src = fetchFromGitHub {
+    owner = "raspberrypi";
+    repo = "linux";
+    rev = "raspberrypi-kernel_${tag}-1";
+    sha256 = "1zjvzk6rhrn3ngc012gjq3v7lxn8hy89ljb7fqwld5g7py9lkf0b";
+  };
+
+  defconfig = {
+    "armv6l-linux" = "bcmrpi_defconfig";
+    "armv7l-linux" = "bcm2709_defconfig";
+    "aarch64-linux" = "bcmrpi3_defconfig";
+  }.${stdenv.hostPlatform.system} or (throw "linux_rpi not supported on '${stdenv.hostPlatform.system}'");
+
+  features = {
+    efiBootStub = false;
+  } // (args.features or {});
+
+  extraMeta.hydraPlatforms = [ "aarch64-linux" ];
+})) (oldAttrs: {
+  postConfigure = ''
+    # The v7 defconfig has this set to '-v7' which screws up our modDirVersion.
+    sed -i $buildRoot/.config -e 's/^CONFIG_LOCALVERSION=.*/CONFIG_LOCALVERSION=""/'
+  '';
+
+  # Make copies of the DTBs named after the upstream names so that U-Boot finds them.
+  # This is ugly as heck, but I don't know a better solution so far.
+  postFixup = ''
+    dtbDir=${if stdenv.isAarch64 then "$out/dtbs/broadcom" else "$out/dtbs"}
+    rm $dtbDir/bcm283*.dtb
+    copyDTB() {
+      cp -v "$dtbDir/$1" "$dtbDir/$2"
+    }
+  '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv6l-linux"]) ''
+    copyDTB bcm2708-rpi-0-w.dtb bcm2835-rpi-zero.dtb
+    copyDTB bcm2708-rpi-0-w.dtb bcm2835-rpi-zero-w.dtb
+    copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-a.dtb
+    copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-b.dtb
+    copyDTB bcm2708-rpi-b.dtb bcm2835-rpi-b-rev2.dtb
+    copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-a-plus.dtb
+    copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-b-plus.dtb
+    copyDTB bcm2708-rpi-b-plus.dtb bcm2835-rpi-zero.dtb
+    copyDTB bcm2708-rpi-cm.dtb bcm2835-rpi-cm.dtb
+  '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv7l-linux"]) ''
+    copyDTB bcm2709-rpi-2-b.dtb bcm2836-rpi-2-b.dtb
+  '' + lib.optionalString (lib.elem stdenv.hostPlatform.system ["armv7l-linux" "aarch64-linux"]) ''
+    copyDTB bcm2710-rpi-3-b.dtb bcm2837-rpi-3-b.dtb
+    copyDTB bcm2710-rpi-3-b-plus.dtb bcm2837-rpi-3-b-plus.dtb
+    copyDTB bcm2710-rpi-cm3.dtb bcm2837-rpi-cm3.dtb
+  '';
+})
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-testing-bcachefs.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-testing-bcachefs.nix
new file mode 100644
index 000000000000..4b9afba0ea92
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-testing-bcachefs.nix
@@ -0,0 +1,22 @@
+{ stdenv, buildPackages, fetchgit, perl, buildLinux, ... } @ args:
+
+buildLinux (args // rec {
+  version = "4.20.2019.03.13";
+  modDirVersion = "4.20.0";
+
+  src = fetchgit {
+    url = "https://evilpiepirate.org/git/bcachefs.git";
+    rev = "986543d24e08a0c0308472403b230d546e7ecbbb";
+    sha256 = "07h9l47wijhlx3xnyxnj8kv1zb9yf2x0gag8n606yq6wn9r523hv";
+  };
+
+  extraConfig = "BCACHEFS_FS m";
+
+  extraMeta = {
+    branch = "master";
+    hydraPlatforms = []; # Should the testing kernels ever be built on Hydra?
+    maintainers = with stdenv.lib.maintainers; [ davidak chiiruno ];
+    platforms = [ "x86_64-linux" ];
+  };
+
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/linux-testing.nix b/nixpkgs/pkgs/os-specific/linux/kernel/linux-testing.nix
new file mode 100644
index 000000000000..fde9e560c46f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/linux-testing.nix
@@ -0,0 +1,16 @@
+{ stdenv, buildPackages, fetchurl, perl, buildLinux, libelf, utillinux, ... } @ args:
+
+buildLinux (args // rec {
+  version = "5.1-rc3";
+  modDirVersion = "5.1.0-rc3";
+  extraMeta.branch = "5.1";
+
+  src = fetchurl {
+    url = "https://git.kernel.org/torvalds/t/linux-${version}.tar.gz";
+    sha256 = "1nc5h0rfd40wfp8ld0d6n90haxp4xqcapwkg4vgn2m0c6dcspl2n";
+  };
+
+  # Should the testing kernels ever be built on Hydra?
+  extraMeta.hydraPlatforms = [];
+
+} // (args.argsOverride or {}))
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/manual-config.nix b/nixpkgs/pkgs/os-specific/linux/kernel/manual-config.nix
new file mode 100644
index 000000000000..4b570c1fe940
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/manual-config.nix
@@ -0,0 +1,298 @@
+{ buildPackages, runCommand, nettools, bc, bison, flex, perl, rsync, gmp, libmpc, mpfr, openssl
+, libelf
+, utillinux
+, writeTextFile
+}:
+
+let
+  readConfig = configfile: import (runCommand "config.nix" {} ''
+    echo "{" > "$out"
+    while IFS='=' read key val; do
+      [ "x''${key#CONFIG_}" != "x$key" ] || continue
+      no_firstquote="''${val#\"}";
+      echo '  "'"$key"'" = "'"''${no_firstquote%\"}"'";' >> "$out"
+    done < "${configfile}"
+    echo "}" >> $out
+  '').outPath;
+in {
+  # Allow overriding stdenv on each buildLinux call
+  stdenv,
+  # The kernel version
+  version,
+  # The version of the kernel module directory
+  modDirVersion ? version,
+  # The kernel source (tarball, git checkout, etc.)
+  src,
+  # a list of { name=..., patch=..., extraConfig=...} patches
+  kernelPatches ? [],
+  # The kernel .config file
+  configfile,
+  # Manually specified nixexpr representing the config
+  # If unspecified, this will be autodetected from the .config
+  config ? stdenv.lib.optionalAttrs allowImportFromDerivation (readConfig configfile),
+  # Use defaultMeta // extraMeta
+  extraMeta ? {},
+  # Whether to utilize the controversial import-from-derivation feature to parse the config
+  allowImportFromDerivation ? false,
+  # ignored
+  features ? null,
+}:
+
+let
+  inherit (stdenv.lib)
+    hasAttr getAttr optional optionals optionalString optionalAttrs maintainers platforms;
+
+  # Dependencies that are required to build kernel modules
+  moduleBuildDependencies = optional (stdenv.lib.versionAtLeast version "4.14") libelf;
+
+  installkernel = writeTextFile { name = "installkernel"; executable=true; text = ''
+    #!${stdenv.shell} -e
+    mkdir -p $4
+    cp -av $2 $4
+    cp -av $3 $4
+  ''; };
+
+  commonMakeFlags = [
+    "O=$(buildRoot)"
+  ] ++ stdenv.lib.optionals (stdenv.hostPlatform.platform ? kernelMakeFlags)
+    stdenv.hostPlatform.platform.kernelMakeFlags;
+
+  drvAttrs = config_: platform: kernelPatches: configfile:
+    let
+      config = let attrName = attr: "CONFIG_" + attr; in {
+        isSet = attr: hasAttr (attrName attr) config;
+
+        getValue = attr: if config.isSet attr then getAttr (attrName attr) config else null;
+
+        isYes = attr: (config.getValue attr) == "y";
+
+        isNo = attr: (config.getValue attr) == "n";
+
+        isModule = attr: (config.getValue attr) == "m";
+
+        isEnabled = attr: (config.isModule attr) || (config.isYes attr);
+
+        isDisabled = attr: (!(config.isSet attr)) || (config.isNo attr);
+      } // config_;
+
+      isModular = config.isYes "MODULES";
+
+      installsFirmware = (config.isEnabled "FW_LOADER") &&
+        (isModular || (config.isDisabled "FIRMWARE_IN_KERNEL")) &&
+        (stdenv.lib.versionOlder version "4.14");
+    in (optionalAttrs isModular { outputs = [ "out" "dev" ]; }) // {
+      passthru = {
+        inherit version modDirVersion config kernelPatches configfile
+          moduleBuildDependencies stdenv;
+      };
+
+      inherit src;
+
+      patches =
+        map (p: p.patch) kernelPatches
+        # Required for deterministic builds along with some postPatch magic.
+        ++ optional (stdenv.lib.versionAtLeast version "4.13") ./randstruct-provide-seed.patch;
+
+      prePatch = ''
+        for mf in $(find -name Makefile -o -name Makefile.include -o -name install.sh); do
+            echo "stripping FHS paths in \`$mf'..."
+            sed -i "$mf" -e 's|/usr/bin/||g ; s|/bin/||g ; s|/sbin/||g'
+        done
+        sed -i Makefile -e 's|= depmod|= ${buildPackages.kmod}/bin/depmod|'
+        sed -i scripts/ld-version.sh -e "s|/usr/bin/awk|${buildPackages.gawk}/bin/awk|"
+      '';
+
+      postPatch = ''
+        # Set randstruct seed to a deterministic but diversified value. Note:
+        # we could have instead patched gen-random-seed.sh to take input from
+        # the buildFlags, but that would require also patching the kernel's
+        # toplevel Makefile to add a variable export. This would be likely to
+        # cause future patch conflicts.
+        if [ -f scripts/gcc-plugins/gen-random-seed.sh ]; then
+          substituteInPlace scripts/gcc-plugins/gen-random-seed.sh \
+            --replace NIXOS_RANDSTRUCT_SEED \
+            $(echo ${src} ${configfile} | sha256sum | cut -d ' ' -f 1 | tr -d '\n')
+        fi
+      '';
+
+      configurePhase = ''
+        runHook preConfigure
+
+        mkdir build
+        export buildRoot="$(pwd)/build"
+
+        echo "manual-config configurePhase buildRoot=$buildRoot pwd=$PWD"
+
+        if [ -f "$buildRoot/.config" ]; then
+          echo "Could not link $buildRoot/.config : file exists"
+          exit 1
+        fi
+        ln -sv ${configfile} $buildRoot/.config
+
+        # reads the existing .config file and prompts the user for options in
+        # the current kernel source that are not found in the file.
+        make $makeFlags "''${makeFlagsArray[@]}" oldconfig
+        runHook postConfigure
+
+        make $makeFlags "''${makeFlagsArray[@]}" prepare
+        actualModDirVersion="$(cat $buildRoot/include/config/kernel.release)"
+        if [ "$actualModDirVersion" != "${modDirVersion}" ]; then
+          echo "Error: modDirVersion ${modDirVersion} specified in the Nix expression is wrong, it should be: $actualModDirVersion"
+          exit 1
+        fi
+
+        # Note: we can get rid of this once http://permalink.gmane.org/gmane.linux.kbuild.devel/13800 is merged.
+        buildFlagsArray+=("KBUILD_BUILD_TIMESTAMP=$(date -u -d @$SOURCE_DATE_EPOCH)")
+
+        cd $buildRoot
+      '';
+
+      buildFlags = [
+        "KBUILD_BUILD_VERSION=1-NixOS"
+        platform.kernelTarget
+        "vmlinux"  # for "perf" and things like that
+      ] ++ optional isModular "modules";
+
+      installFlags = [
+        "INSTALLKERNEL=${installkernel}"
+        "INSTALL_PATH=$(out)"
+      ] ++ (optional isModular "INSTALL_MOD_PATH=$(out)")
+      ++ optional installsFirmware "INSTALL_FW_PATH=$(out)/lib/firmware";
+
+      # Some image types need special install targets (e.g. uImage is installed with make uinstall)
+      installTargets = [ (
+        if platform ? kernelInstallTarget then platform.kernelInstallTarget
+        else if platform.kernelTarget == "uImage" then "uinstall"
+        else if platform.kernelTarget == "zImage" || platform.kernelTarget == "Image.gz" then "zinstall"
+        else "install"
+      ) ];
+
+      postInstall = (optionalString installsFirmware ''
+        mkdir -p $out/lib/firmware
+      '') + (if (platform ? kernelDTB && platform.kernelDTB) then ''
+        make $makeFlags "''${makeFlagsArray[@]}" dtbs dtbs_install INSTALL_DTBS_PATH=$out/dtbs
+      '' else "") + (if isModular then ''
+        mkdir -p $dev
+        cp vmlinux $dev/
+        if [ -z "$dontStrip" ]; then
+          installFlagsArray+=("INSTALL_MOD_STRIP=1")
+        fi
+        make modules_install $makeFlags "''${makeFlagsArray[@]}" \
+          $installFlags "''${installFlagsArray[@]}"
+        unlink $out/lib/modules/${modDirVersion}/build
+        unlink $out/lib/modules/${modDirVersion}/source
+
+        mkdir -p $dev/lib/modules/${modDirVersion}/{build,source}
+
+        # To save space, exclude a bunch of unneeded stuff when copying.
+        (cd .. && rsync --archive --prune-empty-dirs \
+            --exclude='/build/' \
+            --exclude='/Documentation/' \
+            * $dev/lib/modules/${modDirVersion}/source/)
+
+        cd $dev/lib/modules/${modDirVersion}/source
+
+        cp $buildRoot/{.config,Module.symvers} $dev/lib/modules/${modDirVersion}/build
+        make modules_prepare $makeFlags "''${makeFlagsArray[@]}" O=$dev/lib/modules/${modDirVersion}/build
+
+        # Keep some extra files on some arches (powerpc, aarch64)
+        for f in arch/powerpc/lib/crtsavres.o arch/arm64/kernel/ftrace-mod.o; do
+          if [ -f "$buildRoot/$f" ]; then
+            cp $buildRoot/$f $dev/lib/modules/${modDirVersion}/build/$f
+          fi
+        done
+
+        # !!! No documentation on how much of the source tree must be kept
+        # If/when kernel builds fail due to missing files, you can add
+        # them here. Note that we may see packages requiring headers
+        # from drivers/ in the future; it adds 50M to keep all of its
+        # headers on 3.10 though.
+
+        chmod u+w -R ..
+        arch=$(cd $dev/lib/modules/${modDirVersion}/build/arch; ls)
+
+        # Remove unused arches
+        for d in $(cd arch/; ls); do
+          if [ "$d" = "$arch" ]; then continue; fi
+          if [ "$arch" = arm64 ] && [ "$d" = arm ]; then continue; fi
+          rm -rf arch/$d
+        done
+
+        # Remove all driver-specific code (50M of which is headers)
+        rm -fR drivers
+
+        # Keep all headers
+        find .  -type f -name '*.h' -print0 | xargs -0 chmod u-w
+
+        # Keep linker scripts (they are required for out-of-tree modules on aarch64)
+        find .  -type f -name '*.lds' -print0 | xargs -0 chmod u-w
+
+        # Keep root and arch-specific Makefiles
+        chmod u-w Makefile
+        chmod u-w arch/$arch/Makefile*
+
+        # Keep whole scripts dir
+        chmod u-w -R scripts
+
+        # Delete everything not kept
+        find . -type f -perm -u=w -print0 | xargs -0 rm
+
+        # Delete empty directories
+        find -empty -type d -delete
+
+        # Remove reference to kmod
+        sed -i Makefile -e 's|= ${buildPackages.kmod}/bin/depmod|= depmod|'
+      '' else optionalString installsFirmware ''
+        make firmware_install $makeFlags "''${makeFlagsArray[@]}" \
+          $installFlags "''${installFlagsArray[@]}"
+      '');
+
+      requiredSystemFeatures = [ "big-parallel" ];
+
+      meta = {
+        description =
+          "The Linux kernel" +
+          (if kernelPatches == [] then "" else
+            " (with patches: "
+            + stdenv.lib.concatStringsSep ", " (map (x: x.name) kernelPatches)
+            + ")");
+        license = stdenv.lib.licenses.gpl2;
+        homepage = https://www.kernel.org/;
+        repositories.git = https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git;
+        maintainers = [
+          maintainers.thoughtpolice
+        ];
+        platforms = platforms.linux;
+        timeout = 14400; # 4 hours
+      } // extraMeta;
+    };
+in
+
+assert stdenv.lib.versionAtLeast version "4.14" -> libelf != null;
+assert stdenv.lib.versionAtLeast version "4.15" -> utillinux != null;
+stdenv.mkDerivation ((drvAttrs config stdenv.hostPlatform.platform kernelPatches configfile) // {
+  name = "linux-${version}";
+
+  enableParallelBuilding = true;
+
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
+  nativeBuildInputs = [ perl bc nettools openssl rsync gmp libmpc mpfr ]
+      ++ optional (stdenv.hostPlatform.platform.kernelTarget == "uImage") buildPackages.ubootTools
+      ++ optional (stdenv.lib.versionAtLeast version "4.14") libelf
+      ++ optional (stdenv.lib.versionAtLeast version "4.15") utillinux
+      ++ optionals (stdenv.lib.versionAtLeast version "4.16") [ bison flex ]
+      ;
+
+  hardeningDisable = [ "bindnow" "format" "fortify" "stackprotector" "pic" "pie" ];
+
+  # Absolute paths for compilers avoid any PATH-clobbering issues.
+  makeFlags = commonMakeFlags ++ [
+    "CC=${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"
+    "HOSTCC=${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc"
+    "ARCH=${stdenv.hostPlatform.platform.kernelArch}"
+  ] ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [
+    "CROSS_COMPILE=${stdenv.cc.targetPrefix}"
+  ];
+
+  karch = stdenv.hostPlatform.platform.kernelArch;
+})
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/modinst-arg-list-too-long.patch b/nixpkgs/pkgs/os-specific/linux/kernel/modinst-arg-list-too-long.patch
new file mode 100644
index 000000000000..58a9191989ae
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/modinst-arg-list-too-long.patch
@@ -0,0 +1,14 @@
+diff --git a/scripts/Makefile.modinst b/scripts/Makefile.modinst
+index 07650ee..934a7a8 100644
+--- a/scripts/Makefile.modinst
++++ b/scripts/Makefile.modinst
+@@ -9,7 +9,8 @@ include scripts/Kbuild.include
+ 
+ #
+ 
+-__modules := $(sort $(shell grep -h '\.ko$$' /dev/null $(wildcard $(MODVERDIR)/*.mod)))
++__modules := $(sort $(foreach f,$(wildcard $(MODVERDIR)/*.mod),$(shell \
++    grep -h '\.ko$$' '$f')))
+ modules := $(patsubst %.o,%.ko,$(wildcard $(__modules:.ko=.o)))
+ 
+ PHONY += $(modules)
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/p9-fixes.patch b/nixpkgs/pkgs/os-specific/linux/kernel/p9-fixes.patch
new file mode 100644
index 000000000000..f6061b60667a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/p9-fixes.patch
@@ -0,0 +1,85 @@
+diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
+--- a/fs/9p/vfs_inode.c
++++ b/fs/9p/vfs_inode.c
+@@ -483,6 +483,9 @@ static int v9fs_test_inode(struct inode *inode, void *data)
+ 
+ 	if (v9inode->qid.type != st->qid.type)
+ 		return 0;
++
++	if (v9inode->qid.path != st->qid.path)
++		return 0;
+ 	return 1;
+ }
+ 
+diff --git a/fs/9p/vfs_inode_dotl.c b/fs/9p/vfs_inode_dotl.c
+--- a/fs/9p/vfs_inode_dotl.c
++++ b/fs/9p/vfs_inode_dotl.c
+@@ -87,6 +87,9 @@ static int v9fs_test_inode_dotl(struct inode *inode, void *data)
+ 
+ 	if (v9inode->qid.type != st->qid.type)
+ 		return 0;
++
++	if (v9inode->qid.path != st->qid.path)
++		return 0;
+ 	return 1;
+ }
+ 
+diff --git a/net/9p/client.c b/net/9p/client.c
+index 3ce672af1596..f1c8ad373f90 100644
+--- a/net/9p/client.c
++++ b/net/9p/client.c
+@@ -749,8 +749,7 @@ p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
+ 	}
+ again:
+ 	/* Wait for the response */
+-	err = wait_event_interruptible(*req->wq,
+-				       req->status >= REQ_STATUS_RCVD);
++	err = wait_event_killable(*req->wq, req->status >= REQ_STATUS_RCVD);
+ 
+ 	/*
+ 	 * Make sure our req is coherent with regard to updates in other
+diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
+index f24b25c25106..f3a4efcf1456 100644
+--- a/net/9p/trans_virtio.c
++++ b/net/9p/trans_virtio.c
+@@ -286,8 +286,8 @@ p9_virtio_request(struct p9_client *client, struct p9_req_t *req)
+ 		if (err == -ENOSPC) {
+ 			chan->ring_bufs_avail = 0;
+ 			spin_unlock_irqrestore(&chan->lock, flags);
+-			err = wait_event_interruptible(*chan->vc_wq,
+-							chan->ring_bufs_avail);
++			err = wait_event_killable(*chan->vc_wq,
++						  chan->ring_bufs_avail);
+ 			if (err  == -ERESTARTSYS)
+ 				return err;
+ 
+@@ -327,7 +327,7 @@ static int p9_get_mapped_pages(struct virtio_chan *chan,
+ 		 * Other zc request to finish here
+ 		 */
+ 		if (atomic_read(&vp_pinned) >= chan->p9_max_pages) {
+-			err = wait_event_interruptible(vp_wq,
++			err = wait_event_killable(vp_wq,
+ 			      (atomic_read(&vp_pinned) < chan->p9_max_pages));
+ 			if (err == -ERESTARTSYS)
+ 				return err;
+@@ -471,8 +471,8 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
+ 		if (err == -ENOSPC) {
+ 			chan->ring_bufs_avail = 0;
+ 			spin_unlock_irqrestore(&chan->lock, flags);
+-			err = wait_event_interruptible(*chan->vc_wq,
+-						       chan->ring_bufs_avail);
++			err = wait_event_killable(*chan->vc_wq,
++						  chan->ring_bufs_avail);
+ 			if (err  == -ERESTARTSYS)
+ 				goto err_out;
+ 
+@@ -489,8 +489,7 @@ p9_virtio_zc_request(struct p9_client *client, struct p9_req_t *req,
+ 	virtqueue_kick(chan->vq);
+ 	spin_unlock_irqrestore(&chan->lock, flags);
+ 	p9_debug(P9_DEBUG_TRANS, "virtio request kicked\n");
+-	err = wait_event_interruptible(*req->wq,
+-				       req->status >= REQ_STATUS_RCVD);
++	err = wait_event_killable(*req->wq, req->status >= REQ_STATUS_RCVD);
+ 	/*
+ 	 * Non kernel buffers are pinned, unpin them
+ 	 */
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/patches.nix b/nixpkgs/pkgs/os-specific/linux/kernel/patches.nix
new file mode 100644
index 000000000000..4c338b37deca
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/patches.nix
@@ -0,0 +1,60 @@
+{ fetchpatch }:
+
+rec {
+  bridge_stp_helper =
+    { name = "bridge-stp-helper";
+      patch = ./bridge-stp-helper.patch;
+    };
+
+  p9_fixes =
+    { name = "p9-fixes";
+      patch = ./p9-fixes.patch;
+    };
+
+  modinst_arg_list_too_long =
+    { name = "modinst-arglist-too-long";
+      patch = ./modinst-arg-list-too-long.patch;
+    };
+
+  genksyms_fix_segfault =
+    { name = "genksyms-fix-segfault";
+      patch = ./genksyms-fix-segfault.patch;
+    };
+
+  cpu-cgroup-v2 = import ./cpu-cgroup-v2-patches;
+
+  tag_hardened = rec {
+    name = "tag-hardened";
+    patch = ./tag-hardened.patch;
+  };
+
+  # https://bugzilla.kernel.org/show_bug.cgi?id=197591#c6
+  iwlwifi_mvm_support_version_7_scan_req_umac_fw_command = rec {
+    name = "iwlwifi_mvm_support_version_7_scan_req_umac_fw_command";
+    patch = fetchpatch {
+      name = name + ".patch";
+      url = https://bugzilla.kernel.org/attachment.cgi?id=260597;
+      sha256 = "09096npxpgvlwdz3pb3m9brvxh7vy0xc9z9p8hh85xyczyzcsjhr";
+    };
+  };
+
+  # https://github.com/NixOS/nixpkgs/issues/42755
+  xen-netfront_fix_mismatched_rtnl_unlock = rec {
+    name = "xen-netfront_fix_mismatched_rtnl_unlock";
+    patch = fetchpatch {
+      name = name + ".patch";
+      url = https://github.com/torvalds/linux/commit/cb257783c2927b73614b20f915a91ff78aa6f3e8.patch;
+      sha256 = "0xhblx2j8wi3kpnfpgjjwlcwdry97ji2aaq54r3zirk5g5p72zs8";
+    };
+  };
+
+  # https://github.com/NixOS/nixpkgs/issues/42755
+  xen-netfront_update_features_after_registering_netdev = rec {
+    name = "xen-netfront_update_features_after_registering_netdev";
+    patch = fetchpatch {
+      name = name + ".patch";
+      url = https://github.com/torvalds/linux/commit/45c8184c1bed1ca8a7f02918552063a00b909bf5.patch;
+      sha256 = "1l8xq02rd7vakxg52xm9g4zng0ald866rpgm8kjlh88mwwyjkrwv";
+    };
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/perf.nix b/nixpkgs/pkgs/os-specific/linux/kernel/perf.nix
new file mode 100644
index 000000000000..840d4cc9cf7b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/perf.nix
@@ -0,0 +1,75 @@
+{ lib, stdenv, kernel, elfutils, python, perl, newt, slang, asciidoc, xmlto, makeWrapper
+, docbook_xsl, docbook_xml_dtd_45, libxslt, flex, bison, pkgconfig, libunwind, binutils
+, libiberty, audit, libbfd, openssl, systemtap, numactl
+, zlib, withGtk ? false, gtk2 ? null
+}:
+
+with lib;
+
+assert withGtk -> gtk2 != null;
+assert versionAtLeast kernel.version "3.12";
+
+stdenv.mkDerivation {
+  name = "perf-linux-${kernel.version}";
+
+  inherit (kernel) src;
+
+  preConfigure = ''
+    cd tools/perf
+
+    substituteInPlace Makefile \
+      --replace /usr/include/elfutils $elfutils/include/elfutils
+
+    for x in util/build-id.c util/dso.c; do
+      substituteInPlace $x --replace /usr/lib/debug /run/current-system/sw/lib/debug
+    done
+
+    if [ -f bash_completion ]; then
+      sed -i 's,^have perf,_have perf,' bash_completion
+    fi
+  '';
+
+  makeFlags = ["prefix=$(out)" "WERROR=0"] ++ kernel.makeFlags;
+
+  hardeningDisable = [ "format" ];
+
+  # perf refers both to newt and slang
+  nativeBuildInputs = [
+    asciidoc xmlto docbook_xsl docbook_xml_dtd_45 libxslt
+    flex bison libiberty audit makeWrapper pkgconfig python perl
+  ];
+  buildInputs = [
+    elfutils newt slang libunwind libbfd zlib openssl systemtap.stapBuild numactl
+  ] ++ stdenv.lib.optional withGtk gtk2;
+
+  # Note: we don't add elfutils to buildInputs, since it provides a
+  # bad `ld' and other stuff.
+  NIX_CFLAGS_COMPILE =
+    [ "-Wno-error=cpp"
+      "-Wno-error=bool-compare"
+      "-Wno-error=deprecated-declarations"
+      "-DOBJDUMP_PATH=\"${binutils}/bin/objdump\""
+    ]
+    # gcc before 6 doesn't know these options
+    ++ stdenv.lib.optionals (hasPrefix "gcc-6" stdenv.cc.cc.name) [
+      "-Wno-error=unused-const-variable" "-Wno-error=misleading-indentation"
+    ];
+
+  doCheck = false; # requires "sparse"
+  doInstallCheck = false; # same
+
+  separateDebugInfo = true;
+  installFlags = "install install-man ASCIIDOC8=1 prefix=$(out)";
+
+  preFixup = ''
+    wrapProgram $out/bin/perf \
+      --prefix PATH : "${binutils}/bin"
+  '';
+
+  meta = {
+    homepage = https://perf.wiki.kernel.org/;
+    description = "Linux tools to profile with performance counters";
+    maintainers = with stdenv.lib.maintainers; [viric];
+    platforms = with stdenv.lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/randstruct-provide-seed.patch b/nixpkgs/pkgs/os-specific/linux/kernel/randstruct-provide-seed.patch
new file mode 100644
index 000000000000..1328b9cee3c9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/randstruct-provide-seed.patch
@@ -0,0 +1,12 @@
+diff -ru a/scripts/gcc-plugins/gen-random-seed.sh b/scripts/gcc-plugins/gen-random-seed.sh
+--- a/scripts/gcc-plugins/gen-random-seed.sh	2019-01-11 11:50:29.228258920 +0100
++++ b/scripts/gcc-plugins/gen-random-seed.sh	2019-01-11 12:18:33.555902720 +0100
+@@ -2,7 +2,7 @@
+ # SPDX-License-Identifier: GPL-2.0
+ 
+ if [ ! -f "$1" ]; then
+-	SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
++	SEED="NIXOS_RANDSTRUCT_SEED"
+ 	echo "const char *randstruct_seed = \"$SEED\";" > "$1"
+ 	HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
+ 	echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/tag-hardened.patch b/nixpkgs/pkgs/os-specific/linux/kernel/tag-hardened.patch
new file mode 100644
index 000000000000..ff8a3a127973
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/tag-hardened.patch
@@ -0,0 +1,7 @@
+diff --git a/localversion-hardened b/localversion-hardened
+new file mode 100644
+index 0000000000..e578045860
+--- /dev/null
++++ b/localversion-hardened
+@@ -0,0 +1 @@
++-hardened
diff --git a/nixpkgs/pkgs/os-specific/linux/kernel/update.sh b/nixpkgs/pkgs/os-specific/linux/kernel/update.sh
new file mode 100755
index 000000000000..878c3c14fe47
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kernel/update.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+set -e
+
+# Get the latest versions from kernel.org
+LINUXSED='s/.*linux-\([0-9]\+\(.[0-9]\+\)*\).*/\1/p'
+KDATA="$(curl -s https://www.kernel.org | sed -n -e '/Download complete/p')"
+VERSIONS=($(sed -n -e $LINUXSED <<< "$KDATA" | sort -Vr))
+
+# Remove mainline version if there is a stable update
+# Note due to sorting these two will always exist at the bottom
+if grep -q "^${VERSIONS[1]}" <<< "${VERSIONS[0]}"; then
+  VERSIONS=(${VERSIONS[@]:0:1} ${VERSIONS[@]:2})
+fi
+
+# Inspect each file and see if it has the latest version
+NIXPKGS="$(git rev-parse --show-toplevel)"
+ls $NIXPKGS/pkgs/os-specific/linux/kernel | while read FILE; do
+  KERNEL="$(sed -n $LINUXSED <<< "$FILE")"
+  [ -z "$KERNEL" ] && continue
+
+  # Find the matching new kernel version
+  MATCHING=""
+  for V in "${VERSIONS[@]}"; do
+    if grep -q "^$KERNEL" <<< "$V"; then
+      MATCHING="$V"
+      break
+    fi
+  done
+  if [ -z "$MATCHING" ]; then
+    echo "Out-of-support $KERNEL"
+    continue
+  fi
+
+  # Inspect the nix expression to check for changes
+  DATA="$(<$NIXPKGS/pkgs/os-specific/linux/kernel/$FILE)"
+  URL="$(sed -n -e 's/.*url = "\(.*\)";.*/\1/p' <<< "$DATA" | sed -e "s/\${version}/$MATCHING/g")"
+  OLDVER=$(sed -n -e 's/.*version = "\(.*\)".*/\1/p' <<< "$DATA")
+  if [ "$OLDVER" = "$V" ]; then
+    echo "No updates for $KERNEL"
+    continue
+  fi
+
+  # Download the new file for the hash
+  if ! HASH="$(nix-prefetch-url $URL 2>/dev/null)"; then
+    echo "Failed to get hash of $URL"
+    continue
+  fi
+  sed -i "s/sha256 = \".*\"/sha256 = \"$HASH\"/g" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
+
+  # Rewrite the expression
+  sed -i -e '/version = /d' -e '/modDirVersion = /d' $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
+  if grep -q '^[0-9]\+.[0-9]\+$' <<< "$V"; then
+    sed -i "\#buildLinux (args // rec {#a \  modDirVersion = \"${V}.0\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
+  fi
+  sed -i "\#buildLinux (args // rec {#a \  version = \"$V\";" $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
+
+  # Commit the changes
+  git add -u $NIXPKGS/pkgs/os-specific/linux/kernel/$FILE
+  git commit -m "kernel: $OLDVER -> $V" >/dev/null 2>&1
+
+  echo "Updated $OLDVER -> $V"
+done
diff --git a/nixpkgs/pkgs/os-specific/linux/kexectools/default.nix b/nixpkgs/pkgs/os-specific/linux/kexectools/default.nix
new file mode 100644
index 000000000000..7cbf6cb7cee5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kexectools/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, buildPackages, fetchurl, zlib }:
+
+stdenv.mkDerivation rec {
+  name = "kexec-tools-${version}";
+  version = "2.0.18";
+
+  src = fetchurl {
+    urls = [
+      "mirror://kernel/linux/utils/kernel/kexec/${name}.tar.xz"
+      "http://horms.net/projects/kexec/kexec-tools/${name}.tar.xz"
+    ];
+    sha256 = "0f5jnb0470nmxyl1cz2687hqjr8cwqniqc1ycq9bazlp85rz087h";
+  };
+
+  hardeningDisable = [ "format" "pic" "relro" "pie" ];
+
+  configureFlags = [ "BUILD_CC=${buildPackages.stdenv.cc.targetPrefix}cc" ];
+  nativeBuildInputs = [ buildPackages.stdenv.cc ];
+  buildInputs = [ zlib ];
+
+  meta = with stdenv.lib; {
+    homepage = http://horms.net/projects/kexec/kexec-tools;
+    description = "Tools related to the kexec Linux feature";
+    platforms = platforms.linux;
+    license = licenses.gpl2;
+    badPlatforms = platforms.riscv;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/keyutils/default.nix b/nixpkgs/pkgs/os-specific/linux/keyutils/default.nix
new file mode 100644
index 000000000000..1d9497a7eddf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/keyutils/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "keyutils-${version}";
+  version = "1.6";
+
+  src = fetchurl {
+    url = "https://people.redhat.com/dhowells/keyutils/${name}.tar.bz2";
+    sha256 = "05bi5ja6f3h3kdi7p9dihlqlfrsmi1wh1r2bdgxc0180xh6g5bnk";
+  };
+
+  patches = [
+    (fetchurl {
+      # improve reproducibility
+      url = "https://salsa.debian.org/debian/keyutils/raw/4cecffcb8e2a2aa4ef41777ed40e4e4bcfb2e5bf/debian/patches/Make-build-reproducible.patch";
+      sha256 = "0wnvbjfrbk7rghd032z684l7vk7mhy3bd41zvhkrhgp3cd5id0bm";
+    })
+  ];
+
+  BUILDDATE = "1970-01-01";
+  outputs = [ "out" "lib" "dev" ];
+
+  installFlags = [
+    "ETCDIR=$(out)/etc"
+    "BINDIR=$(out)/bin"
+    "SBINDIR=$(out)/sbin"
+    "SHAREDIR=$(out)/share/keyutils"
+    "MANDIR=$(out)/share/man"
+    "INCLUDEDIR=$(dev)/include"
+    "LIBDIR=$(lib)/lib"
+    "USRLIBDIR=$(lib)/lib"
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = https://people.redhat.com/dhowells/keyutils/;
+    description = "Tools used to control the Linux kernel key management system";
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/klibc/default.nix b/nixpkgs/pkgs/os-specific/linux/klibc/default.nix
new file mode 100644
index 000000000000..8cae61d56a92
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/klibc/default.nix
@@ -0,0 +1,48 @@
+{ stdenv, fetchurl, linuxHeaders, perl }:
+
+let
+  commonMakeFlags = [
+    "prefix=$(out)"
+    "SHLIBDIR=$(out)/lib"
+  ];
+in
+
+stdenv.mkDerivation rec {
+  name = "klibc-${version}";
+  version = "2.0.4";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/libs/klibc/2.0/klibc-${version}.tar.xz";
+    sha256 = "7f9a0850586def7cf4faeeb75e5d0f66e613674c524f6e77b0f4d93a26c801cb";
+  };
+
+  patches = [ ./no-reinstall-kernel-headers.patch ];
+
+  nativeBuildInputs = [ perl ];
+
+  hardeningDisable = [ "format" "stackprotector" ];
+
+  makeFlags = commonMakeFlags ++ [
+    "KLIBCARCH=${stdenv.hostPlatform.platform.kernelArch}"
+    "KLIBCKERNELSRC=${linuxHeaders}"
+  ] # TODO(@Ericson2314): We now can get the ABI from
+    # `stdenv.hostPlatform.parsed.abi`, is this still a good idea?
+    ++ stdenv.lib.optional (stdenv.hostPlatform.platform.kernelArch == "arm") "CONFIG_AEABI=y"
+    ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "CROSS_COMPILE=${stdenv.cc.targetPrefix}";
+
+  # Install static binaries as well.
+  postInstall = ''
+    dir=$out/lib/klibc/bin.static
+    mkdir $dir
+    cp $(find $(find . -name static) -type f ! -name "*.g" -a ! -name ".*") $dir/
+    cp usr/dash/sh $dir/
+
+    for file in ${linuxHeaders}/include/*; do
+      ln -sv $file $out/lib/klibc/include
+    done
+  '';
+
+  meta = {
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/klibc/no-reinstall-kernel-headers.patch b/nixpkgs/pkgs/os-specific/linux/klibc/no-reinstall-kernel-headers.patch
new file mode 100644
index 000000000000..d3e55fc8731d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/klibc/no-reinstall-kernel-headers.patch
@@ -0,0 +1,11 @@
+diff -Naur klibc-2.0.3-orig/scripts/Kbuild.install klibc-2.0.3/scripts/Kbuild.install
+--- klibc-2.0.3-orig/scripts/Kbuild.install	2013-12-03 13:53:46.000000000 -0500
++++ klibc-2.0.3/scripts/Kbuild.install	2014-01-04 18:17:09.342609021 -0500
+@@ -95,7 +95,6 @@
+ 	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+ 	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)lib
+ 	$(Q)mkdir -p $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)bin
+-	$(Q)$(MAKE) -C $(KLIBCKERNELSRC) ARCH=$(KLIBCARCH) INSTALL_HDR_PATH=$(INSTALLROOT)$(INSTALLDIR)/$(KCROSS) headers_install
+ 	$(Q)cp -rf usr/include/. $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include/.
+ 	$(Q)chmod -R a+rX $(INSTALLROOT)$(INSTALLDIR)/$(KCROSS)include
+ 	$(Q)$(install-data) $(srctree)/klcc/klcc.1 $(INSTALLROOT)$(mandir)/man1/$(KCROSS)klcc.1
diff --git a/nixpkgs/pkgs/os-specific/linux/klibc/shrunk.nix b/nixpkgs/pkgs/os-specific/linux/klibc/shrunk.nix
new file mode 100644
index 000000000000..f01f3b6a4ec3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/klibc/shrunk.nix
@@ -0,0 +1,28 @@
+{stdenv, klibc}:
+
+stdenv.mkDerivation {
+  # !!! For now, the name has to be exactly as long as the original
+  # name due to the sed hackery below.  Once patchelf 0.4 is in the
+  # tree, we can do this properly.
+  #name = "${klibc.name}-shrunk";
+  name = "${klibc.name}";
+  buildCommand = ''
+    mkdir -p $out/lib
+    cp -prd ${klibc.out}/lib/klibc/bin $out/
+    cp -p ${klibc.out}/lib/*.so $out/lib/
+    chmod +w $out/*
+    old=$(echo ${klibc.out}/lib/klibc-*.so)
+    new=$(echo $out/lib/klibc-*.so)
+    for i in $out/bin/*; do
+      echo $i
+      sed "s^$old^$new^" -i $i
+      # !!! use patchelf
+      #patchelf --set-interpreter $new $i
+    done
+  ''; # */
+  allowedReferences = ["out"];
+
+  meta = {
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kmod-blacklist-ubuntu/default.nix b/nixpkgs/pkgs/os-specific/linux/kmod-blacklist-ubuntu/default.nix
new file mode 100644
index 000000000000..266c94fd8c84
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmod-blacklist-ubuntu/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl, gnugrep, findutils }:
+
+let
+  version = "22-1.1ubuntu1"; # Zesty
+
+in stdenv.mkDerivation {
+  name = "kmod-blacklist-${version}";
+
+  src = fetchurl {
+    url = "https://launchpad.net/ubuntu/+archive/primary/+files/kmod_${version}.debian.tar.xz";
+    sha256 = "1k749g707ccb82l4xmrkp53khl71f57cpj9fzd1qyzrz147fjyhi";
+  };
+
+  installPhase = ''
+    mkdir "$out"
+    for f in modprobe.d/*.conf; do
+      echo "''\n''\n## file: "`basename "$f"`"''\n''\n" >> "$out"/modprobe.conf
+      cat "$f" >> "$out"/modprobe.conf
+      # https://bugs.launchpad.net/ubuntu/+source/kmod/+bug/1475945
+      sed -i '/^blacklist i2c_i801/d' $out/modprobe.conf
+    done
+
+    substituteInPlace "$out"/modprobe.conf \
+      --replace "blacklist bochs-drm" "" \
+      --replace /sbin/lsmod /run/booted-system/sw/bin/lsmod \
+      --replace /sbin/rmmod /run/booted-system/sw/bin/rmmod \
+      --replace /sbin/modprobe /run/booted-system/sw/bin/modprobe \
+      --replace " grep " " ${gnugrep}/bin/grep " \
+      --replace " xargs " " ${findutils}/bin/xargs "
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://packages.ubuntu.com/source/zesty/kmod;
+    description = "Linux kernel module blacklists from Ubuntu";
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kmod-debian-aliases/default.nix b/nixpkgs/pkgs/os-specific/linux/kmod-debian-aliases/default.nix
new file mode 100644
index 000000000000..07ab0427b226
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmod-debian-aliases/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, fetchurl, lib }:
+
+stdenv.mkDerivation rec {
+  name = "kmod-debian-aliases-${version}.conf";
+  version = "22-1.1";
+
+  src = fetchurl {
+    url = "https://snapshot.debian.org/archive/debian/20160404T220610Z/pool/main/k/kmod/kmod_${version}.debian.tar.xz";
+    sha256 = "0daap2n4bvjqcnksaayy6csmdb1px4r02w3xp36bcp6w3lbnqamh";
+  };
+
+  installPhase = ''
+    patch -i patches/aliases_conf
+    cp aliases.conf $out
+  '';
+
+  meta = {
+    homepage = https://packages.debian.org/source/sid/kmod;
+    description = "Linux configuration file for modprobe";
+    maintainers = with lib.maintainers; [ mathnerd314 ];
+    platforms = with lib.platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kmod/aggregator.nix b/nixpkgs/pkgs/os-specific/linux/kmod/aggregator.nix
new file mode 100644
index 000000000000..7d46a13f3562
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmod/aggregator.nix
@@ -0,0 +1,35 @@
+{ stdenv, kmod, modules, buildEnv }:
+
+buildEnv {
+  name = "kernel-modules";
+
+  paths = modules;
+
+  postBuild =
+    ''
+      source ${stdenv}/setup
+
+      if ! test -d "$out/lib/modules"; then
+        echo "No modules found."
+        # To support a kernel without modules
+        exit 0
+      fi
+
+      kernelVersion=$(cd $out/lib/modules && ls -d *)
+      if test "$(echo $kernelVersion | wc -w)" != 1; then
+         echo "inconsistent kernel versions: $kernelVersion"
+         exit 1
+      fi
+
+      echo "kernel version is $kernelVersion"
+
+      shopt -s extglob
+
+      # Regenerate the depmod map files.  Be sure to pass an explicit
+      # kernel version number, otherwise depmod will use `uname -r'.
+      if test -w $out/lib/modules/$kernelVersion; then
+          rm -f $out/lib/modules/$kernelVersion/modules.!(builtin*|order*)
+          ${kmod}/bin/depmod -b $out -a $kernelVersion
+      fi
+    '';
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kmod/darwin.patch b/nixpkgs/pkgs/os-specific/linux/kmod/darwin.patch
new file mode 100644
index 000000000000..69dbf479f9f1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmod/darwin.patch
@@ -0,0 +1,123 @@
+diff --git a/Makefile.am b/Makefile.am
+index 194e111..0a095b5 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -80,8 +80,7 @@ EXTRA_DIST += libkmod/README \
+ 	libkmod/COPYING testsuite/COPYING tools/COPYING COPYING
+ 
+ libkmod_libkmod_la_LDFLAGS = $(AM_LDFLAGS) \
+-	-version-info $(LIBKMOD_CURRENT):$(LIBKMOD_REVISION):$(LIBKMOD_AGE) \
+-	-Wl,--version-script=$(top_srcdir)/libkmod/libkmod.sym
++	-version-info $(LIBKMOD_CURRENT):$(LIBKMOD_REVISION):$(LIBKMOD_AGE)
+ libkmod_libkmod_la_DEPENDENCIES = \
+ 	shared/libshared.la \
+ 	${top_srcdir}/libkmod/libkmod.sym
+@@ -91,8 +90,7 @@ libkmod_libkmod_la_LIBADD = \
+ 
+ noinst_LTLIBRARIES += libkmod/libkmod-internal.la
+ libkmod_libkmod_internal_la_SOURCES = $(libkmod_libkmod_la_SOURCES)
+-libkmod_libkmod_internal_la_LDFLAGS = $(AM_LDFLAGS) \
+-	-Wl,--version-script=$(top_srcdir)/libkmod/libkmod.sym
++libkmod_libkmod_internal_la_LDFLAGS = $(AM_LDFLAGS)
+ libkmod_libkmod_internal_la_DEPENDENCIES  = $(libkmod_libkmod_la_DEPENDENCIES)
+ libkmod_libkmod_internal_la_LIBADD = $(libkmod_libkmod_la_LIBADD)
+ 
+diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
+index 889f264..6f0a285 100644
+--- a/libkmod/libkmod-module.c
++++ b/libkmod/libkmod-module.c
+@@ -787,7 +787,11 @@ KMOD_EXPORT int kmod_module_remove_module(struct kmod_module *mod,
+ 	flags &= KMOD_REMOVE_FORCE;
+ 	flags |= KMOD_REMOVE_NOWAIT;
+ 
++#if defined(__linux__)
+ 	err = delete_module(mod->name, flags);
++#else
++	err = -1;
++#endif
+ 	if (err != 0) {
+ 		err = -errno;
+ 		ERR(mod->ctx, "could not remove '%s': %m\n", mod->name);
+@@ -879,7 +883,11 @@ KMOD_EXPORT int kmod_module_insert_module(struct kmod_module *mod,
+ 	}
+ 	size = kmod_file_get_size(mod->file);
+ 
++#if defined(__linux__)
+ 	err = init_module(mem, size, args);
++#else
++	err = -1;
++#endif
+ init_finished:
+ 	if (err < 0) {
+ 		err = -errno;
+diff --git a/libkmod/libkmod-signature.c b/libkmod/libkmod-signature.c
+index 429ffbd..17a3b9c 100644
+--- a/libkmod/libkmod-signature.c
++++ b/libkmod/libkmod-signature.c
+@@ -17,7 +17,10 @@
+  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+  */
+ 
++#if defined(__linux__)
+ #include <endian.h>
++#endif
++
+ #include <inttypes.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+diff --git a/shared/macro.h b/shared/macro.h
+index 4fc5405..b5a2702 100644
+--- a/shared/macro.h
++++ b/shared/macro.h
+@@ -71,3 +71,7 @@
+ #endif
+ 
+ #define UNIQ __COUNTER__
++
++ #if !defined(__linux__)
++#define program_invocation_short_name getprogname()
++#endif
+diff --git a/shared/missing.h b/shared/missing.h
+index 4c0d136..ad8ec0f 100644
+--- a/shared/missing.h
++++ b/shared/missing.h
+@@ -45,6 +45,9 @@ static inline int finit_module(int fd, const char *uargs, int flags)
+ #endif
+ 
+ #if !HAVE_DECL_BE32TOH
++
++#if defined(__linux__)
++
+ #include <endian.h>
+ #include <byteswap.h>
+ #if __BYTE_ORDER == __LITTLE_ENDIAN
+@@ -52,4 +55,16 @@ static inline int finit_module(int fd, const char *uargs, int flags)
+ #else
+ #define be32toh(x) (x)
+ #endif
++
++#elif defined(__APPLE__)
++
++#include <libkern/OSByteOrder.h>
++#define be32toh(x) OSSwapBigToHostInt32(x)
++
++#else
++
++#error No be32toh known for platform
++
++#endif
++
+ #endif
+diff --git a/shared/util.c b/shared/util.c
+index fd2028d..ecb0141 100644
+--- a/shared/util.c
++++ b/shared/util.c
+@@ -367,7 +367,7 @@ char *path_make_absolute_cwd(const char *p)
+ 	if (path_is_absolute(p))
+ 		return strdup(p);
+ 
+-	cwd = get_current_dir_name();
++	cwd = getcwd(NULL, 0);
+ 	if (!cwd)
+ 		return NULL;
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/kmod/default.nix b/nixpkgs/pkgs/os-specific/linux/kmod/default.nix
new file mode 100644
index 000000000000..8a09d7fea093
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmod/default.nix
@@ -0,0 +1,44 @@
+{ stdenv, buildPackages, lib, fetchurl, autoreconfHook, pkgconfig
+, libxslt, xz, elf-header }:
+
+let
+  systems = [ "/run/current-system/kernel-modules" "/run/booted-system/kernel-modules" "" ];
+  modulesDirs = lib.concatMapStringsSep ":" (x: "${x}/lib/modules") systems;
+
+in stdenv.mkDerivation rec {
+  name = "kmod-${version}";
+  version = "25";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/kernel/kmod/${name}.tar.xz";
+    sha256 = "1kgixs4m3jvwk7fb3d18n6j77qhgi9qfv4csj35rs5ancr4ycrbi";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig libxslt ];
+  buildInputs = [ xz ] ++ lib.optional stdenv.isDarwin elf-header;
+
+  configureFlags = [
+    "--sysconfdir=/etc"
+    "--with-xz"
+    "--with-modulesdirs=${modulesDirs}"
+  ];
+
+  patches = [ ./module-dir.patch ]
+    ++ lib.optional stdenv.isDarwin ./darwin.patch;
+
+  postInstall = ''
+    for prog in rmmod insmod lsmod modinfo modprobe depmod; do
+      ln -sv $out/bin/kmod $out/bin/$prog
+    done
+
+    # Backwards compatibility
+    ln -s bin $out/sbin
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://www.kernel.org/pub/linux/utils/kernel/kmod/;
+    description = "Tools for loading and managing Linux kernel modules";
+    license = licenses.lgpl21;
+    platforms = platforms.unix;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kmod/module-dir.patch b/nixpkgs/pkgs/os-specific/linux/kmod/module-dir.patch
new file mode 100644
index 000000000000..f7432e3756e9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmod/module-dir.patch
@@ -0,0 +1,157 @@
+diff --git a/Makefile.am b/Makefile.am
+index d4eeb7e..5c9f603 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -19,6 +19,7 @@ AM_CPPFLAGS = \
+ 	-include $(top_builddir)/config.h \
+ 	-I$(top_srcdir) \
+ 	-DSYSCONFDIR=\""$(sysconfdir)"\" \
++	-DMODULESDIRS=\""$(shell echo $(modulesdirs) | $(SED) 's|:|\\",\\"|g')"\" \
+ 	${zlib_CFLAGS}
+ 
+ AM_CFLAGS = $(OUR_CFLAGS)
+diff --git a/configure.ac b/configure.ac
+index 23510c8..66490cf 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -202,6 +202,12 @@ GTK_DOC_CHECK([1.14],[--flavour no-tmpl-flat])
+ ], [
+ AM_CONDITIONAL([ENABLE_GTK_DOC], false)])
+ 
++AC_ARG_WITH([modulesdirs],
++	AS_HELP_STRING([--with-modulesdirs=DIRS], [Kernel modules directories, separated by :]),
++	[],
++	[with_modulesdirs=/lib/modules])
++AC_SUBST([modulesdirs], [$with_modulesdirs])
++
+ 
+ #####################################################################
+ # Default CFLAGS and LDFLAGS
+diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
+index 69fe431..d37da32 100644
+--- a/libkmod/libkmod.c
++++ b/libkmod/libkmod.c
+@@ -206,12 +206,15 @@ static int log_priority(const char *priority)
+ 	return 0;
+ }
+ 
+-static const char *dirname_default_prefix = "/lib/modules";
++static const char *dirname_default_prefixes[] = {
++	MODULESDIRS,
++	NULL
++};
+ 
+ static char *get_kernel_release(const char *dirname)
+ {
+ 	struct utsname u;
+-	char *p;
++	char *p, *dirname_prefix;
+ 
+ 	if (dirname != NULL)
+ 		return path_make_absolute_cwd(dirname);
+@@ -219,8 +222,42 @@ static char *get_kernel_release(const char *dirname)
+ 	if (uname(&u) < 0)
+ 		return NULL;
+ 
+-	if (asprintf(&p, "%s/%s", dirname_default_prefix, u.release) < 0)
+-		return NULL;
++	if ((dirname_prefix = getenv("MODULE_DIR")) != NULL) {
++		if(asprintf(&p, "%s/%s", dirname_prefix, u.release) < 0)
++			return NULL;
++	} else {
++		size_t i;
++		char buf[PATH_MAX];
++
++		for (i = 0; dirname_default_prefixes[i] != NULL; i++) {
++			int plen;
++			struct stat dirstat;
++
++			plen = snprintf(buf, sizeof(buf), "%s/%s", dirname_default_prefixes[i], u.release);
++			if (plen < 0)
++				return NULL;
++			else if (plen >= PATH_MAX)
++				continue;
++
++			if (dirname_default_prefixes[i + 1] != NULL) {
++				if (stat(buf, &dirstat) < 0) {
++					if (errno == ENOENT)
++						continue;
++					else
++						return NULL;
++				}
++
++				if (!S_ISDIR(dirstat.st_mode))
++					continue;
++			}
++
++			p = malloc(plen + 1);
++			if (p == NULL)
++				return NULL;
++			memcpy(p, buf, plen + 1);
++			break;
++		}
++	}
+ 
+ 	return p;
+ }
+diff --git a/tools/static-nodes.c b/tools/static-nodes.c
+index 8d2356d..2ed306d 100644
+--- a/tools/static-nodes.c
++++ b/tools/static-nodes.c
+@@ -29,10 +29,11 @@
+ #include <unistd.h>
+ #include <sys/stat.h>
+ #include <sys/types.h>
+-#include <sys/utsname.h>
+ 
+ #include <shared/util.h>
+ 
++#include <libkmod/libkmod.h>
++
+ #include "kmod.h"
+ 
+ struct static_nodes_format {
+@@ -154,8 +155,8 @@ static void help(void)
+ 
+ static int do_static_nodes(int argc, char *argv[])
+ {
+-	struct utsname kernel;
+ 	char modules[PATH_MAX], buf[4096];
++	struct kmod_ctx *ctx;
+ 	const char *output = "/dev/stdout";
+ 	FILE *in = NULL, *out = NULL;
+ 	const struct static_nodes_format *format = &static_nodes_format_human;
+@@ -206,22 +207,25 @@ static int do_static_nodes(int argc, char *argv[])
+ 		}
+ 	}
+ 
+-	if (uname(&kernel) < 0) {
+-		fputs("Error: uname failed!\n", stderr);
++	ctx = kmod_new(NULL, NULL);
++	if (ctx == NULL) {
++		fprintf(stderr, "Error: failed to create kmod context\n");
+ 		ret = EXIT_FAILURE;
+ 		goto finish;
+ 	}
+-
+-	snprintf(modules, sizeof(modules), "/lib/modules/%s/modules.devname", kernel.release);
++	if (snprintf(modules, sizeof(modules), "%s/modules.devname", kmod_get_dirname(ctx)) < 0) {
++		fprintf(stderr, "Error: path to modules.devname is too long\n");
++		ret = EXIT_FAILURE;
++		goto finish;
++	}
++	kmod_unref(ctx);
+ 	in = fopen(modules, "re");
+ 	if (in == NULL) {
+ 		if (errno == ENOENT) {
+-			fprintf(stderr, "Warning: /lib/modules/%s/modules.devname not found - ignoring\n",
+-				kernel.release);
++			fprintf(stderr, "Warning: %s not found - ignoring\n", modules);
+ 			ret = EXIT_SUCCESS;
+ 		} else {
+-			fprintf(stderr, "Error: could not open /lib/modules/%s/modules.devname - %m\n",
+-				kernel.release);
++			fprintf(stderr, "Error: could not open %s - %m\n", modules);
+ 			ret = EXIT_FAILURE;
+ 		}
+ 		goto finish;
diff --git a/nixpkgs/pkgs/os-specific/linux/kmscon/default.nix b/nixpkgs/pkgs/os-specific/linux/kmscon/default.nix
new file mode 100644
index 000000000000..0fff816eac7b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmscon/default.nix
@@ -0,0 +1,58 @@
+{ stdenv
+, fetchurl
+, libtsm
+, systemd
+, libxkbcommon
+, libdrm
+, libGLU_combined
+, pango
+, pixman
+, pkgconfig
+, docbook_xsl
+, libxslt
+}:
+
+stdenv.mkDerivation rec {
+  name = "kmscon-8";
+
+  src = fetchurl {
+    url = "https://www.freedesktop.org/software/kmscon/releases/${name}.tar.xz";
+    sha256 = "0axfwrp3c8f4gb67ap2sqnkn75idpiw09s35wwn6kgagvhf1rc0a";
+  };
+
+  buildInputs = [
+    libtsm
+    systemd
+    libxkbcommon
+    libdrm
+    libGLU_combined
+    pango
+    pixman
+    pkgconfig
+    docbook_xsl
+    libxslt
+  ];
+
+  patches = [ ./kmscon-8-glibc-2.26.patch ];
+
+  # FIXME: Remove as soon as kmscon > 8 comes along.
+  postPatch = ''
+    sed -i -e 's/libsystemd-daemon libsystemd-login/libsystemd/g' configure
+  '';
+
+  configureFlags = [
+    "--enable-multi-seat"
+    "--disable-debug"
+    "--enable-optimizations"
+    "--with-renderers=bbulk,gltex,pixman"
+  ];
+
+  enableParallelBuilding = true;
+
+  meta = {
+    description = "KMS/DRM based System Console";
+    homepage = http://www.freedesktop.org/wiki/Software/kmscon/;
+    license = stdenv.lib.licenses.mit;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/kmscon/kmscon-8-glibc-2.26.patch b/nixpkgs/pkgs/os-specific/linux/kmscon/kmscon-8-glibc-2.26.patch
new file mode 100644
index 000000000000..b70a750180e2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmscon/kmscon-8-glibc-2.26.patch
@@ -0,0 +1,25 @@
+diff --git a/src/pty.c b/src/pty.c
+index 3494104..1443f4a 100644
+--- a/src/pty.c
++++ b/src/pty.c
+@@ -299,7 +299,7 @@ static void setup_child(int master, struct winsize *ws)
+ 	if (ret)
+ 		log_warn("cannot reset blocked signals: %m");
+ 
+-	for (i = 1; i < SIGUNUSED; ++i)
++	for (i = 1; i < SIGSYS; ++i)
+ 		signal(i, SIG_DFL);
+ 
+ 	ret = grantpt(master);
+diff --git a/src/uterm_vt.c b/src/uterm_vt.c
+index af377f5..fbe9e76 100644
+--- a/src/uterm_vt.c
++++ b/src/uterm_vt.c
+@@ -40,6 +40,7 @@
+ #include <sys/ioctl.h>
+ #include <sys/signalfd.h>
+ #include <sys/stat.h>
++#include <sys/sysmacros.h>
+ #include <termios.h>
+ #include <time.h>
+ #include <unistd.h>
diff --git a/nixpkgs/pkgs/os-specific/linux/kmscube/default.nix b/nixpkgs/pkgs/os-specific/linux/kmscube/default.nix
new file mode 100644
index 000000000000..442c54ac8462
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/kmscube/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, fetchgit, autoreconfHook, libdrm, libX11, libGL, mesa_noglu, pkgconfig }:
+
+stdenv.mkDerivation rec {
+  name = "kmscube-2018-06-17";
+
+  src = fetchgit {
+    url = git://anongit.freedesktop.org/mesa/kmscube;
+    rev = "9dcce71e603616ee7a54707e932f962cdf8fb20a";
+    sha256 = "1q5b5yvyfj3127385mp1bfmcbnpnbdswdk8gspp7g4541xk4k933";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ libdrm libX11 libGL mesa_noglu ];
+
+  meta = with stdenv.lib; {
+    description = "Example OpenGL app using KMS/GBM";
+    homepage = https://gitlab.freedesktop.org/mesa/kmscube;
+    license = licenses.mit;
+    maintainers = with maintainers; [ dezgeg ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/latencytop/default.nix b/nixpkgs/pkgs/os-specific/linux/latencytop/default.nix
new file mode 100644
index 000000000000..93d2ac8b0312
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/latencytop/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl, ncurses, glib, pkgconfig, gtk2 }:
+
+stdenv.mkDerivation rec {
+  name = "latencytop-0.5";
+
+  patchPhase = "sed -i s,/usr,$out, Makefile";
+  preInstall = "mkdir -p $out/sbin";
+
+  src = fetchurl {
+    urls = [ "http://latencytop.org/download/${name}.tar.gz"
+     "http://dbg.download.sourcemage.org/mirror/latencytop-0.5.tar.gz" ];
+    sha256 = "1vq3j9zdab6njly2wp900b3d5244mnxfm88j2bkiinbvxbxp4zwy";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ ncurses glib gtk2 ];
+
+  meta = {
+    homepage = http://latencytop.org;
+    description = "Tool to show kernel reports on latencies (LATENCYTOP option)";
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = [ stdenv.lib.maintainers.viric ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ldm/default.nix b/nixpkgs/pkgs/os-specific/linux/ldm/default.nix
new file mode 100644
index 000000000000..0c333feab1c1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ldm/default.nix
@@ -0,0 +1,43 @@
+{ stdenv, fetchgit, udev, utillinux, mountPath ? "/media/" }:
+
+assert mountPath != "";
+
+let
+  version = "0.5";
+  git = https://github.com/LemonBoy/ldm.git;
+in
+stdenv.mkDerivation rec {
+  name = "ldm-${version}";
+
+  # There is a stable release, but we'll use the lvm branch, which
+  # contains important fixes for LVM setups.
+  src = fetchgit {
+    url = meta.repositories.git;
+    rev = "refs/tags/v${version}";
+    sha256 = "0lxfypnbamfx6p9ar5k9wra20gvwn665l4pp2j4vsx4yi5q7rw2n";
+  };
+
+  buildInputs = [ udev utillinux ];
+
+  postPatch = ''
+    substituteInPlace ldm.c \
+      --replace "/mnt/" "${mountPath}"
+    sed '16i#include <sys/stat.h>' -i ldm.c
+  '';
+
+  buildFlags = "ldm";
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp -v ldm $out/bin
+  '';
+
+  meta = {
+    description = "A lightweight device mounter, with libudev as only dependency";
+    license = stdenv.lib.licenses.mit;
+
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.the-kenny ];
+    repositories.git = git;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ledger-udev-rules/default.nix b/nixpkgs/pkgs/os-specific/linux/ledger-udev-rules/default.nix
new file mode 100644
index 000000000000..28027fd4510a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ledger-udev-rules/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  pname = "ledger-udev-rules";
+  version = "unstable-2019-02-13";
+
+  src = fetchFromGitHub {
+    owner = "LedgerHQ";
+    repo = "udev-rules";
+    rev = "20cc1651eb551c4855aaa56628c77eaeb3031c22";
+    sha256 = "0riydkc4in10pv4qlrvbg3w78qsvxly5caa3zwyqcmsm5fmprqky";
+  };
+
+  dontBuild = true;
+  dontConfigure = true;
+
+  installPhase = ''
+    mkdir -p $out/lib/udev/rules.d
+    cp 20-hw1.rules $out/lib/udev/rules.d/20-ledger.rules
+  '';
+
+  meta = with stdenv.lib; {
+    description = "udev rules for Ledger devices";
+    license = licenses.asl20;
+    maintainers = with maintainers; [ asymmetric ];
+    platforms = platforms.linux;
+    homepage = https://github.com/LedgerHQ/udev-rules;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libaio/default.nix b/nixpkgs/pkgs/os-specific/linux/libaio/default.nix
new file mode 100644
index 000000000000..949c8135df7b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libaio/default.nix
@@ -0,0 +1,38 @@
+{ stdenv, fetchurl, fetchpatch }:
+
+stdenv.mkDerivation rec {
+  version = "0.3.110";
+  name = "libaio-${version}";
+
+  src = fetchurl {
+    url = "https://fedorahosted.org/releases/l/i/libaio/${name}.tar.gz";
+    sha256 = "0zjzfkwd1kdvq6zpawhzisv7qbq1ffs343i5fs9p498pcf7046g0";
+  };
+
+  patches = [ (fetchpatch {
+    url = https://pagure.io/libaio/c/da47c32b2ff39e52fbed1622c34b86bc88d7c217.patch;
+    sha256 = "1kqpiswjn549s3w3m89bw5qkl7bw5pvq6gp5cdzd926ymlgivj5c";
+  }) ];
+
+  postPatch = ''
+    patchShebangs harness
+
+    # Makefile is too optimistic, gcc is too smart
+    substituteInPlace harness/Makefile \
+      --replace "-Werror" ""
+  '';
+
+  makeFlags = "prefix=$(out)";
+
+  hardeningDisable = stdenv.lib.optional (stdenv.isi686) "stackprotector";
+
+  checkTarget = "partcheck"; # "check" needs root
+
+  meta = {
+    description = "Library for asynchronous I/O in Linux";
+    homepage = http://lse.sourceforge.net/io/aio.html;
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.lgpl21;
+    maintainers = with stdenv.lib.maintainers; [ fuuzetsu ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libatasmart/default.nix b/nixpkgs/pkgs/os-specific/linux/libatasmart/default.nix
new file mode 100644
index 000000000000..018f8c624350
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libatasmart/default.nix
@@ -0,0 +1,21 @@
+{ stdenv, fetchurl, pkgconfig, udev, buildPackages }:
+
+stdenv.mkDerivation rec {
+  name = "libatasmart-0.19";
+
+  src = fetchurl {
+    url = "http://0pointer.de/public/${name}.tar.xz";
+    sha256 = "138gvgdwk6h4ljrjsr09pxk1nrki4b155hqdzyr8mlk3bwsfmw31";
+  };
+
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ udev ];
+
+  meta = with stdenv.lib; {
+    homepage = http://0pointer.de/blog/projects/being-smart.html;
+    description = "Library for querying ATA SMART status";
+    license = licenses.lgpl21;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libcap-ng/default.nix b/nixpkgs/pkgs/os-specific/linux/libcap-ng/default.nix
new file mode 100644
index 000000000000..838f5c1e8c01
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libcap-ng/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchurl, swig ? null, python2 ? null, python3 ? null }:
+
+assert python2 != null || python3 != null -> swig != null;
+
+stdenv.mkDerivation rec {
+  name = "libcap-ng-${version}";
+  # When updating make sure to test that the version with
+  # all of the python bindings still works
+  version = "0.7.9";
+
+  src = fetchurl {
+    url = "${meta.homepage}/${name}.tar.gz";
+    sha256 = "0a0k484kwv0zilry2mbl9k56cnpdhsjxdxin17jas6kkyfy345aa";
+  };
+
+  nativeBuildInputs = [ swig ];
+  buildInputs = [ python2 python3 ];
+
+  postPatch = ''
+    function get_header() {
+      echo -e "#include <$1>" | gcc -M -xc - | tr ' ' '\n' | grep "$1" | head -n 1
+    }
+
+    # Fix some hardcoding of header paths
+    sed -i "s,/usr/include/linux/capability.h,$(get_header linux/capability.h),g" bindings/python{,3}/Makefile.in
+  '';
+
+  configureFlags = [
+    (if python2 != null then "--with-python" else "--without-python")
+    (if python3 != null then "--with-python3" else "--without-python3")
+  ];
+
+  meta = let inherit (stdenv.lib) platforms licenses maintainers; in {
+    description = "Library for working with POSIX capabilities";
+    homepage = https://people.redhat.com/sgrubb/libcap-ng/;
+    platforms = platforms.linux;
+    license = licenses.lgpl21;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libcap/default.nix b/nixpkgs/pkgs/os-specific/linux/libcap/default.nix
new file mode 100644
index 000000000000..c6055c2e8497
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libcap/default.nix
@@ -0,0 +1,60 @@
+{ stdenv, buildPackages, fetchurl, attr, perl, pam }:
+
+stdenv.mkDerivation rec {
+  name = "libcap-${version}";
+  version = "2.26";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/libs/security/linux-privs/libcap2/${name}.tar.xz";
+    sha256 = "12s5b8fp61jcn4qld8a7fakcz1han4a6l3b8cyl3n6r7hk2bfc5n";
+  };
+
+  outputs = [ "out" "dev" "lib" "man" "doc" "pam" ];
+
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
+  nativeBuildInputs = [ perl ];
+
+  buildInputs = [ pam ];
+
+  propagatedBuildInputs = [ attr ];
+
+  makeFlags = [
+    "lib=lib"
+    "PAM_CAP=yes"
+    "BUILD_CC=$(CC_FOR_BUILD)"
+    "CC:=$(CC)"
+  ];
+
+  prePatch = ''
+    # use relative bash path
+    substituteInPlace progs/capsh.c --replace "/bin/bash" "bash"
+
+    # ensure capsh can find bash in $PATH
+    substituteInPlace progs/capsh.c --replace execve execvpe
+
+    # set prefixes
+    substituteInPlace Make.Rules \
+      --replace 'prefix=/usr' "prefix=$lib" \
+      --replace 'exec_prefix=' "exec_prefix=$out" \
+      --replace 'lib_prefix=$(exec_prefix)' "lib_prefix=$lib" \
+      --replace 'inc_prefix=$(prefix)' "inc_prefix=$dev" \
+      --replace 'man_prefix=$(prefix)' "man_prefix=$doc"
+  '';
+
+  installFlags = "RAISE_SETFCAP=no";
+
+  postInstall = ''
+    rm "$lib"/lib/*.a
+    mkdir -p "$doc/share/doc/${name}"
+    cp License "$doc/share/doc/${name}/"
+  '' + stdenv.lib.optionalString (pam != null) ''
+    mkdir -p "$pam/lib/security"
+    mv "$lib"/lib/security "$pam/lib"
+  '';
+
+  meta = {
+    description = "Library for working with POSIX capabilities";
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.bsd3;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libcgroup/default.nix b/nixpkgs/pkgs/os-specific/linux/libcgroup/default.nix
new file mode 100644
index 000000000000..1e920247a754
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libcgroup/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl, fetchpatch, pam, yacc, flex }:
+
+stdenv.mkDerivation rec {
+  name    = "libcgroup-${version}";
+  version = "0.41";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/libcg/${name}.tar.bz2";
+    sha256 = "0lgvyq37gq84sk30sg18admxaj0j0p5dq3bl6g74a1ppgvf8pqz4";
+  };
+
+  buildInputs = [ pam yacc flex ];
+
+  patches = [
+    (fetchpatch {
+      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/dev-libs/libcgroup/files/libcgroup-0.41-remove-umask.patch?id=33e9f4c81de754bbf76b893ea1133ed023f2a0e5";
+      sha256 = "1x0x29ld0cgmfwq4qy13s6d5c8sym1frfh1j2q47d8gfw6qaxka5";
+    })
+  ];
+
+  postPatch = ''
+    substituteInPlace src/tools/Makefile.in \
+      --replace 'chmod u+s' 'chmod +x'
+  '';
+
+  meta = {
+    description = "Library and tools to manage Linux cgroups";
+    homepage    = "http://libcg.sourceforge.net/";
+    license     = stdenv.lib.licenses.lgpl2;
+    platforms   = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libnl/default.nix b/nixpkgs/pkgs/os-specific/linux/libnl/default.nix
new file mode 100644
index 000000000000..1caf91b0bb69
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libnl/default.nix
@@ -0,0 +1,50 @@
+{ stdenv, file, lib, fetchFromGitHub, fetchpatch, autoreconfHook, bison, flex, pkgconfig
+, pythonSupport ? true, swig ? null, python}:
+
+stdenv.mkDerivation rec {
+  name = "libnl-${version}";
+  version = "3.4.0";
+
+  src = fetchFromGitHub {
+    repo = "libnl";
+    owner = "thom311";
+    rev = "libnl${lib.replaceStrings ["."] ["_"] version}";
+    sha256 = "1bqf1f5glwf285sa98k5pkj9gg79lliixk1jk85j63v5510fbagp";
+  };
+
+  outputs = [ "bin" "dev" "out" "man" ] ++ lib.optional pythonSupport "py";
+
+  patches = stdenv.lib.optional stdenv.hostPlatform.isMusl
+    (fetchpatch {
+      url = "https://raw.githubusercontent.com/gentoo/musl/48d2a28710ae40877fd3e178ead1fb1bb0baa62c/dev-libs/libnl/files/libnl-3.3.0_rc1-musl.patch";
+      sha256 = "0dd7xxikib201i99k2if066hh7gwf2i4ffckrjplq6lr206jn00r";
+    });
+
+  enableParallelBuilding = true;
+
+  nativeBuildInputs = [ autoreconfHook bison flex pkgconfig file ]
+    ++ lib.optional pythonSupport swig;
+
+  postBuild = lib.optionalString (pythonSupport) ''
+      cd python
+      ${python}/bin/python setup.py install --prefix=../pythonlib
+      cd -
+  '';
+
+  postFixup = lib.optionalString pythonSupport ''
+    mv "pythonlib/" "$py"
+  '';
+
+  passthru = {
+    inherit pythonSupport;
+  };
+
+  meta = with lib; {
+    inherit version;
+    homepage = http://www.infradead.org/~tgr/libnl/;
+    description = "Linux Netlink interface library suite";
+    license = licenses.lgpl21;
+    maintainers = with maintainers; [ fpletz ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libratbag/default.nix b/nixpkgs/pkgs/os-specific/linux/libratbag/default.nix
new file mode 100644
index 000000000000..5dab4b34f466
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libratbag/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchFromGitHub, meson, ninja, pkgconfig
+, glib, systemd, udev, libevdev, gitMinimal, check, valgrind, swig, python3 }:
+
+stdenv.mkDerivation rec {
+  name = "libratbag-${version}";
+  version = "0.9.905";
+
+  src = fetchFromGitHub {
+    owner  = "libratbag";
+    repo   = "libratbag";
+    rev    = "v${version}";
+    sha256 = "0bh1nf9sv7wka0vh5bz9krf2cfxz0rr64hrpdm7imsb6cn39k01y";
+  };
+
+  nativeBuildInputs = [
+    meson ninja pkgconfig gitMinimal swig check valgrind
+  ];
+
+  buildInputs = [
+    glib systemd udev libevdev
+    (python3.withPackages (ps: with ps; [ evdev pygobject3 ]))
+  ];
+
+  mesonFlags = [
+    "-Dsystemd-unit-dir=./lib/systemd/system/"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Configuration library for gaming mice";
+    homepage    = https://github.com/libratbag/libratbag;
+    license     = licenses.mit;
+    maintainers = with maintainers; [ mvnetbiz ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libselinux/default.nix b/nixpkgs/pkgs/os-specific/linux/libselinux/default.nix
new file mode 100644
index 000000000000..51e1a3220941
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libselinux/default.nix
@@ -0,0 +1,50 @@
+{ stdenv, fetchurl, pcre, pkgconfig, libsepol
+, enablePython ? true, swig ? null, python ? null
+, fts
+}:
+
+assert enablePython -> swig != null && python != null;
+
+with stdenv.lib;
+
+stdenv.mkDerivation rec {
+  name = "libselinux-${version}";
+  version = "2.7";
+  inherit (libsepol) se_release se_url;
+
+  outputs = [ "bin" "out" "dev" "man" "py" ];
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/libselinux-${version}.tar.gz";
+    sha256 = "0mwcq78v6ngbq06xmb9dvilpg0jnl2vs9fgrpakhmmiskdvc1znh";
+  };
+
+  nativeBuildInputs = [ pkgconfig ] ++ optionals enablePython [ swig python ];
+  buildInputs = [ libsepol pcre fts ] ++ optionals enablePython [ python ];
+
+  # drop fortify here since package uses it by default, leading to compile error:
+  # command-line>:0:0: error: "_FORTIFY_SOURCE" redefined [-Werror]
+  hardeningDisable = [ "fortify" ];
+
+  NIX_CFLAGS_COMPILE = [ "-Wno-error" ];
+
+  makeFlags = [
+    "PREFIX=$(out)"
+    "INCDIR=$(dev)/include/selinux"
+    "INCLUDEDIR=$(dev)/include"
+    "MAN3DIR=$(man)/share/man/man3"
+    "MAN5DIR=$(man)/share/man/man5"
+    "MAN8DIR=$(man)/share/man/man8"
+    "PYSITEDIR=$(py)/${python.sitePackages}"
+    "SBINDIR=$(bin)/sbin"
+    "SHLIBDIR=$(out)/lib"
+
+    "LIBSEPOLA=${stdenv.lib.getLib libsepol}/lib/libsepol.a"
+  ];
+
+  installTargets = [ "install" ] ++ optional enablePython "install-pywrap";
+
+  meta = removeAttrs libsepol.meta ["outputsToInstall"] // {
+    description = "SELinux core library";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libsemanage/default.nix b/nixpkgs/pkgs/os-specific/linux/libsemanage/default.nix
new file mode 100644
index 000000000000..59f5f11d0769
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libsemanage/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchurl, pkgconfig, bison, flex, libsepol, libselinux, bzip2, audit
+, enablePython ? true, swig ? null, python ? null
+}:
+
+with stdenv.lib;
+
+stdenv.mkDerivation rec {
+  name = "libsemanage-${version}";
+  version = "2.7";
+  inherit (libsepol) se_release se_url;
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/libsemanage-${version}.tar.gz";
+    sha256 = "0xnlp1yg8b1aqc6kq3pss1i1nl06rfj4x4pyl5blasnf2ivlgs87";
+  };
+
+  nativeBuildInputs = [ bison flex pkgconfig ];
+  buildInputs = [ libsepol libselinux bzip2 audit ]
+    ++ optionals enablePython [ swig python ];
+
+  preBuild = ''
+    makeFlagsArray+=("PREFIX=$out")
+    makeFlagsArray+=("DESTDIR=$out")
+    makeFlagsArray+=("MAN3DIR=$out/share/man/man3")
+    makeFlagsArray+=("MAN5DIR=$out/share/man/man5")
+    makeFlagsArray+=("PYSITEDIR=$out/lib/${python.libPrefix}/site-packages")
+  '';
+
+  installTargets = [ "install" ] ++ optionals enablePython [ "install-pywrap" ];
+
+  meta = removeAttrs libsepol.meta ["outputsToInstall"] // {
+    description = "Policy management tools for SELinux";
+    license = stdenv.lib.licenses.lgpl21;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libsepol/default.nix b/nixpkgs/pkgs/os-specific/linux/libsepol/default.nix
new file mode 100644
index 000000000000..f16c241a0a1f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libsepol/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchurl, flex }:
+
+stdenv.mkDerivation rec {
+  name = "libsepol-${version}";
+  version = "2.7";
+  se_release = "20170804";
+  se_url = "https://raw.githubusercontent.com/wiki/SELinuxProject/selinux/files/releases";
+
+  outputs = [ "bin" "out" "dev" "man" ];
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/libsepol-${version}.tar.gz";
+    sha256 = "1rzr90d3f1g5wy1b8sh6fgnqb9migys2zgpjmpakn6lhxkc3p7fn";
+  };
+
+  nativeBuildInputs = [ flex ];
+
+  makeFlags = [
+    "PREFIX=$(out)"
+    "BINDIR=$(bin)/bin"
+    "INCDIR=$(dev)/include/sepol"
+    "INCLUDEDIR=$(dev)/include"
+    "MAN3DIR=$(man)/share/man/man3"
+    "MAN8DIR=$(man)/share/man/man8"
+    "SHLIBDIR=$(out)/lib"
+  ];
+
+  NIX_CFLAGS_COMPILE = [ "-Wno-error" ];
+
+  passthru = { inherit se_release se_url; };
+
+  meta = with stdenv.lib; {
+    description = "SELinux binary policy manipulation library";
+    homepage = http://userspace.selinuxproject.org;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.phreedom ];
+    license = stdenv.lib.licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libsmbios/default.nix b/nixpkgs/pkgs/os-specific/linux/libsmbios/default.nix
new file mode 100644
index 000000000000..874faf7799b3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libsmbios/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchFromGitHub, pkgconfig, autoreconfHook, help2man, gettext
+, libxml2, perl, python3, doxygen }:
+
+
+stdenv.mkDerivation rec {
+  name = "libsmbios-${version}";
+  version = "2.4.2";
+
+  src = fetchFromGitHub {
+    owner = "dell";
+    repo = "libsmbios";
+    rev = "v${version}";
+    sha256 = "0bck3byk62a69ngyj0zjpzf4wxwjmkhwhvsqb8z24dww9wz41l9k";
+  };
+
+  nativeBuildInputs = [ autoreconfHook doxygen gettext libxml2 help2man perl pkgconfig ];
+
+  buildInputs = [ python3 ];
+
+  configureFlags = [ "--disable-graphviz" ];
+
+  enableParallelBuilding = true;
+
+  postInstall = ''
+    mkdir -p $out/include
+    cp -a src/include/smbios_c $out/include/
+    cp -a out/public-include/smbios_c $out/include/
+  '';
+
+  preFixup = ''rm -rf "$(pwd)" ''; # Hack to avoid TMPDIR in RPATHs
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/dell/libsmbios;
+    description = "A library to obtain BIOS information";
+    license = with licenses; [ osl21 gpl2Plus ];
+    maintainers = with maintainers; [ ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libudev0-shim/default.nix b/nixpkgs/pkgs/os-specific/linux/libudev0-shim/default.nix
new file mode 100644
index 000000000000..c0c6ad54579c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libudev0-shim/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchFromGitHub, udev }:
+
+stdenv.mkDerivation rec {
+  name = "libudev0-shim-${version}";
+  version = "1";
+
+  src = fetchFromGitHub {
+    owner = "archlinux";
+    repo = "libudev0-shim";
+    rev = "v${version}";
+    sha256 = "1460qm6rp1cqnns39lj24z7191m8sbpvbjabqbzb55dkdd2kw50z";
+  };
+
+  buildInputs = [ udev ];
+
+  installPhase = ''
+    name="$(echo libudev.so.*)"
+    install -Dm755 "$name" "$out/lib/$name"
+    ln -s "$name" "$out/lib/libudev.so.0"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Shim to preserve libudev.so.0 compatibility";
+    homepage = https://github.com/archlinux/libudev0-shim;
+    platforms = platforms.linux;
+    license = licenses.lgpl21;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libvolume_id/default.nix b/nixpkgs/pkgs/os-specific/linux/libvolume_id/default.nix
new file mode 100644
index 000000000000..14c152dc10e9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libvolume_id/default.nix
@@ -0,0 +1,24 @@
+{stdenv, fetchurl}:
+   
+stdenv.mkDerivation {
+  name = "libvolume_id-0.81.1";
+   
+  src = fetchurl {
+    url = https://www.marcuscom.com/downloads/libvolume_id-0.81.1.tar.bz2;
+    sha256 = "029z04vdxxsl8gycm9whcljhv6dy4b12ybsxdb99jr251gl1ifs5";
+  };
+
+  preBuild = "
+    makeFlagsArray=(prefix=$out E=echo RANLIB=ranlib INSTALL='install -c')
+  ";
+
+  # Work around a broken Makefile.
+  postInstall = "
+    rm $out/lib/libvolume_id.so.0
+    cp -f libvolume_id.so.0 $out/lib/
+  ";
+
+  meta = {
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libwebcam/default.nix b/nixpkgs/pkgs/os-specific/linux/libwebcam/default.nix
new file mode 100644
index 000000000000..879e85a0c945
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libwebcam/default.nix
@@ -0,0 +1,55 @@
+{ lib
+, stdenv
+, fetchurl
+, cmake
+, pkgconfig
+, libxml2
+}:
+
+stdenv.mkDerivation rec {
+  pname = "libwebcam";
+  version = "0.2.5";
+  name = "${pname}-${version}";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/project/${pname}/source/${pname}-src-${version}.tar.gz";
+    sha256 = "0hcxv8di83fk41zjh0v592qm7c0v37a3m3n3lxavd643gff1k99w";
+  };
+
+  patches = [
+    ./uvcdynctrl_symlink_support_and_take_data_dir_from_env.patch
+  ];
+
+  buildInputs = [
+    cmake
+    pkgconfig
+    libxml2
+  ];
+
+  postPatch = ''
+    substituteInPlace ./uvcdynctrl/CMakeLists.txt \
+      --replace "/lib/udev" "$out/lib/udev"
+
+    substituteInPlace ./uvcdynctrl/udev/scripts/uvcdynctrl \
+      --replace 'debug=0' 'debug=''${NIX_UVCDYNCTRL_UDEV_DEBUG:-0}' \
+      --replace 'uvcdynctrlpath=uvcdynctrl' "uvcdynctrlpath=$out/bin/uvcdynctrl"
+
+    substituteInPlace ./uvcdynctrl/udev/rules/80-uvcdynctrl.rules \
+      --replace "/lib/udev" "$out/lib/udev"
+  '';
+
+
+  preConfigure = ''
+    cmakeFlagsArray=(
+      $cmakeFlagsArray
+      "-DCMAKE_INSTALL_PREFIX=$out"
+    )
+  '';
+
+  meta = with lib; {
+    description = "The webcam-tools package";
+    platforms = platforms.linux;
+    license = licenses.lgpl3;
+    maintainers = with maintainers; [ jraygauthier ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/libwebcam/uvcdynctrl_symlink_support_and_take_data_dir_from_env.patch b/nixpkgs/pkgs/os-specific/linux/libwebcam/uvcdynctrl_symlink_support_and_take_data_dir_from_env.patch
new file mode 100644
index 000000000000..07e5f0bf852b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/libwebcam/uvcdynctrl_symlink_support_and_take_data_dir_from_env.patch
@@ -0,0 +1,65 @@
+diff --git a/uvcdynctrl/main.c b/uvcdynctrl/main.c
+index b7befd1..f3a768c 100644
+--- a/uvcdynctrl/main.c
++++ b/uvcdynctrl/main.c
+@@ -674,27 +674,31 @@ get_filename (const char *dir_path, const char *vid)
+ 	printf ( "checking dir: %s \n", dir_path);
+ 	while ((dp = readdir(dir)) != NULL) 
+ 	{
+-		if((dp->d_type == DT_DIR) && (fnmatch("[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]", dp->d_name, 0) == 0))
++		if((dp->d_type == DT_DIR || dp->d_type == DT_LNK ) && (fnmatch("[[:xdigit:]][[:xdigit:]][[:xdigit:]][[:xdigit:]]", dp->d_name, 0) == 0))
+ 		{
+ 			if( strcasecmp(vid, dp->d_name) != 0)
+ 			{
+ 				/*doesn't match - clean up and move to the next entry*/
+ 				continue;
+ 			}
+-			
++
+ 			char *tmp = path_cat (dir_path, dp->d_name);
+-			printf("found dir: %s \n", dp->d_name);
++
+ 			DIR * subdir = opendir(tmp);
+-			while ((sdp = readdir(subdir)) != NULL) 
++			if ( subdir != NULL )
+ 			{
+-				if( fnmatch("*.xml", sdp->d_name, 0) == 0 )
++				printf("found dir: %s \n", dp->d_name);
++				while ((sdp = readdir(subdir)) != NULL) 
+ 				{
+-					file_list[nf-1] = path_cat (tmp, sdp->d_name);
+-					printf("found: %s \n", file_list[nf-1]);
+-					nf++;
+-					file_list = realloc(file_list,nf*sizeof(file_list));
+-					file_list[nf-1] = NULL;   
+-				} 
++					if( fnmatch("*.xml", sdp->d_name, 0) == 0 )
++					{
++						file_list[nf-1] = path_cat (tmp, sdp->d_name);
++						printf("found: %s \n", file_list[nf-1]);
++						nf++;
++						file_list = realloc(file_list,nf*sizeof(file_list));
++						file_list[nf-1] = NULL;   
++					} 
++				}
+ 			}
+ 			closedir(subdir);
+ 			free (tmp);
+@@ -869,9 +873,15 @@ main (int argc, char **argv)
+ 			pid_set = 1; /*flag pid.xml check*/
+ 			//printf("vid:%s pid:%s\n", vid, pid);
+ 		}
+-		
++
++		const char* dataDir = getenv( "NIX_UVCDYNCTRL_DATA_DIR" );
++		// When unavailable, fallback on data dir specified at build time.
++		if ( !dataDir ) {
++			dataDir = DATA_DIR;
++		}
++
+ 		/* get xml file list from DATA_DIR/vid/ */ 
+-		char **xml_files = get_filename (DATA_DIR, vid);
++		char **xml_files = get_filename (dataDir, vid);
+  
+ 		/*check for pid.xml*/
+ 		char fname[9];
diff --git a/nixpkgs/pkgs/os-specific/linux/light/default.nix b/nixpkgs/pkgs/os-specific/linux/light/default.nix
new file mode 100644
index 000000000000..1856c8861cc4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/light/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, coreutils }:
+
+stdenv.mkDerivation rec {
+  version = "1.2";
+  name = "light-${version}";
+  src = fetchFromGitHub {
+    owner = "haikarainen";
+    repo = "light";
+    rev = "v${version}";
+    sha256 = "1h286va0r1xgxlnxfaaarrj3qhxmjjsivfn3khwm0wq1mhkfihra";
+  };
+
+  configureFlags = [ "--with-udev" ];
+
+  nativeBuildInputs = [ autoreconfHook ];
+
+  # ensure udev rules can find the commands used
+  postPatch = ''
+    substituteInPlace 90-backlight.rules \
+      --replace '/bin/chgrp' '${coreutils}/bin/chgrp' \
+      --replace '/bin/chmod' '${coreutils}/bin/chmod'
+  '';
+
+  meta = {
+    description = "GNU/Linux application to control backlights";
+    homepage = https://haikarainen.github.io/light/;
+    license = stdenv.lib.licenses.gpl3;
+    maintainers = with stdenv.lib.maintainers; [ puffnfresh dtzWill ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lightum/default.nix b/nixpkgs/pkgs/os-specific/linux/lightum/default.nix
new file mode 100644
index 000000000000..3eaf43631954
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lightum/default.nix
@@ -0,0 +1,38 @@
+{ stdenv, fetchgit, libX11, libXScrnSaver, libXext, glib, dbus, pkgconfig, systemd }:
+
+stdenv.mkDerivation {
+  name = "lightum-2014-06-07";
+  src = fetchgit {
+    url = https://github.com/poliva/lightum;
+    rev = "123e6babe0669b23d4c1dfa5511088608ff2baa8";
+    sha256 = "01x24rcrkgksyvqpgkr9zafg3jgs8nqng8yf0hx0kbmcimar8dbp";
+  };
+
+  buildInputs = [
+    dbus
+    glib
+    libX11
+    libXScrnSaver
+    libXext
+    pkgconfig
+    systemd
+  ];
+
+  patchPhase = ''
+    substituteInPlace Makefile \
+      --replace "libsystemd-login" "libsystemd"
+  '';
+
+  installPhase = ''
+    make install prefix=$out bindir=$out/bin docdir=$out/share/doc \
+      mandir=$out/share/man INSTALL="install -c" INSTALLDATA="install -c -m 644"
+  '';
+
+  meta = {
+    description = "MacBook automatic light sensor daemon";
+    homepage = https://github.com/poliva/lightum;
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = with stdenv.lib.maintainers; [ puffnfresh ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lksctp-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/lksctp-tools/default.nix
new file mode 100644
index 000000000000..6c644c9482a3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lksctp-tools/default.nix
@@ -0,0 +1,17 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "lksctp-tools-1.0.17";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/lksctp/${name}.tar.gz";
+    sha256 = "05da6c2v3acc18ndvmkrag6x5lf914b7s0xkkr6wkvrbvd621sqs";
+  };
+
+  meta = with stdenv.lib; {
+    description = "Linux Kernel Stream Control Transmission Protocol Tools.";
+    homepage = http://lksctp.sourceforge.net/;
+    license = with licenses; [ gpl2 lgpl21 ]; # library is lgpl21
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lm-sensors/default.nix b/nixpkgs/pkgs/os-specific/linux/lm-sensors/default.nix
new file mode 100644
index 000000000000..0536ba064a3d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lm-sensors/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchzip, bison, flex, which, perl
+, sensord ? false, rrdtool ? null
+}:
+
+assert sensord -> rrdtool != null;
+
+stdenv.mkDerivation rec {
+  name = "lm-sensors-${version}";
+  version = "3.5.0";
+
+  src = fetchzip {
+    url = "https://github.com/lm-sensors/lm-sensors/archive/V${stdenv.lib.replaceStrings ["."] ["-"] version}.tar.gz";
+    sha256 = "1mdrnb9r01z1xfdm6dpkywvf9yy9a4yzb59paih9sijwmigv19fj";
+  };
+
+  nativeBuildInputs = [ bison flex which ];
+  buildInputs = [ perl ]
+   ++ stdenv.lib.optional sensord rrdtool;
+
+  preBuild = ''
+    makeFlagsArray=(PREFIX=$out ETCDIR=$out/etc
+    ${stdenv.lib.optionalString sensord "PROG_EXTRA=sensord"})
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://hwmon.wiki.kernel.org/lm_sensors;
+    description = "Tools for reading hardware sensors";
+    license = with licenses; [ gpl2Plus lgpl21Plus ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lockdep/default.nix b/nixpkgs/pkgs/os-specific/linux/lockdep/default.nix
new file mode 100644
index 000000000000..3c7ceb1270c0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lockdep/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name    = "lockdep-${version}";
+  version = "4.1.2";
+  fullver = "4.1.2";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/kernel/v4.x/linux-${version}.tar.xz";
+    sha256 = "1mdyjhnzhh254cblahqmpsk226z006z6sm9dmwvg6jlhpsw4cjhy";
+  };
+
+  preConfigure = "cd tools/lib/lockdep";
+  installPhase = ''
+    mkdir -p $out/bin $out/lib $out/include
+
+    cp -R include/liblockdep $out/include
+    make install DESTDIR=$out prefix=""
+
+    substituteInPlace $out/bin/lockdep --replace "./liblockdep.so" "$out/lib/liblockdep.so.$fullver"
+  '';
+
+  meta = {
+    description = "Userspace locking validation tool built on the Linux kernel";
+    homepage    = "https://kernel.org/";
+    license     = stdenv.lib.licenses.gpl2;
+    platforms   = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/logitech-udev-rules/default.nix b/nixpkgs/pkgs/os-specific/linux/logitech-udev-rules/default.nix
new file mode 100644
index 000000000000..c215d9401940
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/logitech-udev-rules/default.nix
@@ -0,0 +1,19 @@
+{ stdenv, solaar }:
+
+# ltunifi and solaar both provide udev rules but solaar's rules are more
+# up-to-date so we simply use that instead of having to maintain our own rules
+
+stdenv.mkDerivation rec {
+  name = "logitech-udev-rules-${version}";
+  inherit (solaar) version;
+
+  buildCommand = ''
+    install -Dm644 -t $out/etc/udev/rules.d ${solaar.src}/rules.d/*.rules
+  '';
+
+  meta = with stdenv.lib; {
+    description = "udev rules for Logitech devices";
+    inherit (solaar.meta) homepage license platforms;
+    maintainers = with maintainers; [ peterhoeg ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix b/nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix
new file mode 100644
index 000000000000..34dae105a8dd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lsb-release/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchurl, perl, coreutils, getopt, makeWrapper }:
+
+stdenv.mkDerivation rec {
+  version = "1.4";
+  name = "lsb-release-${version}";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/lsb/${name}.tar.gz";
+    sha256 = "0wkiy7ymfi3fh2an2g30raw6yxh6rzf6nz2v90fplbnnz2414clr";
+  };
+
+  preConfigure = ''
+    substituteInPlace help2man \
+      --replace /usr/bin/perl ${perl}/bin/perl
+  '';
+
+  installFlags = [ "prefix=$(out)" ];
+
+  nativeBuildInputs  = [ makeWrapper perl ];
+
+  buildInputs = [ coreutils getopt ];
+
+  # Ensure utilities used are available
+  preFixup = ''
+    wrapProgram $out/bin/lsb_release --prefix PATH : ${stdenv.lib.makeBinPath [ coreutils getopt ]}
+  '';
+
+  meta = {
+    description = "Prints certain LSB (Linux Standard Base) and Distribution information";
+    homepage = http://www.linuxfoundation.org/collaborate/workgroups/lsb;
+    license = [ stdenv.lib.licenses.gpl2Plus stdenv.lib.licenses.gpl3Plus ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lsiutil/default.nix b/nixpkgs/pkgs/os-specific/linux/lsiutil/default.nix
new file mode 100644
index 000000000000..93cab433c9c6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lsiutil/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchurl, unzip }:
+
+let
+
+  version = "1.60";
+
+  src = fetchurl {
+    name = "lsiutil-${version}.zip";
+    url = "http://www.lsi.com/DistributionSystem/AssetDocument/support/downloads/hbas/fibre_channel/hardware_drivers/LSIUtil%20Kit_${version}.zip";
+    sha256 = "1d4337faa56e24f7d98db87b9de94d6e2c17ab671f4e301b93833eea08b9e426";
+  };  
+
+in
+
+stdenv.mkDerivation rec {
+  name = "lsiutils-${version}";
+  
+  srcs = [ src "Source/lsiutil.tar.gz" ];
+
+  buildInputs = [ unzip ];
+
+  sourceRoot = "lsiutil";
+
+  preBuild =
+    ''
+      mkdir -p $out/bin
+      substituteInPlace Makefile --replace /usr/bin $out/bin
+      substituteInPlace lsiutil.c \
+        --replace /sbin/modprobe modprobe \
+        --replace /bin/mknod $(type -P mknod)
+    '';
+
+  installPhase = "true";
+  
+  meta = {
+    homepage = http://www.lsi.com/;
+    description = "LSI Logic Fusion MPT command line management tool";
+    license = stdenv.lib.licenses.unfree;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lsscsi/default.nix b/nixpkgs/pkgs/os-specific/linux/lsscsi/default.nix
new file mode 100644
index 000000000000..aba907039aca
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lsscsi/default.nix
@@ -0,0 +1,19 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation {
+  name = "lsscsi-0.30";
+
+  src = fetchurl {
+    url = "http://sg.danny.cz/scsi/lsscsi-0.30.tgz";
+    sha256 = "05cba72m0hj3kpikk26h7j02cly7zy5lgww2fvswa0jz823j36k1";
+  };
+
+  preConfigure = ''
+    substituteInPlace Makefile.in --replace /usr "$out"
+  '';
+
+  meta = with stdenv.lib; {
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lttng-modules/default.nix b/nixpkgs/pkgs/os-specific/linux/lttng-modules/default.nix
new file mode 100644
index 000000000000..d4b3f374c5bc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lttng-modules/default.nix
@@ -0,0 +1,38 @@
+{ stdenv, fetchurl, kernel }:
+
+stdenv.mkDerivation rec {
+  pname = "lttng-modules-${version}";
+  name = "${pname}-${kernel.version}";
+  version = "2.10.5";
+
+  src = fetchurl {
+    url = "https://lttng.org/files/lttng-modules/lttng-modules-${version}.tar.bz2";
+    sha256 = "07rs01zwr4bmjamplix5qz1c6mb6wdawb68vyn0w6wx68ppbpnxq";
+  };
+
+  buildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  NIX_CFLAGS_COMPILE = [ "-Wno-error=implicit-function-declaration" ];
+
+  preConfigure = ''
+    export KERNELDIR="${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+    export INSTALL_MOD_PATH="$out"
+  '';
+
+  installTargets = [ "modules_install" ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "Linux kernel modules for LTTng tracing";
+    homepage = https://lttng.org/;
+    license = with licenses; [ lgpl21 gpl2 mit ];
+    platforms = platforms.linux;
+    maintainers = [ maintainers.bjornfor ];
+    broken = builtins.compareVersions kernel.version "3.18" == -1
+      || builtins.compareVersions kernel.version "4.16" == 1;
+  };
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lvm2/default.nix b/nixpkgs/pkgs/os-specific/linux/lvm2/default.nix
new file mode 100644
index 000000000000..469096d014d7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lvm2/default.nix
@@ -0,0 +1,93 @@
+{ stdenv, fetchgit, fetchpatch, pkgconfig, systemd, udev, utillinux, libuuid
+, thin-provisioning-tools, libaio
+, enable_dmeventd ? false }:
+
+let
+  version = "2.03.01";
+in
+
+stdenv.mkDerivation {
+  name = "lvm2-${version}";
+
+  src = fetchgit {
+    url = "git://sourceware.org/git/lvm2.git";
+    rev = "v${builtins.replaceStrings [ "." ] [ "_" ] version}";
+    sha256 = "0jlaswf1srdxiqpgpp97j950ddjds8z0kr4pbwmal2za2blrgvbl";
+  };
+
+  configureFlags = [
+    "--disable-readline"
+    "--enable-udev_rules"
+    "--enable-udev_sync"
+    "--enable-pkgconfig"
+    "--enable-applib"
+    "--enable-cmdlib"
+  ] ++ stdenv.lib.optional enable_dmeventd " --enable-dmeventd"
+  ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    "ac_cv_func_malloc_0_nonnull=yes"
+    "ac_cv_func_realloc_0_nonnull=yes"
+  ];
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ udev libuuid thin-provisioning-tools libaio ];
+
+  preConfigure =
+    ''
+      substituteInPlace scripts/lvm2_activation_generator_systemd_red_hat.c \
+        --replace /usr/bin/udevadm ${systemd}/bin/udevadm
+
+      sed -i /DEFAULT_SYS_DIR/d Makefile.in
+      sed -i /DEFAULT_PROFILE_DIR/d conf/Makefile.in
+    '';
+
+  # gcc: error: ../../device_mapper/libdevice-mapper.a: No such file or directory
+  enableParallelBuilding = false;
+
+  #patches = [ ./purity.patch ];
+  patches = stdenv.lib.optionals stdenv.hostPlatform.isMusl [
+    (fetchpatch {
+      name = "fix-stdio-usage.patch";
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/lvm2/fix-stdio-usage.patch?h=3.7-stable&id=31bd4a8c2dc00ae79a821f6fe0ad2f23e1534f50";
+      sha256 = "0m6wr6qrvxqi2d2h054cnv974jq1v65lqxy05g1znz946ga73k3p";
+    })
+    (fetchpatch {
+      name = "mallinfo.patch";
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/lvm2/mallinfo.patch?h=3.7-stable&id=31bd4a8c2dc00ae79a821f6fe0ad2f23e1534f50";
+      sha256 = "0g6wlqi215i5s30bnbkn8w7axrs27y3bnygbpbnf64wwx7rxxlj0";
+    })
+    (fetchpatch {
+      name = "mlockall-default-config.patch";
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/lvm2/mlockall-default-config.patch?h=3.7-stable&id=31bd4a8c2dc00ae79a821f6fe0ad2f23e1534f50";
+      sha256 = "1ivbj3sphgf8n1ykfiv5rbw7s8dgnj5jcr9jl2v8cwf28lkacw5l";
+    })
+  ];
+
+  doCheck = false; # requires root
+
+  # To prevent make install from failing.
+  preInstall = "installFlags=\"OWNER= GROUP= confdir=$out/etc\"";
+
+  # Install systemd stuff.
+  #installTargets = "install install_systemd_generators install_systemd_units install_tmpfiles_configuration";
+
+  postInstall =
+    ''
+      substituteInPlace $out/lib/udev/rules.d/13-dm-disk.rules \
+        --replace $out/sbin/blkid ${utillinux}/sbin/blkid
+
+      # Systemd stuff
+      mkdir -p $out/etc/systemd/system $out/lib/systemd/system-generators
+      cp scripts/blk_availability_systemd_red_hat.service $out/etc/systemd/system
+      cp scripts/lvm2_activation_generator_systemd_red_hat $out/lib/systemd/system-generators
+    '';
+
+  meta = with stdenv.lib; {
+    homepage = http://sourceware.org/lvm2/;
+    description = "Tools to support Logical Volume Management (LVM) on Linux";
+    platforms = platforms.linux;
+    license = with licenses; [ gpl2 bsd2 lgpl21 ];
+    maintainers = with maintainers; [raskin];
+    inherit version;
+    downloadPage = "ftp://sources.redhat.com/pub/lvm2/";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lvm2/default.upstream b/nixpkgs/pkgs/os-specific/linux/lvm2/default.upstream
new file mode 100644
index 000000000000..1e5aaf5ab5cf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lvm2/default.upstream
@@ -0,0 +1,4 @@
+url ftp://sources.redhat.com/pub/lvm2/
+version_link '[.]tgz$'
+version '.*[^0-9.][^.]*[.]([0-9.]+)[.].*' '\1'
+do_overwrite () { do_overwrite_just_version; }
diff --git a/nixpkgs/pkgs/os-specific/linux/lvm2/purity.patch b/nixpkgs/pkgs/os-specific/linux/lvm2/purity.patch
new file mode 100644
index 000000000000..d6990dd9caa5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lvm2/purity.patch
@@ -0,0 +1,44 @@
+diff -ru LVM2.2.02.95-orig/udev/10-dm.rules.in LVM2.2.02.95/udev/10-dm.rules.in
+--- LVM2.2.02.95-orig/udev/10-dm.rules.in	2011-08-11 19:55:29.000000000 +0200
++++ LVM2.2.02.95/udev/10-dm.rules.in	2012-03-19 20:12:35.000000000 +0100
+@@ -19,9 +19,8 @@
+ SUBSYSTEM!="block", GOTO="dm_end"
+ KERNEL!="dm-[0-9]*", GOTO="dm_end"
+ 
+-# Set proper sbin path, /sbin has higher priority than /usr/sbin.
+-ENV{DM_SBIN_PATH}="/sbin"
+-TEST!="$env{DM_SBIN_PATH}/dmsetup", ENV{DM_SBIN_PATH}="/usr/sbin"
++# Set proper sbin path. Exit if dmsetup is not present.
++ENV{DM_SBIN_PATH}="(sbindir)"
+ TEST!="$env{DM_SBIN_PATH}/dmsetup", GOTO="dm_end"
+ 
+ # Device created, major and minor number assigned - "add" event generated.
+diff -ru LVM2.2.02.95-orig/udev/Makefile.in LVM2.2.02.95/udev/Makefile.in
+--- LVM2.2.02.95-orig/udev/Makefile.in	2012-02-24 10:53:12.000000000 +0100
++++ LVM2.2.02.95/udev/Makefile.in	2012-03-19 20:16:09.000000000 +0100
+@@ -12,6 +12,7 @@
+ # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ 
+ srcdir = @srcdir@
++sbindir = @sbindir@
+ top_srcdir = @top_srcdir@
+ top_builddir = @top_builddir@
+ 
+@@ -26,7 +27,7 @@
+ ifeq ("@UDEV_HAS_BUILTIN_BLKID@", "yes")
+ 	BLKID_RULE=IMPORT{builtin}=\"blkid\"
+ else
+-	BLKID_RULE=IMPORT{program}=\"\$$env{DM_SBIN_PATH}\/blkid -o udev -p \$$tempnode\"
++	BLKID_RULE=IMPORT{program}=\"\/sbin\/blkid -o udev -p \$$tempnode\"
+ endif
+ 
+ CLEAN_TARGETS = 10-dm.rules 13-dm-disk.rules
+@@ -36,7 +37,7 @@
+ vpath %.rules $(srcdir)
+ 
+ %.rules: %.rules.in
+-	$(SED) -e "s/(DM_DIR)/$(DM_DIR)/" -e "s/(BLKID_RULE)/$(BLKID_RULE)/" $< >$@
++	$(SED) -e "s/(DM_DIR)/$(DM_DIR)/" -e "s/(BLKID_RULE)/$(BLKID_RULE)/" -e "s|(sbindir)|$(sbindir)|" $< >$@
+ 
+ %_install: %.rules
+ 	$(INSTALL_DATA) -D $< $(udevdir)/$(<F)
diff --git a/nixpkgs/pkgs/os-specific/linux/lxc/default.nix b/nixpkgs/pkgs/os-specific/linux/lxc/default.nix
new file mode 100644
index 000000000000..a8668313465a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lxc/default.nix
@@ -0,0 +1,88 @@
+{ stdenv, fetchurl, autoreconfHook, pkgconfig, perl, docbook2x
+, docbook_xml_dtd_45, python3Packages, pam
+
+# Optional Dependencies
+, libapparmor ? null, gnutls ? null, libselinux ? null, libseccomp ? null
+, libcap ? null, systemd ? null
+}:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+  name = "lxc-${version}";
+  version = "3.1.0";
+
+  src = fetchurl {
+    url = "https://linuxcontainers.org/downloads/lxc/lxc-${version}.tar.gz";
+    sha256 = "1igxqgx8q9cp15mcp1y8j564bl85ijw04jcmgb1s5bmfbg1751sd";
+  };
+
+  nativeBuildInputs = [
+    autoreconfHook pkgconfig perl docbook2x python3Packages.wrapPython
+  ];
+  buildInputs = [
+    pam libapparmor gnutls libselinux libseccomp libcap
+    python3Packages.python python3Packages.setuptools systemd
+  ];
+
+  patches = [
+    ./support-db2x.patch
+  ];
+
+  postPatch = ''
+    sed -i '/chmod u+s/d' src/lxc/Makefile.am
+  '';
+
+  XML_CATALOG_FILES = "${docbook_xml_dtd_45}/xml/dtd/docbook/catalog.xml";
+
+  configureFlags = [
+    "--enable-pam"
+    "--localstatedir=/var"
+    "--sysconfdir=/etc"
+    "--disable-api-docs"
+    "--with-init-script=none"
+    "--with-distro=nixos" # just to be sure it is "unknown"
+  ] ++ optional (libapparmor != null) "--enable-apparmor"
+    ++ optional (libselinux != null) "--enable-selinux"
+    ++ optional (libseccomp != null) "--enable-seccomp"
+    ++ optional (libcap != null) "--enable-capabilities"
+    ++ [
+    "--disable-examples"
+    "--enable-python"
+    "--disable-lua"
+    "--enable-bash"
+    (if doCheck then "--enable-tests" else "--disable-tests")
+    "--with-rootfs-path=/var/lib/lxc/rootfs"
+  ];
+
+  doCheck = false;
+
+  installFlags = [
+    "localstatedir=\${TMPDIR}"
+    "sysconfdir=\${out}/etc"
+    "sysconfigdir=\${out}/etc/default"
+    "bashcompdir=\${out}/share/bash-completion/completions"
+    "READMEdir=\${TMPDIR}/var/lib/lxc/rootfs"
+    "LXCPATH=\${TMPDIR}/var/lib/lxc"
+  ];
+
+  postInstall = ''
+    wrapPythonPrograms
+  '';
+
+  meta = {
+    homepage = https://linuxcontainers.org/;
+    description = "Userspace tools for Linux Containers, a lightweight virtualization system";
+    license = licenses.lgpl21Plus;
+
+    longDescription = ''
+      LXC is the userspace control package for Linux Containers, a
+      lightweight virtual system mechanism sometimes described as
+      "chroot on steroids". LXC builds up from chroot to implement
+      complete virtual systems, adding resource management and isolation
+      mechanisms to Linux’s existing process management infrastructure.
+    '';
+
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ globin fpletz ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/lxc/support-db2x.patch b/nixpkgs/pkgs/os-specific/linux/lxc/support-db2x.patch
new file mode 100644
index 000000000000..16715992d35f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lxc/support-db2x.patch
@@ -0,0 +1,16 @@
+diff --git a/configure.ac b/configure.ac
+index 84f8699..dce9033 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -192,9 +192,9 @@ if test "x$enable_doc" = "xyes" -o "x$enable_doc" = "xauto"; then
+ 	AC_SUBST(db2xman)
+ fi
+ AM_CONDITIONAL([ENABLE_DOCBOOK], [test "x$db2xman" != "x"])
+-AM_CONDITIONAL([USE_DOCBOOK2X], [test "x$db2xman" != "xdocbook2man"])
++AM_CONDITIONAL([USE_DOCBOOK2X], [test "x$db2xman" != "no-no-no"])
+ 
+-if test "x$db2xman" = "xdocbook2man"; then
++if test "x$db2xman" = "no-no-no"; then
+ 	docdtd="\"-//Davenport//DTD DocBook V3.0//EN\""
+ else
+ 	docdtd="\"-//OASIS//DTD DocBook XML\" \"http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd\""
diff --git a/nixpkgs/pkgs/os-specific/linux/lxcfs/default.nix b/nixpkgs/pkgs/os-specific/linux/lxcfs/default.nix
new file mode 100644
index 000000000000..3953ff1915a7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/lxcfs/default.nix
@@ -0,0 +1,42 @@
+{ config, stdenv, fetchFromGitHub, autoreconfHook, pkgconfig, help2man, fuse
+, enableDebugBuild ? config.lxcfs.enableDebugBuild or false }:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+  name = "lxcfs-3.0.3";
+
+  src = fetchFromGitHub {
+    owner = "lxc";
+    repo = "lxcfs";
+    rev = name;
+    sha256 = "0imn031qpi1qfr1qw0ggpgcg8y6v0ykdr3m7f2czkiz3l7qqx2in";
+  };
+
+  nativeBuildInputs = [ pkgconfig help2man autoreconfHook ];
+  buildInputs = [ fuse ];
+
+  preConfigure = stdenv.lib.optionalString enableDebugBuild ''
+    sed -i 's,#AM_CFLAGS += -DDEBUG,AM_CFLAGS += -DDEBUG,' Makefile.am
+  '';
+
+  configureFlags = [
+    "--with-init-script=systemd"
+    "--sysconfdir=/etc"
+    "--localstatedir=/var"
+  ];
+
+  installFlags = [ "SYSTEMD_UNIT_DIR=\${out}/lib/systemd" ];
+
+  postFixup = ''
+    # liblxcfs.so is reloaded with dlopen()
+    patchelf --set-rpath "$(patchelf --print-rpath "$out/bin/lxcfs"):$out/lib" "$out/bin/lxcfs"
+  '';
+
+  meta = {
+    homepage = https://linuxcontainers.org/lxcfs;
+    description = "FUSE filesystem for LXC";
+    license = licenses.asl20;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ mic92 fpletz ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/macchanger/default.nix b/nixpkgs/pkgs/os-specific/linux/macchanger/default.nix
new file mode 100644
index 000000000000..c335031f2e56
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/macchanger/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, texinfo }:
+
+stdenv.mkDerivation rec {
+  name = "macchanger-${version}";
+  version = "1.7.0";
+
+  src = fetchFromGitHub {
+    owner = "alobbs";
+    repo = "macchanger";
+    rev = version;
+    sha256 = "1hypx6sxhd2b1nsxj314hpkhj7q4x9p2kfaaf20rjkkkig0nck9r";
+  };
+
+  nativeBuildInputs = [ autoreconfHook texinfo ];
+
+  outputs = [ "out" "info" ];
+
+  meta = with stdenv.lib; {
+    description = "A utility for viewing/manipulating the MAC address of network interfaces";
+    maintainers = with maintainers; [ joachifm ];
+    license = licenses.gpl2Plus;
+    homepage = https://www.gnu.org/software/macchanger;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mba6x_bl/default.nix b/nixpkgs/pkgs/os-specific/linux/mba6x_bl/default.nix
new file mode 100644
index 000000000000..0a6fc3c977c8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mba6x_bl/default.nix
@@ -0,0 +1,30 @@
+{ fetchFromGitHub, kernel, stdenv }:
+
+stdenv.mkDerivation rec {
+  name = "mba6x_bl-2016-12-08";
+
+  src = fetchFromGitHub {
+    owner = "patjak";
+    repo = "mba6x_bl";
+    rev = "b96aafd30c18200b4ad1f6eb995bc19200f60c47";
+    sha256 = "10payvfxahazdxisch4wm29fhl8y07ki72q4c78sl4rn73sj6yjq";
+  };
+
+  enableParallelBuilding = true;
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  makeFlags = [
+    "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+    "INSTALL_MOD_PATH=$(out)"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "MacBook Air 6,1 and 6,2 (mid 2013) backlight driver";
+    homepage = https://github.com/patjak/mba6x_bl;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.simonvandel ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mbpfan/default.nix b/nixpkgs/pkgs/os-specific/linux/mbpfan/default.nix
new file mode 100644
index 000000000000..7351712b887d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mbpfan/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, lib, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "mbpfan-${version}";
+  version = "2.1.0";
+  src = fetchFromGitHub {
+    owner = "dgraziotin";
+    repo = "mbpfan";
+    rev = "v${version}";
+    sha256 = "1gysq778rkl6dvvj9a1swxcl15wvz0bng5bn4nwq118cl8p8pask";
+  };
+  installPhase = ''
+    mkdir -p $out/bin $out/etc
+    cp bin/mbpfan $out/bin
+    cp mbpfan.conf $out/etc
+  '';
+  meta = with lib; {
+    description = "Daemon that uses input from coretemp module and sets the fan speed using the applesmc module";
+    homepage = https://github.com/dgraziotin/mbpfan;
+    license = licenses.gpl3;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ cstrahan ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mcelog/default.nix b/nixpkgs/pkgs/os-specific/linux/mcelog/default.nix
new file mode 100644
index 000000000000..394dbf63f170
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mcelog/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, fetchFromGitHub, utillinux }:
+
+stdenv.mkDerivation rec {
+  name = "mcelog-${version}";
+  version = "162";
+
+  src = fetchFromGitHub {
+    owner  = "andikleen";
+    repo   = "mcelog";
+    rev    = "v${version}";
+    sha256 = "1zxj545wslp92npll0411grc49l53cgp8dqqn3zb4vcxrvfc4vh9";
+  };
+
+  postPatch = ''
+    for i in mcelog.conf paths.h; do
+      substituteInPlace $i --replace /etc $out/etc
+    done
+    touch mcelog.conf.5 # avoid regeneration requiring Python
+
+    substituteInPlace Makefile --replace '"unknown"' '"${version}"'
+
+    for i in triggers/*; do
+      substituteInPlace $i --replace 'logger' '${utillinux}/bin/logger'
+    done
+  '';
+
+  enableParallelBuilding = true;
+
+  installFlags = [ "DESTDIR=$(out)" "prefix=" "DOCDIR=/share/doc" ];
+
+  postInstall = ''
+    mkdir -p $out/lib/systemd/system
+    substitute mcelog.service $out/lib/systemd/system/mcelog.service \
+      --replace /usr/sbin $out/bin
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Log x86 machine checks: memory, IO, and CPU hardware errors";
+    longDescription = ''
+      The mcelog daemon accounts memory and some other errors in various ways
+      on modern x86 Linux systems. The daemon can be queried and/or execute
+      triggers when configurable error thresholds are exceeded. This is used to
+      implement a range of automatic predictive failure analysis algorithms,
+      including bad page offlining and automatic cache error handling. All
+      errors are logged to /var/log/mcelog or syslog or the journal.
+    '';
+    homepage = http://mcelog.org/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mdadm/default.nix b/nixpkgs/pkgs/os-specific/linux/mdadm/default.nix
new file mode 100644
index 000000000000..d2fc9cf0d26f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mdadm/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, writeScript, fetchurl, groff, system-sendmail }:
+
+stdenv.mkDerivation rec {
+  name = "mdadm-4.1";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/raid/mdadm/${name}.tar.xz";
+    sha256 = "0jjgjgqijpdp7ijh8slzzjjw690kydb1jjadf0x5ilq85628hxmb";
+  };
+
+  # This is to avoid self-references, which causes the initrd to explode
+  # in size and in turn prevents mdraid systems from booting.
+  allowedReferences = [ stdenv.cc.libc.out system-sendmail ];
+
+  patches = [ ./no-self-references.patch ];
+
+  makeFlags = [
+    "NIXOS=1" "INSTALL=install" "INSTALL_BINDIR=$(out)/sbin"
+    "MANDIR=$(out)/share/man" "RUN_DIR=/dev/.mdadm"
+    "STRIP="
+  ] ++ stdenv.lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
+    "CROSS_COMPILE=${stdenv.cc.targetPrefix}"
+  ];
+
+  nativeBuildInputs = [ groff ];
+
+  preConfigure = ''
+    sed -e 's@/lib/udev@''${out}/lib/udev@' \
+        -e 's@ -Werror @ @' \
+        -e 's@/usr/sbin/sendmail@${system-sendmail}@' -i Makefile
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Programs for managing RAID arrays under Linux";
+    homepage = http://neil.brown.name/blog/mdadm;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ ekleog ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mdadm/no-self-references.patch b/nixpkgs/pkgs/os-specific/linux/mdadm/no-self-references.patch
new file mode 100644
index 000000000000..cf0366e52d11
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mdadm/no-self-references.patch
@@ -0,0 +1,130 @@
+diff --git a/Makefile b/Makefile
+index d82e30f..d231cf9 100644
+--- a/Makefile
++++ b/Makefile
+@@ -51,6 +51,9 @@ endif
+ ifdef DEBIAN
+ CPPFLAGS += -DDEBIAN
+ endif
++ifdef NIXOS
++CPPFLAGS += -DNIXOS
++endif
+ ifdef DEFAULT_OLD_METADATA
+  CPPFLAGS += -DDEFAULT_OLD_METADATA
+  DEFAULT_METADATA=0.90
+@@ -105,6 +108,7 @@ endif
+ INSTALL = /usr/bin/install
+ DESTDIR =
+ BINDIR  = /sbin
++INSTALL_BINDIR = ${BINDIR}
+ MANDIR  = /usr/share/man
+ MAN4DIR = $(MANDIR)/man4
+ MAN5DIR = $(MANDIR)/man5
+@@ -259,20 +263,20 @@ sha1.o : sha1.c sha1.h md5.h
+ 	$(CC) $(CFLAGS) -DHAVE_STDINT_H -o sha1.o -c sha1.c
+ 
+ install : mdadm mdmon install-man install-udev
+-	$(INSTALL) -D $(STRIP) -m 755 mdadm $(DESTDIR)$(BINDIR)/mdadm
+-	$(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(BINDIR)/mdmon
++	$(INSTALL) -D $(STRIP) -m 755 mdadm $(DESTDIR)$(INSTALL_BINDIR)/mdadm
++	$(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(INSTALL_BINDIR)/mdmon
+ 
+ install-static : mdadm.static install-man
+-	$(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm
++	$(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(INSTALL_BINDIR)/mdadm
+ 
+ install-tcc : mdadm.tcc install-man
+-	$(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm
++	$(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
+ 
+ install-uclibc : mdadm.uclibc install-man
+-	$(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm
++	$(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
+ 
+ install-klibc : mdadm.klibc install-man
+-	$(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm
++	$(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(INSTALL_BINDIR)/mdadm
+ 
+ install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
+ 	$(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8
+@@ -305,7 +309,7 @@ install-systemd: systemd/mdmon@.service
+ 	if [ -f /etc/SuSE-release -o -n "$(SUSE)" ] ;then $(INSTALL) -D -m 755 systemd/SUSE-mdadm_env.sh $(DESTDIR)$(SYSTEMD_DIR)/../scripts/mdadm_env.sh ;fi
+ 
+ uninstall:
+-	rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
++	rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(INSTALL_BINDIR)/mdadm
+ 
+ test: mdadm mdmon test_stripe swap_super raid6check
+ 	@echo "Please run './test' as root"
+diff --git a/policy.c b/policy.c
+index 064d349..6b2f2b1 100644
+--- a/policy.c
++++ b/policy.c
+@@ -796,12 +796,39 @@ char *find_rule(struct rule *rule, char *rule_type)
+ #define UDEV_RULE_FORMAT \
+ "ACTION==\"add\", SUBSYSTEM==\"block\", " \
+ "ENV{DEVTYPE}==\"%s\", ENV{ID_PATH}==\"%s\", " \
+-"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
++"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n"
+ 
+ #define UDEV_RULE_FORMAT_NOTYPE \
+ "ACTION==\"add\", SUBSYSTEM==\"block\", " \
+ "ENV{ID_PATH}==\"%s\", " \
+-"RUN+=\"" BINDIR "/mdadm --incremental $env{DEVNAME}\"\n"
++"RUN+=\"%s/mdadm --incremental $env{DEVNAME}\"\n"
++
++#ifdef NIXOS
++const char *get_mdadm_bindir(void)
++{
++	static char *bindir = NULL;
++	if (bindir != NULL) {
++		return bindir;
++	} else {
++		int len;
++		bindir = xmalloc(1025);
++		len = readlink("/proc/self/exe", bindir, 1024);
++		if (len > 0) {
++			char *basename;
++			if ((basename = strrchr(bindir, '/')) != NULL)
++				*basename = '\0';
++			else
++				*(bindir + len) = '\0';
++		} else {
++			*bindir = '\0';
++		}
++		return bindir;
++	}
++}
++#define SELF get_mdadm_bindir()
++#else
++#define SELF BINDIR
++#endif
+ 
+ /* Write rule in the rule file. Use format from UDEV_RULE_FORMAT */
+ int write_rule(struct rule *rule, int fd, int force_part)
+@@ -815,9 +842,9 @@ int write_rule(struct rule *rule, int fd, int force_part)
+ 	if (force_part)
+ 		typ = type_part;
+ 	if (typ)
+-		snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth);
++		snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT, typ, pth, SELF);
+ 	else
+-		snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth);
++		snprintf(line, sizeof(line) - 1, UDEV_RULE_FORMAT_NOTYPE, pth, SELF);
+ 	return write(fd, line, strlen(line)) == (int)strlen(line);
+ }
+ 
+diff --git a/util.c b/util.c
+index cc98d3b..1ada2f4 100644
+--- a/util.c
++++ b/util.c
+@@ -1700,7 +1700,9 @@ int start_mdmon(char *devnm)
+ 	char pathbuf[1024];
+ 	char *paths[4] = {
+ 		pathbuf,
++#ifndef NIXOS
+ 		BINDIR "/mdmon",
++#endif
+ 		"./mdmon",
+ 		NULL
+ 	};
diff --git a/nixpkgs/pkgs/os-specific/linux/microcode/amd.nix b/nixpkgs/pkgs/os-specific/linux/microcode/amd.nix
new file mode 100644
index 000000000000..34f19db524ce
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/microcode/amd.nix
@@ -0,0 +1,29 @@
+{ stdenv, firmwareLinuxNonfree, libarchive }:
+
+stdenv.mkDerivation rec {
+  name = "amd-ucode-${firmwareLinuxNonfree.version}";
+
+  src = firmwareLinuxNonfree;
+
+  sourceRoot = ".";
+
+  buildInputs = [ libarchive ];
+
+  buildPhase = ''
+    mkdir -p kernel/x86/microcode
+    find ${firmwareLinuxNonfree}/lib/firmware/amd-ucode -name \*.bin \
+      -exec sh -c 'cat {} >> kernel/x86/microcode/AuthenticAMD.bin' \;
+  '';
+
+  installPhase = ''
+    mkdir -p $out
+    echo kernel/x86/microcode/AuthenticAMD.bin | bsdcpio -o -H newc -R 0:0 > $out/amd-ucode.img
+  '';
+
+  meta = with stdenv.lib; {
+    description = "AMD Processor microcode patch";
+    homepage = http://www.amd64.org/support/microcode.html;
+    license = licenses.unfreeRedistributableFirmware;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/microcode/intel.nix b/nixpkgs/pkgs/os-specific/linux/microcode/intel.nix
new file mode 100644
index 000000000000..2af0e60b9c1a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/microcode/intel.nix
@@ -0,0 +1,32 @@
+{ stdenv, fetchFromGitHub, libarchive, iucode-tool }:
+
+stdenv.mkDerivation rec {
+  pname = "microcode-intel";
+  version = "20190312";
+
+  src = fetchFromGitHub {
+    owner = "intel";
+    repo = "Intel-Linux-Processor-Microcode-Data-Files";
+    rev = "microcode-${version}";
+    sha256 = "0n381dai2mv9indsbbr4nfbmp4y4qhshgflr095fyvq5a8acw94m";
+  };
+
+  nativeBuildInputs = [ iucode-tool libarchive ];
+
+  installPhase = ''
+    runHook preInstall
+
+    mkdir -p $out kernel/x86/microcode
+    iucode_tool -w kernel/x86/microcode/GenuineIntel.bin intel-ucode/
+    echo kernel/x86/microcode/GenuineIntel.bin | bsdcpio -o -H newc -R 0:0 > $out/intel-ucode.img
+
+    runHook postInstall
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://www.intel.com/;
+    description = "Microcode for Intel processors";
+    license = licenses.unfreeRedistributableFirmware;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/microcode/iucode-tool.nix b/nixpkgs/pkgs/os-specific/linux/microcode/iucode-tool.nix
new file mode 100644
index 000000000000..485272b1401b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/microcode/iucode-tool.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchFromGitLab, autoreconfHook }:
+
+stdenv.mkDerivation rec {
+  name = "iucode-tool-${version}";
+  version = "2.3.1";
+
+  src = fetchFromGitLab {
+    owner  = "iucode-tool";
+    repo   = "iucode-tool";
+    rev    = "v${version}";
+    sha256 = "04dlisw87dd3q3hhmkqc5dd58cp22fzx3rzah7pvcyij135yjc3a";
+  };
+
+  nativeBuildInputs = [ autoreconfHook ];
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "Intel® 64 and IA-32 processor microcode tool";
+    homepage = https://gitlab.com/iucode-tool/iucode-tool;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ peterhoeg ];
+    platforms = [ "x86_64-linux" "i686-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mingetty/default.nix b/nixpkgs/pkgs/os-specific/linux/mingetty/default.nix
new file mode 100644
index 000000000000..a29a03734242
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mingetty/default.nix
@@ -0,0 +1,21 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation {
+  name = "mingetty-1.08";
+
+  src = fetchurl {
+    url = mirror://sourceforge/mingetty/mingetty-1.08.tar.gz;
+    sha256 = "05yxrp44ky2kg6qknk1ih0kvwkgbn9fbz77r3vci7agslh5wjm8g";
+  };
+
+  preInstall = ''
+    mkdir -p $out/sbin $out/share/man/man8
+    makeFlagsArray=(SBINDIR=$out/sbin MANDIR=$out/share/man/man8)
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://sourceforge.net/projects/mingetty;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/miraclecast/default.nix b/nixpkgs/pkgs/os-specific/linux/miraclecast/default.nix
new file mode 100644
index 000000000000..c7990466ca73
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/miraclecast/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchFromGitHub, meson, ninja, pkgconfig
+, glib, readline, pcre, systemd, udev }:
+
+stdenv.mkDerivation rec {
+  name = "miraclecast-${version}";
+  version = "1.0-20170427";
+
+  src = fetchFromGitHub {
+    owner  = "albfan";
+    repo   = "miraclecast";
+    rev    = "a395c3c7afc39a958ae8ab805dea0f5d22118f0c";
+    sha256 = "03kbjajv2x0i2g68c5aij0icf9waxnqkc9pp32z60nc8zxy9jk1y";
+  };
+
+  nativeBuildInputs = [ meson ninja pkgconfig ];
+
+  buildInputs = [ glib pcre readline systemd udev ];
+
+  enableParallelBuilding = true;
+
+  mesonFlags = [
+    "-Drely-udev=true"
+    "-Dbuild-tests=true"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Connect external monitors via Wi-Fi";
+    homepage    = https://github.com/albfan/miraclecast;
+    license     = licenses.lgpl21Plus;
+    maintainers = with maintainers; [ tstrobel ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mkinitcpio-nfs-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/mkinitcpio-nfs-utils/default.nix
new file mode 100644
index 000000000000..1b5925a55816
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mkinitcpio-nfs-utils/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "mkinitcpio-nfs-utils-0.3";
+
+  src = fetchurl {
+    url = "https://sources.archlinux.org/other/mkinitcpio/${name}.tar.xz";
+    sha256 = "0fc93sfk41ycpa33083kyd7i4y00ykpbhj5qlw611bjghj4x946j";
+    # ugh, upstream...
+    name = "${name}.tar.gz";
+  };
+
+  makeFlags = [ "DESTDIR=$(out)" "bindir=/bin" ];
+
+  postInstall = ''
+    rm -rf $out/usr
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://archlinux.org/;
+    description = "ipconfig and nfsmount tools for root on NFS, ported from klibc";
+    license = licenses.gpl2;
+    platforms  = platforms.linux;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mmc-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/mmc-utils/default.nix
new file mode 100644
index 000000000000..533cd90a2d3c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mmc-utils/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchgit }:
+
+stdenv.mkDerivation rec {
+  name = "mmc-utils-${version}";
+  version = "2018-03-27";
+
+  src = fetchgit {
+    url = "git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc-utils.git";
+    rev = "b4fe0c8c0e57a74c01755fa9362703b60d7ee49d";
+    sha256 = "01llwan5j40mv5p867f31lm87qh0hcyhy892say60y5pxc0mzpyn";
+  };
+
+  makeFlags = "CC=${stdenv.cc.targetPrefix}cc";
+
+  installPhase = ''
+    make install prefix=$out
+    mkdir -p $out/share/man/man1
+    cp man/mmc.1 $out/share/man/man1/
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Configure MMC storage devices from userspace";
+    homepage = http://git.kernel.org/cgit/linux/kernel/git/cjb/mmc-utils.git/;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.dezgeg ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/molly-guard/default.nix b/nixpkgs/pkgs/os-specific/linux/molly-guard/default.nix
new file mode 100644
index 000000000000..ac083e545fed
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/molly-guard/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchurl, dpkg, busybox, systemd }:
+
+stdenv.mkDerivation rec {
+  name = "molly-guard-${version}";
+  version = "0.6.3";
+
+  src = fetchurl {
+    url = "https://launchpad.net/ubuntu/+source/molly-guard/${version}/+build/8892607/+files/molly-guard_${version}_all.deb";
+    sha256 = "1d1x60m6kh9wfh9lc22g5s0j40aivwgsczykk27ymwl1pvk58dxn";
+  };
+
+  buildInputs = [ dpkg ];
+
+  sourceRoot = ".";
+
+  unpackCmd = ''
+    dpkg-deb -x "$src" .
+  '';
+
+  installPhase = ''
+    sed -i "s|/lib/molly-guard|${systemd}/sbin|g" lib/molly-guard/molly-guard
+    sed -i "s|run-parts|${busybox}/bin/run-parts|g" lib/molly-guard/molly-guard
+    sed -i "s|/etc/molly-guard/|$out/etc/molly-guard/|g" lib/molly-guard/molly-guard
+    cp -r ./ $out/
+  '';
+
+  postFixup = ''
+    for modus in init halt poweroff reboot runlevel shutdown telinit; do
+       ln -sf $out/lib/molly-guard/molly-guard $out/bin/$modus;
+    done;
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Attempts to prevent you from accidentally shutting down or rebooting machines";
+    homepage    = https://anonscm.debian.org/git/collab-maint/molly-guard.git/;
+    license     = licenses.artistic2;
+    platforms   = platforms.linux;
+    maintainers = with maintainers; [ DerTim1 ];
+    priority    = -10;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/msr-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/msr-tools/default.nix
new file mode 100644
index 000000000000..128f3eac2635
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/msr-tools/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, fetchurl, unzip }:
+
+stdenv.mkDerivation rec {
+  name = "msr-tools-${version}";
+  version = "1.3";
+
+  src = fetchurl {
+    url = "https://01.org/sites/default/files/downloads/msr-tools/${name}.zip";
+    sha256 = "07hxmddg0l31kjfmaq84ni142lbbvgq6391r8bd79wpm819pnigr";
+  };
+
+  buildInputs = [ unzip ];
+
+  preInstall = ''
+    mkdir -p $out/bin
+    substituteInPlace Makefile \
+      --replace /usr/sbin $out/bin
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Tool to read/write from/to MSR CPU registers on Linux";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ peterhoeg ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mstpd/default.nix b/nixpkgs/pkgs/os-specific/linux/mstpd/default.nix
new file mode 100644
index 000000000000..ea5790b495b9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mstpd/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, fetchFromGitHub, autoreconfHook }:
+
+stdenv.mkDerivation {
+  name = "mstpd-0.0.5.20171113";
+
+  src = fetchFromGitHub {
+    owner = "mstpd";
+    repo = "mstpd";
+    rev = "2522c6eed201bce8dd81e1583f28748e9c552d0d";
+    sha256 = "0ckk386inwcx3776hf15w78hpw4db2rgv4zgf0i3zcylr83hhsr2";
+  };
+
+  nativeBuildInputs = [ autoreconfHook ];
+
+  installFlags = [ "DESTDIR=$(out)" ];
+
+  meta = with stdenv.lib; {
+    description = "Multiple Spanning Tree Protocol daemon";
+    homepage = https://sourceforge.net/projects/mstpd/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/multipath-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/multipath-tools/default.nix
new file mode 100644
index 000000000000..6488f98565a9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/multipath-tools/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchurl, lvm2, libaio, gzip, readline, systemd, liburcu }:
+
+stdenv.mkDerivation rec {
+  name = "multipath-tools-0.6.2";
+
+  src = fetchurl {
+    name = "${name}.tar.gz";
+    url = "https://git.opensvc.com/";
+    sha256 = "159hxvbk9kh1qay9x04w0gsqzg0hkl5yghfc1wi9kv2n5pcwbkpm";
+  };
+
+  postPatch = ''
+    sed -i -re '
+      s,^( *#define +DEFAULT_MULTIPATHDIR\>).*,\1 "'"$out/lib/multipath"'",
+    ' libmultipath/defaults.h
+    sed -i -e 's,\$(DESTDIR)/\(usr/\)\?,$(prefix)/,g' \
+      kpartx/Makefile libmpathpersist/Makefile
+    sed -i -e "s,GZIP = .*, GZIP = gzip -9n -c," \
+      Makefile.inc
+  '';
+
+  nativeBuildInputs = [ gzip ];
+  buildInputs = [ systemd lvm2 libaio readline liburcu ];
+
+  makeFlags = [
+    "LIB=lib"
+    "prefix=$(out)"
+    "mandir=$(out)/share/man/man8"
+    "man5dir=$(out)/share/man/man5"
+    "man3dir=$(out)/share/man/man3"
+    "unitdir=$(out)/lib/systemd/system"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Tools for the Linux multipathing driver";
+    homepage = http://christophe.varoqui.free.fr/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/musl/default.nix b/nixpkgs/pkgs/os-specific/linux/musl/default.nix
new file mode 100644
index 000000000000..9835a0c96db8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/musl/default.nix
@@ -0,0 +1,120 @@
+{ stdenv, lib, fetchurl
+, linuxHeaders ? null
+, useBSDCompatHeaders ? true
+}:
+let
+  cdefs_h = fetchurl {
+    url = "http://git.alpinelinux.org/cgit/aports/plain/main/libc-dev/sys-cdefs.h";
+    sha256 = "16l3dqnfq0f20rzbkhc38v74nqcsh9n3f343bpczqq8b1rz6vfrh";
+  };
+  queue_h = fetchurl {
+    url = "http://git.alpinelinux.org/cgit/aports/plain/main/libc-dev/sys-queue.h";
+    sha256 = "12qm82id7zys92a1qh2l1qf2wqgq6jr4qlbjmqyfffz3s3nhfd61";
+  };
+  tree_h = fetchurl {
+    url = "http://git.alpinelinux.org/cgit/aports/plain/main/libc-dev/sys-tree.h";
+    sha256 = "14igk6k00bnpfw660qhswagyhvr0gfqg4q55dxvaaq7ikfkrir71";
+  };
+
+  # iconv tool, implemented by musl author.
+  # Original: http://git.etalabs.net/cgit/noxcuse/plain/src/iconv.c?id=02d288d89683e99fd18fe9f54d4e731a6c474a4f
+  # We use copy from Alpine which fixes error messages, see:
+  # https://git.alpinelinux.org/cgit/aports/commit/main/musl/iconv.c?id=a3d97e95f766c9c378194ee49361b375f093b26f
+  iconv_c = fetchurl {
+    name = "iconv.c";
+    url = "https://git.alpinelinux.org/cgit/aports/plain/main/musl/iconv.c?id=a3d97e95f766c9c378194ee49361b375f093b26f";
+    sha256 = "1mzxnc2ncq8lw9x6n7p00fvfklc9p3wfv28m68j0dfz5l8q2k6pp";
+  };
+
+in
+stdenv.mkDerivation rec {
+  pname = "musl";
+  version = "1.1.21";
+
+  src = fetchurl {
+    url    = "https://www.musl-libc.org/releases/${pname}-${version}.tar.gz";
+    sha256 = "0i2z52zgc86af1n1gjiz43hgd85mxjgvgn345zsybja9dxpvchn7";
+  };
+
+  enableParallelBuilding = true;
+
+  # Disable auto-adding stack protector flags,
+  # so musl can selectively disable as needed
+  hardeningDisable = [ "stackprotector" ];
+
+  # Leave these, be friendlier to debuggers/perf tools
+  # Don't force them on, but don't force off either
+  postPatch = ''
+    substituteInPlace configure \
+      --replace -fno-unwind-tables "" \
+      --replace -fno-asynchronous-unwind-tables ""
+  '';
+
+  patches = [
+    # Minor touchup to build system making dynamic linker symlink relative
+    (fetchurl {
+      url = https://raw.githubusercontent.com/openwrt/openwrt/87606e25afac6776d1bbc67ed284434ec5a832b4/toolchain/musl/patches/300-relative.patch;
+      sha256 = "0hfadrycb60sm6hb6by4ycgaqc9sgrhh42k39v8xpmcvdzxrsq2n";
+    })
+  ];
+  CFLAGS = [ "-fstack-protector-strong" ]
+    ++ lib.optional stdenv.hostPlatform.isPower "-mlong-double-64";
+
+  configureFlags = [
+    "--enable-shared"
+    "--enable-static"
+    "--enable-debug"
+    "--enable-wrapper=all"
+    "--syslibdir=${placeholder "out"}/lib"
+  ];
+
+  outputs = [ "out" "dev" ];
+
+  dontDisableStatic = true;
+  separateDebugInfo = true;
+
+  NIX_DONT_SET_RPATH = true;
+
+  postInstall = ''
+    # Not sure why, but link in all but scsi directory as that's what uclibc/glibc do.
+    # Apparently glibc provides scsi itself?
+    (cd $dev/include && ln -s $(ls -d ${linuxHeaders}/include/* | grep -v "scsi$") .)
+
+    # Strip debug out of the static library
+    $STRIP -S $out/lib/libc.a
+    mkdir -p $out/bin
+
+    # Create 'ldd' symlink, builtin
+    ln -rs $out/lib/libc.so $out/bin/ldd
+
+    # (impure) cc wrapper around musl for interactive usuage
+    for i in musl-gcc musl-clang ld.musl-clang; do
+      moveToOutput bin/$i $dev
+    done
+    moveToOutput lib/musl-gcc.specs $dev
+    substituteInPlace $dev/bin/musl-gcc \
+      --replace $out/lib/musl-gcc.specs $dev/lib/musl-gcc.specs
+
+    # provide 'iconv' utility, using just-built headers, libc/ldso
+    $CC ${iconv_c} -o $out/bin/iconv \
+      -I$dev/include \
+      -L$out/lib -Wl,-rpath=$out/lib \
+      -lc \
+      -B $out/lib \
+      -Wl,-dynamic-linker=$(ls $out/lib/ld-*)
+  '' + lib.optionalString useBSDCompatHeaders ''
+    install -D ${queue_h} $dev/include/sys/queue.h
+    install -D ${cdefs_h} $dev/include/sys/cdefs.h
+    install -D ${tree_h} $dev/include/sys/tree.h
+  '';
+
+  passthru.linuxHeaders = linuxHeaders;
+
+  meta = {
+    description = "An efficient, small, quality libc implementation";
+    homepage    = "http://www.musl-libc.org";
+    license     = lib.licenses.mit;
+    platforms   = lib.platforms.linux;
+    maintainers = [ lib.maintainers.thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mwprocapture/default.nix b/nixpkgs/pkgs/os-specific/linux/mwprocapture/default.nix
new file mode 100644
index 000000000000..9490bc911819
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mwprocapture/default.nix
@@ -0,0 +1,67 @@
+{ stdenv, fetchurl, kernel, alsaLib }:
+
+with stdenv.lib;
+
+# The Magewell Pro Capture drivers are not supported for kernels older than 3.2
+assert versionAtLeast kernel.version "3.2.0";
+
+let
+  bits =
+  if stdenv.is64bit then "64"
+  else "32";
+
+  libpath = makeLibraryPath [ stdenv.cc.cc stdenv.glibc alsaLib ];
+
+in
+stdenv.mkDerivation rec {
+  name = "mwprocapture-1.2.${version}-${kernel.version}";
+  version = "4054";
+
+  src = fetchurl {
+    url = "http://www.magewell.com/files/drivers/ProCaptureForLinux_${version}.tar.gz";
+    sha256 = "0ylx75jcwlqds8w6lm11nxdlzxvy7xlz4rka2k5d6gmqa5fv19c2";
+  };
+
+  nativeBuildInputs = [ kernel.moduleBuildDependencies ];
+
+  preConfigure =
+  ''
+    cd ./src
+    export INSTALL_MOD_PATH="$out"
+  '';
+
+  hardeningDisable = [ "pic" "format" ];
+
+  makeFlags = [
+    "KERNELDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  ];
+
+  postInstall = ''
+    cd ../
+    mkdir -p $out/bin
+    cp bin/mwcap-control_${bits} $out/bin/mwcap-control
+    cp bin/mwcap-info_${bits} $out/bin/mwcap-info
+    mkdir -p $out/lib/udev/rules.d
+    # source has a filename typo
+    cp scripts/10-procatpure-event-dev.rules $out/lib/udev/rules.d/10-procapture-event-dev.rules
+    cp -r src/res $out
+
+    patchelf \
+      --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
+      --set-rpath "${libpath}" \
+      "$out"/bin/mwcap-control
+
+    patchelf \
+      --set-interpreter $(cat ${stdenv.cc}/nix-support/dynamic-linker) \
+      --set-rpath "${libpath}" \
+      "$out"/bin/mwcap-info
+  '';
+
+  meta = {
+    homepage = http://www.magewell.com/;
+    description = "Linux driver for the Magewell Pro Capture family";
+    license = licenses.unfreeRedistributable;
+    maintainers = with maintainers; [ MP2E ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/mxu11x0/default.nix b/nixpkgs/pkgs/os-specific/linux/mxu11x0/default.nix
new file mode 100644
index 000000000000..1bf7c8467326
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/mxu11x0/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+stdenv.mkDerivation {
+  name = "mxu11x0-1.3.11+git2017-07-13-${kernel.version}";
+
+  src = fetchFromGitHub {
+    owner = "ellysh";
+    repo = "mxu11x0";
+    rev = "cbbb5ec2045939209117cb5fcd6c7c23bcc109ef";
+    sha256 = "0wf44pnz5aclvg2k1f8ljnwws8hh6191i5h06nz95ijbxhwz63w4";
+  };
+
+  preBuild = ''
+    sed -i -e "s/\$(uname -r).*/${kernel.modDirVersion}/g" driver/mxconf
+    sed -i -e "s/\$(shell uname -r).*/${kernel.modDirVersion}/g" driver/Makefile
+    sed -i -e 's|/lib/modules|${kernel.dev}/lib/modules|' driver/mxconf
+    sed -i -e 's|/lib/modules|${kernel.dev}/lib/modules|' driver/Makefile
+  '';
+  
+  installPhase = ''
+    install -v -D -m 644 ./driver/mxu11x0.ko "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/usb/serial/mxu11x0.ko"
+    install -v -D -m 644 ./driver/mxu11x0.ko "$out/lib/modules/${kernel.modDirVersion}/misc/mxu11x0.ko"
+  '';
+
+  dontStrip = true;
+
+  enableParallelBuilding = true;
+
+  hardeningDisable = [ "pic" ];
+
+  meta = with stdenv.lib; {
+    description = "MOXA UPort 11x0 USB to Serial Hub driver";
+    homepage = https://github.com/ellysh/mxu11x0;
+    license = licenses.gpl1;
+    maintainers = with maintainers; [ uralbash ];
+    platforms = platforms.linux;
+    broken = versionOlder kernel.version "4.9" || !versionOlder kernel.version "4.13";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ndiswrapper/default.nix b/nixpkgs/pkgs/os-specific/linux/ndiswrapper/default.nix
new file mode 100644
index 000000000000..bdb52c0c0916
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ndiswrapper/default.nix
@@ -0,0 +1,49 @@
+{ stdenv, fetchFromGitHub, kernel, perl, kmod, libelf }:
+let
+  version = "1.62-pre";
+in
+stdenv.mkDerivation {
+  name = "ndiswrapper-${version}-${kernel.version}";
+  inherit version;
+
+  hardeningDisable = [ "pic" ];
+
+  patches = [ ./no-sbin.patch ];
+
+  # need at least .config and include
+  kernel = kernel.dev;
+
+  buildPhase = "
+    cd ndiswrapper
+    echo make KBUILD=$(echo \$kernel/lib/modules/*/build);
+    echo -n $kernel/lib/modules/*/build > kbuild_path
+    export PATH=${kmod}/sbin:$PATH
+    make KBUILD=$(echo \$kernel/lib/modules/*/build);
+  ";
+
+  installPhase = ''
+    make install KBUILD=$(cat kbuild_path) DESTDIR=$out
+    mv $out/usr/sbin/* $out/sbin/
+    mv $out/usr/share $out/
+    rm -r $out/usr
+
+    patchShebangs $out/sbin
+  '';
+
+  # should we use unstable?
+  src = fetchFromGitHub {
+    owner = "pgiri";
+    repo = "ndiswrapper";
+    rev = "5e29f6a9d41df949b435066c173e3b1947f179d3";
+    sha256 = "0sprrmxxkf170bmh1nz9xw00gs89dddr84djlf666bn5bhy6jffi";
+  };
+
+  buildInputs = [ perl libelf ];
+
+  meta = {
+    description = "Ndis driver wrapper for the Linux kernel";
+    homepage = https://sourceforge.net/projects/ndiswrapper;
+    license = "GPL";
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ndiswrapper/no-sbin.patch b/nixpkgs/pkgs/os-specific/linux/ndiswrapper/no-sbin.patch
new file mode 100644
index 000000000000..34965540d248
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ndiswrapper/no-sbin.patch
@@ -0,0 +1,13 @@
+diff --git a/ndiswrapper/driver/Makefile b/ndiswrapper/driver/Makefile
+index bf42f7bc..ad23aa2d 100644
+--- a/ndiswrapper/driver/Makefile
++++ b/ndiswrapper/driver/Makefile
+@@ -191,7 +191,7 @@ clean:
+ 	rm -rf .tmp_versions
+ 
+ install: config_check $(MODULE)
+-	@/sbin/modinfo $(MODULE) | grep -q "^vermagic: *$(KVERS) " || \
++	@modinfo $(MODULE) | grep -q "^vermagic: *$(KVERS) " || \
+ 		{ echo "$(MODULE)" is not for Linux $(KVERS); exit 1; }
+ 	mkdir -p -m 755 $(DESTDIR)$(INST_DIR)
+ 	install -m 0644 $(MODULE) $(DESTDIR)$(INST_DIR)
diff --git a/nixpkgs/pkgs/os-specific/linux/net-tools/config.h b/nixpkgs/pkgs/os-specific/linux/net-tools/config.h
new file mode 100644
index 000000000000..dedaac6247d0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/net-tools/config.h
@@ -0,0 +1,79 @@
+/*
+* config.h	Automatically generated configuration includefile
+*
+* NET-TOOLS	A collection of programs that form the base set of the
+*		NET-3 Networking Distribution for the LINUX operating
+*		system.
+*
+*		DO  NOT  EDIT  DIRECTLY
+*
+*/
+
+/* 
+ * 
+ * Internationalization
+ * 
+ * The net-tools package has currently been translated to French,
+ * German and Brazilian Portugese.  Other translations are, of
+ * course, welcome.  Answer `n' here if you have no support for
+ * internationalization on your system.
+ * 
+ */
+#define I18N 0
+
+/* 
+ * 
+ * Protocol Families.
+ * 
+ */
+#define HAVE_AFUNIX 1
+#define HAVE_AFINET 1
+#define HAVE_AFINET6 1
+#define HAVE_AFIPX 1
+#define HAVE_AFATALK 1
+#define HAVE_AFAX25 0
+#define HAVE_AFNETROM 1
+#define HAVE_AFROSE 0
+#define HAVE_AFX25 0
+#define HAVE_AFECONET 0
+#define HAVE_AFDECnet 0
+#define HAVE_AFASH 0
+#define HAVE_AFBLUETOOTH 0
+
+/* 
+ * 
+ * Device Hardware types.
+ * 
+ */
+#define HAVE_HWETHER 1
+#define HAVE_HWARC 1
+#define HAVE_HWSLIP 1
+#define HAVE_HWPPP 1
+#define HAVE_HWTUNNEL 1
+#define HAVE_HWSTRIP 0
+#define HAVE_HWTR 0
+#define HAVE_HWAX25 0
+#define HAVE_HWROSE 0
+#define HAVE_HWNETROM 1
+#define HAVE_HWX25 0
+#define HAVE_HWFR 1
+#define HAVE_HWSIT 1
+#define HAVE_HWFDDI 0
+#define HAVE_HWHIPPI 0
+#define HAVE_HWASH 0
+#define HAVE_HWHDLCLAPB 0
+#define HAVE_HWIRDA 1
+#define HAVE_HWEC 0
+#define HAVE_HWEC 0
+#define HAVE_HWEUI64 1
+#define HAVE_HWIB 1
+
+/* 
+ * 
+ * Other Features.
+ * 
+ */
+#define HAVE_FW_MASQUERADE 0
+#define HAVE_IP_TOOLS 0
+#define HAVE_MII 0
+#define HAVE_SELINUX 0
diff --git a/nixpkgs/pkgs/os-specific/linux/net-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/net-tools/default.nix
new file mode 100644
index 000000000000..42f745b02e30
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/net-tools/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "net-tools-${version}";
+  version = "1.60_p20170221182432";
+
+  src = fetchurl {
+    url = "mirror://gentoo/distfiles/${name}.tar.xz";
+    sha256 = "08r4r2a24g5bm8jwgfa998gs1fld7fgbdf7pilrpsw1m974xn04a";
+  };
+
+  preBuild =
+    ''
+      cp ${./config.h} config.h
+    '';
+
+  makeFlags = [
+    "CC=${stdenv.cc.targetPrefix}cc"
+    "AR=${stdenv.cc.targetPrefix}ar"
+    "BASEDIR=$(out)"
+    "mandir=/share/man"
+    "HAVE_ARP_TOOLS=1"
+    "HAVE_PLIP_TOOLS=1"
+    "HAVE_SERIAL_TOOLS=1"
+    "HAVE_HOSTNAME_TOOLS=1"
+    "HAVE_HOSTNAME_SYMLINKS=1"
+  ];
+
+  meta = {
+    homepage = http://net-tools.sourceforge.net/;
+    description = "A set of tools for controlling the network subsystem in Linux";
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/netatop/default.nix b/nixpkgs/pkgs/os-specific/linux/netatop/default.nix
new file mode 100644
index 000000000000..718cf4815baf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/netatop/default.nix
@@ -0,0 +1,42 @@
+{ stdenv, fetchurl, kernel, zlib }:
+
+let
+  version = "2.0";
+in
+
+stdenv.mkDerivation {
+  name = "netatop-${kernel.version}-${version}";
+
+  src = fetchurl {
+    url = "http://www.atoptool.nl/download/netatop-${version}.tar.gz";
+    sha256 = "03n248p1l3ps7gj2hdlcbrb1fsw1zcmgzypj4j4l4rynjjh7qvf6";
+  };
+
+  buildInputs = [ zlib ];
+
+  hardeningDisable = [ "pic" ];
+
+  preConfigure = ''
+    patchShebangs mkversion
+    sed -i -e 's,^KERNDIR.*,KERNDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build,' \
+        */Makefile
+    sed -i -e 's,/lib/modules.*extra,'$out'/lib/modules/${kernel.modDirVersion}/extra,' \
+        -e s,/usr,$out, \
+        -e /init.d/d \
+        -e /depmod/d \
+        Makefile
+  '';
+
+  preInstall = ''
+    mkdir -p $out/bin $out/sbin $out/share/man/man{4,8}
+    mkdir -p $out/lib/modules/${kernel.modDirVersion}/extra
+  '';
+
+  meta = {
+    description = "Network monitoring module for atop";
+    homepage = https://www.atoptool.nl/downloadnetatop.php;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [viric];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nfs-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/nfs-utils/default.nix
new file mode 100644
index 000000000000..19a5184f8962
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nfs-utils/default.nix
@@ -0,0 +1,121 @@
+{ stdenv, fetchurl, fetchpatch, lib, pkgconfig, utillinux, libcap, libtirpc, libevent
+, sqlite, kerberos, kmod, libuuid, keyutils, lvm2, systemd, coreutils, tcp_wrappers
+, buildEnv, python3
+}:
+
+let
+  statdPath = lib.makeBinPath [ systemd utillinux coreutils ];
+in
+
+stdenv.mkDerivation rec {
+  name = "nfs-utils-${version}";
+  version = "2.3.3";
+
+  src = fetchurl {
+    url = "https://kernel.org/pub/linux/utils/nfs-utils/${version}/${name}.tar.xz";
+    sha256 = "08k36d7l8yqylscnln3p85lcfwi7r7g6n3bnslgmzc1i71wk92zn";
+  };
+
+  # libnfsidmap is built together with nfs-utils from the same source,
+  # put it in the "lib" output, and the headers in "dev"
+  outputs = [ "out" "dev" "lib" "man" ];
+
+  nativeBuildInputs = [ pkgconfig ];
+
+  buildInputs = [
+    libtirpc libcap libevent sqlite lvm2
+    libuuid keyutils kerberos tcp_wrappers
+    python3
+  ];
+
+  enableParallelBuilding = true;
+
+  preConfigure =
+    ''
+      substituteInPlace configure \
+        --replace '$dir/include/gssapi' ${lib.getDev kerberos}/include/gssapi \
+        --replace '$dir/bin/krb5-config' ${lib.getDev kerberos}/bin/krb5-config
+    '';
+
+  #configureScript = "bash -x configure";
+
+  configureFlags =
+    [ "--enable-gss"
+      "--with-statedir=/var/lib/nfs"
+      "--with-krb5=${lib.getLib kerberos}"
+      "--with-systemd=${placeholder "out"}/etc/systemd/system"
+      "--enable-libmount-mount"
+      "--with-pluginpath=${placeholder "lib"}/lib/libnfsidmap" # this installs libnfsidmap
+    ]
+    ++ lib.optional (stdenv ? glibc) "--with-rpcgen=${stdenv.glibc.bin}/bin/rpcgen";
+
+  patches = lib.optionals stdenv.hostPlatform.isMusl [
+    (fetchpatch {
+      url = "https://raw.githubusercontent.com/alpinelinux/aports/cb880042d48d77af412d4688f24b8310ae44f55f/main/nfs-utils/0011-exportfs-only-do-glibc-specific-hackery-on-glibc.patch";
+      sha256 = "0rrddrykz8prk0dcgfvmnz0vxn09dbgq8cb098yjjg19zz6d7vid";
+    })
+    # http://openwall.com/lists/musl/2015/08/18/10
+    (fetchpatch {
+      url = "https://raw.githubusercontent.com/alpinelinux/aports/cb880042d48d77af412d4688f24b8310ae44f55f/main/nfs-utils/musl-getservbyport.patch";
+      sha256 = "1fqws9dz8n1d9a418c54r11y3w330qgy2652dpwcy96cm44sqyhf";
+    })
+  ];
+
+  postPatch =
+    ''
+      patchShebangs tests
+      sed -i "s,/usr/sbin,$out/bin,g" utils/statd/statd.c
+      sed -i "s,^PATH=.*,PATH=$out/bin:${statdPath}," utils/statd/start-statd
+
+      configureFlags="--with-start-statd=$out/bin/start-statd $configureFlags"
+
+      substituteInPlace systemd/nfs-utils.service \
+        --replace "/bin/true" "${coreutils}/bin/true"
+
+      substituteInPlace utils/mount/Makefile.in \
+        --replace "chmod 4511" "chmod 0511"
+
+      sed '1i#include <stdint.h>' -i support/nsm/rpc.c
+    '';
+
+  makeFlags = [
+    "sbindir=$(out)/bin"
+    "generator_dir=$(out)/etc/systemd/system-generators"
+  ];
+
+  installFlags = [
+    "statedir=$(TMPDIR)"
+    "statdpath=$(TMPDIR)"
+  ];
+
+  stripDebugList = [ "lib" "libexec" "bin" "etc/systemd/system-generators" ];
+
+  postInstall =
+    ''
+      # Not used on NixOS
+      sed -i \
+        -e "s,/sbin/modprobe,${kmod}/bin/modprobe,g" \
+        -e "s,/usr/sbin,$out/bin,g" \
+        $out/etc/systemd/system/*
+    '';
+
+  # One test fails on mips.
+  doCheck = !stdenv.isMips;
+
+  disallowedReferences = [ (lib.getDev kerberos) ];
+
+  meta = with stdenv.lib; {
+    description = "Linux user-space NFS utilities";
+
+    longDescription = ''
+      This package contains various Linux user-space Network File
+      System (NFS) utilities, including RPC `mount' and `nfs'
+      daemons.
+    '';
+
+    homepage = https://linux-nfs.org/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nftables/default.nix b/nixpkgs/pkgs/os-specific/linux/nftables/default.nix
new file mode 100644
index 000000000000..b4878ff4eac1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nftables/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchurl, pkgconfig, docbook2x, docbook_xml_dtd_45
+, flex, bison, libmnl, libnftnl, gmp, readline }:
+
+stdenv.mkDerivation rec {
+  version = "0.9.0";
+  name = "nftables-${version}";
+
+  src = fetchurl {
+    url = "https://netfilter.org/projects/nftables/files/${name}.tar.bz2";
+    sha256 = "14bygs6vg2v448cw5r4pxqi8an29hw0m9vab8hpmgjmrzjsq30dd";
+  };
+
+  configureFlags = [
+    "CONFIG_MAN=y"
+    "DB2MAN=docbook2man"
+  ];
+
+  XML_CATALOG_FILES = "${docbook_xml_dtd_45}/xml/dtd/docbook/catalog.xml";
+
+  nativeBuildInputs = [ pkgconfig docbook2x flex bison ];
+  buildInputs = [ libmnl libnftnl gmp readline ];
+
+  meta = with stdenv.lib; {
+    description = "The project that aims to replace the existing {ip,ip6,arp,eb}tables framework";
+    homepage = http://netfilter.org/projects/nftables;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nmon/default.nix b/nixpkgs/pkgs/os-specific/linux/nmon/default.nix
new file mode 100644
index 000000000000..3ec0dc45e16d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nmon/default.nix
@@ -0,0 +1,27 @@
+{ fetchurl, stdenv, ncurses }:
+
+stdenv.mkDerivation rec {
+  name = "nmon-${version}";
+  version = "16i";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/nmon/lmon${version}.c";
+    sha256 = "0k52nvkfhwq7125gbrz7p56gid4rik59am8w22ja8ihiribdfrmg";
+  };
+
+  buildInputs = [ ncurses ];
+  unpackPhase = ":";
+  buildPhase = "cc -o nmon ${src} -g -O2 -D JFS -D GETUSER -Wall -D LARGEMEM -lncurses -lm -g -D X86";
+  installPhase = ''
+    mkdir -p $out/bin
+    cp nmon $out/bin
+  '';
+
+  meta = with stdenv.lib; {
+    description = "AIX & Linux Performance Monitoring tool";
+    homepage = "http://nmon.sourceforge.net";
+    license = licenses.gpl3Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ sveitser ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nss_ldap/crashes.patch b/nixpkgs/pkgs/os-specific/linux/nss_ldap/crashes.patch
new file mode 100644
index 000000000000..48250141e82a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nss_ldap/crashes.patch
@@ -0,0 +1,104 @@
+https://bugzilla.redhat.com/show_bug.cgi?id=488857
+
+
+Distinguish between contexts that are somewhat persistent and one-offs
+which are used to fulfill part of a larger request.
+
+diff -up nss_ldap-253/ldap-grp.c nss_ldap-253/ldap-grp.c
+--- nss_ldap-253/ldap-grp.c	2009-05-08 13:30:43.000000000 -0400
++++ nss_ldap-253/ldap-grp.c	2009-05-08 13:34:41.000000000 -0400
+@@ -857,7 +857,7 @@ ng_chase (const char *dn, ldap_initgroup
+   LA_STRING (a) = dn;
+   LA_TYPE (a) = LA_TYPE_STRING;
+ 
+-  if (_nss_ldap_ent_context_init_locked (&ctx) == NULL)
++  if (_nss_ldap_ent_context_init_internal_locked (&ctx) == NULL)
+     {
+       return NSS_UNAVAIL;
+     }
+@@ -930,7 +930,7 @@ ng_chase_backlink (const char ** members
+   LA_STRING_LIST (a) = filteredMembersOf;
+   LA_TYPE (a) = LA_TYPE_STRING_LIST_OR;
+ 
+-  if (_nss_ldap_ent_context_init_locked (&ctx) == NULL)
++  if (_nss_ldap_ent_context_init_internal_locked (&ctx) == NULL)
+     {
+       free (filteredMembersOf);
+       return NSS_UNAVAIL;
+diff -up nss_ldap-253/ldap-netgrp.c nss_ldap-253/ldap-netgrp.c
+--- nss_ldap-253/ldap-netgrp.c	2009-05-08 13:31:35.000000000 -0400
++++ nss_ldap-253/ldap-netgrp.c	2009-05-08 13:33:14.000000000 -0400
+@@ -691,7 +691,7 @@ do_innetgr_nested (ldap_innetgr_args_t *
+   LA_TYPE (a) = LA_TYPE_STRING;
+   LA_STRING (a) = nested;	/* memberNisNetgroup */
+ 
+-  if (_nss_ldap_ent_context_init_locked (&ctx) == NULL)
++  if (_nss_ldap_ent_context_init_internal_locked (&ctx) == NULL)
+     {
+       debug ("<== do_innetgr_nested: failed to initialize context");
+       return NSS_UNAVAIL;
+diff -up nss_ldap-253/ldap-nss.c nss_ldap-253/ldap-nss.c
+--- nss_ldap-253/ldap-nss.c	2009-05-08 13:27:17.000000000 -0400
++++ nss_ldap-253/ldap-nss.c	2009-05-08 14:05:51.000000000 -0400
+@@ -1961,6 +1961,7 @@ _nss_ldap_ent_context_init_locked (ent_c
+ 	  debug ("<== _nss_ldap_ent_context_init_locked");
+ 	  return NULL;
+ 	}
++      ctx->ec_internal = 0;
+       *pctx = ctx;
+     }
+   else
+@@ -1990,6 +1991,15 @@ _nss_ldap_ent_context_init_locked (ent_c
+ 
+   return ctx;
+ }
++ent_context_t *
++_nss_ldap_ent_context_init_internal_locked (ent_context_t ** pctx)
++{
++  ent_context_t *ctx;
++  ctx = _nss_ldap_ent_context_init_locked (pctx);
++  if (ctx != NULL)
++    ctx->ec_internal = 1;
++  return ctx;
++}
+ 
+ /*
+  * Clears a given context; we require the caller
+@@ -2031,7 +2041,8 @@ _nss_ldap_ent_context_release (ent_conte
+ 
+   LS_INIT (ctx->ec_state);
+ 
+-  if (_nss_ldap_test_config_flag (NSS_LDAP_FLAGS_CONNECT_POLICY_ONESHOT))
++  if (!ctx->ec_internal &&
++      _nss_ldap_test_config_flag (NSS_LDAP_FLAGS_CONNECT_POLICY_ONESHOT))
+     {
+       do_close ();
+     }
+diff -up nss_ldap-253/ldap-nss.h nss_ldap-253/ldap-nss.h
+--- nss_ldap-253/ldap-nss.h	2009-05-08 13:35:47.000000000 -0400
++++ nss_ldap-253/ldap-nss.h	2009-05-08 13:52:25.000000000 -0400
+@@ -560,6 +560,8 @@ struct ent_context
+   ldap_state_t ec_state;	/* eg. for services */
+   int ec_msgid;			/* message ID */
+   LDAPMessage *ec_res;		/* result chain */
++  int ec_internal;		/* this context is just a part of a larger
++				 * query for information */
+   ldap_service_search_descriptor_t *ec_sd;	/* current sd */
+   struct berval *ec_cookie;     /* cookie for paged searches */
+ };
+@@ -744,6 +746,15 @@ ent_context_t *_nss_ldap_ent_context_ini
+ ent_context_t *_nss_ldap_ent_context_init_locked (ent_context_t **);
+ 
+ /*
++ * _nss_ldap_ent_context_init_internal_locked() has the same
++ * behaviour, except it marks the context as one that's being
++ * used to fetch additional data used in answering a request, i.e.
++ * that this isn't the "main" context
++ */
++
++ent_context_t *_nss_ldap_ent_context_init_internal_locked (ent_context_t **);
++
++/*
+  * _nss_ldap_ent_context_release() is used to manually free a context 
+  */
+ void _nss_ldap_ent_context_release (ent_context_t *);
diff --git a/nixpkgs/pkgs/os-specific/linux/nss_ldap/default.nix b/nixpkgs/pkgs/os-specific/linux/nss_ldap/default.nix
new file mode 100644
index 000000000000..c23eb19a482a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nss_ldap/default.nix
@@ -0,0 +1,38 @@
+{stdenv, fetchurl, openldap, perl}:
+
+stdenv.mkDerivation {
+  name = "nss_ldap-265";
+
+  src = fetchurl {
+    url = http://www.padl.com/download/nss_ldap-265.tar.gz;
+    sha256 = "1a16q9p97d2blrj0h6vl1xr7dg7i4s8x8namipr79mshby84vdbp";
+  };
+
+  preConfigure = ''
+    patchShebangs ./vers_string
+    sed -i s,vers_string,./vers_string, Makefile*
+    substituteInPlace vers_string --replace "cvslib.pl" "./cvslib.pl"
+  '';
+
+  patches = [ ./crashes.patch ];
+
+  postPatch = ''
+    patch -p0 < ${./nss_ldap-265-glibc-2.16.patch}
+  '';
+
+  preInstall = ''
+    installFlagsArray=(INST_UID=$(id -u) INST_GID=$(id -g) LIBC_VERS=2.5 NSS_VERS=2 NSS_LDAP_PATH_CONF=$out/etc/ldap.conf)
+    substituteInPlace Makefile \
+      --replace '/usr$(libdir)' $TMPDIR \
+      --replace 'install-data-local:' 'install-data-local-disabled:'
+    mkdir -p $out/etc
+  '';
+
+  buildInputs = [ openldap perl ];
+
+  meta = with stdenv.lib; {
+    description = "LDAP module for the Solaris Nameservice Switch (NSS)";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nss_ldap/nss_ldap-265-glibc-2.16.patch b/nixpkgs/pkgs/os-specific/linux/nss_ldap/nss_ldap-265-glibc-2.16.patch
new file mode 100644
index 000000000000..8b0b9289327a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nss_ldap/nss_ldap-265-glibc-2.16.patch
@@ -0,0 +1,139 @@
+https://github.com/archlinuxarm/PKGBUILDs/issues/296
+
+Fixes the bug causing a segfault on nscd and sshd:
+symbol lookup error: /usr/lib/libnss_ldap.so.2: undefined symbol: __libc_lock_lock
+
+--- ldap-nss.c.orig	2012-10-17 12:32:03.908730283 +0000
++++ ldap-nss.c	2012-10-17 12:38:10.906767283 +0000
+@@ -148,7 +148,7 @@
+  */
+ static ldap_session_t __session = { NULL, NULL, 0, LS_UNINITIALIZED };
+ 
+-#if defined(HAVE_PTHREAD_ATFORK) || defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#if defined(HAVE_PTHREAD_ATFORK) || defined(HAVE___LIBC_ONCE)
+ static pthread_once_t __once = PTHREAD_ONCE_INIT;
+ #endif
+ 
+@@ -168,7 +168,7 @@
+ static int __ssl_initialized = 0;
+ #endif /* HAVE_LDAPSSL_CLIENT_INIT */
+ 
+-#if defined(HAVE_PTHREAD_ATFORK) || defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#if defined(HAVE_PTHREAD_ATFORK) || defined(HAVE___LIBC_ONCE)
+ /*
+  * Prepare for fork(); lock mutex.
+  */
+@@ -519,7 +519,7 @@
+ }
+ #endif /* HAVE_NSSWITCH_H */
+ 
+-#if defined(HAVE_PTHREAD_ATFORK) || defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#if defined(HAVE_PTHREAD_ATFORK) || defined(HAVE___LIBC_ONCE)
+ static void
+ do_atfork_prepare (void)
+ {
+@@ -553,7 +553,7 @@
+ #ifdef HAVE_PTHREAD_ATFORK
+   (void) pthread_atfork (do_atfork_prepare, do_atfork_parent,
+ 			 do_atfork_child);
+-#elif defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#elif defined(HAVE___LIBC_ATFORK)
+   (void) __libc_atfork (do_atfork_prepare, do_atfork_parent, do_atfork_child);
+ #endif
+ 
+@@ -1119,7 +1119,7 @@
+     }
+ 
+ #ifndef HAVE_PTHREAD_ATFORK
+-#if defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#if defined(HAVE___LIBC_ONCE)
+   /*
+    * This bogosity is necessary because Linux uses different
+    * PIDs for different threads (like IRIX, which we don't
+@@ -1151,7 +1151,7 @@
+     pid = -1;			/* linked against libpthreads, don't care */
+ #else
+   pid = getpid ();
+-#endif /* HAVE_LIBC_LOCK_H || HAVE_BITS_LIBC_LOCK_H */
++#endif /* HAVE___LIBC_ONCE */
+ #endif /* HAVE_PTHREAD_ATFORK */
+ 
+   euid = geteuid ();
+@@ -1161,7 +1161,7 @@
+   syslog (LOG_DEBUG,
+ 	  "nss_ldap: __session.ls_state=%d, __session.ls_conn=%p, __euid=%i, euid=%i",
+ 	  __session.ls_state, __session.ls_conn, __euid, euid);
+-#elif defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#elif defined(HAVE___LIBC_ONCE)
+   syslog (LOG_DEBUG,
+ 	  "nss_ldap: libpthreads=%s, __session.ls_state=%d, __session.ls_conn=%p, __pid=%i, pid=%i, __euid=%i, euid=%i",
+  	  ((__pthread_once == NULL || __pthread_atfork == NULL) ? "FALSE" : "TRUE"),
+@@ -1185,11 +1185,11 @@
+     }
+   else
+ #ifndef HAVE_PTHREAD_ATFORK
+-#if defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#if defined(HAVE___LIBC_ONCE)
+   if ((__pthread_once == NULL || __pthread_atfork == NULL) && __pid != pid)
+ #else
+   if (__pid != pid)
+-#endif /* HAVE_LIBC_LOCK_H || HAVE_BITS_LIBC_LOCK_H */
++#endif /* HAVE___LIBC_ONCE */
+     {
+       do_close_no_unbind ();
+     }
+@@ -1250,9 +1250,9 @@
+       debug ("<== do_init (pthread_once failed)");
+       return NSS_UNAVAIL;
+     }
+-#elif defined(HAVE_PTHREAD_ATFORK) && ( defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H) )
++#elif defined(HAVE_PTHREAD_ATFORK) && defined(HAVE___LIBC_ONCE)
+   __libc_once (__once, do_atfork_setup);
+-#elif defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#elif defined(HAVE___LIBC_ONCE)
+   /*
+    * Only install the pthread_atfork() handlers i
+    * we are linked against libpthreads. Otherwise,
+--- ldap-nss.h.orig	2012-10-17 12:33:05.681379283 +0000
++++ ldap-nss.h	2012-10-17 12:34:06.337050753 +0000
+@@ -671,7 +671,7 @@
+ #define NSS_LDAP_LOCK(m)		mutex_lock(&m)
+ #define NSS_LDAP_UNLOCK(m)		mutex_unlock(&m)
+ #define NSS_LDAP_DEFINE_LOCK(m)		static mutex_t m = DEFAULTMUTEX
+-#elif defined(HAVE_LIBC_LOCK_H) || defined(HAVE_BITS_LIBC_LOCK_H)
++#elif defined(HAVE___LIBC_LOCK_LOCK) && defined(HAVE___LIBC_LOCK_UNLOCK)
+ #define NSS_LDAP_LOCK(m)		__libc_lock_lock(m)
+ #define NSS_LDAP_UNLOCK(m)		__libc_lock_unlock(m)
+ #define NSS_LDAP_DEFINE_LOCK(m)		static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER
+--- ldap-nss.c.orig	2012-10-17 12:58:20.270783283 +0000
++++ ldap-nss.c	2012-10-17 12:58:43.699267283 +0000
+@@ -156,7 +156,7 @@
+ static FILE *__debugfile;
+ #endif /* LBER_OPT_LOG_PRINT_FILE */
+ 
+-#ifndef HAVE_PTHREAD_ATFORK
++#if !defined(HAVE_PTHREAD_ATFORK) || !defined(HAVE___LIBC_ONCE)
+ /* 
+  * Process ID that opened the session.
+  */
+--- configure.in.orig	2012-10-17 12:59:31.707235283 +0000
++++ configure.in	2012-10-17 13:00:15.854289283 +0000
+@@ -255,6 +255,7 @@
+ AC_CHECK_FUNCS(pthread_once)
+ AC_CHECK_FUNCS(ether_aton)
+ AC_CHECK_FUNCS(ether_ntoa)
++AC_CHECK_FUNCS(__libc_once __libc_atfork __libc_lock_lock __libc_lock_unlock)
+ 
+ AC_MSG_CHECKING(for struct ether_addr)
+ AC_TRY_COMPILE([#include <sys/types.h>
+--- ldap-nss.c.orig	2012-10-17 13:02:01.418010283 +0000
++++ ldap-nss.c	2012-10-17 13:03:25.017240283 +0000
+@@ -1102,7 +1102,7 @@
+ do_init (void)
+ {
+   ldap_config_t *cfg;
+-#ifndef HAVE_PTHREAD_ATFORK
++#if !defined(HAVE_PTHREAD_ATFORK) || !defined(HAVE___LIBC_ONCE)
+   pid_t pid;
+ #endif
+   uid_t euid;
diff --git a/nixpkgs/pkgs/os-specific/linux/numactl/default.nix b/nixpkgs/pkgs/os-specific/linux/numactl/default.nix
new file mode 100644
index 000000000000..3bdb9886d39a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/numactl/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchFromGitHub, fetchpatch, autoreconfHook }:
+
+stdenv.mkDerivation rec {
+  name = "numactl-${version}";
+  version = "2.0.12";
+
+  src = fetchFromGitHub {
+    owner = "numactl";
+    repo = "numactl";
+    rev = "v${version}";
+    sha256 = "0crhpxwakp0gvd7wwpbkfd3brnrdf89lkbf03axnbrs0b6kaygg2";
+  };
+
+  nativeBuildInputs = [ autoreconfHook ];
+
+  postPatch = ''
+    patchShebangs test
+  '';
+
+  # You probably shouldn't ever run these! They will reconfigure Linux
+  # NUMA settings, which on my build machine makes the rest of package
+  # building ~5% slower until reboot. Ugh!
+  doCheck = false; # never ever!
+
+  meta = with stdenv.lib; {
+    description = "Library and tools for non-uniform memory access (NUMA) machines";
+    homepage = https://github.com/numactl/numactl;
+    license = with licenses; [ gpl2 lgpl21 ]; # libnuma is lgpl21
+    platforms = [ "i686-linux" "x86_64-linux" "aarch64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/numad/default.nix b/nixpkgs/pkgs/os-specific/linux/numad/default.nix
new file mode 100644
index 000000000000..ed84c41001b6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/numad/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "numad-0.5";
+
+  src = fetchurl {
+    url = "https://git.fedorahosted.org/cgit/numad.git/snapshot/${name}.tar.xz";
+    sha256 = "08zd1yc3w00yv4mvvz5sq1gf91f6p2s9ljcd72m33xgnkglj60v4";
+  };
+
+  hardeningDisable = [ "format" ];
+
+  patches = [
+    ./numad-linker-flags.patch
+  ];
+  postPatch = ''
+    substituteInPlace Makefile --replace "install -m" "install -Dm"
+  '';
+
+  makeFlags = "prefix=$(out)";
+
+  meta = with stdenv.lib; {
+    description = "A user-level daemon that monitors NUMA topology and processes resource consumption to facilitate good NUMA resource access";
+    homepage = https://fedoraproject.org/wiki/Features/numad;
+    license = licenses.lgpl21;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ domenkozar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/numad/numad-linker-flags.patch b/nixpkgs/pkgs/os-specific/linux/numad/numad-linker-flags.patch
new file mode 100644
index 000000000000..97f3dc8b6cf7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/numad/numad-linker-flags.patch
@@ -0,0 +1,33 @@
+From 9eb3cc5c51d846c8c8b750a4eb55545d7b5fea6c Mon Sep 17 00:00:00 2001
+From: Mike Frysinger <vapier@gentoo.org>
+Date: Wed, 23 Apr 2014 15:41:26 -0400
+Subject: [PATCH] use LDLIBS for linker flags
+
+When you put -lfoo into the dependency line of make, it forces it to
+search /lib and /usr/lib for files to link against.  This can cause
+problems when trying to cross-compile or build for different ABIs.
+Use the standard LDLIBS variable instead.
+
+URL: https://bugs.gentoo.org/505760
+Reported-by: Georgi Georgiev <chutzimir@gmail.com>
+Signed-off-by: Mike Frysinger <vapier@gentoo.org>
+---
+ Makefile | 3 ++-
+ 1 file changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/Makefile b/Makefile
+index f3838b4..f2e9a6e 100644
+--- a/Makefile
++++ b/Makefile
+@@ -31,7 +31,8 @@ docdir := ${prefix}/share/doc
+ 
+ all: numad
+ 
+-numad: numad.o -lpthread
++LDLIBS := -lpthread
++numad: numad.o
+ 
+ AR ?= ar
+ RANLIB ?= ranlib
+-- 
+1.9.2
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/atomic64_t.patch b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/atomic64_t.patch
new file mode 100644
index 000000000000..18fcca314a86
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/atomic64_t.patch
@@ -0,0 +1,12 @@
+diff --git a/kernel/conftest.sh b/kernel/conftest.sh
+index e8de161..6c284e9 100755
+--- a/kernel/conftest.sh
++++ b/kernel/conftest.sh
+@@ -1784,7 +1784,6 @@ compile_test() {
+                 atomic64_t data;
+                 atomic64_read(&data);
+                 atomic64_set(&data, 0);
+-                atomic64_inc(&data);
+             }"
+ 
+             compile_check_conftest "$CODE" "NV_ATOMIC64_PRESENT" "" "types"
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/builder.sh b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/builder.sh
new file mode 100755
index 000000000000..56012aafea9c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/builder.sh
@@ -0,0 +1,146 @@
+source $stdenv/setup
+
+unpackManually() {
+    skip=$(sed 's/^skip=//; t; d' $src)
+    tail -n +$skip $src | xz -d | tar xvf -
+    sourceRoot=.
+}
+
+
+unpackFile() {
+    sh $src -x || unpackManually
+}
+
+
+buildPhase() {
+    if [ -n "$bin" ]; then
+        # Create the module.
+        echo "Building linux driver against kernel: $kernel";
+        cd kernel
+        sysSrc=$(echo $kernel/lib/modules/$kernelVersion/source)
+        sysOut=$(echo $kernel/lib/modules/$kernelVersion/build)
+        unset src # used by the nv makefile
+        make SYSSRC=$sysSrc SYSOUT=$sysOut module -j$NIX_BUILD_CORES
+
+        cd ..
+    fi
+}
+
+
+installPhase() {
+    # Install libGL and friends.
+
+    # since version 391, 32bit libraries are bundled in the 32/ sub-directory
+    if [ "$i686bundled" = "1" ]; then
+        mkdir -p "$lib32/lib"
+        cp -prd 32/*.so.* "$lib32/lib/"
+        if [ -d 32/tls ]; then
+            cp -prd 32/tls "$lib32/lib/"
+        fi
+    fi
+
+    mkdir -p "$out/lib"
+    cp -prd *.so.* "$out/lib/"
+    if [ -d tls ]; then
+        cp -prd tls "$out/lib/"
+    fi
+
+    for i in $lib32 $out; do
+        rm -f $i/lib/lib{glx,nvidia-wfb}.so.* # handled separately
+        rm -f $i/lib/libnvidia-gtk* # built from source
+        if [ "$useGLVND" = "1" ]; then
+            # Pre-built libglvnd
+            rm $i/lib/lib{GL,GLX,EGL,GLESv1_CM,GLESv2,OpenGL,GLdispatch}.so.*
+        fi
+        # Use ocl-icd instead
+        rm -f $i/lib/libOpenCL.so*
+        # Move VDPAU libraries to their place
+        mkdir $i/lib/vdpau
+        mv $i/lib/libvdpau* $i/lib/vdpau
+
+        # Install ICDs.
+        install -Dm644 nvidia.icd $i/etc/OpenCL/vendors/nvidia.icd
+        if [ -e nvidia_icd.json.template ]; then
+            sed "s#__NV_VK_ICD__#libGLX_nvidia.so#" nvidia_icd.json.template > nvidia_icd.json
+            install -Dm644 nvidia_icd.json $i/share/vulkan/icd.d/nvidia.json
+        fi
+        if [ "$useGLVND" = "1" ]; then
+            install -Dm644 10_nvidia.json $i/share/glvnd/egl_vendor.d/nvidia.json
+        fi
+
+    done
+
+
+    if [ -n "$bin" ]; then
+        # Install the X drivers.
+        mkdir -p $bin/lib/xorg/modules
+        if [ -f libnvidia-wfb.so ]; then
+            cp -p libnvidia-wfb.* $bin/lib/xorg/modules/
+        fi
+        mkdir -p $bin/lib/xorg/modules/drivers
+        cp -p nvidia_drv.so $bin/lib/xorg/modules/drivers
+        mkdir -p $bin/lib/xorg/modules/extensions
+        cp -p libglx*.so* $bin/lib/xorg/modules/extensions
+
+        # Install the kernel module.
+        mkdir -p $bin/lib/modules/$kernelVersion/misc
+        for i in $(find ./kernel -name '*.ko'); do
+            nuke-refs $i
+            cp $i $bin/lib/modules/$kernelVersion/misc/
+        done
+
+        # Install application profiles.
+        if [ "$useProfiles" = "1" ]; then
+            mkdir -p $bin/share/nvidia
+            cp nvidia-application-profiles-*-rc $bin/share/nvidia/nvidia-application-profiles-rc
+            cp nvidia-application-profiles-*-key-documentation $bin/share/nvidia/nvidia-application-profiles-key-documentation
+        fi
+    fi
+
+    # All libs except GUI-only are installed now, so fixup them.
+    for libname in $(find "$out/lib/" $(test -n "$lib32" && echo "$lib32/lib/") $(test -n "$bin" && echo "$bin/lib/") -name '*.so.*')
+    do
+      # I'm lazy to differentiate needed libs per-library, as the closure is the same.
+      # Unfortunately --shrink-rpath would strip too much.
+      patchelf --set-rpath "$out/lib:$libPath" "$libname"
+
+      libname_short=`echo -n "$libname" | sed 's/so\..*/so/'`
+
+      if [[ "$libname" != "$libname_short" ]]; then
+        ln -srnf "$libname" "$libname_short"
+      fi
+
+      if [[ $libname_short =~ libEGL.so || $libname_short =~ libEGL_nvidia.so || $libname_short =~ libGLX.so || $libname_short =~ libGLX_nvidia.so ]]; then
+          major=0
+      else
+          major=1
+      fi
+
+      if [[ "$libname" != "$libname_short.$major" ]]; then
+        ln -srnf "$libname" "$libname_short.$major"
+      fi
+    done
+
+    if [ -n "$bin" ]; then
+        # Install /share files.
+        mkdir -p $bin/share/man/man1
+        cp -p *.1.gz $bin/share/man/man1
+        rm -f $bin/share/man/man1/{nvidia-xconfig,nvidia-settings,nvidia-persistenced}.1.gz
+
+        # Install the programs.
+        for i in nvidia-cuda-mps-control nvidia-cuda-mps-server nvidia-smi nvidia-debugdump; do
+            if [ -e "$i" ]; then
+                install -Dm755 $i $bin/bin/$i
+                # unmodified binary backup for mounting in containers
+                install -Dm755 $i $bin/origBin/$i
+                patchelf --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
+                    --set-rpath $out/lib:$libPath $bin/bin/$i
+            fi
+        done
+        # FIXME: needs PATH and other fixes
+        # install -Dm755 nvidia-bug-report.sh $bin/bin/nvidia-bug-report.sh
+    fi
+}
+
+
+genericBuild
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/default.nix b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/default.nix
new file mode 100644
index 000000000000..c729a35925fc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/default.nix
@@ -0,0 +1,80 @@
+{ lib, callPackage, fetchurl, stdenv }:
+
+let
+  generic = args: callPackage (import ./generic.nix args) { };
+  kernel = callPackage # a hacky way of extracting parameters from callPackage
+    ({ kernel, libsOnly ? false }: if libsOnly then { } else kernel) { };
+
+  maybePatch_drm_legacy =
+    lib.optional (lib.versionOlder "4.14" (kernel.version or "0"))
+      (fetchurl {
+        url = "https://raw.githubusercontent.com/MilhouseVH/LibreELEC.tv/b5d2d6a1"
+            + "/packages/x11/driver/xf86-video-nvidia-legacy/patches/"
+            + "xf86-video-nvidia-legacy-0010-kernel-4.14.patch";
+        sha256 = "18clfpw03g8dxm61bmdkmccyaxir3gnq451z6xqa2ilm3j820aa5";
+      });
+in
+rec {
+  # Policy: use the highest stable version as the default (on our master).
+  stable = if stdenv.hostPlatform.system == "x86_64-linux" then stable_418 else legacy_390;
+
+  # No active beta right now
+  beta = stable;
+
+  stable_418 = generic {
+    version = "418.43";
+    sha256_64bit = "0zrjd8wfc8cknfwiyy3llsnn1mympfxxszz7gzakncp3vs1jrghq";
+    settingsSha256 = "1rzxxn7nrhwndl2lgjakxi0rblfkqjyl1n70fl7rcs6g75mi1qsq";
+    persistencedSha256 = "14m4x5r0yc23sg4xx523ccfpxsr6dgm2n3xy9zdibl1cpzz50ikc";
+  };
+
+  # Last one supporting x86
+  legacy_390 = generic {
+    version = "390.116";
+    sha256_32bit = "0aavzi99ps7r6nrchf4h9gw3fkvm2z6wppkqkz5fwcy7x03ky4qk";
+    sha256_64bit = "106qc62a7m9imchqfq8rfn8fwyrjxg383354q7z2wr8112fyhyg1";
+    settingsSha256 = "0inmzjhnlal5ih2iyv2x4y3jx7c4lz9xln8sy9j20yj9azp51qz0";
+    persistencedSha256 = "04ycijijlcbib2afcxjsyyzza1i3adh17sddrz3sah7rj38mrlgx";
+
+    patches = lib.optional (kernel.meta.branch == "4.19") ./drm_mode_connector.patch;
+  };
+
+  legacy_340 = generic {
+    version = "340.107";
+    sha256_32bit = "0mh83affz6bim26ws7kkwwcfj2s6vkdy4d45hifsbshr82qd52wd";
+    sha256_64bit = "0pv9yv3x0kg9hfkmc50xb54ahxkbnyy2vyy4hj2h0s6m9sb5kqz3";
+    settingsSha256 = "1rgaa24acdyqa1rqrx56293vxpskr792njqqpigqmps04llsx703";
+    persistencedSha256 = "0nwv6kh4gxgy80x1zs6gcg5hy3amg25xhsfa2v4mwqa36sblxz6l";
+    useGLVND = false;
+
+    patches = [ ./vm_operations_struct-fault.patch ];
+  };
+
+  legacy_304 = generic {
+    version = "304.137";
+    sha256_32bit = "1y34c2gvmmacxk2c72d4hsysszncgfndc4s1nzldy2q9qagkg66a";
+    sha256_64bit = "1qp3jv6279k83k3z96p6vg3dd35y9bhmlyyyrkii7sib7bdmc7zb";
+    settingsSha256 = "0i5znfq6jkabgi8xpcy12pdpww6a67i8mq60z1kjq36mmnb25pmi";
+    persistencedSha256 = null;
+    useGLVND = false;
+    useProfiles = false;
+    settings32Bit = true;
+
+    prePatch = let
+      debPatches = fetchurl {
+        url = "mirror://debian/pool/non-free/n/nvidia-graphics-drivers-legacy-304xx/"
+            + "nvidia-graphics-drivers-legacy-304xx_304.137-5.debian.tar.xz";
+        sha256 = "0n8512mfcnvklfbg8gv4lzbkm3z6nncwj6ix2b8ngdkmc04f3b6l";
+      };
+      prefix = "debian/module/debian/patches";
+      applyPatches = pnames: if pnames == [] then null else
+        ''
+          tar xf '${debPatches}'
+          sed 's|^\([+-]\{3\} [ab]\)/|\1/kernel/|' -i ${prefix}/*.patch
+          patches="$patches ${lib.concatMapStringsSep " " (pname: "${prefix}/${pname}.patch") pnames}"
+        '';
+    in applyPatches [ "fix-typos" ];
+    patches = maybePatch_drm_legacy;
+    broken = stdenv.lib.versionAtLeast kernel.version "4.18";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/drm_mode_connector.patch b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/drm_mode_connector.patch
new file mode 100644
index 000000000000..58cf06fae45f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/drm_mode_connector.patch
@@ -0,0 +1,24 @@
+diff -ura a/kernel/nvidia-drm/nvidia-drm-connector.c b/kernel/nvidia-drm/nvidia-drm-connector.c
+--- a/kernel/nvidia-drm/nvidia-drm-connector.c	2018-09-07 17:38:31.807453997 -0400
++++ b/kernel/nvidia-drm/nvidia-drm-connector.c	2018-09-07 17:39:22.446185824 -0400
+@@ -226,7 +226,7 @@
+ 
+ 
+     if (nv_connector->edid != NULL) {
+-        drm_mode_connector_update_edid_property(
++        drm_connector_update_edid_property(
+             connector, nv_connector->edid);
+     }
+ 
+diff -ura a/kernel/nvidia-drm/nvidia-drm-encoder.c b/kernel/nvidia-drm/nvidia-drm-encoder.c
+--- a/kernel/nvidia-drm/nvidia-drm-encoder.c	2018-09-07 17:38:31.807453997 -0400
++++ b/kernel/nvidia-drm/nvidia-drm-encoder.c	2018-09-07 17:39:35.083798484 -0400
+@@ -216,7 +216,7 @@
+ 
+     /* Attach encoder and connector */
+ 
+-    ret = drm_mode_connector_attach_encoder(connector, encoder);
++    ret = drm_connector_attach_encoder(connector, encoder);
+ 
+     if (ret != 0) {
+         NV_DRM_DEV_LOG_ERR(
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/generic.nix b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/generic.nix
new file mode 100644
index 000000000000..1a08a89dc233
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/generic.nix
@@ -0,0 +1,99 @@
+{ version
+, sha256_32bit ? null
+, sha256_64bit
+, settingsSha256
+, persistencedSha256
+, useGLVND ? true
+, useProfiles ? true
+, preferGtk2 ? false
+, settings32Bit ? false
+
+, prePatch ? ""
+, patches ? []
+, broken ? false
+}:
+
+{ stdenv, callPackage, pkgsi686Linux, fetchurl
+, kernel ? null, xorg, zlib, perl, nukeReferences
+, # Whether to build the libraries only (i.e. not the kernel module or
+  # nvidia-settings).  Used to support 32-bit binaries on 64-bit
+  # Linux.
+  libsOnly ? false
+}:
+
+with stdenv.lib;
+
+assert !libsOnly -> kernel != null;
+assert versionOlder version "391" -> sha256_32bit != null;
+assert ! versionOlder version "391" -> stdenv.hostPlatform.system == "x86_64-linux";
+
+let
+  nameSuffix = optionalString (!libsOnly) "-${kernel.version}";
+  pkgSuffix = optionalString (versionOlder version "304") "-pkg0";
+  i686bundled = versionAtLeast version "391";
+
+
+  self = stdenv.mkDerivation {
+    name = "nvidia-x11-${version}${nameSuffix}";
+
+    builder = ./builder.sh;
+
+    src =
+      if stdenv.hostPlatform.system == "x86_64-linux" then
+        fetchurl {
+          url = "https://download.nvidia.com/XFree86/Linux-x86_64/${version}/NVIDIA-Linux-x86_64-${version}${pkgSuffix}.run";
+          sha256 = sha256_64bit;
+        }
+      else if stdenv.hostPlatform.system == "i686-linux" then
+        fetchurl {
+          url = "https://download.nvidia.com/XFree86/Linux-x86/${version}/NVIDIA-Linux-x86-${version}${pkgSuffix}.run";
+          sha256 = sha256_32bit;
+        }
+      else throw "nvidia-x11 does not support platform ${stdenv.hostPlatform.system}";
+
+    patches = if libsOnly then null else patches;
+    inherit prePatch;
+    inherit version useGLVND useProfiles;
+    inherit (stdenv.hostPlatform) system;
+    inherit i686bundled;
+
+    outputs = [ "out" ]
+        ++ optional i686bundled "lib32"
+        ++ optional (!libsOnly) "bin";
+    outputDev = if libsOnly then null else "bin";
+
+    kernel = if libsOnly then null else kernel.dev;
+    kernelVersion = if libsOnly then null else kernel.modDirVersion;
+
+    hardeningDisable = [ "pic" "format" ];
+
+    dontStrip = true;
+    dontPatchELF = true;
+
+    libPath = makeLibraryPath [ xorg.libXext xorg.libX11 xorg.libXv xorg.libXrandr xorg.libxcb zlib stdenv.cc.cc ];
+
+    nativeBuildInputs = [ perl nukeReferences ]
+      ++ optionals (!libsOnly) kernel.moduleBuildDependencies;
+
+    disallowedReferences = optional (!libsOnly) [ kernel.dev ];
+
+    passthru = {
+      settings = (if settings32Bit then pkgsi686Linux.callPackage else callPackage) (import ./settings.nix self settingsSha256) {
+        withGtk2 = preferGtk2;
+        withGtk3 = !preferGtk2;
+      };
+      persistenced = mapNullable (hash: callPackage (import ./persistenced.nix self hash) { }) persistencedSha256;
+    };
+
+    meta = with stdenv.lib; {
+      homepage = http://www.nvidia.com/object/unix.html;
+      description = "X.org driver and kernel module for NVIDIA graphics cards";
+      license = licenses.unfreeRedistributable;
+      platforms = [ "i686-linux" "x86_64-linux" ];
+      maintainers = with maintainers; [ baracoder ];
+      priority = 4; # resolves collision with xorg-server's "lib/xorg/modules/extensions/libglx.so"
+      inherit broken;
+    };
+  };
+
+in self
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/persistenced.nix b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/persistenced.nix
new file mode 100644
index 000000000000..c6993d146f19
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/persistenced.nix
@@ -0,0 +1,35 @@
+nvidia_x11: sha256:
+
+{ stdenv, fetchurl, m4 }:
+
+stdenv.mkDerivation rec {
+  name = "nvidia-persistenced-${nvidia_x11.version}";
+  inherit (nvidia_x11) version;
+
+  src = fetchurl {
+    url = "https://download.nvidia.com/XFree86/nvidia-persistenced/${name}.tar.bz2";
+    inherit sha256;
+  };
+
+  nativeBuildInputs = [ m4 ];
+
+  installFlags = [ "PREFIX=$(out)" ];
+
+  postFixup = ''
+    # Save a copy of persistenced for mounting in containers
+    mkdir $out/origBin
+    cp $out/{bin,origBin}/nvidia-persistenced
+    patchelf --set-interpreter /lib64/ld-linux-x86-64.so.2 $out/origBin/nvidia-persistenced
+
+    patchelf --set-rpath "$(patchelf --print-rpath $out/bin/nvidia-persistenced):${nvidia_x11}/lib" \
+      $out/bin/nvidia-persistenced
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://www.nvidia.com/object/unix.html;
+    description = "Settings application for NVIDIA graphics cards";
+    license = licenses.unfreeRedistributable;
+    platforms = nvidia_x11.meta.platforms;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/settings.nix b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/settings.nix
new file mode 100644
index 000000000000..e2ef51da3803
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/settings.nix
@@ -0,0 +1,89 @@
+nvidia_x11: sha256:
+
+{ stdenv, lib, fetchurl, pkgconfig, m4, jansson, gtk2, dbus, gtk3, libXv, libXrandr, libXext, libXxf86vm, libvdpau
+, librsvg, wrapGAppsHook
+, withGtk2 ? false, withGtk3 ? true
+}:
+
+let
+  src = fetchurl {
+    url = "https://download.nvidia.com/XFree86/nvidia-settings/nvidia-settings-${nvidia_x11.version}.tar.bz2";
+    inherit sha256;
+  };
+
+  libXNVCtrl = stdenv.mkDerivation {
+    name = "libXNVCtrl-${nvidia_x11.version}";
+    inherit (nvidia_x11) version;
+    inherit src;
+
+    buildInputs = [ libXrandr libXext ];
+
+    preBuild = ''
+      cd src/libXNVCtrl
+    '';
+
+    installPhase = ''
+      mkdir -p $out/lib
+      mkdir -p $out/include/NVCtrl
+
+      cp libXNVCtrl.a $out/lib
+      cp NVCtrl.h     $out/include/NVCtrl
+      cp NVCtrlLib.h  $out/include/NVCtrl
+    '';
+  };
+
+in
+
+stdenv.mkDerivation rec {
+  name = "nvidia-settings-${nvidia_x11.version}";
+  inherit (nvidia_x11) version;
+  inherit src;
+
+  nativeBuildInputs = [ pkgconfig m4 ];
+
+  buildInputs = [ jansson libXv libXrandr libXext libXxf86vm libvdpau nvidia_x11 gtk2 dbus ]
+             ++ lib.optionals withGtk3 [ gtk3 librsvg wrapGAppsHook ];
+
+  makeFlags = [ "NV_USE_BUNDLED_LIBJANSSON=0" ];
+  installFlags = [ "PREFIX=$(out)" ];
+
+  postPatch = lib.optionalString nvidia_x11.useProfiles ''
+    sed -i 's,/usr/share/nvidia/,${nvidia_x11.bin}/share/nvidia/,g' src/gtk+-2.x/ctkappprofile.c
+  '';
+
+  preBuild = ''
+    if [ -e src/libXNVCtrl/libXNVCtrl.a ]; then
+      ( cd src/libXNVCtrl
+        make
+      )
+    fi
+  '';
+
+  postInstall = ''
+    ${lib.optionalString (!withGtk2) ''
+      rm -f $out/lib/libnvidia-gtk2.so.*
+    ''}
+    ${lib.optionalString (!withGtk3) ''
+      rm -f $out/lib/libnvidia-gtk3.so.*
+    ''}
+  '';
+
+  binaryName = if withGtk3 then ".nvidia-settings-wrapped" else "nvidia-settings";
+
+  postFixup = ''
+    patchelf --set-rpath "$(patchelf --print-rpath $out/bin/$binaryName):$out/lib:${libXv}/lib" \
+      $out/bin/$binaryName
+  '';
+
+  passthru = {
+    inherit libXNVCtrl;
+  };
+
+  meta = with stdenv.lib; {
+    homepage = http://www.nvidia.com/object/unix.html;
+    description = "Settings application for NVIDIA graphics cards";
+    license = licenses.unfreeRedistributable;
+    platforms = nvidia_x11.meta.platforms;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidia-x11/vm_operations_struct-fault.patch b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/vm_operations_struct-fault.patch
new file mode 100644
index 000000000000..6ce5c1205e2d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidia-x11/vm_operations_struct-fault.patch
@@ -0,0 +1,31 @@
+https://devtalk.nvidia.com/default/topic/1025051/fully-working-patches-2-of-them-for-nvidia-driver-340-104-compiler-installer-file-and-linux-kernels-4-13-amp-4-14/?offset=5
+--- a/kernel/uvm/nvidia_uvm_lite.c
++++ b/kernel/uvm/nvidia_uvm_lite.c
+@@ -818,8 +818,15 @@ done:
+ }
+
+ #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
+ int _fault(struct vm_area_struct *vma, struct vm_fault *vmf)
++#else
++int _fault(struct vm_fault *vmf)
++#endif
+ {
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
++    struct vm_area_struct *vma = vmf->vma;
++#endif
+ #if defined(NV_VM_FAULT_HAS_ADDRESS)
+     unsigned long vaddr = vmf->address;
+ #else
+@@ -866,7 +873,11 @@ static struct vm_operations_struct uvmlite_vma_ops =
+ // it's dealing with anonymous mapping (see handle_pte_fault).
+ //
+ #if defined(NV_VM_OPERATIONS_STRUCT_HAS_FAULT)
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0)
+ int _sigbus_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
++#else
++int _sigbus_fault(struct vm_fault *vmf)
++#endif
+ {
+     vmf->page = NULL;
+     return VM_FAULT_SIGBUS;
diff --git a/nixpkgs/pkgs/os-specific/linux/nvidiabl/default.nix b/nixpkgs/pkgs/os-specific/linux/nvidiabl/default.nix
new file mode 100644
index 000000000000..02161f7133ce
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvidiabl/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+stdenv.mkDerivation rec {
+  name = "nvidiabl-${version}-${kernel.version}";
+  version = "2017-09-26";
+
+  # We use a fork which adds support for newer kernels -- upstream has been abandoned.
+  src = fetchFromGitHub {
+    owner = "yorickvP";
+    repo = "nvidiabl";
+    rev = "2d909f4dfceb24ce98479fd571411c6ec3b71bea";
+    sha256 = "0dsar8fsaxwywjh6rbrxkhdp142vqjnsyxfz6bgpbqml6slpiqs1";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  preConfigure = ''
+    sed -i 's|/sbin/depmod|#/sbin/depmod|' Makefile
+  '';
+
+  makeFlags = [
+    "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+    "DESTDIR=$(out)"
+    "KVER=${kernel.modDirVersion}"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Linux driver for setting the backlight brightness on laptops using NVIDIA GPU";
+    homepage = https://github.com/guillaumezin/nvidiabl;
+    license = licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = with maintainers; [ yorickvp ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/nvme-cli/default.nix b/nixpkgs/pkgs/os-specific/linux/nvme-cli/default.nix
new file mode 100644
index 000000000000..49171697ffec
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/nvme-cli/default.nix
@@ -0,0 +1,23 @@
+{ lib, stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "nvme-cli-${version}";
+  version = "1.7";
+
+  src = fetchFromGitHub {
+    owner = "linux-nvme";
+    repo = "nvme-cli";
+    rev = "v${version}";
+    sha256 = "1wwr31s337km3v528hvsq72j2ph17fir0j3rr622z74k68pzdh1x";
+  };
+
+  makeFlags = [ "DESTDIR=$(out)" "PREFIX=" ];
+
+  meta = with lib; {
+    inherit (src.meta) homepage;
+    description = "NVM-Express user space tooling for Linux";
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ primeos tavyc ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/odp-dpdk/default.nix b/nixpkgs/pkgs/os-specific/linux/odp-dpdk/default.nix
new file mode 100644
index 000000000000..bead5f84eac9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/odp-dpdk/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchurl, autoreconfHook, pkgconfig
+, dpdk, libconfig, libpcap, numactl, openssl
+}:
+
+stdenv.mkDerivation rec {
+  name = "odp-dpdk-${version}";
+  version = "1.19.0.0_DPDK_17.11";
+
+  src = fetchurl {
+    url = "https://git.linaro.org/lng/odp-dpdk.git/snapshot/${name}.tar.gz";
+    sha256 = "05bwjaxl9hqc6fbkp95nniq11g3kvzmlxw0bq55i7p2v35nv38px";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ dpdk libconfig libpcap numactl openssl ];
+
+  RTE_SDK = "${dpdk}/share/dpdk";
+  RTE_TARGET = "x86_64-native-linuxapp-gcc";
+
+  dontDisableStatic = true;
+
+  configureFlags = [
+    "--disable-shared"
+    "--with-dpdk-path=${dpdk}"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "Open Data Plane optimized for DPDK";
+    homepage = https://www.opendataplane.org;
+    license = licenses.bsd3;
+    platforms =  [ "x86_64-linux" ];
+    maintainers = [ maintainers.abuibrahim ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ofp/default.nix b/nixpkgs/pkgs/os-specific/linux/ofp/default.nix
new file mode 100644
index 000000000000..93cf33979f4b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ofp/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchFromGitHub, pkgconfig, autoreconfHook
+, openssl, libpcap, odp-dpdk, dpdk
+}:
+
+stdenv.mkDerivation rec {
+  name = "ofp-${version}";
+  version = "2.0.0";
+
+  src = fetchFromGitHub {
+    owner = "OpenFastPath";
+    repo = "ofp";
+    rev = "${version}";
+    sha256 = "05902593fycgkwzk5g7wzgk0k40nrrgybplkdka3rqnlj6aydhqf";
+  };
+
+  nativeBuildInputs = [ pkgconfig autoreconfHook ];
+  buildInputs = [ openssl libpcap odp-dpdk dpdk ];
+
+  dontDisableStatic = true;
+
+  postPatch = ''
+    substituteInPlace configure.ac --replace m4_esyscmd m4_esyscmd_s
+    substituteInPlace scripts/git_hash.sh --replace /bin/bash ${stdenv.shell}
+    echo ${version} > .scmversion
+  '';
+
+  configureFlags = [
+    "--with-odp=${odp-dpdk}"
+    "--with-odp-lib=odp-dpdk"
+    "--disable-shared"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "High performance TCP/IP stack";
+    homepage = http://www.openfastpath.org;
+    license = licenses.bsd3;
+    platforms =  [ "x86_64-linux" ];
+    maintainers = [ maintainers.abuibrahim ];
+    broken = true;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/open-iscsi/default.nix b/nixpkgs/pkgs/os-specific/linux/open-iscsi/default.nix
new file mode 100644
index 000000000000..a2644fcbc3fd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/open-iscsi/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchFromGitHub, automake, autoconf, libtool, gettext
+, utillinux, openisns, openssl, kmod, perl, systemd, pkgconf
+}:
+
+stdenv.mkDerivation rec {
+  name = "open-iscsi-${version}";
+  version = "2.0.877";
+
+  nativeBuildInputs = [ autoconf automake gettext libtool perl pkgconf ];
+  buildInputs = [ kmod openisns.lib openssl systemd utillinux ];
+
+  src = fetchFromGitHub {
+    owner = "open-iscsi";
+    repo = "open-iscsi";
+    rev = version;
+    sha256 = "0v3dsrl34pdx0yl5jsanrpgg3vw466rl8k81hkshgq3a5mq5qhf6";
+  };
+
+  DESTDIR = "$(out)";
+
+  NIX_LDFLAGS = "-lkmod -lsystemd";
+  NIX_CFLAGS_COMPILE = "-DUSE_KMOD";
+
+  preConfigure = ''
+    sed -i 's|/usr|/|' Makefile
+  '';
+
+  postInstall = ''
+    cp usr/iscsistart $out/sbin/
+    $out/sbin/iscsistart -v
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A high performance, transport independent, multi-platform implementation of RFC3720";
+    license = licenses.gpl2;
+    homepage = https://www.open-iscsi.com;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ cleverca22 zaninime ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/open-isns/default.nix b/nixpkgs/pkgs/os-specific/linux/open-isns/default.nix
new file mode 100644
index 000000000000..21d32af3ba83
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/open-isns/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, openssl, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "open-isns-${version}";
+  version = "0.99";
+
+  src = fetchFromGitHub {
+    owner = "gonzoleeman";
+    repo = "open-isns";
+    rev = "v${version}";
+    sha256 = "0m294aiv80rkihacw5094093pc0kd5bkbxqgs6i32jsglxy33hvf";
+  };
+
+  propagatedBuildInputs = [ openssl ];
+  outputs = [ "out" "lib" ];
+  outputInclude = "lib";
+
+  configureFlags = [ "--enable-shared" ];
+
+  installFlags = "etcdir=$(out)/etc vardir=$(out)/var/lib/isns";
+  installTargets = "install install_hdrs install_lib";
+
+  meta = {
+    description = "iSNS server and client for Linux";
+    license = stdenv.lib.licenses.lgpl21;
+    homepage = https://github.com/gonzoleeman/open-isns;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/builder.sh b/nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/builder.sh
new file mode 100644
index 000000000000..cd21899e60e7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/builder.sh
@@ -0,0 +1,16 @@
+source $stdenv/setup
+
+mkdir -p $out/lib
+
+ln -s /usr/lib/libGL.so.1 $out/lib/
+ln -s /usr/lib/libGLU.so.1 $out/lib/
+ln -s /usr/lib/libGLcore.so.1 $out/lib/
+ln -s /usr/lib/tls/libnvidia-tls.so.1 $out/lib/
+#ln -s /usr/lib/libdrm.so.2 $out/lib/
+
+for i in $neededLibs; do
+    ln -s $i/lib/*.so* $out/lib/
+done
+
+
+
diff --git a/nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/default.nix b/nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/default.nix
new file mode 100644
index 000000000000..f4043f700306
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/opengl/xorg-sys/default.nix
@@ -0,0 +1,20 @@
+# This is a very dirty hack to allow hardware acceleration of OpenGL
+# applications for most (?) users.  It will use the driver that your
+# Linux distribution installed in /usr/lib/libGL.so.1.  Hopefully,
+# this driver uses hardware acceleration.
+#
+# Of course, use of the driver in /usr/lib is highly impure.  But it
+# might actually work ;-)
+
+{stdenv, xorg, expat, libdrm}:
+
+stdenv.mkDerivation {
+  name = "xorg-sys-opengl-3";
+  builder = ./builder.sh;
+  neededLibs = map (p: p.out)
+    [xorg.libXxf86vm xorg.libXext expat libdrm stdenv.cc.cc];
+
+  meta = {
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/openvswitch/default.nix b/nixpkgs/pkgs/os-specific/linux/openvswitch/default.nix
new file mode 100644
index 000000000000..a2a272f1b3a5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/openvswitch/default.nix
@@ -0,0 +1,77 @@
+{ stdenv, fetchurl, makeWrapper, pkgconfig, utillinux, which
+, procps, libcap_ng, openssl, python27 , perl
+, kernel ? null }:
+
+with stdenv.lib;
+
+let
+  _kernel = kernel;
+in stdenv.mkDerivation rec {
+  version = "2.5.4";
+  name = "openvswitch-${version}";
+
+  src = fetchurl {
+    url = "http://openvswitch.org/releases/${name}.tar.gz";
+    sha256 = "1lji87wg953lqcdf02f1zv2m54vhd2x9jd03bb91lnlb4qlhifiv";
+  };
+
+  kernel = optional (_kernel != null) _kernel.dev;
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ makeWrapper utillinux openssl libcap_ng python27
+                  perl procps which ];
+
+  configureFlags = [
+    "--localstatedir=/var"
+    "--sharedstatedir=/var"
+    "--sbindir=$(out)/bin"
+  ] ++ (optionals (_kernel != null) ["--with-linux"]);
+
+  # Leave /var out of this!
+  installFlags = [
+    "LOGDIR=$(TMPDIR)/dummy"
+    "RUNDIR=$(TMPDIR)/dummy"
+    "PKIDIR=$(TMPDIR)/dummy"
+  ];
+
+  postBuild = ''
+    # fix tests
+    substituteInPlace xenserver/opt_xensource_libexec_interface-reconfigure --replace '/usr/bin/env python' '${python27.interpreter}'
+    substituteInPlace vtep/ovs-vtep --replace '/usr/bin/env python' '${python27.interpreter}'
+  '';
+
+  enableParallelBuilding = true;
+  doCheck = false; # bash-completion test fails with "compgen: command not found"
+
+  postInstall = ''
+    cp debian/ovs-monitor-ipsec $out/share/openvswitch/scripts
+    makeWrapper \
+      $out/share/openvswitch/scripts/ovs-monitor-ipsec \
+      $out/bin/ovs-monitor-ipsec \
+      --prefix PYTHONPATH : "$out/share/openvswitch/python"
+    substituteInPlace $out/share/openvswitch/scripts/ovs-monitor-ipsec \
+      --replace "UnixctlServer.create(None)" "UnixctlServer.create(os.environ['UNIXCTLPATH'])"
+    substituteInPlace $out/share/openvswitch/scripts/ovs-monitor-ipsec \
+      --replace "self.psk_file" "root_prefix + self.psk_file"
+    substituteInPlace $out/share/openvswitch/scripts/ovs-monitor-ipsec \
+      --replace "self.cert_dir" "root_prefix + self.cert_dir"
+  '';
+
+  meta = with stdenv.lib; {
+    platforms = platforms.linux;
+    description = "A multilayer virtual switch";
+    longDescription =
+      ''
+      Open vSwitch is a production quality, multilayer virtual switch
+      licensed under the open source Apache 2.0 license. It is
+      designed to enable massive network automation through
+      programmatic extension, while still supporting standard
+      management interfaces and protocols (e.g. NetFlow, sFlow, SPAN,
+      RSPAN, CLI, LACP, 802.1ag). In addition, it is designed to
+      support distribution across multiple physical servers similar
+      to VMware's vNetwork distributed vswitch or Cisco's Nexus 1000V.
+      '';
+    homepage = http://openvswitch.org/;
+    license = licenses.asl20;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/otpw/default.nix b/nixpkgs/pkgs/os-specific/linux/otpw/default.nix
new file mode 100644
index 000000000000..a0464e1996a5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/otpw/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchurl, pam }:
+
+stdenv.mkDerivation rec {
+  name = "otpw-1.3";
+
+  src = fetchurl {
+    url = "https://www.cl.cam.ac.uk/~mgk25/download/${name}.tar.gz";
+    sha256 = "1k3hc7xbxz6hkc55kvddi3cibafwf93ivn58sy1l888d3l5dwmrk";
+  };
+
+  patchPhase = ''
+    sed -i 's/^CFLAGS.*/CFLAGS=-O2 -fPIC/' Makefile
+    sed -i -e 's,PATH=.*;,,' conf.h
+    sed -i -e '/ENTROPY_ENV/d' otpw-gen.c
+  '';
+
+  installPhase = ''
+    mkdir -p $out/bin $out/lib/security $out/share/man/man{1,8}
+    cp pam_*.so $out/lib/security
+    cp otpw-gen $out/bin
+    cp *.1 $out/share/man/man1
+    cp *.8 $out/share/man/man8
+  '';
+
+  buildInputs = [ pam ];
+
+  hardeningDisable = [ "stackprotector" ];
+
+  meta = {
+    homepage = http://www.cl.cam.ac.uk/~mgk25/otpw.html;
+    description = "A one-time password login package";
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pagemon/default.nix b/nixpkgs/pkgs/os-specific/linux/pagemon/default.nix
new file mode 100644
index 000000000000..9354811fd6f3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pagemon/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchFromGitHub, ncurses }:
+
+stdenv.mkDerivation rec {
+  name = "pagemon-${version}";
+  version = "0.01.14";
+
+  src = fetchFromGitHub {
+    sha256 = "1gkyfn1jbrs6w83sxa33csj62a6pyqqsmn92932qf7ns6y00dyk4";
+    rev = "V${version}";
+    repo = "pagemon";
+    owner = "ColinIanKing";
+  };
+
+  buildInputs = [ ncurses ];
+
+  makeFlags = [
+    "BINDIR=$(out)/bin"
+    "MANDIR=$(out)/share/man/man8"
+  ];
+
+  meta = with stdenv.lib; {
+    inherit (src.meta) homepage;
+    description = "Interactive memory/page monitor for Linux";
+    longDescription = ''
+      pagemon is an ncurses based interactive memory/page monitoring tool
+      allowing one to browse the memory map of an active running process
+      on Linux.
+      pagemon reads the PTEs of a given process and display the soft/dirty
+      activity in real time. The tool identifies the type of memory mapping
+      a page belongs to, so one can easily scan through memory looking at
+      pages of memory belonging data, code, heap, stack, anonymous mappings
+      or even swapped-out pages.
+    '';
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam/default.nix b/nixpkgs/pkgs/os-specific/linux/pam/default.nix
new file mode 100644
index 000000000000..9db581ad527d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam/default.nix
@@ -0,0 +1,66 @@
+{ stdenv, buildPackages, fetchurl, fetchpatch, flex, cracklib, db4 }:
+
+stdenv.mkDerivation rec {
+  name = "linux-pam-${version}";
+  version = "1.3.0";
+
+  src = fetchurl {
+    url = "http://www.linux-pam.org/library/Linux-PAM-${version}.tar.bz2";
+    sha256 = "1fyi04d5nsh8ivd0rn2y0z83ylgc0licz7kifbb6xxi2ylgfs6i4";
+  };
+
+  patches = stdenv.lib.optionals (stdenv.hostPlatform.libc == "musl") [
+    (fetchpatch {
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/linux-pam/fix-compat.patch?id=05a62bda8ec255d7049a2bd4cf0fdc4b32bdb2cc";
+      sha256 = "1h5yp5h2mqp1fcwiwwklyfpa69a3i03ya32pivs60fd7g5bqa7sf";
+    })
+    (fetchpatch {
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/linux-pam/libpam-fix-build-with-eglibc-2.16.patch?id=05a62bda8ec255d7049a2bd4cf0fdc4b32bdb2cc";
+      sha256 = "1ib6shhvgzinjsc603k2x1lxh9dic6qq449fnk110gc359m23j81";
+    })
+    (fetchpatch {
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/linux-pam/musl-fix-pam_exec.patch?id=05a62bda8ec255d7049a2bd4cf0fdc4b32bdb2cc";
+      sha256 = "04dx6s9d8cxl40r7m7dc4si47ds4niaqm7902y1d6wcjvs11vrf0";
+    })
+  ];
+
+  outputs = [ "out" "doc" "man" /* "modules" */ ];
+
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
+  nativeBuildInputs = [ flex ];
+
+  buildInputs = [ cracklib db4 ];
+
+  enableParallelBuilding = true;
+
+  postInstall = ''
+    mv -v $out/sbin/unix_chkpwd{,.orig}
+    ln -sv /run/wrappers/bin/unix_chkpwd $out/sbin/unix_chkpwd
+  ''; /*
+    rm -rf $out/etc
+    mkdir -p $modules/lib
+    mv $out/lib/security $modules/lib/
+  '';*/
+  # don't move modules, because libpam needs to (be able to) find them,
+  # which is done by dlopening $out/lib/security/pam_foo.so
+  # $out/etc was also missed: pam_env(login:session): Unable to open config file
+
+  preConfigure = ''
+    configureFlags="$configureFlags --includedir=$out/include/security"
+  '' + stdenv.lib.optionalString (stdenv.hostPlatform.libc == "musl") ''
+      # export ac_cv_search_crypt=no
+      # (taken from Alpine linux, apparently insecure but also doesn't build O:))
+      # disable insecure modules
+      # sed -e 's/pam_rhosts//g' -i modules/Makefile.am
+      sed -e 's/pam_rhosts//g' -i modules/Makefile.in
+  '';
+
+  doCheck = false; # fails
+
+  meta = with stdenv.lib; {
+    homepage = http://www.linux-pam.org/;
+    description = "Pluggable Authentication Modules, a flexible mechanism for authenticating user";
+    platforms = platforms.linux;
+    license = licenses.bsd3;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_ccreds/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_ccreds/default.nix
new file mode 100644
index 000000000000..8293ac0a830a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_ccreds/default.nix
@@ -0,0 +1,22 @@
+{stdenv, fetchurl, pam, openssl, db}:
+
+stdenv.mkDerivation {
+  name = "pam_ccreds-10";
+
+  src = fetchurl {
+    url = "http://www.padl.com/download/pam_ccreds.tgz";
+    sha256 = "1h7zyg1b1h69civyvrj95w22dg0y7lgw3hq4gqkdcg35w1y76fhz";
+  };
+  patchPhase = ''
+    sed 's/-o root -g root//' -i Makefile.in
+  '';
+
+  buildInputs = [ pam openssl db ];
+
+  meta = with stdenv.lib; {
+    homepage = http://www.padl.com/OSS/pam_ccreds.html;
+    description = "PAM module to locally authenticate using an enterprise identity when the network is unavailable";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_krb5/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_krb5/default.nix
new file mode 100644
index 000000000000..3b23c286e19a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_krb5/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, fetchurl, pam, kerberos }:
+
+stdenv.mkDerivation rec {
+  name = "pam-krb5-4.8";
+
+  src = fetchurl {
+    url = "https://archives.eyrie.org/software/kerberos/${name}.tar.gz";
+    sha256 = "0j96jfaxzkj1ifc3qxagjmaxvgda7ndqaaxx2ka018is9f5lbfrs";
+  };
+
+  buildInputs = [ pam kerberos ];
+
+  meta = with stdenv.lib; {
+    homepage = https://www.eyrie.org/~eagle/software/pam-krb5/;
+    description = "PAM module allowing PAM-aware applications to authenticate users by performing an AS exchange with a Kerberos KDC";
+    longDescription = ''
+      pam_krb5 can optionally convert Kerberos 5 credentials to Kerberos IV
+      credentials and/or use them to set up AFS tokens for a user's session.
+    '';
+    platforms = platforms.linux;
+    license = licenses.bsd3;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_ldap/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_ldap/default.nix
new file mode 100644
index 000000000000..5b34a8bc82b5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_ldap/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl, pam, openldap, perl }:
+
+stdenv.mkDerivation rec {
+  name = "pam_ldap-186";
+
+  src = fetchurl {
+    url = "http://www.padl.com/download/${name}.tar.gz";
+    sha256 = "0lv4f7hc02jrd2l3gqxd247qq62z11sp3fafn8lgb8ymb7aj5zn8";
+  };
+
+  postPatch = ''
+    patchShebangs ./vers_string
+    substituteInPlace vers_string --replace "cvslib.pl" "./cvslib.pl"
+  '';
+
+  preInstall = "
+    substituteInPlace Makefile --replace '-o root -g root' ''
+  ";
+
+  nativeBuildInputs = [ perl ];
+  buildInputs = [ pam openldap ];
+
+  meta = {
+    homepage = http://www.padl.com/OSS/pam_ldap.html;
+    description = "LDAP backend for PAM";
+    longDescription = ''
+      The pam_ldap module provides the means for Solaris and Linux servers and
+      workstations to authenticate against LDAP directories, and to change their
+      passwords in the directory.'';
+    license = "LGPL";
+    inherit (pam.meta) platforms;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_mount/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_mount/default.nix
new file mode 100644
index 000000000000..29ed9375c2e3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_mount/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchurl, autoconf, automake, pkgconfig, libtool, pam, libHX, libxml2, pcre, perl, openssl, cryptsetup, utillinux }:
+
+stdenv.mkDerivation rec {
+  name = "pam_mount-2.16";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/pam-mount/pam_mount/2.16/${name}.tar.xz";
+    sha256 = "1rvi4irb7ylsbhvx1cr6islm2xxw1a4b19q6z4a9864ndkm0f0mf";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ autoconf automake libtool pam libHX utillinux libxml2 pcre perl openssl cryptsetup ];
+
+  patches = [ ./insert_utillinux_path_hooks.patch ];
+
+  preConfigure = ''
+    substituteInPlace src/mtcrypt.c --replace @@NIX_UTILLINUX@@ ${utillinux}/bin
+    sh autogen.sh --prefix=$out
+    '';
+
+  makeFlags = "DESTDIR=$(out)";
+
+  # Probably a hack, but using DESTDIR and PREFIX makes everything work!
+  postInstall = ''
+    mkdir -p $out
+    cp -r $out/$out/* $out
+    rm -r $out/nix
+    '';
+
+  meta = with stdenv.lib; {
+    homepage = http://pam-mount.sourceforge.net/;
+    description = "PAM module to mount volumes for a user session";
+    maintainers = [ maintainers.tstrobel ];
+    license = with licenses; [ gpl2 gpl3 lgpl21 lgpl3 ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_mount/insert_utillinux_path_hooks.patch b/nixpkgs/pkgs/os-specific/linux/pam_mount/insert_utillinux_path_hooks.patch
new file mode 100644
index 000000000000..6d9da05da295
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_mount/insert_utillinux_path_hooks.patch
@@ -0,0 +1,30 @@
+diff -uNr pam_mount-2.15_old/src/mtcrypt.c pam_mount-2.15/src/mtcrypt.c
+--- pam_mount-2.15_old/src/mtcrypt.c	2015-07-04 16:00:12.917943336 +0200
++++ pam_mount-2.15/src/mtcrypt.c	2015-07-04 16:03:45.685302493 +0200
+@@ -534,7 +534,7 @@
+ 
+ 	/* candidate for replacement by some libmount calls, I guess. */
+ 	argk = 0;
+-	mount_args[argk++] = "mount";
++	mount_args[argk++] = "@@NIX_UTILLINUX@@/mount";
+ 	if (opt->fstype != NULL) {
+ 		mount_args[argk++] = "-t";
+ 		mount_args[argk++] = opt->fstype;
+@@ -668,7 +668,7 @@
+ 
+ 	if (!opt->no_update)
+ 		pmt_smtab_remove(mntpt, SMTABF_MOUNTPOINT);
+-	rmt_args[argk++] = "mount";
++	rmt_args[argk++] = "@@NIX_UTILLINUX@@/mount";
+ 	rmt_args[argk++] = "-o";
+ 	rmt_args[argk++] = opt->extra_opts;
+ 	rmt_args[argk++] = mntpt;
+@@ -749,7 +749,7 @@
+ 		pmt_smtab_remove(mountpoint, SMTABF_MOUNTPOINT);
+ 	pmt_cmtab_remove(mountpoint);
+ 
+-	umount_args[argk++] = "umount";
++	umount_args[argk++] = "@@NIX_UTILLINUX@@/umount";
+ 	umount_args[argk++] = "-i";
+ 	umount_args[argk++] = mountpoint;
+ 	umount_args[argk]   = NULL;
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_pgsql/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_pgsql/default.nix
new file mode 100644
index 000000000000..10856bb52c9c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_pgsql/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, pkgconfig, postgresql, libgcrypt, pam }:
+
+stdenv.mkDerivation rec {
+  name = "pam_pgsql-${version}";
+  version = "0.7.3.2";
+
+  src = fetchFromGitHub {
+    owner = "pam-pgsql";
+    repo = "pam-pgsql";
+    rev = "release-${version}";
+    sha256 = "1a68krq5m07zspdxwl1wmkr5j98zr9bdg4776kvplrsdcg97h4jk";
+  };
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ libgcrypt pam postgresql ];
+
+  meta = with stdenv.lib; {
+    description = "Support to authenticate against PostgreSQL for PAM-enabled appliations";
+    homepage = https://github.com/pam-pgsql/pam-pgsql;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/default.nix
new file mode 100644
index 000000000000..48c02be9c389
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl, pam, openssl, perl }:
+
+stdenv.mkDerivation rec {
+  name = "pam_ssh_agent_auth-0.10.3";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/pamsshagentauth/${name}.tar.bz2";
+    sha256 = "0qx78x7nvqdscyp04hfijl4rgyf64xy03prr28hipvgasrcd6lrw";
+  };
+
+  patches =
+    [ # Allow multiple colon-separated authorized keys files to be
+      # specified in the file= option.
+      ./multiple-key-files.patch
+    ];
+
+  buildInputs = [ pam openssl perl ];
+
+  enableParallelBuilding = true;
+
+  meta = {
+    homepage = http://pamsshagentauth.sourceforge.net/;
+    description = "PAM module for authentication through the SSH agent";
+    maintainers = [ stdenv.lib.maintainers.eelco ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/multiple-key-files.patch b/nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/multiple-key-files.patch
new file mode 100644
index 000000000000..190325251c9a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_ssh_agent_auth/multiple-key-files.patch
@@ -0,0 +1,365 @@
+diff -u pam_ssh_agent_auth-0.10.3-orig/iterate_ssh_agent_keys.c pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c
+--- pam_ssh_agent_auth-0.10.3-orig/iterate_ssh_agent_keys.c	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.c	2017-03-02 23:47:18.012203283 -0800
+@@ -176,7 +176,7 @@
+     return;
+ }
+ 
+-int
++const char *
+ pamsshagentauth_find_authorized_keys(const char * user, const char * ruser, const char * servicename)
+ {
+     Buffer session_id2 = { 0 };
+@@ -184,7 +184,7 @@
+     Key *key;
+     AuthenticationConnection *ac;
+     char *comment;
+-    uint8_t retval = 0;
++    const char *key_file = 0;
+     uid_t uid = getpwnam(ruser)->pw_uid;
+ 
+     OpenSSL_add_all_digests();
+@@ -199,13 +199,11 @@
+                 id->key = key;
+                 id->filename = comment;
+                 id->ac = ac;
+-                if(userauth_pubkey_from_id(ruser, id, &session_id2)) {
+-                    retval = 1;
+-                }
++                key_file = userauth_pubkey_from_id(ruser, id, &session_id2);
+                 pamsshagentauth_xfree(id->filename);
+                 pamsshagentauth_key_free(id->key);
+                 pamsshagentauth_xfree(id);
+-                if(retval == 1)
++                if(key_file)
+                     break;
+             }
+         }
+@@ -217,5 +215,5 @@
+     }
+     /* pamsshagentauth_xfree(session_id2); */
+     EVP_cleanup();
+-    return retval;
++    return key_file;
+ }
+diff -u pam_ssh_agent_auth-0.10.3-orig/iterate_ssh_agent_keys.h pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.h
+--- pam_ssh_agent_auth-0.10.3-orig/iterate_ssh_agent_keys.h	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/iterate_ssh_agent_keys.h	2017-03-02 23:48:06.345803339 -0800
+@@ -31,6 +31,6 @@
+ #ifndef _ITERATE_SSH_AGENT_KEYS_H
+ #define _ITERATE_SSH_AGENT_KEYS_H
+ 
+-int pamsshagentauth_find_authorized_keys(const char * user, const char * ruser, const char * servicename);
++const char * pamsshagentauth_find_authorized_keys(const char * user, const char * ruser, const char * servicename);
+ 
+ #endif
+diff -u pam_ssh_agent_auth-0.10.3-orig/pam_ssh_agent_auth.c pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c
+--- pam_ssh_agent_auth-0.10.3-orig/pam_ssh_agent_auth.c	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.c	2017-03-02 23:51:57.642669946 -0800
+@@ -61,7 +61,6 @@
+ #define strncasecmp_literal(A,B) strncasecmp( A, B, sizeof(B) - 1)
+ #define UNUSED(expr) do { (void)(expr); } while (0)
+ 
+-char           *authorized_keys_file = NULL;
+ uint8_t         allow_user_owned_authorized_keys_file = 0;
+ char           *authorized_keys_command = NULL;
+ char           *authorized_keys_command_user = NULL;
+@@ -171,15 +170,13 @@
+         goto cleanexit;
+     }
+ 
+-    if(authorized_keys_file_input && user) {
+-        /*
+-         * user is the name of the target-user, and so must be used for validating the authorized_keys file
+-         */
+-        parse_authorized_key_file(user, authorized_keys_file_input);
+-    } else {
+-        pamsshagentauth_verbose("Using default file=/etc/security/authorized_keys");
+-        authorized_keys_file = pamsshagentauth_xstrdup("/etc/security/authorized_keys");
+-    }
++    if (!authorized_keys_file_input || !user)
++        authorized_keys_file_input = "/etc/security/authorized_keys";
++
++    /*
++     * user is the name of the target-user, and so must be used for validating the authorized_keys file
++     */
++    parse_authorized_key_files(user, authorized_keys_file_input);
+ 
+     /*
+      * PAM_USER and PAM_RUSER do not necessarily have to get set by the calling application, and we may be unable to divine the latter.
+@@ -187,16 +184,17 @@
+      */
+ 
+     if(user && strlen(ruser) > 0) {
+-        pamsshagentauth_verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
++        pamsshagentauth_verbose("Attempting authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file_input);
+ 
+         /*
+          * this pw_uid is used to validate the SSH_AUTH_SOCK, and so must be the uid of the ruser invoking the program, not the target-user
+          */
+-        if(pamsshagentauth_find_authorized_keys(user, ruser, servicename)) { /* getpwnam(ruser)->pw_uid)) { */
+-            pamsshagentauth_logit("Authenticated: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
++        const char *key_file;
++        if((key_file = pamsshagentauth_find_authorized_keys(user, ruser, servicename))) { /* getpwnam(ruser)->pw_uid)) { */
++            pamsshagentauth_logit("Authenticated: `%s' as `%s' using %s", ruser, user, key_file);
+             retval = PAM_SUCCESS;
+         } else {
+-            pamsshagentauth_logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file);
++            pamsshagentauth_logit("Failed Authentication: `%s' as `%s' using %s", ruser, user, authorized_keys_file_input);
+         }
+     } else {
+         pamsshagentauth_logit("No %s specified, cannot continue with this form of authentication", (user) ? "ruser" : "user" );
+@@ -208,7 +206,7 @@
+     free(__progname);
+ #endif
+ 
+-    free(authorized_keys_file);
++    free_authorized_key_files();
+ 
+     return retval;
+ }
+diff -u pam_ssh_agent_auth-0.10.3-orig/pam_ssh_agent_auth.pod pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.pod
+--- pam_ssh_agent_auth-0.10.3-orig/pam_ssh_agent_auth.pod	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/pam_ssh_agent_auth.pod	2017-03-02 23:52:28.914857449 -0800
+@@ -31,7 +31,7 @@
+ 
+ =item file=<path to authorized_keys>
+ 
+-Specify the path to the authorized_keys file(s) you would like to use for authentication. Subject to tilde and % EXPANSIONS (below) 
++Specify the path(s) to the authorized_keys file(s) you would like to use for authentication. Subject to tilde and % EXPANSIONS (below). Paths are separated using colons.
+ 
+ =item allow_user_owned_authorized_keys_file
+ 
+diff -u pam_ssh_agent_auth-0.10.3-orig/pam_user_authorized_keys.c pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c
+--- pam_ssh_agent_auth-0.10.3-orig/pam_user_authorized_keys.c	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.c	2017-03-03 00:07:45.201322570 -0800
+@@ -79,8 +79,12 @@
+ 
+ #include "identity.h"
+ #include "pam_user_key_allowed2.h"
++#include "pam_user_authorized_keys.h"
+ 
+-extern char *authorized_keys_file;
++#define MAX_AUTHORIZED_KEY_FILES 16
++
++char *authorized_keys_files[MAX_AUTHORIZED_KEY_FILES];
++unsigned int nr_authorized_keys_files = 0;
+ 
+ extern char *authorized_keys_command;
+ 
+@@ -91,79 +95,88 @@
+ uid_t authorized_keys_file_allowed_owner_uid;
+ 
+ void
+-parse_authorized_key_file(const char *user,
+-                          const char *authorized_keys_file_input)
++parse_authorized_key_files(const char *user,
++                           const char *authorized_keys_file_input)
+ {
+-    char fqdn[HOST_NAME_MAX] = "";
++    const char *pos = authorized_keys_file_input;
+     char hostname[HOST_NAME_MAX] = "";
+-    char auth_keys_file_buf[4096] = "";
+-    char *slash_ptr = NULL;
+-    char owner_uname[128] = "";
+-    size_t owner_uname_len = 0;
+-
+-    /* 
+-     * temporary copy, so that both tilde expansion and percent expansion both
+-     * get to apply to the path
+-     */
+-    strncat(auth_keys_file_buf, authorized_keys_file_input,
+-            sizeof(auth_keys_file_buf) - 1);
++    char fqdn[HOST_NAME_MAX] = "";
+ 
+-    if(allow_user_owned_authorized_keys_file)
+-        authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
++#if HAVE_GETHOSTNAME
++    *hostname = '\0';
++    gethostname(fqdn, HOST_NAME_MAX);
++    strncat(hostname, fqdn, strcspn(fqdn,"."));
++#endif
+ 
+-    if(*auth_keys_file_buf == '~') {
+-        if(*(auth_keys_file_buf + 1) == '/') {
+-            authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
++    while (pos) {
++        const char *colon = strchr(pos, ':');
++        char auth_keys_file_buf[4096] = "";
++        char *slash_ptr = NULL;
++        char owner_uname[128] = "";
++        size_t owner_uname_len = 0;
++
++        strncat(auth_keys_file_buf, pos, sizeof(auth_keys_file_buf) - 1);
++        if (colon) {
++            auth_keys_file_buf[colon - pos] = 0;
++            pos = colon + 1;
+         } else {
+-            slash_ptr = strchr(auth_keys_file_buf, '/');
+-            if(!slash_ptr)
+-                pamsshagentauth_fatal
+-                    ("cannot expand tilde in path without a `/'");
+-
+-            owner_uname_len = slash_ptr - auth_keys_file_buf - 1;
+-            if(owner_uname_len > (sizeof(owner_uname) - 1))
+-                pamsshagentauth_fatal("Username too long");
+-
+-            strncat(owner_uname, auth_keys_file_buf + 1, owner_uname_len);
+-            if(!authorized_keys_file_allowed_owner_uid)
+-                authorized_keys_file_allowed_owner_uid =
+-                    getpwnam(owner_uname)->pw_uid;
++            pos = 0;
++        }
++
++        if(allow_user_owned_authorized_keys_file)
++            authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
++
++        if(*auth_keys_file_buf == '~') {
++            if(*(auth_keys_file_buf+1) == '/') {
++                authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
++            }
++            else {
++                slash_ptr = strchr(auth_keys_file_buf,'/');
++                if(!slash_ptr)
++                    pamsshagentauth_fatal("cannot expand tilde in path without a `/'");
++
++                owner_uname_len = slash_ptr - auth_keys_file_buf - 1;
++                if(owner_uname_len > (sizeof(owner_uname) - 1) )
++                    pamsshagentauth_fatal("Username too long");
++
++                strncat(owner_uname, auth_keys_file_buf + 1, owner_uname_len);
++                if(!authorized_keys_file_allowed_owner_uid)
++                    authorized_keys_file_allowed_owner_uid = getpwnam(owner_uname)->pw_uid;
++            }
++            char *tmp = pamsshagentauth_tilde_expand_filename(auth_keys_file_buf, authorized_keys_file_allowed_owner_uid);
++            strncpy(auth_keys_file_buf, tmp, sizeof(auth_keys_file_buf) - 1 );
++            pamsshagentauth_xfree(tmp);
+         }
+-        authorized_keys_file =
+-            pamsshagentauth_tilde_expand_filename(auth_keys_file_buf,
+-                                                  authorized_keys_file_allowed_owner_uid);
+-        strncpy(auth_keys_file_buf, authorized_keys_file,
+-                sizeof(auth_keys_file_buf) - 1);
+-        pamsshagentauth_xfree(authorized_keys_file)        /* when we
+-                                                              percent_expand
+-                                                              later, we'd step
+-                                                              on this, so free
+-                                                              it immediately */ ;
+-    }
+ 
+-    if(strstr(auth_keys_file_buf, "%h")) {
+-        authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
++        if(strstr(auth_keys_file_buf, "%h")) {
++            authorized_keys_file_allowed_owner_uid = getpwnam(user)->pw_uid;
++        }
++
++        if (nr_authorized_keys_files >= MAX_AUTHORIZED_KEY_FILES)
++            pamsshagentauth_fatal("Too many authorized key files");
++        authorized_keys_files[nr_authorized_keys_files++] =
++            pamsshagentauth_percent_expand(auth_keys_file_buf, "h", getpwnam(user)->pw_dir, "H", hostname, "f", fqdn, "u", user, NULL);
+     }
+-#if HAVE_GETHOSTNAME
+-    *hostname = '\0';
+-    gethostname(fqdn, HOST_NAME_MAX);
+-    strncat(hostname, fqdn, strcspn(fqdn, "."));
+-#endif
+-    authorized_keys_file =
+-        pamsshagentauth_percent_expand(auth_keys_file_buf, "h",
+-                                       getpwnam(user)->pw_dir, "H", hostname,
+-                                       "f", fqdn, "u", user, NULL);
+ }
+ 
+-int
++void
++free_authorized_key_files()
++{
++    unsigned int n;
++    for (n = 0; n < nr_authorized_keys_files; n++)
++        free(authorized_keys_files[n]);
++    nr_authorized_keys_files = 0;
++}
++
++const char *
+ pam_user_key_allowed(const char *ruser, Key * key)
+ {
+-    return
+-        pamsshagentauth_user_key_allowed2(getpwuid(authorized_keys_file_allowed_owner_uid),
+-                                          key, authorized_keys_file)
+-        || pamsshagentauth_user_key_allowed2(getpwuid(0), key,
+-                                             authorized_keys_file)
+-        || pamsshagentauth_user_key_command_allowed2(authorized_keys_command,
+-                                                     authorized_keys_command_user,
+-                                                     getpwnam(ruser), key);
++    unsigned int n;
++    for (n = 0; n < nr_authorized_keys_files; n++) {
++        if (pamsshagentauth_user_key_allowed2(getpwuid(authorized_keys_file_allowed_owner_uid), key, authorized_keys_files[n])
++            || pamsshagentauth_user_key_allowed2(getpwuid(0), key, authorized_keys_files[n])
++            || pamsshagentauth_user_key_command_allowed2(authorized_keys_command, authorized_keys_command_user, getpwnam(ruser), key))
++            return authorized_keys_files[n];
++    }
++    return 0;
+ }
+diff -u pam_ssh_agent_auth-0.10.3-orig/pam_user_authorized_keys.h pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.h
+--- pam_ssh_agent_auth-0.10.3-orig/pam_user_authorized_keys.h	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/pam_user_authorized_keys.h	2017-03-03 00:09:17.256064914 -0800
+@@ -28,11 +28,12 @@
+  */
+ 
+ 
+-#ifndef _PAM_USER_KEY_ALLOWED_H
+-#define _PAM_USER_KEY_ALLOWED_H
++#ifndef _PAM_USER_AUTHORIZED_KEYS_H
++#define _PAM_USER_AUTHORIZED_KEYS_H
+ 
+ #include "identity.h"
+-int pam_user_key_allowed(const char *, Key *);
+-void parse_authorized_key_file(const char *, const char *);
++const char * pam_user_key_allowed(const char *, Key *);
++void parse_authorized_key_files(const char *, const char *);
++void free_authorized_key_files();
+ 
+ #endif
+diff -u pam_ssh_agent_auth-0.10.3-orig/userauth_pubkey_from_id.c pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c
+--- pam_ssh_agent_auth-0.10.3-orig/userauth_pubkey_from_id.c	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.c	2017-03-03 00:10:33.163545380 -0800
+@@ -52,7 +52,7 @@
+ extern uint8_t  session_id_len;
+  */
+ 
+-int
++const char *
+ userauth_pubkey_from_id(const char *ruser, Identity * id, Buffer * session_id2)
+ {
+     Buffer          b = { 0 };
+@@ -60,11 +60,12 @@
+     u_char         *pkblob = NULL, *sig = NULL;
+     u_int           blen = 0, slen = 0;
+     int             authenticated = 0;
++    const char     *key_file;
+ 
+     pkalg = (char *) key_ssh_name(id->key);
+ 
+     /* first test if this key is even allowed */
+-    if(! pam_user_key_allowed(ruser, id->key))
++    if(!(key_file = pam_user_key_allowed(ruser, id->key)))
+         goto user_auth_clean_exit;
+ 
+     if(pamsshagentauth_key_to_blob(id->key, &pkblob, &blen) == 0)
+@@ -97,5 +98,5 @@
+     if(pkblob != NULL)
+         pamsshagentauth_xfree(pkblob);
+     CRYPTO_cleanup_all_ex_data();
+-    return authenticated;
++    return authenticated ? key_file : 0;
+ }
+diff -u pam_ssh_agent_auth-0.10.3-orig/userauth_pubkey_from_id.h pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.h
+--- pam_ssh_agent_auth-0.10.3-orig/userauth_pubkey_from_id.h	2016-11-12 19:24:32.000000000 -0800
++++ pam_ssh_agent_auth-0.10.3/userauth_pubkey_from_id.h	2017-03-03 00:10:59.067046872 -0800
+@@ -32,6 +32,6 @@
+ #define _USERAUTH_PUBKEY_FROM_ID_H
+ 
+ #include <identity.h>
+-int userauth_pubkey_from_id(const char *, Identity *, Buffer *);
++const char * userauth_pubkey_from_id(const char *, Identity *, Buffer *);
+ 
+ #endif
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_u2f/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_u2f/default.nix
new file mode 100644
index 000000000000..58e3f79d42b2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_u2f/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchurl, pkgconfig, libu2f-host, libu2f-server, pam }:
+
+stdenv.mkDerivation rec {
+  name    = "pam_u2f-${version}";
+  version = "1.0.7";
+
+  src     = fetchurl {
+    url = "https://developers.yubico.com/pam-u2f/Releases/${name}.tar.gz";
+    sha256 = "1kz7d3vr5dag1d5zq14kcp887p5d0q079dy1sqyl8ndi567asjh3";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ libu2f-host libu2f-server pam ];
+
+  # Fix the broken include in 1.0.1
+  CFLAGS = "-I${libu2f-host}/include/u2f-host";
+
+  preConfigure = ''
+    configureFlagsArray+=("--with-pam-dir=$out/lib/security")
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://developers.yubico.com/pam-u2f/;
+    description = "A PAM module for allowing authentication with a U2F device";
+    license = licenses.bsd2;
+    platforms = platforms.unix;
+    maintainers = with maintainers; [ philandstuff ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pam_usb/default.nix b/nixpkgs/pkgs/os-specific/linux/pam_usb/default.nix
new file mode 100644
index 000000000000..9b9157255142
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pam_usb/default.nix
@@ -0,0 +1,76 @@
+{ stdenv, fetchurl, makeWrapper, dbus, libxml2, pam, pkgconfig, pmount, pythonPackages, writeScript, runtimeShell }:
+
+let
+
+  # Search in the environment if the same program exists with a set uid or
+  # set gid bit.  If it exists, run the first program found, otherwise run
+  # the default binary.
+  useSetUID = drv: path:
+    let
+      name = baseNameOf path;
+      bin = "${drv}${path}";
+    in assert name != "";
+      writeScript "setUID-${name}" ''
+        #!${runtimeShell}
+        inode=$(stat -Lc %i ${bin})
+        for file in $(type -ap ${name}); do
+          case $(stat -Lc %a $file) in
+            ([2-7][0-7][0-7][0-7])
+              if test -r "$file".real; then
+                orig=$(cat "$file".real)
+                if test $inode = $(stat -Lc %i "$orig"); then
+                  exec "$file" "$@"
+                fi
+              fi;;
+          esac
+        done
+        exec ${bin} "$@"
+      '';
+
+  pmountBin = useSetUID pmount "/bin/pmount";
+  pumountBin = useSetUID pmount "/bin/pumount";
+  inherit (pythonPackages) python dbus-python;
+in
+
+stdenv.mkDerivation rec {
+  name = "pam_usb-0.5.0";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/pamusb/${name}.tar.gz";
+    sha256 = "1g1w0s9d8mfld8abrn405ll5grv3xgs0b0hsganrz6qafdq9j7q1";
+  };
+
+  buildInputs = [
+    makeWrapper
+    # pam_usb dependencies
+    dbus libxml2 pam pmount pkgconfig
+    # pam_usb's tools dependencies
+    python
+    # cElementTree is included with python 2.5 and later.
+  ];
+
+  preBuild = ''
+    makeFlagsArray=(DESTDIR=$out)
+    substituteInPlace ./src/volume.c \
+      --replace 'pmount' '${pmountBin}' \
+      --replace 'pumount' '${pumountBin}'
+  '';
+
+  # pmount is append to the PATH because pmounts binaries should have a set uid bit.
+  postInstall = ''
+    mv $out/usr/* $out/. # fix color */
+    rm -rf $out/usr
+    for prog in $out/bin/pamusb-conf $out/bin/pamusb-agent; do
+      substituteInPlace $prog --replace '/usr/bin/env python' '/bin/python'
+      wrapProgram $prog \
+        --prefix PYTHONPATH : "$(toPythonPath ${dbus-python})"
+    done
+  '';
+
+  meta = {
+    homepage = http://pamusb.org/;
+    description = "Authentication using USB Flash Drives";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pax-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/pax-utils/default.nix
new file mode 100644
index 000000000000..5de0081a411c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pax-utils/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "pax-utils-${version}";
+  version = "1.2.2";
+
+  src = fetchurl {
+    url = "https://dev.gentoo.org/~vapier/dist/${name}.tar.xz";
+    sha512 = "26f7lqr1s2iywj8qfbf24sm18bl6f7cwsf77nxwwvgij1z88gvh6yx3gp65zap92l0xjdp8kwq9y96xld39p86zd9dmkm447czykbvb";
+  };
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  meta = with stdenv.lib; {
+    description = "ELF utils that can check files for security relevant properties";
+    longDescription = ''
+      A suite of ELF tools to aid auditing systems. Contains
+      various ELF related utils for ELF32, ELF64 binaries useful
+      for displaying PaX and security info on a large groups of
+      binary files.
+    '';
+    homepage = https://wiki.gentoo.org/wiki/Hardened/PaX_Utilities;
+    license = licenses.gpl2;
+    platforms = platforms.unix;
+    maintainers = with maintainers; [ thoughtpolice joachifm ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/paxctl/default.nix b/nixpkgs/pkgs/os-specific/linux/paxctl/default.nix
new file mode 100644
index 000000000000..8fdd2356c30d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/paxctl/default.nix
@@ -0,0 +1,34 @@
+{ fetchurl, stdenv, elf-header }:
+
+stdenv.mkDerivation rec {
+  name = "paxctl-${version}";
+  version = "0.9";
+
+  src = fetchurl {
+    url = "https://pax.grsecurity.net/${name}.tar.gz";
+    sha256 = "0biw882fp1lmgs6kpxznp1v6758r7dg9x8iv5a06k0b82bcdsc53";
+  };
+
+  buildInputs = [ elf-header ];
+
+  preBuild = ''
+    sed -i Makefile \
+      -e 's|--owner 0 --group 0||g' \
+      -e '/CC:=gcc/d'
+  '';
+
+  makeFlags = [
+    "DESTDIR=$(out)"
+    "MANDIR=share/man/man1"
+  ];
+
+  setupHook = ./setup-hook.sh;
+
+  meta = with stdenv.lib; {
+    description = "A tool for controlling PaX flags on a per binary basis";
+    homepage    = "https://pax.grsecurity.net";
+    license     = licenses.gpl2;
+    platforms   = platforms.all;
+    maintainers = with maintainers; [ thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/paxctl/setup-hook.sh b/nixpkgs/pkgs/os-specific/linux/paxctl/setup-hook.sh
new file mode 100644
index 000000000000..11a6bb9910f9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/paxctl/setup-hook.sh
@@ -0,0 +1,8 @@
+# PaX-mark binaries.
+paxmark() {
+    local flags="$1"
+    shift
+
+    paxctl -c "$@"
+    paxctl -zex -${flags} "$@"
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/paxtest/default.nix b/nixpkgs/pkgs/os-specific/linux/paxtest/default.nix
new file mode 100644
index 000000000000..c1500e51ac37
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/paxtest/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, paxctl }:
+
+stdenv.mkDerivation rec {
+  name    = "paxtest-${version}";
+  version = "0.9.15";
+
+  src = fetchurl {
+    url    = "https://www.grsecurity.net/~spender/${name}.tar.gz";
+    sha256 = "0zv6vlaszlik98gj9200sv0irvfzrvjn46rnr2v2m37x66288lym";
+  };
+
+  enableParallelBuilding = true;
+
+  makefile     = "Makefile.psm";
+  makeFlags    = [ "PAXBIN=${paxctl}/bin/paxctl" "BINDIR=$(out)/bin" "RUNDIR=$(out)/lib/paxtest" ];
+  installFlags = ''DESTDIR=""'';
+
+  meta = with stdenv.lib; {
+    description = "Test various memory protection measures";
+    license     = licenses.gpl2;
+    platforms   = platforms.linux;
+    maintainers = with maintainers; [ copumpkin joachifm ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pcm/default.nix b/nixpkgs/pkgs/os-specific/linux/pcm/default.nix
new file mode 100644
index 000000000000..43810210a88b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pcm/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  version = "201710";
+  name = "pcm-${version}";
+
+  src = fetchFromGitHub {
+    owner = "opcm";
+    repo = "pcm";
+    rev = "${version}";
+    sha256 = "02rq8739zwwbfrhagvcgf6qpmnswxl9b0qsld26rg6zp91v2npbj";
+  };
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp pcm*.x $out/bin
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Processor counter monitor";
+    homepage = https://www.intel.com/software/pcm;
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ roosemberth ];
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pcmciautils/default.nix b/nixpkgs/pkgs/os-specific/linux/pcmciautils/default.nix
new file mode 100644
index 000000000000..aeb4d78d0ec4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pcmciautils/default.nix
@@ -0,0 +1,55 @@
+{ config, lib, stdenv, fetchurl
+, yacc, flex
+, sysfsutils, kmod, udev
+, firmware   ? config.pcmciaUtils.firmware or [] # Special pcmcia cards.
+, configOpts ? config.pcmciaUtils.config or null # Special hardware (map memory & port & irq)
+}:                   # used to generate postInstall script.
+
+# FIXME: should add an option to choose between hotplug and udev.
+stdenv.mkDerivation rec {
+  name = "pcmciautils-018";
+
+  src = fetchurl {
+    url = "https://kernel.org/pub/linux/utils/kernel/pcmcia/${name}.tar.gz";
+    sha256 = "0sfm3w2n73kl5w7gb1m6q8gy5k4rgwvzz79n6yhs9w3sag3ix8sk";
+  };
+
+  buildInputs = [udev yacc sysfsutils kmod flex];
+
+  patchPhase = ''
+    sed -i "
+      s,/sbin/modprobe,${kmod}&,;
+      s,/lib/udev/,$out/sbin/,;
+    " udev/* # fix-color */
+    sed -i "
+      s,/lib/firmware,$out&,;
+      s,/etc/pcmcia,$out&,;
+    " src/{startup.c,pcmcia-check-broken-cis.c} # fix-color */
+  ''
+  + (if firmware == [] then ''sed -i "s,STARTUP = true,STARTUP = false," Makefile'' else "")
+  + (if configOpts == null then "" else ''
+    ln -sf ${configOpts} ./config/config.opts'')
+  ;
+
+  makeFlags = "LEX=flex";
+  installFlags = ''INSTALL=install DESTDIR=''${out}'';
+  postInstall =
+    lib.concatMapStrings (path: ''
+      for f in : $(find ${path} -type f); do
+        test "$f" == ":" && continue;
+        mkdir -p $(dirname $out/lib/firmware/$\{f#${path}});
+        ln -s $f $out/lib/firmware/$\{f#${path}};
+      done;
+    '') firmware;
+
+  meta = {
+    homepage = https://www.kernel.org/pub/linux/utils/kernel/pcmcia/;
+    longDescription = "
+      PCMCIAutils contains the initialization tools necessary to allow
+      the PCMCIA subsystem to behave (almost) as every other
+      hotpluggable bus system.
+    ";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/perf-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/perf-tools/default.nix
new file mode 100644
index 000000000000..ee12251ae5e3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/perf-tools/default.nix
@@ -0,0 +1,44 @@
+{ lib, stdenv, fetchFromGitHub, perl }:
+
+stdenv.mkDerivation {
+  name = "perf-tools-20171219";
+
+  src = fetchFromGitHub {
+    owner = "brendangregg";
+    repo = "perf-tools";
+    rev = "98d42a2a1493d2d1c651a5c396e015d4f082eb20";
+    sha256 = "09qnss9pd4kr6qadvp62m2g8sfrj86fksi1rr8m8w4314pzfb93c";
+  };
+
+  buildInputs = [ perl ];
+
+  patchPhase =
+    ''
+      for i in execsnoop iolatency iosnoop kernel/funcslower killsnoop opensnoop; do
+        substituteInPlace $i \
+          --replace /usr/bin/gawk "$(type -p gawk)" \
+          --replace /usr/bin/mawk /no-such-path \
+          --replace /usr/bin/getconf "$(type -p getconf)" \
+          --replace awk=awk "awk=$(type -p gawk)"
+      done
+
+      rm -rf examples deprecated
+    '';
+
+  installPhase =
+    ''
+      d=$out/libexec/perf-tools
+      mkdir -p $d $out/share
+      cp -prvd . $d/
+      ln -s $d/bin $out/bin
+      mv $d/man $out/share/
+    '';
+
+  meta = with stdenv.lib; {
+    platforms = platforms.linux;
+    homepage = https://github.com/brendangregg/perf-tools;
+    description = "Performance analysis tools based on Linux perf_events (aka perf) and ftrace";
+    maintainers = [ maintainers.eelco ];
+    license = licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pflask/default.nix b/nixpkgs/pkgs/os-specific/linux/pflask/default.nix
new file mode 100644
index 000000000000..1155a793b014
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pflask/default.nix
@@ -0,0 +1,23 @@
+{ lib, stdenv, fetchurl, python, wafHook }:
+
+stdenv.mkDerivation rec {
+  name = "pflask-${version}";
+  version = "git-2015-12-17";
+  rev = "599418bb6453eaa0ccab493f9411f13726c1a636";
+
+  src = fetchurl {
+    url = "https://github.com/ghedo/pflask/archive/${rev}.tar.gz";
+    sha256 = "2545fca37f9da484b46b6fb5e3a9bbba6526a9725189fe4af5227ef6e6fca440";
+  };
+
+  nativeBuildInputs = [ wafHook ];
+  buildInputs = [ python ];
+
+  meta = {
+    description = "Lightweight process containers for Linux";
+    homepage    = "https://ghedo.github.io/pflask/";
+    license     = lib.licenses.bsd2;
+    platforms   = lib.platforms.linux;
+    maintainers = with lib.maintainers; [ ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/phc-intel/default.nix b/nixpkgs/pkgs/os-specific/linux/phc-intel/default.nix
new file mode 100644
index 000000000000..75fce129e934
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/phc-intel/default.nix
@@ -0,0 +1,53 @@
+{ stdenv, fetchurl, kernel, which }:
+
+# Don't bother with older versions, though some might even work:
+assert stdenv.lib.versionAtLeast kernel.version "4.10";
+
+let
+  release = "0.4.0";
+  revbump = "rev25"; # don't forget to change forum download id...
+in stdenv.mkDerivation rec {
+  name = "linux-phc-intel-${version}-${kernel.version}";
+  version = "${release}-${revbump}";
+
+  src = fetchurl {
+    sha256 = "1w91hpphd8i0br7g5qra26jdydqar45zqwq6jq8yyz6l0vb10zlz";
+    url = "http://www.linux-phc.org/forum/download/file.php?id=194";
+    name = "phc-intel-pack-${revbump}.tar.bz2";
+  };
+
+  nativeBuildInputs = [ which ] ++ kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  makeFlags = with kernel; [
+    "DESTDIR=$(out)"
+    "KERNELSRC=${dev}/lib/modules/${modDirVersion}/build"
+  ];
+
+  configurePhase = ''
+    make $makeFlags brave
+  '';
+
+  enableParallelBuilding = false;
+
+  installPhase = ''
+    install -m 755   -d $out/lib/modules/${kernel.modDirVersion}/extra/
+    install -m 644 *.ko $out/lib/modules/${kernel.modDirVersion}/extra/
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Undervolting kernel driver for Intel processors";
+    longDescription = ''
+      PHC is a Linux kernel patch to undervolt processors. This can divide the
+      power consumption of the CPU by two or more, increasing battery life
+      while noticably reducing fan noise. This driver works only on supported
+      Intel architectures.
+    '';
+    homepage = http://www.linux-phc.org/;
+    downloadPage = "http://www.linux-phc.org/forum/viewtopic.php?f=7&t=267";
+    license = licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    broken = stdenv.lib.versionAtLeast kernel.version "4.18";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/piper/default.nix b/nixpkgs/pkgs/os-specific/linux/piper/default.nix
new file mode 100644
index 000000000000..e177b284bbda
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/piper/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, meson, ninja, pkgconfig, gettext, fetchFromGitHub, python3
+, wrapGAppsHook, gtk3, glib, desktop-file-utils, appstream-glib, gnome3
+, gobject-introspection }:
+
+python3.pkgs.buildPythonApplication rec {
+  pname = "piper";
+  version = "0.2.903";
+
+  format = "other";
+
+  src = fetchFromGitHub {
+    owner  = "libratbag";
+    repo   = "piper";
+    rev    =  version;
+    sha256 = "0zh4lm074x5gwvx663bapdyv8lf84yjwfg8cpf77rszyja1hx13a";
+  };
+
+  nativeBuildInputs = [ meson ninja gettext pkgconfig wrapGAppsHook desktop-file-utils appstream-glib gobject-introspection ];
+  buildInputs = [ gtk3 glib gnome3.adwaita-icon-theme python3 ];
+  propagatedBuildInputs = with python3.pkgs; [ lxml evdev pygobject3 ];
+
+  postPatch = ''
+    chmod +x meson_install.sh # patchShebangs requires executable file
+    patchShebangs meson_install.sh
+  '';
+
+  meta = with stdenv.lib; {
+    description = "GTK frontend for ratbagd mouse config daemon";
+    homepage    = https://github.com/libratbag/piper;
+    license     = licenses.gpl2;
+    maintainers = with maintainers; [ mvnetbiz ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pipework/default.nix b/nixpkgs/pkgs/os-specific/linux/pipework/default.nix
new file mode 100644
index 000000000000..523f7382a2cf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pipework/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, lib, fetchFromGitHub, makeWrapper
+, bridge-utils, iproute, lxc, openvswitch, docker, busybox, dhcpcd, dhcp
+}:
+
+stdenv.mkDerivation rec {
+  name = "pipework-${version}";
+  version = "2017-08-22";
+  src = fetchFromGitHub {
+    owner = "jpetazzo";
+    repo = "pipework";
+    rev = "ae42f1b5fef82b3bc23fe93c95c345e7af65fef3";
+    sha256 = "0c342m0bpq6ranr7dsxk9qi5mg3j5aw9wv85ql8gprdb2pz59qy8";
+  };
+  buildInputs = [ makeWrapper ];
+  installPhase = ''
+    install -D pipework $out/bin/pipework
+    wrapProgram $out/bin/pipework --prefix PATH : \
+      ${lib.makeBinPath [ bridge-utils iproute lxc openvswitch docker busybox dhcpcd dhcp ]};
+  '';
+  meta = with lib; {
+    description = "Software-Defined Networking tools for LXC";
+    homepage = https://github.com/jpetazzo/pipework;
+    license = licenses.asl20;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ cstrahan ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pktgen/default.nix b/nixpkgs/pkgs/os-specific/linux/pktgen/default.nix
new file mode 100644
index 000000000000..a7bb4a81510d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pktgen/default.nix
@@ -0,0 +1,64 @@
+{ stdenv, lib, fetchurl, pkgconfig
+, dpdk, libpcap, numactl, utillinux
+, gtk2, withGtk ? false
+}:
+
+let
+
+  # pktgen needs a specific version of lua to apply its patch (see lib/lua/Makefile).
+  lua = rec {
+    name = "lua-5.3.4";
+    basename = name + ".tar.gz";
+    src = fetchurl {
+      url = "https://www.lua.org/ftp/${basename}";
+      sha256 = "0320a8dg3aci4hxla380dx1ifkw8gj4gbw5c4dz41g1kh98sm0gn";
+    };
+  };
+
+in stdenv.mkDerivation rec {
+  name = "pktgen-${version}";
+  version = "3.5.0";
+
+  src = fetchurl {
+    url = "http://dpdk.org/browse/apps/pktgen-dpdk/snapshot/pktgen-${version}.tar.xz";
+    sha256 = "1gy99jr9dbwzi9pd3w5k673h3pfnbkz6rbzmrkwcyis72pnphy5z";
+  };
+
+  nativeBuildInputs = stdenv.lib.optionals withGtk [ pkgconfig ];
+
+  buildInputs =
+    [ dpdk libpcap numactl ]
+    ++ stdenv.lib.optionals withGtk [gtk2];
+
+  RTE_SDK = "${dpdk}/share/dpdk";
+  RTE_TARGET = "x86_64-native-linuxapp-gcc";
+  GUI = stdenv.lib.optionalString withGtk "true";
+
+  NIX_CFLAGS_COMPILE = [ "-msse3" ];
+
+  postPatch = let dpdkMajor = lib.versions.major dpdk.version; in ''
+    substituteInPlace app/Makefile --replace 'yy :=' 'yy := ${dpdkMajor} #'
+    substituteInPlace lib/common/lscpu.h --replace /usr/bin/lscpu ${utillinux}/bin/lscpu
+
+    ln -s ${lua.src} lib/lua/${lua.basename}
+    make -C lib/lua get_tarball # unpack and patch
+    substituteInPlace lib/lua/${lua.name}/src/luaconf.h --replace /usr/local $out
+  '';
+
+  installPhase = ''
+    install -d $out/bin
+    install -m 0755 app/${RTE_TARGET}/pktgen $out/bin
+    install -d $out/lib/lua/5.3
+    install -m 0644 Pktgen.lua $out/lib/lua/5.3
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "Traffic generator powered by DPDK";
+    homepage = http://dpdk.org/;
+    license = licenses.bsdOriginal;
+    platforms =  [ "x86_64-linux" ];
+    maintainers = [ maintainers.abuibrahim ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/ply/default.nix b/nixpkgs/pkgs/os-specific/linux/ply/default.nix
new file mode 100644
index 000000000000..43f184f384dd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/ply/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, kernel, fetchFromGitHub, autoreconfHook, yacc, flex, p7zip }:
+
+assert kernel != null -> stdenv.lib.versionAtLeast kernel.version "4.0";
+
+let
+  version = "1.0.beta1-9e810b1";
+in stdenv.mkDerivation {
+  name = "ply-${version}";
+  nativeBuildInputs = [ autoreconfHook flex yacc p7zip ];
+
+  src = fetchFromGitHub {
+    owner = "iovisor";
+    repo = "ply";
+    rev = "9e810b157ba079c32c430a7d4c6034826982056e";
+    sha256 = "15cp6iczawaqlhsa0af6i37zn5iq53kh6ya8s2hzd018yd7mhg50";
+  };
+
+  preAutoreconf = ''
+    # If kernel sources are a folder (i.e. fetched from git), we just copy them in
+    # Since they are owned by uid 0 and read-only, we need to fix permissions
+    if [ -d ${kernel.src} ]; then
+      cp -r ${kernel.src} linux-${kernel.version}
+      chown -R $(whoami): linux-${kernel.version}
+      chmod -R a+w linux-${kernel.version}
+    else
+      # ply wants to install header files to its build directory
+      # use 7z to handle multiple archive formats transparently
+      7z x ${kernel.src} -so | 7z x -aoa -si -ttar
+    fi
+
+    configureFlagsArray+=(--with-kerneldir=$(echo $(pwd)/linux-*))
+    ./autogen.sh --prefix=$out
+  '';
+
+  meta = with stdenv.lib; {
+    description = "dynamic Tracing in Linux";
+    homepage = https://wkz.github.io/ply/;
+    license = [ licenses.gpl2 ];
+    maintainers = with maintainers; [ mic92 mbbx6spp ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/plymouth/default.nix b/nixpkgs/pkgs/os-specific/linux/plymouth/default.nix
new file mode 100644
index 000000000000..2092a50041f1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/plymouth/default.nix
@@ -0,0 +1,65 @@
+{ stdenv, fetchurl, autoreconfHook, pkgconfig, libxslt, docbook_xsl
+, gtk3, udev, systemd
+}:
+
+stdenv.mkDerivation rec {
+  name = "plymouth-${version}";
+  version = "0.9.4";
+
+  src = fetchurl {
+    url = "https://www.freedesktop.org/software/plymouth/releases/${name}.tar.xz";
+    sha256 = "0l8kg7b2vfxgz9gnrn0v2w4jvysj2cirp0nxads5sy05397pl6aa";
+  };
+
+  nativeBuildInputs = [
+    autoreconfHook pkgconfig libxslt docbook_xsl
+  ];
+
+  buildInputs = [
+    gtk3 udev systemd
+  ];
+
+  postPatch = ''
+    sed -i \
+      -e "s#\$(\$PKG_CONFIG --variable=systemdsystemunitdir systemd)#$out/etc/systemd/system#g" \
+      -e "s#plymouthplugindir=.*#plymouthplugindir=/etc/plymouth/plugins/#" \
+      -e "s#plymouththemedir=.*#plymouththemedir=/etc/plymouth/themes#" \
+      -e "s#plymouthpolicydir=.*#plymouthpolicydir=/etc/plymouth/#" \
+      configure.ac
+
+    configureFlags="
+      --prefix=$out
+      --bindir=$out/bin
+      --sbindir=$out/sbin
+      --exec-prefix=$out
+      --libdir=$out/lib
+      --libexecdir=$out/lib
+      --sysconfdir=/etc
+      --with-systemdunitdir=$out/etc/systemd/system
+      --localstatedir=/var
+      --with-logo=/etc/plymouth/logo.png
+      --with-background-color=0x000000
+      --with-background-start-color-stop=0x000000
+      --with-background-end-color-stop=0x000000
+      --with-release-file=/etc/os-release
+      --without-system-root-install
+      --without-rhgb-compat-link
+      --enable-tracing
+      --enable-systemd-integration
+      --enable-pango
+      --enable-gdm-transition
+      --enable-gtk"
+
+    installFlags="
+      plymouthd_defaultsdir=$out/share/plymouth
+      plymouthd_confdir=$out/etc/plymouth"
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://www.freedesktop.org/wiki/Software/Plymouth;
+    description = "A graphical boot animation";
+    license = licenses.gpl2;
+    maintainers = [ maintainers.goibhniu ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pm-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/pm-utils/default.nix
new file mode 100644
index 000000000000..b314e8db8379
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pm-utils/default.nix
@@ -0,0 +1,55 @@
+{ stdenv, fetchurl, coreutils, gnugrep, utillinux, kmod
+, procps, kbd, dbus }:
+
+let
+
+  binPath = stdenv.lib.makeBinPath
+    [ coreutils gnugrep utillinux kmod procps kbd dbus ];
+
+  sbinPath = stdenv.lib.makeSearchPathOutput "bin" "sbin"
+    [ procps ];
+
+in
+
+stdenv.mkDerivation rec {
+  name = "pm-utils-1.4.1";
+
+  src = fetchurl {
+    url = "https://pm-utils.freedesktop.org/releases/${name}.tar.gz";
+    sha256 = "02qc6zaf7ams6qcc470fwb6jvr4abv3lrlx16clqpn36501rkn4f";
+  };
+
+  configureFlags = [ "--sysconfdir=/etc" ];
+
+  preConfigure =
+    ''
+      # Install the manpages (xmlto isn't really needed).
+      substituteInPlace man/Makefile.in --replace '@HAVE_XMLTO_TRUE@' ""
+
+      # Set the PATH properly.
+      substituteInPlace pm/pm-functions.in --replace '/sbin:/usr/sbin:/bin:/usr/bin' '$PATH:${binPath}:${sbinPath}'
+
+      substituteInPlace src/pm-action.in --replace 'tr ' '${coreutils}/bin/tr '
+
+      substituteInPlace pm/sleep.d/00logging --replace /bin/uname "$(type -P uname)"
+
+      substituteInPlace pm/sleep.d/90clock --replace /sbin/hwclock hwclock
+    '';
+
+  postInstall =
+    ''
+      # Remove some hooks that have doubtful usefulness.  See
+      # http://zinc.canonical.com/~cking/power-benchmarking/pm-utils-results/results.txt.
+      # In particular, journal-commit breaks things if you have
+      # read-only bind mounts, since it ends up remounting the
+      # underlying filesystem read-only.
+      rm $out/lib/pm-utils/power.d/{journal-commit,readahead}
+    '';
+
+  meta = {
+    homepage = https://pm-utils.freedesktop.org/wiki/;
+    description = "A small collection of scripts that handle suspend and resume on behalf of HAL";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pmount/default.nix b/nixpkgs/pkgs/os-specific/linux/pmount/default.nix
new file mode 100644
index 000000000000..cd0e277b2c6b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pmount/default.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchurl, intltool, ntfs3g, utillinux
+, mediaDir ? "/media/"
+, lockDir ? "/var/lock/pmount"
+, whiteList ? "/etc/pmount.allow"
+}:
+
+# constraint mention in the configure.ac
+assert stdenv.lib.hasSuffix "/" mediaDir;
+
+stdenv.mkDerivation rec {
+  name = "pmount-${version}";
+  version = "0.9.23";
+
+  src = fetchurl {
+    url = "mirror://debian/pool/main/p/pmount/pmount_${version}.orig.tar.bz2";
+    sha256 = "db38fc290b710e8e9e9d442da2fb627d41e13b3ee80326c15cc2595ba00ea036";
+  };
+
+  buildInputs = [ intltool utillinux ];
+
+  configureFlags = [
+    "--with-media-dir=${mediaDir}"
+    "--with-lock-dir=${lockDir}"
+    "--with-whitelist=${whiteList}"
+    "--with-mount-prog=${utillinux}/bin/mount"
+    "--with-umount-prog=${utillinux}/bin/umount"
+    "--with-mount-ntfs3g=${ntfs3g}/sbin/mount.ntfs-3g"
+  ];
+
+  postConfigure = ''
+    # etc/Mafile.am is hardcoded and it does not respect the --prefix option.
+    substituteInPlace ./etc/Makefile --replace DESTDIR prefix
+    # Do not change ownership & Do not add the set user ID bit
+    substituteInPlace ./src/Makefile --replace '-o root -g root -m 4755 ' '-m 755 '
+  '';
+
+  doCheck = false; # fails 1 out of 1 tests with "Error: could not open fstab-type file: No such file or directory"
+
+  meta = {
+    homepage = https://bazaar.launchpad.net/~fourmond/pmount/main/files;
+    description = "Mount removable devices as normal user";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/policycoreutils/default.nix b/nixpkgs/pkgs/os-specific/linux/policycoreutils/default.nix
new file mode 100644
index 000000000000..a7cac46ae6a0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/policycoreutils/default.nix
@@ -0,0 +1,36 @@
+{ stdenv, fetchurl, gettext, libsepol, libselinux, libsemanage }:
+
+stdenv.mkDerivation rec {
+  name = "policycoreutils-${version}";
+  version = "2.7";
+  inherit (libsepol) se_release se_url;
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/policycoreutils-${version}.tar.gz";
+    sha256 = "1x742c7lkw30namhkw87yg7z384qzqjz0pvmqs0lk19v6958l6qa";
+  };
+
+  postPatch = ''
+    # Fix install references
+    substituteInPlace po/Makefile \
+       --replace /usr/bin/install install --replace /usr/share /share
+    substituteInPlace newrole/Makefile --replace /usr/share /share
+  '';
+
+  nativeBuildInputs = [ gettext ];
+  buildInputs = [ libsepol libselinux libsemanage ];
+
+  preBuild = ''
+    makeFlagsArray+=("PREFIX=$out")
+    makeFlagsArray+=("DESTDIR=$out")
+    makeFlagsArray+=("BASHCOMPLETIONDIR=$out/share/bash-completion/completions")
+    makeFlagsArray+=("LOCALEDIR=$out/share/locale")
+    makeFlagsArray+=("MAN5DIR=$out/share/man/man5")
+  '';
+
+  meta = with stdenv.lib; {
+    description = "SELinux policy core utilities";
+    license = licenses.gpl2;
+    inherit (libsepol.meta) homepage platforms maintainers;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pommed-light/default.nix b/nixpkgs/pkgs/os-specific/linux/pommed-light/default.nix
new file mode 100644
index 000000000000..06ea49034a01
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pommed-light/default.nix
@@ -0,0 +1,65 @@
+{ stdenv
+, fetchFromGitHub
+, pciutils
+, libconfuse
+, alsaLib
+, audiofile
+, pkgconfig
+, zlib
+, eject
+}:
+
+stdenv.mkDerivation rec {
+  pkgname = "pommed-light";
+  version = "1.51lw";
+  name = "${pkgname}-${version}";
+
+  src = fetchFromGitHub {
+    owner = "bytbox";
+    repo = pkgname;
+    rev = "v${version}";
+    sha256 = "18fvdwwhcl6s4bpf2f2i389s71c8k4g0yb81am9rdddqmzaw27iy";
+  };
+
+  postPatch = ''
+    substituteInPlace pommed.conf.mactel --replace /usr $out
+    substituteInPlace pommed.conf.pmac --replace /usr $out
+    substituteInPlace pommed/beep.h --replace /usr $out
+    substituteInPlace pommed/cd_eject.c --replace /usr/bin/eject ${eject}/bin/eject
+  '';
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [
+    pciutils
+    libconfuse
+    alsaLib
+    audiofile
+    zlib
+    eject
+  ];
+
+  installPhase = ''
+    install -Dm755 pommed/pommed $out/bin/pommed
+    install -Dm644 pommed.conf.mactel $out/etc/pommed.conf.mactel
+    install -Dm644 pommed.conf.pmac $out/etc/pommed.conf.pmac
+
+    # Man page
+    install -Dm644 pommed.1 $out/share/man/man1/pommed.1
+
+    # Sounds
+    install -Dm644 pommed/data/goutte.wav $out/share/pommed/goutte.wav
+    install -Dm644 pommed/data/click.wav $out/share/pommed/click.wav
+  '';
+
+  meta = {
+    description = "A trimmed version of the pommed hotkey handler for MacBooks";
+    longDescription = ''
+      This is a stripped-down version of pommed with client, dbus, and
+      ambient light sensor support removed, optimized for use with dwm
+      and the like.
+    '';
+    homepage = https://github.com/bytbox/pommed-light;
+    platforms = [ "x86_64-linux" ];
+    license = stdenv.lib.licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/powerstat/default.nix b/nixpkgs/pkgs/os-specific/linux/powerstat/default.nix
new file mode 100644
index 000000000000..1031cc9a56ed
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/powerstat/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, lib, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "powerstat-${version}";
+  version = "0.02.18";
+  src = fetchurl {
+    url = "http://kernel.ubuntu.com/~cking/tarballs/powerstat/powerstat-${version}.tar.gz";
+    sha256 = "1glryfmq9h7h8hsasg5ffl9vrcbjkkq3xqdxmbdhxmn137w7vgm5";
+  };
+  installFlags = [ "DESTDIR=$(out)" ];
+  postInstall = ''
+    mv $out/usr/* $out
+    rm -r $out/usr
+  '';
+  meta = with lib; {
+    description = "Laptop power measuring tool";
+    homepage = http://kernel.ubuntu.com/~cking/powerstat/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ womfoo ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/powertop/default.nix b/nixpkgs/pkgs/os-specific/linux/powertop/default.nix
new file mode 100644
index 000000000000..691b216073fd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/powertop/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchurl, fetchpatch, gettext, libnl, ncurses, pciutils, pkgconfig, zlib }:
+
+stdenv.mkDerivation rec {
+  pname = "powertop";
+  version = "2.10";
+
+  src = fetchurl {
+    url = "https://01.org/sites/default/files/downloads/${pname}-v${version}.tar.gz";
+    sha256 = "0xaazqccyd42v2q532dxx40nqhb9sfsa6cyx8641rl57mfg4bdyk";
+  };
+
+  outputs = [ "out" "man" ];
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ gettext libnl ncurses pciutils zlib ];
+
+  patches = stdenv.lib.optional stdenv.hostPlatform.isMusl (
+    fetchpatch {
+      name = "strerror_r.patch";
+      url = "https://git.alpinelinux.org/cgit/aports/plain/main/powertop/strerror_r.patch?id=3b9214d436f1611f297b01f72469d66bfe729d6e";
+      sha256 = "1kzddhcrb0n2iah4lhgxwwy4mkhq09ch25jjngyq6pdj6pmfkpfw";
+    }
+  ) ++ [
+    # Fix vertical scrolling, see: https://lists.01.org/pipermail/powertop/2019-March/002046.html
+    ./fix-vertical-scrolling.patch
+  ];
+
+  postPatch = ''
+    substituteInPlace src/main.cpp --replace "/sbin/modprobe" "modprobe"
+    substituteInPlace src/calibrate/calibrate.cpp --replace "/usr/bin/xset" "xset"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Analyze power consumption on Intel-based laptops";
+    homepage = https://01.org/powertop;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ fpletz ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/powertop/fix-vertical-scrolling.patch b/nixpkgs/pkgs/os-specific/linux/powertop/fix-vertical-scrolling.patch
new file mode 100644
index 000000000000..b9b3fdbaf343
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/powertop/fix-vertical-scrolling.patch
@@ -0,0 +1,13 @@
+diff --git a/src/display.cpp b/src/display.cpp
+index 07227c5..7b3a7a2 100644
+--- a/src/display.cpp
++++ b/src/display.cpp
+@@ -244,7 +244,7 @@ void cursor_down(void)
+ 	w = tab_windows[tab_names[current_tab]];
+ 	if (w) {
+ 		if (w->ypad_pos < 1000) {
+-			if (tab_names[current_tab] == "Tunables" || "WakeUp") {
++			if (tab_names[current_tab] == "Tunables" || tab_names[current_tab] == "WakeUp") {
+ 		                if ((w->cursor_pos + 7) >= LINES) { 
+ 					prefresh(w->win, ++w->ypad_pos, w->xpad_pos, 
+ 						1, 0, LINES - 3, COLS - 1);
diff --git a/nixpkgs/pkgs/os-specific/linux/pps-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/pps-tools/default.nix
new file mode 100644
index 000000000000..e4f7d4b3616e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pps-tools/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  baseName = "pps-tools";
+  version = "1.0.2";
+  name = "${baseName}-${version}";
+
+  src = fetchFromGitHub {
+    owner = "redlab-i";
+    repo = "${baseName}";
+    rev = "v${version}";
+    sha256 = "1yh9g0l59dkq4ci0wbb03qin3c3cizfngmn9jy1vwm5zm6axlxhf";
+  };
+
+  outputs = [ "out" "dev" ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    mkdir -p $dev/include
+    mkdir -p $out/{usr/bin,usr/include/sys}
+    make install DESTDIR=$out
+    mv $out/usr/bin/* $out/bin
+    mv $out/usr/include/* $dev/include/
+    rm -rf $out/usr/
+  '';
+
+  meta = with stdenv.lib;{
+    description = "User-space tools for LinuxPPS";
+    homepage = http://linuxpps.org/;
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ sorki ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/prl-tools/autostart.desktop b/nixpkgs/pkgs/os-specific/linux/prl-tools/autostart.desktop
new file mode 100644
index 000000000000..b8eb27fdd992
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/prl-tools/autostart.desktop
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Version=@version@
+Encoding=UTF-8
+Name=@description@
+Type=Application
+Exec=@exec@
+X-KDE-autostart-phase=1
+GenericName[en_US]=
diff --git a/nixpkgs/pkgs/os-specific/linux/prl-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/prl-tools/default.nix
new file mode 100644
index 000000000000..1a4919a5d9d4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/prl-tools/default.nix
@@ -0,0 +1,170 @@
+{ stdenv, lib, makeWrapper, p7zip
+, gawk, utillinux, xorg, glib, dbus-glib, zlib
+, kernel ? null, libsOnly ? false
+, undmg, fetchurl
+}:
+
+assert (!libsOnly) -> kernel != null;
+# Disable for kernels 4.15 and above due to compatibility issues
+assert kernel != null -> stdenv.lib.versionOlder kernel.version "4.15";
+
+let xorgFullVer = (builtins.parseDrvName xorg.xorgserver.name).version;
+    xorgVer = lib.concatStringsSep "." (lib.take 2 (lib.splitString "." xorgFullVer));
+    x64 = if stdenv.hostPlatform.system == "x86_64-linux" then true
+          else if stdenv.hostPlatform.system == "i686-linux" then false
+          else throw "Parallels Tools for Linux only support {x86-64,i686}-linux targets";
+in
+stdenv.mkDerivation rec {
+  version = "${prl_major}.2.1-41615";
+  prl_major = "12";
+  name = "prl-tools-${version}";
+
+  # We download the full distribution to extract prl-tools-lin.iso from
+  # => ${dmg}/Parallels\ Desktop.app/Contents/Resources/Tools/prl-tools-lin.iso
+  src = fetchurl {
+    url =  "https://download.parallels.com/desktop/v${prl_major}/${version}/ParallelsDesktop-${version}.dmg";
+    sha256 = "1jwzwif69qlhmfky9kigjaxpxfj0lyrl1iyrpqy4iwqvajdgbbym";
+  };
+
+  hardeningDisable = [ "pic" "format" ];
+
+  # also maybe python2 to generate xorg.conf
+  nativeBuildInputs = [ p7zip undmg ] ++ lib.optionals (!libsOnly) [ makeWrapper ] ++ kernel.moduleBuildDependencies;
+
+  inherit libsOnly;
+
+  unpackPhase = ''
+    undmg < "${src}"
+
+    export sourceRoot=prl-tools-build
+    7z x "Parallels Desktop.app/Contents/Resources/Tools/prl-tools-lin.iso" -o$sourceRoot
+    if test -z "$libsOnly"; then
+      ( cd $sourceRoot/kmods; tar -xaf prl_mod.tar.gz )
+    fi
+    ( cd $sourceRoot/tools; tar -xaf prltools${if x64 then ".x64" else ""}.tar.gz )
+  '';
+
+  kernelVersion = if libsOnly then "" else (builtins.parseDrvName kernel.name).version;
+  kernelDir = if libsOnly then "" else "${kernel.dev}/lib/modules/${kernelVersion}";
+  scriptPath = lib.concatStringsSep ":" (lib.optionals (!libsOnly) [ "${utillinux}/bin" "${gawk}/bin" ]);
+
+  buildPhase = ''
+    if test -z "$libsOnly"; then
+      ( # kernel modules
+        cd kmods
+        make -f Makefile.kmods \
+          KSRC=$kernelDir/source \
+          HEADERS_CHECK_DIR=$kernelDir/source \
+          KERNEL_DIR=$kernelDir/build \
+          SRC=$kernelDir/build \
+          KVER=$kernelVersion
+      )
+
+      # Xorg config (maybe would be useful for other versions)
+      #python2 installer/xserver-config.py xorg ${xorgVer} /dev/null parallels.conf
+    fi
+  '';
+
+  libPath = with xorg;
+            stdenv.lib.makeLibraryPath ([ stdenv.cc.cc libXrandr libXext libX11 libXcomposite libXinerama ]
+            ++ lib.optionals (!libsOnly) [ libXi glib dbus-glib zlib ]);
+
+
+  installPhase = ''
+    if test -z "$libsOnly"; then
+      ( # kernel modules
+        cd kmods
+        mkdir -p $out/lib/modules/${kernelVersion}/extra
+        cp prl_eth/pvmnet/prl_eth.ko $out/lib/modules/${kernelVersion}/extra
+        cp prl_tg/Toolgate/Guest/Linux/prl_tg/prl_tg.ko $out/lib/modules/${kernelVersion}/extra
+        cp prl_fs/SharedFolders/Guest/Linux/prl_fs/prl_fs.ko $out/lib/modules/${kernelVersion}/extra
+        cp prl_fs_freeze/Snapshot/Guest/Linux/prl_freeze/prl_fs_freeze.ko $out/lib/modules/${kernelVersion}/extra
+      )
+    fi
+
+    ( # tools
+      cd tools
+      mkdir -p $out/lib
+
+      if test -z "$libsOnly"; then
+        # install binaries
+        for i in bin/* sbin/prl_nettool sbin/prl_snapshot; do
+          install -Dm755 $i $out/$i
+        done
+        # other binaries
+        for i in xorg.7.1/usr/bin/*; do
+          cp $i $out/bin
+        done
+
+        for i in $out/bin/* $out/sbin/*; do
+          patchelf \
+            --interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" \
+            --set-rpath "$out/lib:$libPath" \
+            $i || true
+        done
+
+        mkdir -p $out/bin
+        install -Dm755 ../installer/prlfsmountd.sh $out/sbin/prlfsmountd
+        wrapProgram $out/sbin/prlfsmountd \
+          --prefix PATH ':' "$scriptPath"
+
+        for i in lib/*.a; do
+          cp $i $out/lib
+        done
+
+        for i in xorg.7.1/usr/lib/libprl_wmouse_watcher.*; do
+          cp $i $out/lib
+        done
+
+        mkdir -p $out/lib/udev/rules.d
+        for i in *.rules; do
+          sed 's,/bin/bash,${stdenv.shell},g' $i > $out/lib/udev/rules.d/$i
+        done
+
+        (
+          cd xorg.${xorgVer}
+          # Install the X modules.
+          (
+            cd x-server/modules
+            for i in */*; do
+              install -Dm755 $i $out/lib/xorg/modules/$i
+            done
+          )
+          (
+            cd usr/lib
+            libGLXname=$(echo libglx.so*)
+            install -Dm755 $libGLXname $out/lib/xorg/modules/extensions/$libGLXname
+            ln -s $libGLXname $out/lib/xorg/modules/extensions/libglx.so
+            ln -s $libGLXname $out/lib/xorg/modules/extensions/libglx.so.1
+          )
+        )
+      fi
+
+      for i in xorg.7.1/usr/lib/libGL.*; do
+        cp $i $out/lib
+      done
+
+      cd $out
+      find -name \*.so\* -type f -exec \
+        patchelf --set-rpath "$out/lib:$libPath" {} \;
+
+      cd lib
+      libGLname=$(echo libGL.so*)
+      ln -s $libGLname libGL.so
+      ln -s $libGLname libGL.so.1
+    )
+  '';
+
+  dontStrip = true;
+  dontPatchELF = true;
+
+  meta = with stdenv.lib; {
+    description = "Parallels Tools for Linux guests";
+    homepage = https://parallels.com;
+    platforms = [ "i686-linux" "x86_64-linux" ];
+    license = licenses.unfree;
+    # I was making this package blindly and requesting testing from the real user,
+    # so I can't even test it by myself and won't provide future updates.
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/procdump/default.nix b/nixpkgs/pkgs/os-specific/linux/procdump/default.nix
new file mode 100644
index 000000000000..aa7d0ec46043
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/procdump/default.nix
@@ -0,0 +1,48 @@
+{ stdenv, fetchFromGitHub, fetchpatch, bash, coreutils, gdb, zlib }:
+
+stdenv.mkDerivation rec {
+  name = "procdump-${version}";
+  version = "1.0.1";
+
+  src = fetchFromGitHub {
+    owner = "Microsoft";
+    repo = "ProcDump-for-Linux";
+    rev = version;
+    sha256 = "1lkm05hq4hl1vadj9ifm18hi7cbf5045xlfxdfbrpsl6kxgfwcc4";
+  };
+
+  nativeBuildInputs = [ zlib ];
+  buildInputs = [ bash coreutils gdb ];
+
+  patches = [
+    # Fix name conflict when built with musl
+    # TODO: check if fixed upstream https://github.com/Microsoft/ProcDump-for-Linux/pull/50
+    (fetchpatch {
+      url = "https://github.com/Microsoft/ProcDump-for-Linux/commit/1b7b50b910f20b463fb628c8213663c8a8d11d0d.patch";
+      sha256 = "0h0dj3gi6hw1wdpc0ih9s4kkagv0d9jzrg602cr85r2z19lmb7yk";
+    })
+  ];
+
+  postPatch = ''
+    substituteInPlace src/CoreDumpWriter.c \
+      --replace '"gcore ' '"${gdb}/bin/gcore ' \
+      --replace '"rm ' '"${coreutils}/bin/rm ' \
+      --replace '/bin/bash' '${bash}/bin/bash'
+  '';
+
+  makeFlags = [
+    "DESTDIR=$(out)"
+    "INSTALLDIR=/bin"
+    "MANDIR=/share/man/man1"
+  ];
+
+  doCheck = false; # needs root
+
+  meta = with stdenv.lib; {
+    description = "A Linux version of the ProcDump Sysinternals tool";
+    homepage = https://github.com/Microsoft/ProcDump-for-Linux;
+    license = licenses.mit;
+    maintainers = with maintainers; [ c0bw3b ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/procps-ng/default.nix b/nixpkgs/pkgs/os-specific/linux/procps-ng/default.nix
new file mode 100644
index 000000000000..272812ccb588
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/procps-ng/default.nix
@@ -0,0 +1,54 @@
+{ lib, stdenv, fetchurl, ncurses, pkgconfig
+
+# `ps` with systemd support is able to properly report different
+# attributes like unit name, so we want to have it on linux.
+, withSystemd ? stdenv.isLinux
+, systemd ? null
+
+# procps is mostly Linux-only. Most commands require a running Linux
+# system (or very similar like that found in Cygwin). The one
+# exception is ‘watch’ which is portable enough to run on pretty much
+# any UNIX-compatible system.
+, watchOnly ? !(stdenv.isLinux || stdenv.isCygwin)
+}:
+
+stdenv.mkDerivation rec {
+  name = "procps-${version}";
+  version = "3.3.15";
+
+  # The project's releases are on SF, but git repo on gitlab.
+  src = fetchurl {
+    url = "mirror://sourceforge/procps-ng/procps-ng-${version}.tar.xz";
+    sha256 = "0r84kwa5fl0sjdashcn4vh7hgfm7ahdcysig3mcjvpmkzi7p9g8h";
+  };
+
+  buildInputs = [ ncurses ]
+    ++ lib.optional withSystemd systemd;
+  nativeBuildInputs = [ pkgconfig ];
+
+  makeFlags = [ "usrbin_execdir=$(out)/bin" ]
+    ++ lib.optionals watchOnly [ "watch" "PKG_LDFLAGS="];
+
+  enableParallelBuilding = true;
+
+  # Too red
+  configureFlags = [ "--disable-modern-top" ]
+    ++ lib.optional withSystemd "--with-systemd"
+    ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform)
+    [ "ac_cv_func_malloc_0_nonnull=yes"
+      "ac_cv_func_realloc_0_nonnull=yes" ];
+
+  installPhase = if watchOnly then ''
+    install -m 0755 -D watch $out/bin/watch
+    install -m 0644 -D watch.1 $out/share/man/man1/watch.1
+  '' else null;
+
+  meta = {
+    homepage = https://gitlab.com/procps-ng/procps;
+    description = "Utilities that give information about processes using the /proc filesystem";
+    priority = 10; # less than coreutils, which also provides "kill" and "uptime"
+    license = lib.licenses.gpl2;
+    platforms = lib.platforms.unix;
+    maintainers = [ lib.maintainers.typetetris ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/pscircle/default.nix b/nixpkgs/pkgs/os-specific/linux/pscircle/default.nix
new file mode 100644
index 000000000000..b6c169483393
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/pscircle/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, fetchFromGitLab, meson, pkgconfig, ninja, cairo }:
+
+stdenv.mkDerivation rec {
+  name = "pscircle-${version}";
+  version = "1.3.0";
+
+  src = fetchFromGitLab {
+    owner = "mildlyparallel";
+    repo = "pscircle";
+    rev = "v${version}";
+    sha256 = "0qsif00dkqa8ky3vl2ycx5anx2yk62nrv47f5lrlqzclz91f00fx";
+  };
+
+  buildInputs = [
+      meson
+      pkgconfig
+      cairo
+      ninja
+  ];
+
+  meta = with stdenv.lib; {
+    homepage = https://gitlab.com/mildlyparallel/pscircle;
+    description = "Visualize Linux processes in a form of a radial tree";
+    license = licenses.gpl2;
+    maintainers = [ maintainers.ldesgoui ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/psmisc/default.nix b/nixpkgs/pkgs/os-specific/linux/psmisc/default.nix
new file mode 100644
index 000000000000..68e51afdf1bb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/psmisc/default.nix
@@ -0,0 +1,34 @@
+{stdenv, fetchFromGitLab, autoconf, automake, gettext, ncurses}:
+
+stdenv.mkDerivation rec {
+  pname = "psmisc";
+  version = "23.2";
+  name = "${pname}-${version}";
+
+  src = fetchFromGitLab {
+    owner = pname;
+    repo = pname;
+    rev = "v${version}";
+    sha256 = "0d90wmibxpkl0d7sdibvvkwpyxyg6m6ksh5gwrjh15vf1swvd5i1";
+  };
+
+  nativeBuildInputs = [ autoconf automake gettext ];
+  buildInputs = [ ncurses ];
+
+  preConfigure = stdenv.lib.optionalString (stdenv.buildPlatform != stdenv.hostPlatform) ''
+    # Goes past the rpl_malloc linking failure
+    export ac_cv_func_malloc_0_nonnull=yes
+    export ac_cv_func_realloc_0_nonnull=yes
+  '' + ''
+    echo $version > .tarball-version
+    ./autogen.sh
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://gitlab.com/psmisc/psmisc;
+    description = "A set of small useful utilities that use the proc filesystem (such as fuser, killall and pstree)";
+    platforms = platforms.linux;
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ ryantm ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/r8168/default.nix b/nixpkgs/pkgs/os-specific/linux/r8168/default.nix
new file mode 100644
index 000000000000..f2c87b97c4ff
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/r8168/default.nix
@@ -0,0 +1,56 @@
+{ stdenv, lib, fetchFromGitHub, kernel }:
+
+
+let modDestDir = "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/realtek/r8168";
+
+in stdenv.mkDerivation rec {
+  name = "r8168-${kernel.version}-${version}";
+  # on update please verify that the source matches the realtek version
+  version = "8.046.00";
+
+  # This is a mirror. The original website[1] doesn't allow non-interactive
+  # downloads, instead emailing you a download link.
+  # [1] http://www.realtek.com.tw/downloads/downloadsView.aspx?PFid=5&Level=5&Conn=4&DownTypeID=3
+  # I've verified manually (`diff -r`) that the source code for version 8.046.00
+  # is the same as the one available on the realtek website.
+  src = fetchFromGitHub {
+    owner = "mtorromeo";
+    repo = "r8168";
+    rev = version;
+    sha256 = "0y8w3biw5mshn5bvl24b9rybfh67f1s9gfzkcv9p4m7s7nchj2dg";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  # avoid using the Makefile directly -- it doesn't understand
+  # any kernel but the current.
+  # based on the ArchLinux pkgbuild: https://git.archlinux.org/svntogit/community.git/tree/trunk/PKGBUILD?h=packages/r8168
+  preBuild = ''
+    makeFlagsArray+=("-C${kernel.dev}/lib/modules/${kernel.modDirVersion}/build")
+    makeFlagsArray+=("SUBDIRS=$PWD/src")
+    makeFlagsArray+=("EXTRA_CFLAGS=-DCONFIG_R8168_NAPI -DCONFIG_R8168_VLAN")
+    makeFlagsArray+=("modules")
+  '';
+
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    mkdir -p ${modDestDir}
+    find . -name '*.ko' -exec cp --parents '{}' ${modDestDir} \;
+    find ${modDestDir} -name '*.ko' -exec xz -f '{}' \;
+  '';
+
+  meta = with lib; {
+    description = "Realtek r8168 driver";
+    longDescription = ''
+      A kernel module for Realtek 8168 network cards.
+      If you want to use this driver, you might need to blacklist the r8169 driver
+      by adding "r8169" to boot.blacklistedKernelModules.
+    '';
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ timokau ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/radeontools/default.nix b/nixpkgs/pkgs/os-specific/linux/radeontools/default.nix
new file mode 100644
index 000000000000..81e5a2af9cdf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/radeontools/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, fetchurl, pciutils }:
+
+stdenv.mkDerivation {
+  name = "radeontool-1.5";
+
+  inherit pciutils;
+
+  # Don't know wether it's a good idea to hardcode the lspci path..
+  # But it will work on nix..
+  postUnpack = ''
+    cd $sourceRoot
+    sed -i "s%lspci%$pciutils/sbin/lspci%g" radeontool.c
+    cd ..
+  '';
+
+  src = fetchurl {
+    url = http://fdd.com/software/radeon/radeontool-1.5.tar.gz;
+    sha256 = "0qbkawhhq0y0gqbbql7q04y0v0hims5c4jkjsbc1y03rf9kr10ar";
+  };
+
+  installPhase = ''
+    mkdir -p $out/bin
+    chmod +x lightwatch.pl
+    cp radeontool lightwatch.pl $out/bin
+  '';
+
+  meta = {
+    description = "Control the backlight and external video output of ATI Radeon Mobility graphics cards";
+    homepage = http://fdd.com/software/radeon/;
+    license = stdenv.lib.licenses.zlib;
+    broken = true;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/radeontop/default.nix b/nixpkgs/pkgs/os-specific/linux/radeontop/default.nix
new file mode 100644
index 000000000000..504d25957858
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/radeontop/default.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchFromGitHub, pkgconfig, gettext, makeWrapper
+, ncurses, libdrm, libpciaccess, libxcb }:
+
+stdenv.mkDerivation rec {
+  name = "radeontop-${version}";
+  version = "2018-03-25";
+
+  src = fetchFromGitHub {
+    sha256 = "0s41xy9nrzxmimkdg23fr86rqcfiw6iqh99zpph0j990l8yzmv9b";
+    rev = "v1.1";
+    repo = "radeontop";
+    owner = "clbr";
+  };
+
+  buildInputs = [ ncurses libdrm libpciaccess libxcb ];
+  nativeBuildInputs = [ pkgconfig gettext makeWrapper ];
+
+  enableParallelBuilding = true;
+
+  patchPhase = ''
+    substituteInPlace getver.sh --replace ver=unknown ver=${version}
+  '';
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  postInstall = ''
+    wrapProgram $out/sbin/radeontop \
+      --prefix LD_LIBRARY_PATH : $out/lib
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Top-like tool for viewing AMD Radeon GPU utilization";
+    longDescription = ''
+      View GPU utilization, both for the total activity percent and individual
+      blocks. Supports R600 and later cards: even Southern Islands should work.
+      Works with both the open drivers and AMD Catalyst. Total GPU utilization
+      is also valid for OpenCL loads; the other blocks are only useful for GL
+      loads. Requires root rights or other permissions to read /dev/mem.
+    '';
+    homepage = https://github.com/clbr/radeontop;
+    platforms = platforms.linux;
+    license = licenses.gpl3;
+    maintainers = with maintainers; [ rycee ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rdma-core/default.nix b/nixpkgs/pkgs/os-specific/linux/rdma-core/default.nix
new file mode 100644
index 000000000000..192e1d61e43e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rdma-core/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchFromGitHub, cmake, pkgconfig, pandoc
+, ethtool, iproute, libnl, udev, python, perl
+} :
+
+let
+  version = "23";
+
+in stdenv.mkDerivation {
+  name = "rdma-core-${version}";
+
+  src = fetchFromGitHub {
+    owner = "linux-rdma";
+    repo = "rdma-core";
+    rev = "v${version}";
+    sha256 = "1n0v075ndczwrc87b70vxhx42nv1p953cqycmgnz334790zg002g";
+  };
+
+  nativeBuildInputs = [ cmake pkgconfig pandoc ];
+  buildInputs = [ libnl ethtool iproute udev python perl ];
+
+  cmakeFlags = [
+    "-DCMAKE_INSTALL_RUNDIR=/run"
+    "-DCMAKE_INSTALL_SHAREDSTATEDIR=/var/lib"
+  ];
+
+  postPatch = ''
+    substituteInPlace providers/rxe/rxe_cfg.in \
+      --replace ethtool "${ethtool}/bin/ethtool" \
+      --replace 'ip addr' "${iproute}/bin/ip addr" \
+      --replace 'ip link' "${iproute}/bin/ip link"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "RDMA Core Userspace Libraries and Daemons";
+    homepage = https://github.com/linux-rdma/rdma-core;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ markuskowa ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/read-edid/default.nix b/nixpkgs/pkgs/os-specific/linux/read-edid/default.nix
new file mode 100644
index 000000000000..3e57bbc11bdc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/read-edid/default.nix
@@ -0,0 +1,28 @@
+{ stdenv, lib, fetchurl, cmake, libx86 }:
+
+stdenv.mkDerivation rec {
+  name = "read-edid-${version}";
+  version = "3.0.2";
+
+  src = fetchurl {
+    url = "http://www.polypux.org/projects/read-edid/${name}.tar.gz";
+    sha256 = "0vqqmwsgh2gchw7qmpqk6idgzcm5rqf2fab84y7gk42v1x2diin7";
+  };
+
+  nativeBuildInputs = [ cmake ];
+  buildInputs = lib.optional (stdenv.isi686 || stdenv.isx86_64) libx86;
+
+  cmakeFlags = [ "-DCLASSICBUILD=${if stdenv.isi686 || stdenv.isx86_64 then "ON" else "OFF"}" ];
+
+  patchPhase = ''
+    substituteInPlace CMakeLists.txt --replace 'COPYING' 'LICENSE'
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Tool for reading and parsing EDID data from monitors";
+    homepage = http://www.polypux.org/projects/read-edid/;
+    license = licenses.bsd2; # Quoted: "This is an unofficial license. Let's call it BSD-like."
+    maintainers = [ maintainers.dezgeg ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/regionset/default.nix b/nixpkgs/pkgs/os-specific/linux/regionset/default.nix
new file mode 100644
index 000000000000..ee7325edbe70
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/regionset/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl }:
+
+let version = "0.2"; in
+stdenv.mkDerivation {
+  name = "regionset-${version}";
+
+  src = fetchurl {
+    url = "http://linvdr.org/download/regionset/regionset-${version}.tar.gz";
+    sha256 = "1fgps85dmjvj41a5bkira43vs2aiivzhqwzdvvpw5dpvdrjqcp0d";
+  };
+
+  installPhase = ''
+    install -Dm755 {.,$out/bin}/regionset
+    install -Dm644 {.,$out/share/man/man8}/regionset.8
+  '';
+
+  meta = with stdenv.lib; {
+    inherit version;
+    homepage = http://linvdr.org/projects/regionset/;
+    description = "Tool for changing the region code setting of DVD players";
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/reptyr/default.nix b/nixpkgs/pkgs/os-specific/linux/reptyr/default.nix
new file mode 100644
index 000000000000..bd25dc65ec85
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/reptyr/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, lib, fetchFromGitHub, python2 }:
+
+stdenv.mkDerivation rec {
+  version = "0.7.0";
+  name = "reptyr-${version}";
+
+  src = fetchFromGitHub {
+    owner = "nelhage";
+    repo = "reptyr";
+    rev = "reptyr-${version}";
+    sha256 = "1hnijfz1ab34j2h2cxc3f43rmbclyihgn9x9wxa7jqqgb2xm71hj";
+  };
+
+  makeFlags = [ "PREFIX=" "DESTDIR=$(out)" ];
+
+  checkInputs = [ (python2.withPackages (p: [ p.pexpect ])) ];
+  doCheck = true;
+
+  meta = {
+    platforms = [
+      "i686-linux"
+      "x86_64-linux"
+      "i686-freebsd"
+      "x86_64-freebsd"
+      "armv5tel-linux"
+      "armv6l-linux"
+      "armv7l-linux"
+      "aarch64-linux"
+    ];
+    maintainers = with lib.maintainers; [raskin];
+    license = lib.licenses.mit;
+    description = "Reparent a running program to a new terminal";
+    homepage = https://github.com/nelhage/reptyr;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rewritefs/default.nix b/nixpkgs/pkgs/os-specific/linux/rewritefs/default.nix
new file mode 100644
index 000000000000..8c7b75a881f4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rewritefs/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, fetchFromGitHub, pkgconfig, fuse, pcre }: 
+
+stdenv.mkDerivation rec {
+  name = "rewritefs-${version}";
+  version = "2017-08-14";
+
+  src = fetchFromGitHub {
+    owner  = "sloonz";
+    repo   = "rewritefs";
+    rev    = "33fb844d8e8ff441a3fc80d2715e8c64f8563d81";
+    sha256 = "15bcxprkxf0xqxljsqhb0jpi7p1vwqcb00sjs7nzrj7vh2p7mqla";
+  };
+ 
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ fuse pcre ];
+
+  prePatch = ''
+    # do not set sticky bit in nix store
+    substituteInPlace Makefile --replace 6755 0755
+  '';
+
+  preConfigure = "substituteInPlace Makefile --replace /usr/local $out";
+
+  meta = with stdenv.lib; {
+    description = ''A FUSE filesystem intended to be used
+      like Apache mod_rewrite'';
+    homepage    = https://github.com/sloonz/rewritefs;
+    license     = licenses.gpl2;
+    maintainers = with maintainers; [ rnhmjoj ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rfkill/default.nix b/nixpkgs/pkgs/os-specific/linux/rfkill/default.nix
new file mode 100644
index 000000000000..6b6bef29cc36
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rfkill/default.nix
@@ -0,0 +1,20 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "rfkill-0.5";
+
+  src = fetchurl {
+    url = "mirror://kernel/software/network/rfkill/${name}.tar.bz2";
+    sha256 = "01zs7p9kd92pxgcgwl5w46h3iyx4acfg6m1j5fgnflsaa350q5iy";
+  };
+
+  makeFlags = "PREFIX=$(out)";
+
+  meta = with stdenv.lib; {
+    homepage = http://wireless.kernel.org/en/users/Documentation/rfkill;
+    description = "A tool to query, enable and disable wireless devices";
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
+    license = licenses.isc;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rfkill/rfkill-hook.sh b/nixpkgs/pkgs/os-specific/linux/rfkill/rfkill-hook.sh
new file mode 100755
index 000000000000..75716e40daee
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rfkill/rfkill-hook.sh
@@ -0,0 +1,19 @@
+#!@shell@
+
+# Executes a hook in case of a change to the
+# rfkill state. The hook can be passed as
+# environment variable, or present as executable
+# file.
+
+if [ -z "$RFKILL_STATE" ]; then
+  echo "rfkill-hook: error: RFKILL_STATE variable not set"
+  exit 1
+fi
+
+if [ -x /run/current-system/etc/rfkill.hook ]; then
+  exec /run/current-system/etc/rfkill.hook
+elif [ ! -z "$RFKILL_HOOK" ]; then
+  exec $RFKILL_HOOK
+else
+  echo "rfkill-hook: $RFKILL_STATE"
+fi
diff --git a/nixpkgs/pkgs/os-specific/linux/rfkill/udev.nix b/nixpkgs/pkgs/os-specific/linux/rfkill/udev.nix
new file mode 100644
index 000000000000..6ba4f8d4b064
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rfkill/udev.nix
@@ -0,0 +1,55 @@
+{ stdenv, substituteAll }:
+
+# Provides a facility to hook into rfkill changes.
+#
+# Exemplary usage:
+#
+# Add this package to udev.packages, e.g.:
+#   udev.packages = [ pkgs.rfkill_udev ];
+#
+# Add a hook script in the managed etc directory, e.g.:
+#   etc = [
+#     { source = pkgs.writeScript "rtfkill.hook" ''
+#         #!${pkgs.runtimeShell}
+#
+#         if [ "$RFKILL_STATE" -eq "1" ]; then
+#           exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-on
+#         else
+#           exec ${config.system.build.upstart}/sbin/initctl emit -n antenna-off
+#         fi
+#       '';
+#       target = "rfkill.hook";
+#     }
+
+# Note: this package does not need the binaries
+# in the rfkill package.
+
+let
+  rfkillHook =
+    substituteAll {
+    inherit (stdenv) shell;
+    src = ./rfkill-hook.sh;
+  };
+in stdenv.mkDerivation {
+  name = "rfkill-udev";
+
+  unpackPhase = "true";
+  dontBuild = true;
+
+  installPhase = ''
+    mkdir -p "$out/etc/udev/rules.d/";
+    cat > "$out/etc/udev/rules.d/90-rfkill.rules" << EOF
+      SUBSYSTEM=="rfkill", ATTR{type}=="wlan", RUN+="$out/bin/rfkill-hook.sh"
+    EOF
+
+    mkdir -p "$out/bin/";
+    cp ${rfkillHook} "$out/bin/rfkill-hook.sh"
+    chmod +x "$out/bin/rfkill-hook.sh";
+  '';
+
+  meta = {
+    homepage = http://wireless.kernel.org/en/users/Documentation/rfkill;
+    description = "Rules+hook for udev to catch rfkill state changes";
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/roccat-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/roccat-tools/default.nix
new file mode 100644
index 000000000000..c2fb55b344b4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/roccat-tools/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchurl, cmake, pkgconfig, gettext
+, dbus, dbus-glib, libgaminggear, libgudev, lua
+}:
+
+stdenv.mkDerivation rec {
+  name = "roccat-tools-${version}";
+  version = "5.7.0";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/roccat/${name}.tar.bz2";
+    sha256 = "15gxplcm62167xhk65k8v6gg3j6jr0c5a64wlz72y1vfq0ai7qm6";
+  };
+
+  postPatch = ''
+    sed -i -re 's,/(etc/xdg),\1,' roccateventhandler/CMakeLists.txt
+
+    sed -i -e '/roccat_profile_dir(void).*{/,/}/ {
+      /return/c \
+        return g_build_path("/", g_get_user_data_dir(), "roccat", NULL);
+    }' libroccat/roccat_helper.c
+  '';
+
+  nativeBuildInputs = [ cmake pkgconfig gettext ];
+  buildInputs = [ dbus dbus-glib libgaminggear libgudev lua ];
+
+  enableParallelBuilding = true;
+
+  cmakeFlags = [
+    "-DUDEVDIR=\${out}/lib/udev/rules.d"
+    "-DCMAKE_MODULE_PATH=${libgaminggear.dev}/lib/cmake"
+    "-DWITH_LUA=${lua.luaversion}"
+    "-DLIBDIR=lib"
+  ];
+
+  meta = {
+    description = "Tools to configure ROCCAT devices";
+    homepage = http://roccat.sourceforge.net/;
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.gpl2Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtkit/default.nix b/nixpkgs/pkgs/os-specific/linux/rtkit/default.nix
new file mode 100644
index 000000000000..78bcd925aea0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtkit/default.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchurl, fetchpatch, pkgconfig, dbus, libcap }:
+
+stdenv.mkDerivation rec {
+  name = "rtkit-0.11";
+
+  src = fetchurl {
+    url = "http://0pointer.de/public/${name}.tar.xz";
+    sha256 = "1l5cb1gp6wgpc9vq6sx021qs6zb0nxg3cn1ba00hjhgnrw4931b8";
+  };
+
+  configureFlags = [
+    "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
+  ];
+
+  patches = [
+    # Drop removed ControlGroup stanza
+    (fetchpatch {
+      url = "http://git.0pointer.net/rtkit.git/patch/?id=6c28e20c0be2f616a025059fda0ffac84e7f4f17";
+      sha256 = "0lsxk5nv08i1wjb4xh20i5fcwg3x0qq0k4f8bc0r9cczph2sv7ck";
+    })
+
+    # security patch: Pass uid of caller to polkit
+    (fetchpatch {
+      url = "http://git.0pointer.net/rtkit.git/patch/?id=88d4082ef6caf6b071d749dca1c50e7edde914cc";
+      sha256 = "0hp1blbi359qz8fmr6nj4w9yc0jf3dd176f8pn25wdj38n13qkix";
+    })
+
+    # Fix format string errors due to -Werror=format-security
+    (fetchpatch {
+      url = "https://sources.debian.org/data/main/r/rtkit/0.11-6/debian/patches/0006-fix-format-strings.patch";
+      sha256 = "09mr89lh16jvz6cqw00zmh0xk919bjfhjkvna1czwmafwy9p7kgp";
+    })
+  ];
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ dbus libcap ];
+  NIX_LDFLAGS = [ "-lrt" ];
+
+  meta = with stdenv.lib; {
+    homepage = http://0pointer.de/blog/projects/rtkit;
+    description = "A daemon that hands out real-time priority to processes";
+    license = with licenses; [ gpl3 bsd0 ]; # lib is bsd license
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtl8192eu/default.nix b/nixpkgs/pkgs/os-specific/linux/rtl8192eu/default.nix
new file mode 100644
index 000000000000..52542aabfded
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtl8192eu/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, lib, fetchFromGitHub, kernel }:
+
+with lib;
+
+let modDestDir = "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/realtek/rtl8192eu";
+
+in stdenv.mkDerivation rec {
+  name = "rtl8192eu-${kernel.version}-${version}";
+  version = "4.4.1";
+
+  src = fetchFromGitHub {
+    owner = "Mange";
+    repo = "rtl8192eu-linux-driver";
+    rev = "4094004";
+    sha256 = "0rgcsp8bd5i5ik9b35qipdhq0xd8pva8kdijixxfaxm4vw6kbrvr";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  makeFlags = "KSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
+
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    mkdir -p ${modDestDir}
+    find . -name '*.ko' -exec cp --parents {} ${modDestDir} \;
+    find ${modDestDir} -name '*.ko' -exec xz -f {} \;
+  '';
+
+  meta = {
+    description = "Realtek rtl8192eu driver";
+    homepage = https://github.com/Mange/rtl8192eu-linux-driver;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with maintainers; [ troydm ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtl8723bs/default.nix b/nixpkgs/pkgs/os-specific/linux/rtl8723bs/default.nix
new file mode 100644
index 000000000000..b1e01f705dcf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtl8723bs/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchFromGitHub, nukeReferences, kernel }:
+with stdenv.lib;
+stdenv.mkDerivation rec {
+  name = "rtl8723bs-${kernel.version}-${version}";
+  version = "2017-04-06";
+
+  src = fetchFromGitHub {
+    owner = "hadess";
+    repo = "rtl8723bs";
+    rev = "db2c4f61d48fe3b47c167c8bcd722ce83c24aca5";
+    sha256 = "0pxqya14a61vv2v5ky1ldybc0mjfin9mpvmajlmv0lls904rph7g";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  buildInputs = [ nukeReferences ];
+
+  makeFlags = concatStringsSep " " [
+    "ARCH=${stdenv.hostPlatform.platform.kernelArch}" # Normally not needed, but the Makefile sets ARCH in a broken way.
+    "KSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" # Makefile uses $(uname -r); breaks us.
+  ];
+
+  enableParallelBuilding = true;
+
+  # The Makefile doesn't use env-vars well, so install manually:
+  installPhase = ''
+    mkdir -p      $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless
+    cp r8723bs.ko $out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless
+
+    nuke-refs $(find $out -name "*.ko")
+  '';
+
+  meta = {
+    description = "Realtek SDIO Wi-Fi driver";
+    homepage = https://github.com/hadess/rtl8723bs;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+    broken = (! versionOlder kernel.version "4.12"); # Now in kernel staging drivers
+    maintainers = with maintainers; [ elitak ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtl8812au/default.nix b/nixpkgs/pkgs/os-specific/linux/rtl8812au/default.nix
new file mode 100644
index 000000000000..4205cab6da69
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtl8812au/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchFromGitHub, kernel, bc }:
+
+stdenv.mkDerivation rec {
+  name = "rtl8812au-${kernel.version}-${version}";
+  version = "5.2.20.2_28373.20180619";
+
+  src = fetchFromGitHub {
+    owner = "zebulon2";
+    repo = "rtl8812au-driver-5.2.20";
+    rev = "2dad788f5d71d50df4f692b67a4428967ba3d42c";
+    sha256 = "17pn73j2xqya0g8f86hn1jyf9x9wp52md05yrg1md58ixsbh1kz3";
+  };
+
+  nativeBuildInputs = [ bc ];
+  buildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" "format" ];
+
+  prePatch = ''
+    substituteInPlace ./Makefile --replace /lib/modules/ "${kernel.dev}/lib/modules/"
+    substituteInPlace ./Makefile --replace '$(shell uname -r)' "${kernel.modDirVersion}"
+    substituteInPlace ./Makefile --replace /sbin/depmod \#
+    substituteInPlace ./Makefile --replace '$(MODDESTDIR)' "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  preInstall = ''
+    mkdir -p "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Driver for Realtek 802.11ac, rtl8812au, provides the 8812au mod";
+    homepage = https://github.com/zebulon2/rtl8812au-driver-5.2.20;
+    license = licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = with maintainers; [ danielfullmer ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtl8814au/default.nix b/nixpkgs/pkgs/os-specific/linux/rtl8814au/default.nix
new file mode 100644
index 000000000000..c54d45773428
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtl8814au/default.nix
@@ -0,0 +1,39 @@
+{ stdenv, fetchFromGitHub, kernel }:
+
+stdenv.mkDerivation rec {
+  name = "rtl8814au-${kernel.version}-${version}";
+  version = "4.3.21";
+
+  src = fetchFromGitHub {
+    owner = "zebulon2";
+    repo = "rtl8814au";
+    rev = "a58c56a5a6cb99ffb872f07cb67b68197911854f";
+    sha256 = "1ffm67da183nz009gm5v9w1bab081hrm113kk8knl9s5qbqnn13q";
+  };
+
+  buildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  NIX_CFLAGS_COMPILE="-Wno-error=incompatible-pointer-types";
+
+  prePatch = ''
+    substituteInPlace ./Makefile \
+      --replace /lib/modules/ "${kernel.dev}/lib/modules/" \
+      --replace '$(shell uname -r)' "${kernel.modDirVersion}" \
+      --replace /sbin/depmod \# \
+      --replace '$(MODDESTDIR)' "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  preInstall = ''
+    mkdir -p "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Realtek 8814AU USB WiFi driver";
+    homepage = https://github.com/zebulon2/rtl8814au;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.lassulus ];
+    platforms = [ "x86_64-linux" "i686-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtl8821au/default.nix b/nixpkgs/pkgs/os-specific/linux/rtl8821au/default.nix
new file mode 100644
index 000000000000..9cb28d5dc8dc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtl8821au/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchFromGitHub, kernel, bc }:
+
+stdenv.mkDerivation rec {
+  name = "rtl8821au-${kernel.version}-${version}";
+  version = "5.1.5";
+
+  src = fetchFromGitHub {
+    owner = "zebulon2";
+    repo = "rtl8812au";
+    rev = "61d0cd95afc01eae64da0c446515803910de1a00";
+    sha256 = "0dlzyiaa3hmb2qj3lik52px88n4mgrx7nblbm4s0hn36g19ylssw";
+  };
+
+  nativeBuildInputs = [ bc ];
+  buildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" "format" ];
+
+  NIX_CFLAGS_COMPILE="-Wno-error=incompatible-pointer-types";
+
+  prePatch = ''
+    substituteInPlace ./Makefile \
+      --replace /lib/modules/ "${kernel.dev}/lib/modules/" \
+      --replace '$(shell uname -r)' "${kernel.modDirVersion}" \
+      --replace /sbin/depmod \# \
+      --replace '$(MODDESTDIR)' "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  preInstall = ''
+    mkdir -p "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "rtl8821AU, rtl8812AU and rtl8811AU chipset driver with firmware";
+    homepage = https://github.com/zebulon2/rtl8812au;
+    license = licenses.gpl2;
+    platforms = [ "x86_64-linux" "i686-linux" ];
+    maintainers = with maintainers; [ plchldr ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtl8821ce/default.nix b/nixpkgs/pkgs/os-specific/linux/rtl8821ce/default.nix
new file mode 100644
index 000000000000..4be462991223
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtl8821ce/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchFromGitHub, kernel, bc }:
+stdenv.mkDerivation rec {
+  name = "rtl8821ce-${kernel.version}-${version}";
+  version = "5.2.5_1.26055.20180108";
+
+  src = fetchFromGitHub {
+    owner = "tomaspinho";
+    repo = "rtl8821ce";
+    rev = "ab6154e150bbc7d12b0525d4cc1298ae196e45de";
+    sha256 = "1my0hidqnv4s7hi5897m81pq0sjw05np0g27hlkg9fwb83b5kzsg";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  nativeBuildInputs = [ bc ];
+  buildInputs = kernel.moduleBuildDependencies;
+
+  prePatch = ''
+    substituteInPlace ./Makefile \
+      --replace /lib/modules/ "${kernel.dev}/lib/modules/" \
+      --replace '$(shell uname -r)' "${kernel.modDirVersion}" \
+      --replace /sbin/depmod \# \
+      --replace '$(MODDESTDIR)' "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  preInstall = ''
+    mkdir -p "$out/lib/modules/${kernel.modDirVersion}/kernel/net/wireless/"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Realtek rtl8821ce driver";
+    homepage = "https://github.com/tomaspinho/rtl8821ce";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.hhm ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/rtlwifi_new/default.nix b/nixpkgs/pkgs/os-specific/linux/rtlwifi_new/default.nix
new file mode 100644
index 000000000000..b29b1f639cf7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/rtlwifi_new/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, lib, fetchFromGitHub, kernel }:
+
+with lib;
+
+let modDestDir = "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/net/wireless/realtek/rtlwifi";
+
+in stdenv.mkDerivation rec {
+  name = "rtlwifi_new-${version}";
+  version = "2018-02-17";
+
+  src = fetchFromGitHub {
+    owner = "lwfinger";
+    repo = "rtlwifi_new";
+    rev = "0588ac0cc5f530e7764705416370b70d3c2afedc";
+    sha256 = "1vs8rfw19lcs04bapa97zlnl5x0kf02sdw5ik0hdm27wgk0z969m";
+  };
+
+  hardeningDisable = [ "pic" "format" ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  makeFlags = "KSRC=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
+
+  enableParallelBuilding = true;
+
+  installPhase = ''
+    mkdir -p ${modDestDir}
+    find . -name '*.ko' -exec cp --parents {} ${modDestDir} \;
+    find ${modDestDir} -name '*.ko' -exec xz -f {} \;
+  '';
+
+  meta = {
+    description = "The newest Realtek rtlwifi codes";
+    inherit (src.meta) homepage;
+    license = stdenv.lib.licenses.gpl2;
+    platforms = with platforms; linux;
+    maintainers = with maintainers; [ tvorog ];
+    priority = -1;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/s6-linux-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/s6-linux-utils/default.nix
new file mode 100644
index 000000000000..bd6b84ea73cf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/s6-linux-utils/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, skawarePackages }:
+
+with skawarePackages;
+
+buildPackage {
+  pname = "s6-linux-utils";
+  version = "2.5.0.1";
+  sha256 = "0bpcaah3rbz4i013bkarr7wxmfvisjyxg0z78xg5zfbgajpgjxx1";
+
+  description = "A set of minimalistic Linux-specific system utilities";
+  platforms = stdenv.lib.platforms.linux;
+
+  outputs = [ "bin" "dev" "doc" "out" ];
+
+  # TODO: nsss support
+  configureFlags = [
+    "--bindir=\${bin}/bin"
+    "--includedir=\${dev}/include"
+    "--with-sysdeps=${skalibs.lib}/lib/skalibs/sysdeps"
+    "--with-include=${skalibs.dev}/include"
+    "--with-lib=${skalibs.lib}/lib"
+    "--with-dynlib=${skalibs.lib}/lib"
+  ];
+
+  postInstall = ''
+    # remove all s6 executables from build directory
+    rm $(find -name "s6-*" -type f -mindepth 1 -maxdepth 1 -executable)
+
+    mv doc $doc/share/doc/s6-linux-utils/html
+  '';
+
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sch_cake/default.nix b/nixpkgs/pkgs/os-specific/linux/sch_cake/default.nix
new file mode 100644
index 000000000000..68fc8a6e0170
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sch_cake/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, lib, fetchFromGitHub, kernel }:
+
+assert stdenv.lib.versionAtLeast kernel.version "4.4";
+
+stdenv.mkDerivation {
+  name = "sch_cake-2017-07-16";
+
+  src = fetchFromGitHub {
+    owner = "dtaht";
+    repo = "sch_cake";
+    rev = "e641a56f27b6848736028f87eda65ac3df9f99f7";
+    sha256 = "08582jy01j32b3mj8hf6m8687qrcz64zv2m236j24inlkmd94q21";
+  };
+
+  hardeningDisable = [ "pic" ];
+
+  makeFlags = [
+    "KERNEL_VERSION=${kernel.version}"
+    "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  ];
+
+  installPhase = ''
+    install -v -m 644 -D sch_cake.ko \
+      $out/lib/modules/${kernel.modDirVersion}/kernel/net/sched/sch_cake.ko
+  '';
+
+  meta = with lib; {
+    description = "The cake qdisc scheduler";
+    homepage = https://www.bufferbloat.net/projects/codel/wiki/Cake/;
+    license = with licenses; [ bsd3 gpl2 ];
+    maintainers = with maintainers; [ fpletz ];
+    platforms = platforms.linux;
+    broken = !stdenv.lib.versionOlder kernel.version "4.13";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/schedtool/default.nix b/nixpkgs/pkgs/os-specific/linux/schedtool/default.nix
new file mode 100644
index 000000000000..f24996562d8b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/schedtool/default.nix
@@ -0,0 +1,20 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "schedtool-1.3.0";
+
+  src = fetchurl {
+    url = "http://freequaos.host.sk/schedtool/${name}.tar.bz2";
+    sha256 = "1ky8q3jg4lsxbnlmm51q3jkxh160zy0l6a4xkdy2yncxc4m2l02f";
+  };
+
+  makeFlags = [ "DESTDIR=$(out)" "DESTPREFIX=" ];
+
+  meta = with stdenv.lib; {
+    description = "Query or alter a process' scheduling policy under Linux";
+    homepage = http://freequaos.host.sk/schedtool/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ abbradar ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/default.nix b/nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/default.nix
new file mode 100644
index 000000000000..28e1f0257897
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/default.nix
@@ -0,0 +1,37 @@
+{ lib, fetchurl, runCommandCC, skawarePackages }:
+
+with skawarePackages;
+
+let
+  # From https://skarnet.org/software/misc/sdnotify-wrapper.c,
+  # which is unversioned.
+  src = ./sdnotify-wrapper.c;
+
+in runCommandCC "sdnotify-wrapper" {
+
+   outputs = [ "bin" "doc" "out" ];
+
+   meta = {
+     homepage = "https://skarnet.org/software/misc/sdnotify-wrapper.c";
+     description = "Use systemd sd_notify without having to link against libsystemd";
+     platforms = lib.platforms.all;
+     license = lib.licenses.isc;
+     maintainers = with lib.maintainers; [ Profpatsch ];
+   };
+
+} ''
+  mkdir -p $bin/bin
+  mkdir $out
+
+  # just dynamic for now
+  $CC \
+    -o $bin/bin/sdnotify-wrapper \
+    -I${skalibs.dev}/include \
+    -L${skalibs.lib}/lib \
+    -lskarnet \
+    ${src}
+
+  mkdir -p $doc/share/doc/sdnotify-wrapper
+  # copy the documentation comment
+  sed -ne '/Usage:/,/*\//p' ${src} > $doc/share/doc/sdnotify-wrapper/README
+''
diff --git a/nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/sdnotify-wrapper.c b/nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/sdnotify-wrapper.c
new file mode 100644
index 000000000000..0d1ae96068a4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sdnotify-wrapper/sdnotify-wrapper.c
@@ -0,0 +1,172 @@
+/*
+   Copyright: (C)2015-2017 Laurent Bercot.  http://skarnet.org/
+   ISC license. See http://opensource.org/licenses/ISC
+
+   Build-time requirements: skalibs.  http://skarnet.org/software/skalibs/
+   Run-time requirements: none, if you link skalibs statically.
+ 
+   Compilation:
+     gcc -o sdnotify-wrapper -L/usr/lib/skalibs sdnotify-wrapper.c -lskarnet
+   Use /usr/lib/skalibs/libskarnet.a instead of -lskarnet to link statically.
+   Adapt gcc's -I and -L options to your skalibs installation paths.
+
+   Usage: if a daemon would be launched by systemd as "foobard args...",
+   launch it as "sdnotify-wrapper foobard args..." instead, and you can now
+   tell systemd that this daemon supports readiness notification.
+
+   Instead of using sd_notify() and having to link against the systemd
+   library, the daemon notifies readiness by writing whatever it wants
+   to a file descriptor (by default: stdout), then a newline. (Then it
+   should close that file descriptor.) The simplest way is something like
+   int notify_readiness() { write(1, "\n", 1) ; close(1) ; }
+   This mechanism is understandable by any notification readiness framework.
+
+   Readiness notification occurs when the newline is written, not when
+   the descriptor is closed; but since sdnotify-wrapper stops reading
+   after the first newline and will exit, any subsequent writes will
+   fail and it's best to simply close the descriptor right away.
+
+   sdnotify-wrapper sees the notification when it occurs and sends it
+   to systemd using the sd_notify format.
+
+   Options:
+     -d fd: the daemon will write its notification on descriptor fd.
+     Default is 1.
+     -f: do not doublefork. Use if the daemon waits for children it does
+     not know it has (for instance, superservers do this). When in doubt,
+     do not use that option, or you may have a zombie hanging around.
+     -t timeout: if the daemon has not sent a notification after timeout
+     milliseconds, give up and exit; systemd will not be notified.
+     -k: keep the NOTIFY_SOCKET environment variable when execing into the
+     daemon. By default, the variable is unset: the daemon should not need it.
+
+   Notes:
+     sdnotify-wrapper does not change the daemon's pid. It runs as a
+     (grand)child of the daemon.
+     If the NOTIFY_SOCKET environment variable is not set, sdnotify-wrapper
+     does nothing - it only execs into the daemon.
+     sdnotify-wrapper is more liberal than sd_notify(). It will accept
+     a relative path in NOTIFY_SOCKET.
+*/
+
+
+#include <sys/types.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <skalibs/uint64.h>
+#include <skalibs/types.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/env.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/tai.h>
+#include <skalibs/iopause.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/webipc.h>
+
+#define USAGE "sdnotify-wrapper [ -d fd ] [ -f ] [ -t timeout ] [ -k ] prog..."
+#define dieusage() strerr_dieusage(100, USAGE)
+
+#define VAR "NOTIFY_SOCKET"
+
+static inline int ipc_sendto (int fd, char const *s, size_t len, char const *path)
+{
+  struct sockaddr_un sa ;
+  size_t l = strlen(path) ;
+  if (l > IPCPATH_MAX) return (errno = ENAMETOOLONG, 0) ;
+  memset(&sa, 0, sizeof sa) ;
+  sa.sun_family = AF_UNIX ;
+  memcpy(sa.sun_path, path, l+1) ;
+  if (path[0] == '@') sa.sun_path[0] = 0 ;
+  return sendto(fd, s, len, MSG_NOSIGNAL, (struct sockaddr *)&sa, sizeof sa) >= 0 ;
+}
+
+static inline void notify_systemd (pid_t pid, char const *socketpath)
+{
+  size_t n = 16 ;
+  char fmt[16 + PID_FMT] = "READY=1\nMAINPID=" ;
+  int fd = ipc_datagram_b() ;
+  if (fd < 0) strerr_diefu1sys(111, "create socket") ;
+  n += pid_fmt(fmt + n, pid) ;
+  fmt[n++] = '\n' ;
+  if (!ipc_sendto(fd, fmt, n, socketpath))
+    strerr_diefu2sys(111, "send notification message to ", socketpath) ;
+  close(fd) ;
+}
+
+static inline int run_child (int fd, unsigned int timeout, pid_t pid, char const *s)
+{
+  char dummy[4096] ;
+  iopause_fd x = { .fd = fd, .events = IOPAUSE_READ } ;
+  tain_t deadline ;
+  tain_now_g() ;
+  if (timeout) tain_from_millisecs(&deadline, timeout) ;
+  else deadline = tain_infinite_relative ;
+  tain_add_g(&deadline, &deadline) ;
+  for (;;)
+  {
+    int r = iopause_g(&x, 1, &deadline) ;
+    if (r < 0) strerr_diefu1sys(111, "iopause") ;
+    if (!r) return 99 ;
+    r = sanitize_read(fd_read(fd, dummy, 4096)) ;
+    if (r < 0)
+      if (errno == EPIPE) return 1 ;
+      else strerr_diefu1sys(111, "read from parent") ;
+    else if (r && memchr(dummy, '\n', r)) break ;
+  }
+  close(fd) ;
+  notify_systemd(pid, s) ;
+  return 0 ;
+}
+
+int main (int argc, char const *const *argv, char const *const *envp)
+{
+  char const *s = env_get2(envp, VAR) ;
+  unsigned int fd = 1 ;
+  unsigned int timeout = 0 ;
+  int df = 1, keep = 0 ;
+  PROG = "sdnotify-wrapper" ;
+  {
+    subgetopt_t l = SUBGETOPT_ZERO ;
+    for (;;)
+    {
+      register int opt = subgetopt_r(argc, argv, "d:ft:k", &l) ;
+      if (opt == -1) break ;
+      switch (opt)
+      {
+        case 'd' : if (!uint0_scan(l.arg, &fd)) dieusage() ; break ;
+        case 'f' : df = 0 ; break ;
+        case 't' : if (!uint0_scan(l.arg, &timeout)) dieusage() ; break ;
+        case 'k' : keep = 1 ; break ;
+        default : dieusage() ;
+      }
+    }
+    argc -= l.ind ; argv += l.ind ;
+  }
+  if (!argc) dieusage() ;
+
+  if (!s) xpathexec_run(argv[0], argv, envp) ;
+  else
+  {
+    pid_t parent = getpid() ;
+    pid_t child ;
+    int p[2] ;
+    if (pipe(p) < 0) strerr_diefu1sys(111, "pipe") ;
+    child = df ? doublefork() : fork() ;
+    if (child < 0) strerr_diefu1sys(111, df ? "doublefork" : "fork") ;
+    else if (!child)
+    {
+      PROG = "sdnotify-wrapper (child)" ;
+      close(p[1]) ;
+      return run_child(p[0], timeout, parent, s) ;
+    }
+    close(p[0]) ;
+    if (fd_move((int)fd, p[1]) < 0) strerr_diefu1sys(111, "move descriptor") ;
+    if (keep) xpathexec_run(argv[0], argv, envp) ;
+    else xpathexec_r(argv, envp, env_len(envp), VAR, sizeof(VAR)) ;
+  }
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sdparm/default.nix b/nixpkgs/pkgs/os-specific/linux/sdparm/default.nix
new file mode 100644
index 000000000000..a8d5112c63b9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sdparm/default.nix
@@ -0,0 +1,18 @@
+{stdenv, fetchurl}:
+
+stdenv.mkDerivation rec {
+  name = "sdparm-${version}";
+  version = "1.10";
+
+  src = fetchurl {
+    url = "http://sg.danny.cz/sg/p/${name}.tar.xz";
+    sha256 = "1jjq3lzgfy4r76rc26q02lv4wm5cb4dx5nh913h489zjrr4f3jbx";
+  };
+
+  meta = with stdenv.lib; {
+    homepage = http://sg.danny.cz/sg/sdparm.html;
+    description = "A utility to access SCSI device parameters";
+    license = licenses.bsd3;
+    platforms = with platforms; linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/selinux-python/default.nix b/nixpkgs/pkgs/os-specific/linux/selinux-python/default.nix
new file mode 100644
index 000000000000..527c94de46b3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/selinux-python/default.nix
@@ -0,0 +1,49 @@
+{ stdenv, fetchurl, python3
+, libselinux, libsemanage, libsepol, setools }:
+
+# this is python3 only because setools only supports python3
+
+with stdenv.lib;
+with python3.pkgs;
+
+stdenv.mkDerivation rec {
+  name = "selinux-python-${version}";
+  version = "2.7";
+  se_release = "20170804";
+  se_url = "https://raw.githubusercontent.com/wiki/SELinuxProject/selinux/files/releases";
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/selinux-python-${version}.tar.gz";
+    sha256 = "1va0y4b7cah7rprh04b3ylmwqgnivpkw5z2zw68nrafdbsbcn5s2";
+  };
+
+  nativeBuildInputs = [ wrapPython ];
+  buildInputs = [ libsepol python3 ];
+  propagatedBuildInputs = [ libselinux libsemanage setools ipy ];
+
+  postPatch = ''
+    substituteInPlace sepolicy/Makefile --replace "echo --root" "echo --prefix"
+  '';
+
+  preBuild = ''
+    makeFlagsArray+=("PREFIX=$out")
+    makeFlagsArray+=("DESTDIR=$out")
+    makeFlagsArray+=("LOCALEDIR=$out/share/locale")
+    makeFlagsArray+=("LIBSEPOLA=${stdenv.lib.getLib libsepol}/lib/libsepol.a")
+    makeFlagsArray+=("BASHCOMPLETIONDIR=$out/share/bash-completion/completions")
+    makeFlagsArray+=("PYTHON=${python3}/bin/python")
+    makeFlagsArray+=("PYTHONLIBDIR=lib/${python3.libPrefix}/site-packages")
+  '';
+
+  postFixup = ''
+    wrapPythonPrograms
+  '';
+
+  meta = {
+    description = "SELinux policy core utilities written in Python";
+    license = licenses.gpl2;
+    homepage = https://selinuxproject.org;
+    platforms = platforms.linux;
+  };
+}
+
diff --git a/nixpkgs/pkgs/os-specific/linux/selinux-sandbox/default.nix b/nixpkgs/pkgs/os-specific/linux/selinux-sandbox/default.nix
new file mode 100644
index 000000000000..71d2ee6e80af
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/selinux-sandbox/default.nix
@@ -0,0 +1,61 @@
+{ stdenv, fetchurl, bash, coreutils, python3
+, libcap_ng, policycoreutils, selinux-python, dbus
+, xorgserver, openbox, xmodmap }:
+
+# this is python3 only as it depends on selinux-python
+
+with stdenv.lib; 
+with python3.pkgs;
+
+stdenv.mkDerivation rec {
+  name = "selinux-sandbox-${version}";
+  version = "2.7";
+  se_release = "20170804";
+
+  src = fetchurl {
+    url = "https://raw.githubusercontent.com/wiki/SELinuxProject/selinux/files/releases/${se_release}/selinux-sandbox-${version}.tar.gz";
+    sha256 = "0hf5chm90iapb42njaps6p5460ys3ajh5446ja544vdbh01n544l";
+  };
+
+  nativeBuildInputs = [ wrapPython ];
+  buildInputs = [ bash coreutils libcap_ng policycoreutils python3 xorgserver openbox xmodmap dbus ];
+  propagatedBuildInputs = [ pygobject3 selinux-python ];
+
+  postPatch = ''
+    # Fix setuid install
+    substituteInPlace Makefile --replace "-m 4755" "-m 755"
+    substituteInPlace sandboxX.sh \
+      --replace "#!/bin/sh" "#!${bash}/bin/sh" \
+      --replace "/usr/share/sandbox/start" "${placeholder "out"}/share/sandbox/start" \
+      --replace "/usr/bin/cut" "${coreutils}/bin/cut" \
+      --replace "/usr/bin/Xephyr" "${xorgserver}/bin/Xepyhr" \
+      --replace "secon" "${policycoreutils}/bin/secon"
+    substituteInPlace sandbox \
+      --replace "/usr/sbin/seunshare" "$out/bin/seunshare" \
+      --replace "/usr/share/sandbox" "$out/share/sandbox" \
+      --replace "/usr/share/locale" "${policycoreutils}/share/locale" \
+      --replace "/usr/bin/openbox" "${openbox}/bin/openbox" \
+      --replace "#!/bin/sh" "#!${bash}/bin/sh" \
+      --replace "dbus-" "${dbus}/bin/dbus-" \
+      --replace "/usr/bin/xmodmap" "${xmodmap}/bin/xmodmap" \
+      --replace "/usr/bin/shred" "${coreutils}/bin/shred" \
+      --replace "/usr/bin/test" "${coreutils}/bin/test" \
+  '';
+
+  preBuild = ''
+    makeFlagsArray+=("PREFIX=$out")
+    makeFlagsArray+=("DESTDIR=$out")
+  '';
+
+  postFixup = ''
+    wrapPythonPrograms
+  '';
+
+  meta = {
+    description = "SELinux sandbox utility";
+    license = licenses.gpl2;
+    homepage = https://selinuxproject.org;
+    platforms = platforms.linux;
+  };
+}
+
diff --git a/nixpkgs/pkgs/os-specific/linux/semodule-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/semodule-utils/default.nix
new file mode 100644
index 000000000000..10ba1a3c7d07
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/semodule-utils/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl, libsepol }:
+
+stdenv.mkDerivation rec {
+  name = "semodule-utils-${version}";
+  version = "2.7";
+
+  inherit (libsepol) se_release se_url;
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/${name}.tar.gz";
+    sha256 = "1fl60x4w8rn5bcwy68sy48aydwsn1a17d48slni4sfx4c8rqpjch";
+  };
+
+  buildInputs = [ libsepol ];
+
+  makeFlags = [
+    "PREFIX=$(out)"
+    "LIBSEPOLA=${stdenv.lib.getLib libsepol}/lib/libsepol.a"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "SELinux policy core utilities (packaging additions)";
+    license = licenses.gpl2;
+    inherit (libsepol.meta) homepage platforms;
+    maintainers = [ maintainers.e-user ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sepolgen/default.nix b/nixpkgs/pkgs/os-specific/linux/sepolgen/default.nix
new file mode 100644
index 000000000000..4067e5f70e27
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sepolgen/default.nix
@@ -0,0 +1,24 @@
+{ stdenv, fetchurl, libsepol, python }:
+
+stdenv.mkDerivation rec {
+  name = "sepolgen-${version}";
+  version = "1.2.2";
+  inherit (libsepol) se_release se_url;
+
+  src = fetchurl {
+    url = "${se_url}/${se_release}/sepolgen-${version}.tar.gz";
+    sha256 = "09139kspr41zgksayi4dh982p8080lrfl96p4dld51nknbpaigdy";
+  };
+
+  preBuild = ''
+    makeFlagsArray+=("PREFIX=$out")
+    makeFlagsArray+=("DESTDIR=$out")
+    makeFlagsArray+=("PYTHONLIBDIR=lib/${python.libPrefix}/site-packages")
+  '';
+
+  meta = with stdenv.lib; {
+    inherit (libsepol.meta) homepage platforms maintainers;
+    description = "SELinux policy generation library";
+    license = licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/service-wrapper/default.nix b/nixpkgs/pkgs/os-specific/linux/service-wrapper/default.nix
new file mode 100644
index 000000000000..6c9635b3aee4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/service-wrapper/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, runCommand, substituteAll, coreutils }:
+
+let
+  name = "service-wrapper-${version}";
+  version = "16.04.0"; # Ajar to Ubuntu Release
+in
+runCommand "${name}" {
+  script = substituteAll {
+    src = ./service-wrapper.sh;
+    inherit (stdenv) shell;
+    inherit coreutils;
+  };
+
+  meta = with stdenv.lib; {
+    description = "A convenient wrapper for the systemctl commands, borrow from Ubuntu";
+    license     = licenses.gpl2Plus;
+    platforms   = platforms.linux;
+    maintainers = with maintainers; [ DerTim1 ];
+  };
+}
+''
+  mkdir -p $out/bin
+  ln -s $out/bin $out/sbin
+  cp $script $out/bin/service
+  chmod a+x $out/bin/service
+''
diff --git a/nixpkgs/pkgs/os-specific/linux/service-wrapper/service-wrapper.sh b/nixpkgs/pkgs/os-specific/linux/service-wrapper/service-wrapper.sh
new file mode 100755
index 000000000000..460bf678e6ac
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/service-wrapper/service-wrapper.sh
@@ -0,0 +1,247 @@
+#!@shell@
+
+###########################################################################
+# /usr/bin/service
+#
+# A convenient wrapper for the /etc/init.d init scripts.
+#
+# This script is a modified version of the /sbin/service utility found on
+# Red Hat/Fedora systems (licensed GPLv2+).
+#
+# Copyright (C) 2006 Red Hat, Inc. All rights reserved.
+# Copyright (C) 2008 Canonical Ltd.
+#   * August 2008 - Dustin Kirkland <kirkland@canonical.com>
+# Copyright (C) 2013 Michael Stapelberg <stapelberg@debian.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+#
+# On Debian GNU/Linux systems, the complete text of the GNU General
+# Public License can be found in `/usr/share/common-licenses/GPL-2'.
+###########################################################################
+
+
+is_ignored_file() {
+	case "$1" in
+		skeleton | README | *.dpkg-dist | *.dpkg-old | rc | rcS | single | reboot | bootclean.sh)
+			return 0
+		;;
+	esac
+	return 1
+}
+
+VERSION=$(@coreutils@/bin/basename $0)" ver. 0.91-ubuntu1"
+USAGE="Usage: "$(@coreutils@/bin/basename $0)" < option > | --status-all | \
+[ service_name [ command | --full-restart ] ]"
+SERVICE=
+ACTION=
+SERVICEDIR="/etc/init.d"
+OPTIONS=
+is_systemd=
+
+
+if [ $# -eq 0 ]; then
+   echo "${USAGE}" >&2
+   exit 1
+fi
+
+if [ -d /run/systemd/system ]; then
+   is_systemd=1
+fi
+
+cd /
+while [ $# -gt 0 ]; do
+  case "${1}" in
+    --help | -h | --h* )
+       echo "${USAGE}" >&2
+       exit 0
+       ;;
+    --version | -V )
+       echo "${VERSION}" >&2
+       exit 0
+       ;;
+    *)
+       if [ -z "${SERVICE}" -a $# -eq 1 -a "${1}" = "--status-all" ]; then
+          if [ -d "${SERVICEDIR}" ]; then
+             cd ${SERVICEDIR}
+	     for SERVICE in * ; do
+	       case "${SERVICE}" in
+	         functions | halt | killall | single| linuxconf| kudzu)
+	             ;;
+	         *)
+	           if ! is_ignored_file "${SERVICE}" \
+	   	    && [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+	                   out=$(env -i LANG="$LANG" LANGUAGE="$LANGUAGE" LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC" LC_TIME="$LC_TIME" LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY" LC_MESSAGES="$LC_MESSAGES" LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME" LC_ADDRESS="$LC_ADDRESS" LC_TELEPHONE="$LC_TELEPHONE" LC_MEASUREMENT="$LC_MEASUREMENT" LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status 2>&1)
+	                   retval=$?
+	                   if echo "$out" | egrep -iq "usage:"; then
+	                     #printf " %s %-60s %s\n" "[?]" "$SERVICE:" "unknown" 1>&2
+	                     echo " [ ? ]  $SERVICE" 1>&2
+	                     continue
+	                   else
+	                     if [ "$retval" = "0" -a -n "$out" ]; then
+	                       #printf " %s %-60s %s\n" "[+]" "$SERVICE:" "running"
+	                       echo " [ + ]  $SERVICE"
+	                       continue
+	                     else
+	                       #printf " %s %-60s %s\n" "[-]" "$SERVICE:" "NOT running"
+	                       echo " [ - ]  $SERVICE"
+	                       continue
+	                     fi
+	                   fi
+	             #env -i LANG="$LANG" LANGUAGE="$LANGUAGE" LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC" LC_TIME="$LC_TIME" LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY" LC_MESSAGES="$LC_MESSAGES" LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME" LC_ADDRESS="$LC_ADDRESS" LC_TELEPHONE="$LC_TELEPHONE" LC_MEASUREMENT="$LC_MEASUREMENT" LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" status
+	           fi
+	           ;;
+	       esac
+	     done
+          else
+             systemctl $sctl_args list-units
+          fi
+          exit 0
+       elif [ $# -eq 2 -a "${2}" = "--full-restart" ]; then
+          SERVICE="${1}"
+          # On systems using systemd, we just perform a normal restart:
+          # A restart with systemd is already a full restart.
+          if [ -n "$is_systemd" ]; then
+             ACTION="restart"
+          else
+             if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+               env -i LANG="$LANG" LANGUAGE="$LANGUAGE" LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC" LC_TIME="$LC_TIME" LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY" LC_MESSAGES="$LC_MESSAGES" LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME" LC_ADDRESS="$LC_ADDRESS" LC_TELEPHONE="$LC_TELEPHONE" LC_MEASUREMENT="$LC_MEASUREMENT" LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" stop
+               env -i LANG="$LANG" LANGUAGE="$LANGUAGE" LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC" LC_TIME="$LC_TIME" LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY" LC_MESSAGES="$LC_MESSAGES" LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME" LC_ADDRESS="$LC_ADDRESS" LC_TELEPHONE="$LC_TELEPHONE" LC_MEASUREMENT="$LC_MEASUREMENT" LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" start
+               exit $?
+             fi
+          fi
+       elif [ -z "${SERVICE}" ]; then
+         SERVICE="${1}"
+       elif [ -z "${ACTION}" ]; then
+         ACTION="${1}"
+       else
+         OPTIONS="${OPTIONS} ${1}"
+       fi
+       shift
+       ;;
+   esac
+done
+
+# Operate against system upstart, not session
+unset UPSTART_SESSION
+if [ -r "/etc/init/${SERVICE}.conf" ] && which initctl >/dev/null \
+   && initctl version 2>/dev/null | grep -q upstart \
+   && initctl status ${SERVICE} 2>/dev/null 1>/dev/null
+then
+   # Upstart configuration exists for this job and we're running on upstart
+   case "${ACTION}" in
+      start|stop|status|reload)
+         # Action is a valid upstart action
+         exec ${ACTION} ${SERVICE} ${OPTIONS}
+      ;;
+      restart|force-reload)
+        # Map restart to the usual sysvinit behavior.
+        # Map force-reload to restart as per Debian policy 9.3.2,
+        # since there is no way to know if "reload" is supported
+         stop ${SERVICE} ${OPTIONS} || :
+         exec start ${SERVICE} ${OPTIONS}
+      ;;
+   esac
+fi
+
+
+run_via_sysvinit() {
+   # Otherwise, use the traditional sysvinit
+   if [ -x "${SERVICEDIR}/${SERVICE}" ]; then
+      exec env -i LANG="$LANG" LANGUAGE="$LANGUAGE" LC_CTYPE="$LC_CTYPE" LC_NUMERIC="$LC_NUMERIC" LC_TIME="$LC_TIME" LC_COLLATE="$LC_COLLATE" LC_MONETARY="$LC_MONETARY" LC_MESSAGES="$LC_MESSAGES" LC_PAPER="$LC_PAPER" LC_NAME="$LC_NAME" LC_ADDRESS="$LC_ADDRESS" LC_TELEPHONE="$LC_TELEPHONE" LC_MEASUREMENT="$LC_MEASUREMENT" LC_IDENTIFICATION="$LC_IDENTIFICATION" LC_ALL="$LC_ALL" PATH="$PATH" TERM="$TERM" "$SERVICEDIR/$SERVICE" ${ACTION} ${OPTIONS}
+   else
+      echo "${SERVICE}: unrecognized service" >&2
+      exit 1
+   fi
+}
+
+update_openrc_started_symlinks() {
+   # maintain the symlinks of /run/openrc/started so that
+   # rc-status works with the service command as well
+   if [ -d /run/openrc/started ] ; then
+      case "${ACTION}" in
+      start)
+         if [ ! -h /run/openrc/started/$SERVICE ] ; then
+            ln -s $SERVICEDIR/$SERVICE /run/openrc/started/$SERVICE || true
+         fi
+      ;;
+      stop)
+         rm /run/openrc/started/$SERVICE || true
+      ;;
+      esac
+   fi
+}
+
+# When this machine is running systemd, standard service calls are turned into
+# systemctl calls.
+if [ -n "$is_systemd" ]
+then
+   UNIT="${SERVICE%.sh}.service"
+   # avoid deadlocks during bootup and shutdown from units/hooks
+   # which call "invoke-rc.d service reload" and similar, since
+   # the synchronous wait plus systemd's normal behaviour of
+   # transactionally processing all dependencies first easily
+   # causes dependency loops
+   if ! systemctl --quiet is-active multi-user.target; then
+       sctl_args="--job-mode=ignore-dependencies"
+   fi
+
+   case "${ACTION}" in
+      restart|status)
+         exec systemctl $sctl_args ${ACTION} ${UNIT}
+      ;;
+      start|stop)
+         # Follow the principle of least surprise for SysV people:
+         # When running "service foo stop" and foo happens to be a service that
+         # has one or more .socket files, we also stop the .socket units.
+         # Users who need more control will use systemctl directly.
+         for unit in $(systemctl list-unit-files --full --type=socket 2>/dev/null | sed -ne 's/\.socket\s*[a-z]*\s*$/.socket/p'); do
+             if [ "$(systemctl -p Triggers show $unit)" = "Triggers=${UNIT}" ]; then
+                systemctl $sctl_args ${ACTION} $unit
+             fi
+         done
+         exec systemctl $sctl_args ${ACTION} ${UNIT}
+      ;;
+      reload)
+         _canreload="$(SYSTEMCTL -p CanReload show ${UNIT} 2>/dev/null)"
+         if [ "$_canreload" = "CanReload=no" ]; then
+            # The reload action falls back to the sysv init script just in case
+            # the systemd service file does not (yet) support reload for a
+            # specific service.
+            run_via_sysvinit
+         else
+            exec systemctl $sctl_args reload "${UNIT}"
+         fi
+         ;;
+      force-stop)
+         exec systemctl --signal=KILL kill "${UNIT}"
+         ;;
+      force-reload)
+         _canreload="$(systemctl -p CanReload show ${UNIT} 2>/dev/null)"
+         if [ "$_canreload" = "CanReload=no" ]; then
+            exec systemctl $sctl_args restart "${UNIT}"
+         else
+            exec systemctl $sctl_args reload "${UNIT}"
+         fi
+         ;;
+      *)
+         # We try to run non-standard actions by running
+         # the init script directly.
+         run_via_sysvinit
+         ;;
+   esac
+fi
+
+update_openrc_started_symlinks
+run_via_sysvinit
diff --git a/nixpkgs/pkgs/os-specific/linux/setools/default.nix b/nixpkgs/pkgs/os-specific/linux/setools/default.nix
new file mode 100644
index 000000000000..039d875060a2
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/setools/default.nix
@@ -0,0 +1,42 @@
+{ stdenv, fetchFromGitHub, bison, flex, python3 , swig
+, libsepol, libselinux, checkpolicy
+, withGraphics ? false
+}:
+
+with stdenv.lib;
+with python3.pkgs;
+
+buildPythonApplication rec {
+  pname = "setools";
+  version = "2017-11-10";
+
+  src = fetchFromGitHub {
+    owner = "TresysTechnology";
+    repo = pname;
+    rev = "a1aa0f33f5c428d3f9fe82960ed5de36f38047f7";
+    sha256 = "0iyj35fff93cprjkzbkg9dn5xz8dg5h2kjx3476fl625nxxskndn";
+  };
+
+  nativeBuildInputs = [ bison flex swig ];
+  buildInputs = [ libsepol ];
+  propagatedBuildInputs = [ enum34 libselinux networkx ]
+    ++ optionals withGraphics [ pyqt5 ];
+
+  checkInputs = [ tox checkpolicy ];
+  preCheck = ''
+    export CHECKPOLICY=${checkpolicy}/bin/checkpolicy
+  '';
+
+  setupPyBuildFlags = [ "-i" ];
+
+  preBuild = ''
+    export SEPOL="${stdenv.lib.getLib libsepol}/lib/libsepol.a"
+  '';
+
+  meta = {
+    description = "SELinux Tools";
+    homepage = https://github.com/TresysTechnology/setools/wiki;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/seturgent/default.nix b/nixpkgs/pkgs/os-specific/linux/seturgent/default.nix
new file mode 100644
index 000000000000..15582574ecb0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/seturgent/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchurl, libX11, xorgproto, unzip }:
+
+stdenv.mkDerivation {
+  name = "seturgent-2012-08-17";
+
+  src = fetchurl {
+    url = "https://github.com/hiltjo/seturgent/archive/ada70dcb15865391e5cdcab27a0739a304a17e03.zip";
+    sha256 = "0q1sr6aljkw2jr9b4xxzbc01qvnd5vk3pxrypif9yd8xjw4wqwri";
+  };
+
+  buildInputs = [
+    libX11 xorgproto unzip
+  ];
+
+  installPhase = ''
+    mkdir -pv $out/bin
+    mv seturgent $out/bin
+  '';
+
+  meta = {
+      platforms = stdenv.lib.platforms.linux;
+      description = "Set an application's urgency hint (or not)";
+      maintainers = [ stdenv.lib.maintainers.yarr ];
+      homepage = https://github.com/hiltjo/seturgent;
+      license = stdenv.lib.licenses.mit;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/shadow/default.nix b/nixpkgs/pkgs/os-specific/linux/shadow/default.nix
new file mode 100644
index 000000000000..8c778e72b704
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/shadow/default.nix
@@ -0,0 +1,93 @@
+{ stdenv, fetchpatch, fetchFromGitHub, autoreconfHook, libxslt, libxml2
+, docbook_xml_dtd_412, docbook_xsl, gnome-doc-utils, flex, bison
+, pam ? null, glibcCross ? null
+}:
+
+let
+
+  glibc =
+    if stdenv.hostPlatform != stdenv.buildPlatform
+    then glibcCross
+    else assert stdenv.hostPlatform.libc == "glibc"; stdenv.cc.libc;
+
+  dots_in_usernames = fetchpatch {
+    url = http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-apps/shadow/files/shadow-4.1.3-dots-in-usernames.patch;
+    sha256 = "1fj3rg6x3jppm5jvi9y7fhd2djbi4nc5pgwisw00xlh4qapgz692";
+  };
+
+in
+
+stdenv.mkDerivation rec {
+  name = "shadow-${version}";
+  version = "4.6";
+
+  src = fetchFromGitHub {
+    owner = "shadow-maint";
+    repo = "shadow";
+    rev = "${version}";
+    sha256 = "1llcv77lvpc4h3rgww9ms736kbdisiylcr2z02863f41afxbwl82";
+  };
+
+  buildInputs = stdenv.lib.optional (pam != null && stdenv.isLinux) pam;
+  nativeBuildInputs = [autoreconfHook libxslt libxml2
+    docbook_xml_dtd_412 docbook_xsl gnome-doc-utils flex bison
+    ];
+
+  patches =
+    [ ./keep-path.patch
+      dots_in_usernames
+    ];
+
+  # The nix daemon often forbids even creating set[ug]id files.
+  postPatch =
+    ''sed 's/^\(s[ug]idperms\) = [0-9]755/\1 = 0755/' -i src/Makefile.am
+    '';
+
+  outputs = [ "out" "su" "man" ];
+
+  enableParallelBuilding = true;
+
+  # Assume System V `setpgrp (void)', which is the default on GNU variants
+  # (`AC_FUNC_SETPGRP' is not cross-compilation capable.)
+  preConfigure = ''
+    export ac_cv_func_setpgrp_void=yes
+    export shadow_cv_logdir=/var/log
+    (
+    head -n -1 "${docbook_xml_dtd_412}/xml/dtd/docbook/catalog.xml"
+    tail -n +3 "${docbook_xsl}/share/xml/docbook-xsl/catalog.xml"
+    ) > xmlcatalog
+    configureFlags="$configureFlags --with-xml-catalog=$PWD/xmlcatalog ";
+  '';
+
+  configureFlags = [
+    "--enable-man"
+    "--with-group-name-max-length=32"
+  ] ++ stdenv.lib.optional (stdenv.hostPlatform.libc != "glibc") "--disable-nscd";
+
+  preBuild = stdenv.lib.optionalString (stdenv.hostPlatform.libc == "glibc")
+    ''
+      substituteInPlace lib/nscd.c --replace /usr/sbin/nscd ${glibc.bin}/bin/nscd
+    '';
+
+  postInstall =
+    ''
+      # Don't install ‘groups’, since coreutils already provides it.
+      rm $out/bin/groups
+      rm $man/share/man/man1/groups.*
+
+      # Move the su binary into the su package
+      mkdir -p $su/bin
+      mv $out/bin/su $su/bin
+    '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/shadow-maint;
+    description = "Suite containing authentication-related tools such as passwd and su";
+    license = licenses.bsd3;
+    platforms = platforms.linux;
+  };
+
+  passthru = {
+    shellPath = "/bin/nologin";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/shadow/keep-path.patch b/nixpkgs/pkgs/os-specific/linux/shadow/keep-path.patch
new file mode 100644
index 000000000000..99fd17c27bc9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/shadow/keep-path.patch
@@ -0,0 +1,19 @@
+diff -ru shadow-4.1.5.1-orig/src/su.c shadow-4.1.5.1/src/su.c
+--- shadow-4.1.5.1-orig/src/su.c	2012-05-25 07:51:55.000000000 -0400
++++ shadow-4.1.5.1/src/su.c	2012-07-25 17:22:57.013547930 -0400
+@@ -879,6 +879,7 @@
+ 		}
+ 	}
+ 
++#if 0
+ 	cp = getdef_str ((pw->pw_uid == 0) ? "ENV_SUPATH" : "ENV_PATH");
+ 	if (NULL == cp) {
+ 		addenv ((pw->pw_uid == 0) ? "PATH=/sbin:/bin:/usr/sbin:/usr/bin" : "PATH=/bin:/usr/bin", NULL);
+@@ -887,6 +888,7 @@
+ 	} else {
+ 		addenv ("PATH", cp);
+ 	}
++#endif
+ 
+ 	if (getenv ("IFS") != NULL) {	/* don't export user IFS ... */
+ 		addenv ("IFS= \t\n", NULL);	/* ... instead, set a safe IFS */
diff --git a/nixpkgs/pkgs/os-specific/linux/sinit/default.nix b/nixpkgs/pkgs/os-specific/linux/sinit/default.nix
new file mode 100644
index 000000000000..32761970d81c
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sinit/default.nix
@@ -0,0 +1,37 @@
+{stdenv, fetchgit, rcinit ? null, rcshutdown ? null, rcreboot ? null}:
+let
+  s = # Generated upstream information
+  rec {
+    baseName="sinit";
+    version="1.0";
+    name="${baseName}-${version}";
+    url="https://git.suckless.org/sinit/";
+    sha256="0cf8yylgrrj1wxm5v6jdlbnxpx97m38yxrc9nmv1l8hldjqsj9pc";
+    rev = "refs/tags/v${version}";
+  };
+  buildInputs = [
+    (stdenv.lib.getOutput "static" stdenv.cc.libc)
+  ];
+in
+stdenv.mkDerivation {
+  inherit (s) name version;
+  inherit buildInputs;
+  src = fetchgit {
+    inherit (s) url sha256 rev;
+  };
+  makeFlags = ["PREFIX=$(out)"];
+  preConfigure = ""
+    + (stdenv.lib.optionalString (rcinit != null) ''sed -re 's@(rcinitcmd[^"]*")[^"]*"@\1${rcinit}"@' -i config.def.h; '')
+    + (stdenv.lib.optionalString (rcshutdown != null) ''sed -re 's@(rc(reboot|poweroff)cmd[^"]*")[^"]*"@\1${rcshutdown}"@' -i config.def.h; '')
+    + (stdenv.lib.optionalString (rcreboot != null) ''sed -re 's@(rc(reboot)cmd[^"]*")[^"]*"@\1${rcreboot}"@' -i config.def.h; '')
+    ;
+  meta = {
+    inherit (s) version;
+    description = ''A very minimal Linux init implementation from suckless.org'';
+    license = stdenv.lib.licenses.mit ;
+    maintainers = [stdenv.lib.maintainers.raskin];
+    platforms = stdenv.lib.platforms.linux;
+    homepage = https://tools.suckless.org/sinit;
+    downloadPage = "https://git.suckless.org/sinit";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/smem/default.nix b/nixpkgs/pkgs/os-specific/linux/smem/default.nix
new file mode 100644
index 000000000000..de12b3719af3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/smem/default.nix
@@ -0,0 +1,29 @@
+{ lib, stdenv, fetchurl, python }:
+
+stdenv.mkDerivation rec {
+  name = "smem-${version}";
+  version = "1.5";
+
+  src = fetchurl {
+    url = "https://selenic.com/repo/smem/archive/${version}.tar.bz2";
+    sha256 = "19ibv1byxf2b68186ysrgrhy5shkc5mc69abark1h18yigp3j34m";
+  };
+
+  buildInputs = [ python ];
+
+  makeFlags = [ "smemcap" ];
+
+  installPhase =
+    ''
+      install -Dm555 -t $out/bin/ smem smemcap
+      install -Dm444 -t $out/share/man/man8/ smem.8
+    '';
+
+  meta = {
+    homepage = https://www.selenic.com/smem/;
+    description = "A memory usage reporting tool that takes shared memory into account";
+    platforms = lib.platforms.linux;
+    maintainers = [ lib.maintainers.eelco ];
+    license = lib.licenses.gpl2Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/smemstat/default.nix b/nixpkgs/pkgs/os-specific/linux/smemstat/default.nix
new file mode 100644
index 000000000000..6abbd2d1ec56
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/smemstat/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, lib, fetchurl, ncurses }:
+
+stdenv.mkDerivation rec {
+  name = "smemstat-${version}";
+  version = "0.02.03";
+  src = fetchurl {
+    url = "http://kernel.ubuntu.com/~cking/tarballs/smemstat/smemstat-${version}.tar.xz";
+    sha256 = "04q06wb37n4g1dlsjl8j2bwzd7qis4wanm0f4xg8y29br6skljx1";
+  };
+  buildInputs = [ ncurses ];
+  installFlags = [ "DESTDIR=$(out)" ];
+  postInstall = ''
+    mv $out/usr/* $out
+    rm -r $out/usr
+  '';
+  meta = with lib; {
+    description = "Memory usage monitoring tool";
+    homepage = http://kernel.ubuntu.com/~cking/smemstat/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ womfoo ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/speedometer/default.nix b/nixpkgs/pkgs/os-specific/linux/speedometer/default.nix
new file mode 100644
index 000000000000..f9c971502921
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/speedometer/default.nix
@@ -0,0 +1,26 @@
+{ stdenv, lib, fetchurl, pythonPackages }:
+
+pythonPackages.buildPythonApplication rec {
+  name = "speedometer-${version}";
+  version = "2.8";
+
+  src = fetchurl {
+    url = "http://excess.org/speedometer/speedometer-${version}.tar.gz";
+    sha256 = "060bikv3gwr203jbdmvawsfhc0yq0bg1m42dk8czx1nqvwvgv6fm";
+  };
+
+  propagatedBuildInputs = [ pythonPackages.urwid ];
+
+  postPatch = ''
+    sed -i "/'entry_points': {/d" setup.py
+    sed -i "/'console_scripts': \['speedometer = speedometer:console'\],},/d" setup.py
+  '';
+
+  meta = with lib; {
+    description = "Measure and display the rate of data across a network connection or data being stored in a file";
+    homepage = http://excess.org/speedometer/;
+    license = licenses.lgpl21Plus;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ Baughn ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/spl/default.nix b/nixpkgs/pkgs/os-specific/linux/spl/default.nix
new file mode 100644
index 000000000000..bf435cc862c1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/spl/default.nix
@@ -0,0 +1,56 @@
+{ fetchFromGitHub, stdenv, autoreconfHook, coreutils, gawk
+, fetchpatch
+# Kernel dependencies
+, kernel
+}:
+
+with stdenv.lib;
+
+assert kernel != null;
+
+stdenv.mkDerivation rec {
+  name = "spl-${version}-${kernel.version}";
+  version = "0.7.13";
+
+  src = fetchFromGitHub {
+    owner = "zfsonlinux";
+    repo = "spl";
+    rev = "spl-${version}";
+    sha256 = "1rzqgiszy8ad2gx20577azp1y5jgad0907slfzl5y2zb05jgaipa";
+  };
+
+  patches = [ ./install_prefix.patch ];
+
+  nativeBuildInputs = [ autoreconfHook ] ++ kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "fortify" "stackprotector" "pic" ];
+
+  preConfigure = ''
+    substituteInPlace ./module/spl/spl-generic.c --replace /usr/bin/hostid hostid
+    substituteInPlace ./module/spl/spl-generic.c --replace "PATH=/sbin:/usr/sbin:/bin:/usr/bin" "PATH=${coreutils}:${gawk}:/bin"
+    substituteInPlace ./module/splat/splat-vnode.c --replace "PATH=/sbin:/usr/sbin:/bin:/usr/bin" "PATH=${coreutils}:/bin"
+    substituteInPlace ./module/splat/splat-linux.c --replace "PATH=/sbin:/usr/sbin:/bin:/usr/bin" "PATH=${coreutils}:/bin"
+  '';
+
+  configureFlags = [
+    "--with-config=kernel"
+    "--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
+    "--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  ];
+
+  enableParallelBuilding = true;
+
+  meta = {
+    description = "Kernel module driver for solaris porting layer (needed by in-kernel zfs)";
+
+    longDescription = ''
+      This kernel module is a porting layer for ZFS to work inside the linux
+      kernel.
+    '';
+
+    homepage = http://zfsonlinux.org/;
+    platforms = platforms.linux;
+    license = licenses.gpl2Plus;
+    maintainers = with maintainers; [ jcumming wizeman fpletz globin ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/spl/install_prefix.patch b/nixpkgs/pkgs/os-specific/linux/spl/install_prefix.patch
new file mode 100644
index 000000000000..566aab828ef7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/spl/install_prefix.patch
@@ -0,0 +1,168 @@
+diff --git a/Makefile.am b/Makefile.am
+index 4977448..ac17217 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -12,10 +12,10 @@ endif
+ if CONFIG_KERNEL
+ SUBDIRS += module
+ 
+-extradir = @prefix@/src/spl-$(VERSION)
++extradir = @prefix@/libexec/spl
+ extra_HEADERS = spl.release.in spl_config.h.in
+ 
+-kerneldir = @prefix@/src/spl-$(VERSION)/$(LINUX_VERSION)
++kerneldir = @prefix@/libexec/spl/$(LINUX_VERSION)
+ nodist_kernel_HEADERS = spl.release spl_config.h module/$(LINUX_SYMBOLS)
+ endif
+ 
+diff --git a/include/Makefile.am b/include/Makefile.am
+index 3200222..4a47aaa 100644
+--- a/include/Makefile.am
++++ b/include/Makefile.am
+@@ -13,6 +13,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include
++kerneldir = @prefix@/libexec/spl/include
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/fs/Makefile.am b/include/fs/Makefile.am
+index e0da4b3..d6d7af0 100644
+--- a/include/fs/Makefile.am
++++ b/include/fs/Makefile.am
+@@ -8,6 +8,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/fs
++kerneldir = @prefix@/libexec/spl/include/fs
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/linux/Makefile.am b/include/linux/Makefile.am
+index 712e94e..4af9fb7 100644
+--- a/include/linux/Makefile.am
++++ b/include/linux/Makefile.am
+@@ -18,6 +18,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/linux
++kerneldir = @prefix@/libexec/spl/include/linux
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/rpc/Makefile.am b/include/rpc/Makefile.am
+index cfc8246..4fbd33d 100644
+--- a/include/rpc/Makefile.am
++++ b/include/rpc/Makefile.am
+@@ -9,6 +9,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/rpc
++kerneldir = @prefix@/libexec/spl/include/rpc
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/sharefs/Makefile.am b/include/sharefs/Makefile.am
+index 10e7093..febecdf 100644
+--- a/include/sharefs/Makefile.am
++++ b/include/sharefs/Makefile.am
+@@ -8,6 +8,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/sharefs
++kerneldir = @prefix@/libexec/spl/include/sharefs
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/sys/Makefile.am b/include/sys/Makefile.am
+index 73c4a84..31a9f50 100644
+--- a/include/sys/Makefile.am
++++ b/include/sys/Makefile.am
+@@ -107,7 +107,7 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/sys
++kerneldir = @prefix@/libexec/spl/include/sys
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+ 
+diff --git a/include/sys/fm/Makefile.am b/include/sys/fm/Makefile.am
+index 2821cbe..a84ce8e 100644
+--- a/include/sys/fm/Makefile.am
++++ b/include/sys/fm/Makefile.am
+@@ -9,6 +9,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/sys/fm
++kerneldir = @prefix@/libexec/spl/include/sys/fm
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/sys/fs/Makefile.am b/include/sys/fs/Makefile.am
+index 581083e..0c35fb7 100644
+--- a/include/sys/fs/Makefile.am
++++ b/include/sys/fs/Makefile.am
+@@ -8,6 +8,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/sys/fs
++kerneldir = @prefix@/libexec/spl/include/sys/fs
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/util/Makefile.am b/include/util/Makefile.am
+index e2bf09f..3f5d6ce 100644
+--- a/include/util/Makefile.am
++++ b/include/util/Makefile.am
+@@ -9,6 +9,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/util
++kerneldir = @prefix@/libexec/spl/include/util
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+diff --git a/include/vm/Makefile.am b/include/vm/Makefile.am
+index 7faab0a..8148b3d 100644
+--- a/include/vm/Makefile.am
++++ b/include/vm/Makefile.am
+@@ -10,6 +10,6 @@ USER_H =
+ EXTRA_DIST = $(COMMON_H) $(KERNEL_H) $(USER_H)
+ 
+ if CONFIG_KERNEL
+-kerneldir = @prefix@/src/spl-$(VERSION)/include/vm
++kerneldir = @prefix@/libexec/spl/include/vm
+ kernel_HEADERS = $(KERNEL_H)
+ endif
+--- a/module/Makefile.in
++++ b/module/Makefile.in
+@@ -21,22 +21,22 @@
+ modules_install:
+ 	@# Install the kernel modules
+ 	$(MAKE) -C @LINUX_OBJ@ M=`pwd` $@ \
+-		INSTALL_MOD_PATH=$(DESTDIR)$(INSTALL_MOD_PATH) \
++		INSTALL_MOD_PATH=@prefix@/$(INSTALL_MOD_PATH) \
+ 		INSTALL_MOD_DIR=$(INSTALL_MOD_DIR) \
+ 		KERNELRELEASE=@LINUX_VERSION@
+ 	@# Remove extraneous build products when packaging
+-	kmoddir=$(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \
+-	if [ -n "$(DESTDIR)" ]; then \
++	kmoddir=@prefix@/$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@; \
++	if [ -n "@prefix@" ]; then \
+ 		find $$kmoddir -name 'modules.*' | xargs $(RM); \
+ 	fi
+-	sysmap=$(DESTDIR)$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \
++	sysmap=@prefix@/$(INSTALL_MOD_PATH)/boot/System.map-@LINUX_VERSION@; \
+ 	if [ -f $$sysmap ]; then \
+ 		depmod -ae -F $$sysmap @LINUX_VERSION@; \
+ 	fi
+ 
+ modules_uninstall:
+ 	@# Uninstall the kernel modules
+-	kmoddir=$(DESTDIR)$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@
++	kmoddir=@prefix@/$(INSTALL_MOD_PATH)/lib/modules/@LINUX_VERSION@
+ 	list='$(subdir-m)'; for subdir in $$list; do \
+ 		$(RM) -R $$kmoddir/$(INSTALL_MOD_DIR)/$$subdir; \
+ 	done
diff --git a/nixpkgs/pkgs/os-specific/linux/sssd/default.nix b/nixpkgs/pkgs/os-specific/linux/sssd/default.nix
new file mode 100644
index 000000000000..fdde2bedf552
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sssd/default.nix
@@ -0,0 +1,91 @@
+{ stdenv, fetchurl, fetchpatch, glibc, augeas, dnsutils, c-ares, curl,
+  cyrus_sasl, ding-libs, libnl, libunistring, nss, samba, nfs-utils, doxygen,
+  python, python3, pam, popt, talloc, tdb, tevent, pkgconfig, ldb, openldap,
+  pcre, kerberos, cifs-utils, glib, keyutils, dbus, fakeroot, libxslt, libxml2,
+  libuuid, ldap, systemd, nspr, check, cmocka, uid_wrapper,
+  nss_wrapper, ncurses, Po4a, http-parser, jansson,
+  docbook_xsl, docbook_xml_dtd_44,
+  withSudo ? false }:
+
+let
+  docbookFiles = "${docbook_xsl}/share/xml/docbook-xsl/catalog.xml:${docbook_xml_dtd_44}/xml/dtd/docbook/catalog.xml";
+in
+stdenv.mkDerivation rec {
+  name = "sssd-${version}";
+  version = "1.16.4";
+
+  src = fetchurl {
+    url = "https://fedorahosted.org/released/sssd/${name}.tar.gz";
+    sha256 = "0ngr7cgimyjc6flqkm7psxagp1m4jlzpqkn28pliifbmdg6i5ckb";
+  };
+
+  # Something is looking for <libxml/foo.h> instead of <libxml2/libxml/foo.h>
+  NIX_CFLAGS_COMPILE = "-I${libxml2.dev}/include/libxml2";
+
+  preConfigure = ''
+    export SGML_CATALOG_FILES="${docbookFiles}"
+    export PYTHONPATH=${ldap}/lib/python2.7/site-packages
+    export PATH=$PATH:${openldap}/libexec
+
+    configureFlagsArray=(
+      --prefix=$out
+      --sysconfdir=/etc
+      --localstatedir=/var
+      --enable-pammoddir=$out/lib/security
+      --with-os=fedora
+      --with-pid-path=/run
+      --with-python2-bindings
+      --with-python3-bindings
+      --with-syslog=journald
+      --without-selinux
+      --without-semanage
+      --with-xml-catalog-path=''${SGML_CATALOG_FILES%%:*}
+      --with-ldb-lib-dir=$out/modules/ldb
+      --with-nscd=${glibc.bin}/sbin/nscd
+    )
+  '' + stdenv.lib.optionalString withSudo ''
+    configureFlagsArray+=("--with-sudo")
+  '';
+
+  enableParallelBuilding = true;
+  buildInputs = [ augeas dnsutils c-ares curl cyrus_sasl ding-libs libnl libunistring nss
+                  samba nfs-utils doxygen python python3 popt
+                  talloc tdb tevent pkgconfig ldb pam openldap pcre kerberos
+                  cifs-utils glib keyutils dbus fakeroot libxslt libxml2
+                  libuuid ldap systemd nspr check cmocka uid_wrapper
+                  nss_wrapper ncurses Po4a http-parser jansson ];
+
+  makeFlags = [
+    "SGML_CATALOG_FILES=${docbookFiles}"
+  ];
+
+  installFlags = [
+     "sysconfdir=$(out)/etc"
+     "localstatedir=$(out)/var"
+     "pidpath=$(out)/run"
+     "sss_statedir=$(out)/var/lib/sss"
+     "logpath=$(out)/var/log/sssd"
+     "pubconfpath=$(out)/var/lib/sss/pubconf"
+     "dbpath=$(out)/var/lib/sss/db"
+     "mcpath=$(out)/var/lib/sss/mc"
+     "pipepath=$(out)/var/lib/sss/pipes"
+     "gpocachepath=$(out)/var/lib/sss/gpo_cache"
+     "secdbpath=$(out)/var/lib/sss/secrets"
+     "initdir=$(out)/rc.d/init"
+  ];
+
+  postInstall = ''
+    rm -rf "$out"/run
+    rm -rf "$out"/rc.d
+    rm -f "$out"/modules/ldb/memberof.la
+    find "$out" -depth -type d -exec rmdir --ignore-fail-on-non-empty {} \;
+  '';
+
+  meta = with stdenv.lib; {
+    description = "System Security Services Daemon";
+    homepage = https://fedorahosted.org/sssd/;
+    license = licenses.gpl3;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.e-user ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/statifier/default.nix b/nixpkgs/pkgs/os-specific/linux/statifier/default.nix
new file mode 100644
index 000000000000..376ae47ffbe0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/statifier/default.nix
@@ -0,0 +1,24 @@
+{ multiStdenv, fetchurl }:
+
+let version = "1.7.4"; in
+multiStdenv.mkDerivation {
+  name = "statifier-${version}";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/statifier/statifier-${version}.tar.gz";
+    sha256 = "03lzkla6knjhh186b43cac410x2fmhi28pkmzb3d211n3zp5i9y8";
+  };
+
+  phaseNames = [ "patchPhase" "installPhase" ];
+
+  postPatch = ''
+    sed -e s@/usr/@"$out/"@g -i */Makefile src/statifier
+    sed -e s@/bin/bash@"${multiStdenv.shell}"@g -i src/*.sh
+  '';
+
+  meta = with multiStdenv.lib; {
+    description = "Tool for creating static Linux binaries";
+    platforms = platforms.linux;
+    license = licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/syscall_limiter/default.nix b/nixpkgs/pkgs/os-specific/linux/syscall_limiter/default.nix
new file mode 100644
index 000000000000..c7543aee9337
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/syscall_limiter/default.nix
@@ -0,0 +1,37 @@
+{ stdenv
+, fetchFromGitHub
+, libseccomp
+, perl
+, which
+}:
+
+stdenv.mkDerivation rec {
+  name    = "syscall_limiter-${version}";
+  version = "2017-01-23";
+
+  src = fetchFromGitHub {
+    owner  = "vi";
+    repo   = "syscall_limiter";
+    rev    = "481c8c883f2e1260ebc83b352b63bf61a930a341";
+    sha256 = "0z5arj1kq1xczgrbw1b8m9kicbv3vs9bd32wvgfr4r6ndingsp5m";
+  };
+
+  buildInputs = [ libseccomp ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp -v limit_syscalls $out/bin
+    cp -v monitor.sh $out/bin/limit_syscalls_monitor.sh
+    substituteInPlace $out/bin/limit_syscalls_monitor.sh \
+      --replace perl ${perl}/bin/perl \
+      --replace which ${which}/bin/which
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Start Linux programs with only selected syscalls enabled";
+    homepage    = https://github.com/vi/syscall_limiter;
+    license     = licenses.mit;
+    maintainers = with maintainers; [ obadz ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sysdig/default.nix b/nixpkgs/pkgs/os-specific/linux/sysdig/default.nix
new file mode 100644
index 000000000000..33f1bbdd893f
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysdig/default.nix
@@ -0,0 +1,64 @@
+{ stdenv, fetchFromGitHub, cmake, kernel
+, luajit, zlib, ncurses, perl, jsoncpp, libb64, openssl, curl, jq, gcc, elfutils, tbb
+}:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+  name = "sysdig-${version}";
+  version = "0.24.2";
+
+  src = fetchFromGitHub {
+    owner = "draios";
+    repo = "sysdig";
+    rev = version;
+    sha256 = "16gz6gcp0zfhrqldw9cms38w0x5h3qhlx64dayqgsqbkw914b31a";
+  };
+
+  nativeBuildInputs = [ cmake perl ];
+  buildInputs = [
+    zlib luajit ncurses jsoncpp libb64 openssl curl jq gcc elfutils tbb
+  ] ++ optional (kernel != null) kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  cmakeFlags = [
+    "-DUSE_BUNDLED_DEPS=OFF"
+    "-DSYSDIG_VERSION=${version}"
+  ] ++ optional (kernel == null) "-DBUILD_DRIVER=OFF";
+
+  # needed since luajit-2.1.0-beta3
+  NIX_CFLAGS_COMPILE = [
+    "-DluaL_reg=luaL_Reg"
+    "-DluaL_getn(L,i)=((int)lua_objlen(L,i))"
+  ];
+
+  preConfigure = ''
+    export INSTALL_MOD_PATH="$out"
+  '' + optionalString (kernel != null) ''
+    export KERNELDIR="${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  '';
+
+  postInstall = optionalString (kernel != null) ''
+    make install_driver
+    kernel_dev=${kernel.dev}
+    kernel_dev=''${kernel_dev#/nix/store/}
+    kernel_dev=''${kernel_dev%%-linux*dev*}
+    if test -f "$out/lib/modules/${kernel.modDirVersion}/extra/sysdig-probe.ko"; then
+        sed -i "s#$kernel_dev#................................#g" $out/lib/modules/${kernel.modDirVersion}/extra/sysdig-probe.ko
+    else
+        xz -d $out/lib/modules/${kernel.modDirVersion}/extra/sysdig-probe.ko.xz
+        sed -i "s#$kernel_dev#................................#g" $out/lib/modules/${kernel.modDirVersion}/extra/sysdig-probe.ko
+        xz $out/lib/modules/${kernel.modDirVersion}/extra/sysdig-probe.ko
+    fi
+  '';
+
+  meta = {
+    description = "A tracepoint-based system tracing tool for Linux (with clients for other OSes)";
+    license = with licenses; [ asl20 gpl2 mit ];
+    maintainers = [maintainers.raskin];
+    platforms = ["x86_64-linux"] ++ platforms.darwin;
+    broken = kernel != null && versionOlder kernel.version "4.14";
+    homepage = "https://sysdig.com/opensource/";
+    downloadPage = "https://github.com/draios/sysdig/releases";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sysdig/default.upstream b/nixpkgs/pkgs/os-specific/linux/sysdig/default.upstream
new file mode 100644
index 000000000000..485de5741d79
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysdig/default.upstream
@@ -0,0 +1,8 @@
+url https://github.com/draios/sysdig/releases
+ensure_choice
+version '.*/([0-9.]+)[.]tar[.].*' '\1'
+do_overwrite () {
+  ensure_hash
+  set_var_value sha256 $CURRENT_HASH
+  set_var_value version $CURRENT_VERSION
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sysfsutils/default.nix b/nixpkgs/pkgs/os-specific/linux/sysfsutils/default.nix
new file mode 100644
index 000000000000..485f3d94a73d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysfsutils/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "sysfsutils-2.1.0";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/linux-diag/${name}.tar.gz";
+    sha256 = "e865de2c1f559fff0d3fc936e660c0efaf7afe662064f2fb97ccad1ec28d208a";
+  };
+
+  meta = {
+    homepage = http://linux-diag.sourceforge.net/Sysfsutils.html;
+    longDescription =
+      ''
+        These are a set of utilites built upon sysfs, a new virtual
+        filesystem in Linux kernel versions 2.5+ that exposes a system's
+        device tree.
+      '';
+    license = with stdenv.lib.licenses; [ gpl2 lgpl21 ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sysklogd/default.nix b/nixpkgs/pkgs/os-specific/linux/sysklogd/default.nix
new file mode 100644
index 000000000000..513503ff98e6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysklogd/default.nix
@@ -0,0 +1,28 @@
+{stdenv, fetchurl}:
+
+stdenv.mkDerivation {
+  name = "sysklogd-1.5.1";
+
+  src = fetchurl {
+    url = http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.1.tar.gz;
+    sha256 = "00f2wy6f0qng7qzga4iicyzl9j8b7mp6mrpfky5jxj93ms2w2rji";
+  };
+
+  patches = [ ./systemd.patch ./union-wait.patch ];
+
+  NIX_CFLAGS_COMPILE = "-DSYSV";
+
+  installFlags = "BINDIR=$(out)/sbin MANDIR=$(out)/share/man INSTALL=install";
+
+  preConfigure =
+    ''
+      sed -e 's@-o \''${MAN_USER} -g \''${MAN_GROUP} -m \''${MAN_PERMS} @@' -i Makefile
+    '';
+
+  preInstall = "mkdir -p $out/share/man/man5/ $out/share/man/man8/ $out/sbin";
+
+  meta = {
+    description = "A system logging daemon";
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sysklogd/systemd.patch b/nixpkgs/pkgs/os-specific/linux/sysklogd/systemd.patch
new file mode 100644
index 000000000000..0a7fb166bd75
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysklogd/systemd.patch
@@ -0,0 +1,845 @@
+Based on http://ftp.free.org/mirrors/rsync.frugalware.org/frugalware-testing/source/apps-extra/sysklogd/sysklogd-1.5-systemd.diff
+
+diff -ruN -x '*~' sysklogd-1.5-old/Makefile sysklogd-1.5/Makefile
+--- sysklogd-1.5-old/Makefile	2007-05-30 17:28:48.000000000 +0200
++++ sysklogd-1.5/Makefile	2013-05-09 16:01:14.428638113 +0200
+@@ -20,7 +20,7 @@
+ CC= gcc
+ #SKFLAGS= -g -DSYSV -Wall
+ #LDFLAGS= -g
+-SKFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce
++SKFLAGS= $(RPM_OPT_FLAGS) -O3 -DSYSV -fomit-frame-pointer -Wall -fno-strength-reduce -I.
+ # -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
+ # -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
+ # $(shell getconf LFS_SKFLAGS)
+@@ -79,8 +79,8 @@
+ 
+ install: install_man install_exec
+ 
+-syslogd: syslogd.o pidfile.o
+-	${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o ${LIBS}
++syslogd: syslogd.o pidfile.o sd-daemon.o
++	${CC} ${LDFLAGS} -o syslogd syslogd.o pidfile.o sd-daemon.o ${LIBS}
+ 
+ klogd:	klogd.o syslog.o pidfile.o ksym.o ksym_mod.o
+ 	${CC} ${LDFLAGS} -o klogd klogd.o syslog.o pidfile.o ksym.o \
+@@ -101,6 +101,9 @@
+ syslog.o: syslog.c
+ 	${CC} ${SKFLAGS} ${SYSLOG_FLAGS} -c syslog.c
+ 
++sd-daemon.o: sd-daemon.c sd-daemon.h
++	${CC} ${SKFLAGS} ${SYSLOG_FLAGS} -c sd-daemon.c
++
+ klogd.o: klogd.c klogd.h version.h
+ 	${CC} ${SKFLAGS} ${KLOGD_FLAGS} $(DEB) -c klogd.c
+ 
+diff -ruN -x '*~' sysklogd-1.5-old/sd-daemon.c sysklogd-1.5/sd-daemon.c
+--- sysklogd-1.5-old/sd-daemon.c	1970-01-01 01:00:00.000000000 +0100
++++ sysklogd-1.5/sd-daemon.c	2013-05-09 16:01:14.429638107 +0200
+@@ -0,0 +1,436 @@
++/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
++
++/***
++  Copyright 2010 Lennart Poettering
++
++  Permission is hereby granted, free of charge, to any person
++  obtaining a copy of this software and associated documentation files
++  (the "Software"), to deal in the Software without restriction,
++  including without limitation the rights to use, copy, modify, merge,
++  publish, distribute, sublicense, and/or sell copies of the Software,
++  and to permit persons to whom the Software is furnished to do so,
++  subject to the following conditions:
++
++  The above copyright notice and this permission notice shall be
++  included in all copies or substantial portions of the Software.
++
++  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
++  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
++  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
++  SOFTWARE.
++***/
++
++#ifndef _GNU_SOURCE
++#define _GNU_SOURCE
++#endif
++
++#include <sys/types.h>
++#include <sys/stat.h>
++#include <sys/socket.h>
++#include <sys/un.h>
++#include <sys/fcntl.h>
++#include <netinet/in.h>
++#include <stdlib.h>
++#include <errno.h>
++#include <unistd.h>
++#include <string.h>
++#include <stdarg.h>
++#include <stdio.h>
++#include <stddef.h>
++
++#include "sd-daemon.h"
++
++int sd_listen_fds(int unset_environment) {
++
++#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
++        return 0;
++#else
++        int r, fd;
++        const char *e;
++        char *p = NULL;
++        unsigned long l;
++
++        if (!(e = getenv("LISTEN_PID"))) {
++                r = 0;
++                goto finish;
++        }
++
++        errno = 0;
++        l = strtoul(e, &p, 10);
++
++        if (errno != 0) {
++                r = -errno;
++                goto finish;
++        }
++
++        if (!p || *p || l <= 0) {
++                r = -EINVAL;
++                goto finish;
++        }
++
++        /* Is this for us? */
++        if (getpid() != (pid_t) l) {
++                r = 0;
++                goto finish;
++        }
++
++        if (!(e = getenv("LISTEN_FDS"))) {
++                r = 0;
++                goto finish;
++        }
++
++        errno = 0;
++        l = strtoul(e, &p, 10);
++
++        if (errno != 0) {
++                r = -errno;
++                goto finish;
++        }
++
++        if (!p || *p) {
++                r = -EINVAL;
++                goto finish;
++        }
++
++        for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
++                int flags;
++
++                if ((flags = fcntl(fd, F_GETFD)) < 0) {
++                        r = -errno;
++                        goto finish;
++                }
++
++                if (flags & FD_CLOEXEC)
++                        continue;
++
++                if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) {
++                        r = -errno;
++                        goto finish;
++                }
++        }
++
++        r = (int) l;
++
++finish:
++        if (unset_environment) {
++                unsetenv("LISTEN_PID");
++                unsetenv("LISTEN_FDS");
++        }
++
++        return r;
++#endif
++}
++
++int sd_is_fifo(int fd, const char *path) {
++        struct stat st_fd;
++
++        if (fd < 0)
++                return -EINVAL;
++
++        memset(&st_fd, 0, sizeof(st_fd));
++        if (fstat(fd, &st_fd) < 0)
++                return -errno;
++
++        if (!S_ISFIFO(st_fd.st_mode))
++                return 0;
++
++        if (path) {
++                struct stat st_path;
++
++                memset(&st_path, 0, sizeof(st_path));
++                if (stat(path, &st_path) < 0) {
++
++                        if (errno == ENOENT || errno == ENOTDIR)
++                                return 0;
++
++                        return -errno;
++                }
++
++                return
++                        st_path.st_dev == st_fd.st_dev &&
++                        st_path.st_ino == st_fd.st_ino;
++        }
++
++        return 1;
++}
++
++static int sd_is_socket_internal(int fd, int type, int listening) {
++        struct stat st_fd;
++
++        if (fd < 0 || type < 0)
++                return -EINVAL;
++
++        if (fstat(fd, &st_fd) < 0)
++                return -errno;
++
++        if (!S_ISSOCK(st_fd.st_mode))
++                return 0;
++
++        if (type != 0) {
++                int other_type = 0;
++                socklen_t l = sizeof(other_type);
++
++                if (getsockopt(fd, SOL_SOCKET, SO_TYPE, &other_type, &l) < 0)
++                        return -errno;
++
++                if (l != sizeof(other_type))
++                        return -EINVAL;
++
++                if (other_type != type)
++                        return 0;
++        }
++
++        if (listening >= 0) {
++                int accepting = 0;
++                socklen_t l = sizeof(accepting);
++
++                if (getsockopt(fd, SOL_SOCKET, SO_ACCEPTCONN, &accepting, &l) < 0)
++                        return -errno;
++
++                if (l != sizeof(accepting))
++                        return -EINVAL;
++
++                if (!accepting != !listening)
++                        return 0;
++        }
++
++        return 1;
++}
++
++union sockaddr_union {
++        struct sockaddr sa;
++        struct sockaddr_in in4;
++        struct sockaddr_in6 in6;
++        struct sockaddr_un un;
++        struct sockaddr_storage storage;
++};
++
++int sd_is_socket(int fd, int family, int type, int listening) {
++        int r;
++
++        if (family < 0)
++                return -EINVAL;
++
++        if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
++                return r;
++
++        if (family > 0) {
++                union sockaddr_union sockaddr;
++                socklen_t l;
++
++                memset(&sockaddr, 0, sizeof(sockaddr));
++                l = sizeof(sockaddr);
++
++                if (getsockname(fd, &sockaddr.sa, &l) < 0)
++                        return -errno;
++
++                if (l < sizeof(sa_family_t))
++                        return -EINVAL;
++
++                return sockaddr.sa.sa_family == family;
++        }
++
++        return 1;
++}
++
++int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) {
++        union sockaddr_union sockaddr;
++        socklen_t l;
++        int r;
++
++        if (family != 0 && family != AF_INET && family != AF_INET6)
++                return -EINVAL;
++
++        if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
++                return r;
++
++        memset(&sockaddr, 0, sizeof(sockaddr));
++        l = sizeof(sockaddr);
++
++        if (getsockname(fd, &sockaddr.sa, &l) < 0)
++                return -errno;
++
++        if (l < sizeof(sa_family_t))
++                return -EINVAL;
++
++        if (sockaddr.sa.sa_family != AF_INET &&
++            sockaddr.sa.sa_family != AF_INET6)
++                return 0;
++
++        if (family > 0)
++                if (sockaddr.sa.sa_family != family)
++                        return 0;
++
++        if (port > 0) {
++                if (sockaddr.sa.sa_family == AF_INET) {
++                        if (l < sizeof(struct sockaddr_in))
++                                return -EINVAL;
++
++                        return htons(port) == sockaddr.in4.sin_port;
++                } else {
++                        if (l < sizeof(struct sockaddr_in6))
++                                return -EINVAL;
++
++                        return htons(port) == sockaddr.in6.sin6_port;
++                }
++        }
++
++        return 1;
++}
++
++int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) {
++        union sockaddr_union sockaddr;
++        socklen_t l;
++        int r;
++
++        if ((r = sd_is_socket_internal(fd, type, listening)) <= 0)
++                return r;
++
++        memset(&sockaddr, 0, sizeof(sockaddr));
++        l = sizeof(sockaddr);
++
++        if (getsockname(fd, &sockaddr.sa, &l) < 0)
++                return -errno;
++
++        if (l < sizeof(sa_family_t))
++                return -EINVAL;
++
++        if (sockaddr.sa.sa_family != AF_UNIX)
++                return 0;
++
++        if (path) {
++                if (length <= 0)
++                        length = strlen(path);
++
++                if (length <= 0)
++                        /* Unnamed socket */
++                        return l == offsetof(struct sockaddr_un, sun_path);
++
++                if (path[0])
++                        /* Normal path socket */
++                        return
++                                (l >= offsetof(struct sockaddr_un, sun_path) + length + 1) &&
++                                memcmp(path, sockaddr.un.sun_path, length+1) == 0;
++                else
++                        /* Abstract namespace socket */
++                        return
++                                (l == offsetof(struct sockaddr_un, sun_path) + length) &&
++                                memcmp(path, sockaddr.un.sun_path, length) == 0;
++        }
++
++        return 1;
++}
++
++int sd_notify(int unset_environment, const char *state) {
++#if defined(DISABLE_SYSTEMD) || !defined(__linux__) || !defined(SOCK_CLOEXEC)
++        return 0;
++#else
++        int fd = -1, r;
++        struct msghdr msghdr;
++        struct iovec iovec;
++        union sockaddr_union sockaddr;
++        const char *e;
++
++        if (!state) {
++                r = -EINVAL;
++                goto finish;
++        }
++
++        if (!(e = getenv("NOTIFY_SOCKET")))
++                return 0;
++
++        /* Must be an abstract socket, or an absolute path */
++        if ((e[0] != '@' && e[0] != '/') || e[1] == 0) {
++                r = -EINVAL;
++                goto finish;
++        }
++
++        if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
++                r = -errno;
++                goto finish;
++        }
++
++        memset(&sockaddr, 0, sizeof(sockaddr));
++        sockaddr.sa.sa_family = AF_UNIX;
++        strncpy(sockaddr.un.sun_path, e, sizeof(sockaddr.un.sun_path));
++
++        if (sockaddr.un.sun_path[0] == '@')
++                sockaddr.un.sun_path[0] = 0;
++
++        memset(&iovec, 0, sizeof(iovec));
++        iovec.iov_base = (char*) state;
++        iovec.iov_len = strlen(state);
++
++        memset(&msghdr, 0, sizeof(msghdr));
++        msghdr.msg_name = &sockaddr;
++        msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + strlen(e);
++
++        if (msghdr.msg_namelen > sizeof(struct sockaddr_un))
++                msghdr.msg_namelen = sizeof(struct sockaddr_un);
++
++        msghdr.msg_iov = &iovec;
++        msghdr.msg_iovlen = 1;
++
++        if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0) {
++                r = -errno;
++                goto finish;
++        }
++
++        r = 1;
++
++finish:
++        if (unset_environment)
++                unsetenv("NOTIFY_SOCKET");
++
++        if (fd >= 0)
++                close(fd);
++
++        return r;
++#endif
++}
++
++int sd_notifyf(int unset_environment, const char *format, ...) {
++#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
++        return 0;
++#else
++        va_list ap;
++        char *p = NULL;
++        int r;
++
++        va_start(ap, format);
++        r = vasprintf(&p, format, ap);
++        va_end(ap);
++
++        if (r < 0 || !p)
++                return -ENOMEM;
++
++        r = sd_notify(unset_environment, p);
++        free(p);
++
++        return r;
++#endif
++}
++
++int sd_booted(void) {
++#if defined(DISABLE_SYSTEMD) || !defined(__linux__)
++        return 0;
++#else
++
++        struct stat a, b;
++
++        /* We simply test whether the systemd cgroup hierarchy is
++         * mounted */
++
++        if (lstat("/sys/fs/cgroup", &a) < 0)
++                return 0;
++
++        if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
++                return 0;
++
++        return a.st_dev != b.st_dev;
++#endif
++}
+diff -ruN -x '*~' sysklogd-1.5-old/sd-daemon.h sysklogd-1.5/sd-daemon.h
+--- sysklogd-1.5-old/sd-daemon.h	1970-01-01 01:00:00.000000000 +0100
++++ sysklogd-1.5/sd-daemon.h	2013-05-09 16:01:14.429638107 +0200
+@@ -0,0 +1,265 @@
++/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
++
++#ifndef foosddaemonhfoo
++#define foosddaemonhfoo
++
++/***
++  Copyright 2010 Lennart Poettering
++
++  Permission is hereby granted, free of charge, to any person
++  obtaining a copy of this software and associated documentation files
++  (the "Software"), to deal in the Software without restriction,
++  including without limitation the rights to use, copy, modify, merge,
++  publish, distribute, sublicense, and/or sell copies of the Software,
++  and to permit persons to whom the Software is furnished to do so,
++  subject to the following conditions:
++
++  The above copyright notice and this permission notice shall be
++  included in all copies or substantial portions of the Software.
++
++  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
++  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
++  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
++  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
++  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
++  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
++  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
++  SOFTWARE.
++***/
++
++#include <sys/types.h>
++#include <inttypes.h>
++
++#ifdef __cplusplus
++extern "C" {
++#endif
++
++/*
++  Reference implementation of a few systemd related interfaces for
++  writing daemons. These interfaces are trivial to implement. To
++  simplify porting we provide this reference implementation.
++  Applications are welcome to reimplement the algorithms described
++  here if they do not want to include these two source files.
++
++  The following functionality is provided:
++
++  - Support for logging with log levels on stderr
++  - File descriptor passing for socket-based activation
++  - Daemon startup and status notification
++  - Detection of systemd boots
++
++  You may compile this with -DDISABLE_SYSTEMD to disable systemd
++  support. This makes all those calls NOPs that are directly related to
++  systemd (i.e. only sd_is_xxx() will stay useful).
++
++  Since this is drop-in code we don't want any of our symbols to be
++  exported in any case. Hence we declare hidden visibility for all of
++  them.
++
++  You may find an up-to-date version of these source files online:
++
++  http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h
++  http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c
++
++  This should compile on non-Linux systems, too, but with the
++  exception of the sd_is_xxx() calls all functions will become NOPs.
++
++  See sd-daemon(7) for more information.
++*/
++
++#ifndef _sd_printf_attr_
++#if __GNUC__ >= 4
++#define _sd_printf_attr_(a,b) __attribute__ ((format (printf, a, b)))
++#else
++#define _sd_printf_attr_(a,b)
++#endif
++#endif
++
++#ifndef _sd_hidden_
++#if (__GNUC__ >= 4) && !defined(SD_EXPORT_SYMBOLS)
++#define _sd_hidden_ __attribute__ ((visibility("hidden")))
++#else
++#define _sd_hidden_
++#endif
++#endif
++
++/*
++  Log levels for usage on stderr:
++
++          fprintf(stderr, SD_NOTICE "Hello World!\n");
++
++  This is similar to printk() usage in the kernel.
++*/
++#define SD_EMERG   "<0>"  /* system is unusable */
++#define SD_ALERT   "<1>"  /* action must be taken immediately */
++#define SD_CRIT    "<2>"  /* critical conditions */
++#define SD_ERR     "<3>"  /* error conditions */
++#define SD_WARNING "<4>"  /* warning conditions */
++#define SD_NOTICE  "<5>"  /* normal but significant condition */
++#define SD_INFO    "<6>"  /* informational */
++#define SD_DEBUG   "<7>"  /* debug-level messages */
++
++/* The first passed file descriptor is fd 3 */
++#define SD_LISTEN_FDS_START 3
++
++/*
++  Returns how many file descriptors have been passed, or a negative
++  errno code on failure. Optionally, removes the $LISTEN_FDS and
++  $LISTEN_PID file descriptors from the environment (recommended, but
++  problematic in threaded environments). If r is the return value of
++  this function you'll find the file descriptors passed as fds
++  SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
++  errno style error code on failure. This function call ensures that
++  the FD_CLOEXEC flag is set for the passed file descriptors, to make
++  sure they are not passed on to child processes. If FD_CLOEXEC shall
++  not be set, the caller needs to unset it after this call for all file
++  descriptors that are used.
++
++  See sd_listen_fds(3) for more information.
++*/
++int sd_listen_fds(int unset_environment) _sd_hidden_;
++
++/*
++  Helper call for identifying a passed file descriptor. Returns 1 if
++  the file descriptor is a FIFO in the file system stored under the
++  specified path, 0 otherwise. If path is NULL a path name check will
++  not be done and the call only verifies if the file descriptor
++  refers to a FIFO. Returns a negative errno style error code on
++  failure.
++
++  See sd_is_fifo(3) for more information.
++*/
++int sd_is_fifo(int fd, const char *path) _sd_hidden_;
++
++/*
++  Helper call for identifying a passed file descriptor. Returns 1 if
++  the file descriptor is a socket of the specified family (AF_INET,
++  ...) and type (SOCK_DGRAM, SOCK_STREAM, ...), 0 otherwise. If
++  family is 0 a socket family check will not be done. If type is 0 a
++  socket type check will not be done and the call only verifies if
++  the file descriptor refers to a socket. If listening is > 0 it is
++  verified that the socket is in listening mode. (i.e. listen() has
++  been called) If listening is == 0 it is verified that the socket is
++  not in listening mode. If listening is < 0 no listening mode check
++  is done. Returns a negative errno style error code on failure.
++
++  See sd_is_socket(3) for more information.
++*/
++int sd_is_socket(int fd, int family, int type, int listening) _sd_hidden_;
++
++/*
++  Helper call for identifying a passed file descriptor. Returns 1 if
++  the file descriptor is an Internet socket, of the specified family
++  (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
++  SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
++  check is not done. If type is 0 a socket type check will not be
++  done. If port is 0 a socket port check will not be done. The
++  listening flag is used the same way as in sd_is_socket(). Returns a
++  negative errno style error code on failure.
++
++  See sd_is_socket_inet(3) for more information.
++*/
++int sd_is_socket_inet(int fd, int family, int type, int listening, uint16_t port) _sd_hidden_;
++
++/*
++  Helper call for identifying a passed file descriptor. Returns 1 if
++  the file descriptor is an AF_UNIX socket of the specified type
++  (SOCK_DGRAM, SOCK_STREAM, ...) and path, 0 otherwise. If type is 0
++  a socket type check will not be done. If path is NULL a socket path
++  check will not be done. For normal AF_UNIX sockets set length to
++  0. For abstract namespace sockets set length to the length of the
++  socket name (including the initial 0 byte), and pass the full
++  socket path in path (including the initial 0 byte). The listening
++  flag is used the same way as in sd_is_socket(). Returns a negative
++  errno style error code on failure.
++
++  See sd_is_socket_unix(3) for more information.
++*/
++int sd_is_socket_unix(int fd, int type, int listening, const char *path, size_t length) _sd_hidden_;
++
++/*
++  Informs systemd about changed daemon state. This takes a number of
++  newline separated environment-style variable assignments in a
++  string. The following variables are known:
++
++     READY=1      Tells systemd that daemon startup is finished (only
++                  relevant for services of Type=notify). The passed
++                  argument is a boolean "1" or "0". Since there is
++                  little value in signalling non-readiness the only
++                  value daemons should send is "READY=1".
++
++     STATUS=...   Passes a single-line status string back to systemd
++                  that describes the daemon state. This is free-from
++                  and can be used for various purposes: general state
++                  feedback, fsck-like programs could pass completion
++                  percentages and failing programs could pass a human
++                  readable error message. Example: "STATUS=Completed
++                  66% of file system check..."
++
++     ERRNO=...    If a daemon fails, the errno-style error code,
++                  formatted as string. Example: "ERRNO=2" for ENOENT.
++
++     BUSERROR=... If a daemon fails, the D-Bus error-style error
++                  code. Example: "BUSERROR=org.freedesktop.DBus.Error.TimedOut"
++
++     MAINPID=...  The main pid of a daemon, in case systemd did not
++                  fork off the process itself. Example: "MAINPID=4711"
++
++  Daemons can choose to send additional variables. However, it is
++  recommened to prefix variable names not listed above with X_.
++
++  Returns a negative errno-style error code on failure. Returns > 0
++  if systemd could be notified, 0 if it couldn't possibly because
++  systemd is not running.
++
++  Example: When a daemon finished starting up, it could issue this
++  call to notify systemd about it:
++
++     sd_notify(0, "READY=1");
++
++  See sd_notifyf() for more complete examples.
++
++  See sd_notify(3) for more information.
++*/
++int sd_notify(int unset_environment, const char *state) _sd_hidden_;
++
++/*
++  Similar to sd_notify() but takes a format string.
++
++  Example 1: A daemon could send the following after initialization:
++
++     sd_notifyf(0, "READY=1\n"
++                   "STATUS=Processing requests...\n"
++                   "MAINPID=%lu",
++                   (unsigned long) getpid());
++
++  Example 2: A daemon could send the following shortly before
++  exiting, on failure:
++
++     sd_notifyf(0, "STATUS=Failed to start up: %s\n"
++                   "ERRNO=%i",
++                   strerror(errno),
++                   errno);
++
++  See sd_notifyf(3) for more information.
++*/
++int sd_notifyf(int unset_environment, const char *format, ...) _sd_printf_attr_(2,3) _sd_hidden_;
++
++/*
++  Returns > 0 if the system was booted with systemd. Returns < 0 on
++  error. Returns 0 if the system was not booted with systemd. Note
++  that all of the functions above handle non-systemd boots just
++  fine. You should NOT protect them with a call to this function. Also
++  note that this function checks whether the system, not the user
++  session is controlled by systemd. However the functions above work
++  for both user and system services.
++
++  See sd_booted(3) for more information.
++*/
++int sd_booted(void) _sd_hidden_;
++
++#ifdef __cplusplus
++}
++#endif
++
++#endif
+diff -ruN -x '*~' sysklogd-1.5-old/syslogd.c sysklogd-1.5/syslogd.c
+--- sysklogd-1.5-old/syslogd.c	2007-07-04 21:04:01.000000000 +0200
++++ sysklogd-1.5/syslogd.c	2013-05-09 16:04:32.106602589 +0200
+@@ -551,6 +551,7 @@
+ 
+ #if defined(__linux__)
+ #include <paths.h>
++#include <sd-daemon.h>
+ #endif
+ 
+ #ifndef UTMP_FILE
+@@ -965,8 +966,11 @@
+ 			}
+ 			signal (SIGTERM, SIG_DFL);
+ 			num_fds = getdtablesize();
+-			for (i= 0; i < num_fds; i++)
+-				(void) close(i);
++#if defined(__linux__)
++			if (sd_listen_fds(0) <= 0)
++#endif
++				for (i = 0; i < num_fds; i++)
++					(void) close(i);
+ 			untty();
+ 		}
+ 		else
+@@ -1253,6 +1257,60 @@
+ 	if (path[0] == '\0')
+ 		return -1;
+ 
++#if defined(__linux__)
++	if (strcmp(path, _PATH_LOG) == 0) {
++		int r;
++ 
++		/* Check whether an FD was passed in from systemd. If
++		 * so, it's the /dev/log socket, so use it. */
++ 
++		r = sd_listen_fds(0);
++		if (r < 0) {
++			logerror("Failed to acquire systemd socket");
++#ifndef SYSV
++			dienow();
++#else
++			return -1;
++#endif
++		}
++
++ 
++		if (r > 1) {
++			logerror("Wrong number of systemd sockets passed");
++#ifndef SYSV
++			dienow();
++#else
++			return -1;
++#endif
++		}
++ 
++		if (r == 1) {
++			fd = SD_LISTEN_FDS_START;
++			r = sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/syslog", 0);
++			if (r < 0) {
++				logerror("Failed to verify systemd socket type");
++#ifndef SYSV
++				dienow();
++#else
++				return -1;
++#endif
++			}
++ 
++			if (!r) {
++				logerror("Passed systemd socket of wrong type");
++#ifndef SYSV
++				dienow();
++#else
++				return -1;
++#endif
++			}
++ 
++		        dprintf("Using systemd socket (%d).\n", fd);
++			return fd;
++		}
++	}
++#endif
++
+ 	(void) unlink(path);
+ 
+ 	memset(&sunx, 0, sizeof(sunx));
+@@ -2254,9 +2312,11 @@
+ 	if (InetInuse) close(inetm);
+ 
+ 	/* Clean-up files. */
+-        for (i = 0; i < nfunix; i++)
+-		if (funixn[i] && funix[i] != -1)
+-			(void)unlink(funixn[i]);
++	i = 0;
++#if defined(__linux__)
++	if (sd_listen_fds(0) > 0)
++		i = 1;
++#endif
+ #ifndef TESTING
+ 	(void) remove_pid(PidFile);
+ #endif
diff --git a/nixpkgs/pkgs/os-specific/linux/sysklogd/union-wait.patch b/nixpkgs/pkgs/os-specific/linux/sysklogd/union-wait.patch
new file mode 100644
index 000000000000..e4bffa5d6953
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysklogd/union-wait.patch
@@ -0,0 +1,11 @@
+--- sysklogd-1.5-old/syslogd.c	2016-08-30 22:50:59.812926945 +0100
++++ sysklogd-1.5/syslogd.c	2016-08-30 22:51:12.008842890 +0100
+@@ -2094,7 +2094,7 @@
+ 	(void) signal(SIGCHLD, reapchild);	/* reset signal handler -ASP */
+ 	wait ((int *)0);
+ #else
+-	union wait status;
++	int status;
+ 
+ 	while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0)
+ 		;
diff --git a/nixpkgs/pkgs/os-specific/linux/syslinux/default.nix b/nixpkgs/pkgs/os-specific/linux/syslinux/default.nix
new file mode 100644
index 000000000000..8965b5da4f49
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/syslinux/default.nix
@@ -0,0 +1,85 @@
+{ stdenv, fetchFromGitHub, fetchurl, nasm, perl, python, libuuid, mtools, makeWrapper }:
+
+stdenv.mkDerivation rec {
+  name = "syslinux-2015-11-09";
+
+  src = fetchFromGitHub {
+    owner = "geneC";
+    repo = "syslinux";
+    rev = "0cc9a99e560a2f52bcf052fd85b1efae35ee812f";
+    sha256 = "0wk3r5ki4lc334f9jpml07wpl8d0bnxi9h1l4h4fyf9a0d7n4kmw";
+  };
+
+  patches = let
+    mkURL = commit: patchName:
+      "https://salsa.debian.org/images-team/syslinux/raw/${commit}/debian/patches/"
+      + patchName;
+  in [
+    ./perl-deps.patch
+    (fetchurl {
+      # ldlinux.elf: Not enough room for program headers, try linking with -N
+      name = "not-enough-room.patch";
+      url = mkURL "a556ad7" "0014_fix_ftbfs_no_dynamic_linker.patch";
+      sha256 = "0ijqjsjmnphmvsx0z6ppnajsfv6xh6crshy44i2a5klxw4nlvrsw";
+    })
+    (fetchurl {
+      # mbr.bin: too big (452 > 440)
+      # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=906414
+      url = mkURL "7468ef0e38c43" "0016-strip-gnu-property.patch";
+      sha256 = "17n63b8wz6szv8npla1234g1ip7lqgzx2whrpv358ppf67lq8vwm";
+    })
+    (fetchurl {
+      # mbr.bin: too big (452 > 440)
+      url = mkURL "012e1dd312eb" "0017-single-load-segment.patch";
+      sha256 = "0azqzicsjw47b9ppyikhzaqmjl4lrvkxris1356bkmgcaiv6d98b";
+    })
+  ];
+
+  postPatch = ''
+    substituteInPlace Makefile --replace /bin/pwd $(type -P pwd)
+    substituteInPlace gpxe/src/Makefile.housekeeping --replace /bin/echo $(type -P echo)
+    substituteInPlace utils/ppmtolss16 --replace /usr/bin/perl $(type -P perl)
+    substituteInPlace gpxe/src/Makefile --replace /usr/bin/perl $(type -P perl)
+
+    # fix tests
+    substituteInPlace tests/unittest/include/unittest/unittest.h \
+      --replace /usr/include/ ""
+  '';
+
+  nativeBuildInputs = [ nasm perl python ];
+  buildInputs = [ libuuid makeWrapper ];
+
+  enableParallelBuilding = false; # Fails very rarely with 'No rule to make target: ...'
+  hardeningDisable = [ "pic" "stackprotector" "fortify" ];
+
+  stripDebugList = "bin sbin share/syslinux/com32";
+
+  makeFlags = [
+    "BINDIR=$(out)/bin"
+    "SBINDIR=$(out)/sbin"
+    "LIBDIR=$(out)/lib"
+    "INCDIR=$(out)/include"
+    "DATADIR=$(out)/share"
+    "MANDIR=$(out)/share/man"
+    "PERL=perl"
+    "bios"
+  ];
+
+  doCheck = false; # fails. some fail in a sandbox, others require qemu
+
+  postInstall = ''
+    wrapProgram $out/bin/syslinux \
+      --prefix PATH : "${mtools}/bin"
+
+    # Delete com32 headers to save space, nobody seems to be using them
+    rm -rf $out/share/syslinux/com32
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://www.syslinux.org/;
+    description = "A lightweight bootloader";
+    license = licenses.gpl2;
+    maintainers = [ maintainers.samueldr ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/syslinux/perl-deps.patch b/nixpkgs/pkgs/os-specific/linux/syslinux/perl-deps.patch
new file mode 100644
index 000000000000..82c9820809e1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/syslinux/perl-deps.patch
@@ -0,0 +1,81 @@
+http://git.ipxe.org/ipxe.git/commitdiff/719b498
+
+diff -ru -x '*~' -x '*.orig' -x '*.rej' syslinux-4.02-orig/gpxe/src/arch/i386/Makefile.pcbios syslinux-4.02/gpxe/src/arch/i386/Makefile.pcbios
+--- syslinux-4.02-orig/gpxe/src/arch/i386/Makefile.pcbios	2010-07-21 21:33:13.000000000 +0200
++++ syslinux-4.02/gpxe/src/arch/i386/Makefile.pcbios	2010-08-06 23:32:57.000000000 +0200
+@@ -24,11 +24,11 @@
+ 
+ # Padding rules
+ #
+-PAD_rom		= $(PADIMG) --blksize=512 --byte=0xff $@
++PAD_rom		= $(PERL) $(PADIMG) --blksize=512 --byte=0xff $@
+ PAD_hrom	= $(PAD_rom)
+ PAD_xrom	= $(PAD_rom)
+-PAD_dsk		= $(PADIMG) --blksize=512 $@
+-PAD_hd		= $(PADIMG) --blksize=32768 $@
++PAD_dsk		= $(PERL) $(PADIMG) --blksize=512 $@
++PAD_hd		= $(PERL) $(PADIMG) --blksize=32768 $@
+ 
+ # rule to make a non-emulation ISO boot image
+ NON_AUTO_MEDIA	+= iso
+diff -ru -x '*~' -x '*.orig' -x '*.rej' syslinux-4.02-orig/gpxe/src/Makefile syslinux-4.02/gpxe/src/Makefile
+--- syslinux-4.02-orig/gpxe/src/Makefile	2010-07-21 21:33:13.000000000 +0200
++++ syslinux-4.02/gpxe/src/Makefile	2010-08-06 23:31:15.000000000 +0200
+@@ -31,12 +31,12 @@
+ OBJCOPY		:= $(CROSS_COMPILE)objcopy
+ NM		:= $(CROSS_COMPILE)nm
+ OBJDUMP		:= $(CROSS_COMPILE)objdump
+-PARSEROM	:= $(PERL) ./util/parserom.pl
+-MAKEROM		:= $(PERL) ./util/makerom.pl
+-SYMCHECK	:= $(PERL) ./util/symcheck.pl
+-SORTOBJDUMP	:= $(PERL) ./util/sortobjdump.pl
+-PADIMG		:= $(PERL) ./util/padimg.pl
+-LICENCE		:= $(PERL) ./util/licence.pl
++PARSEROM	:= ./util/parserom.pl
++MAKEROM		:= ./util/makerom.pl
++SYMCHECK	:= ./util/symcheck.pl
++SORTOBJDUMP	:= ./util/sortobjdump.pl
++PADIMG		:= ./util/padimg.pl
++LICENCE		:= ./util/licence.pl
+ NRV2B		:= ./util/nrv2b
+ ZBIN		:= ./util/zbin
+ ELF2EFI32	:= ./util/elf2efi32
+diff -ru -x '*~' -x '*.orig' -x '*.rej' syslinux-4.02-orig/gpxe/src/Makefile.housekeeping syslinux-4.02/gpxe/src/Makefile.housekeeping
+--- syslinux-4.02-orig/gpxe/src/Makefile.housekeeping	2010-07-21 21:33:13.000000000 +0200
++++ syslinux-4.02/gpxe/src/Makefile.housekeeping	2010-08-06 23:31:49.000000000 +0200
+@@ -456,7 +456,7 @@
+ 		 '\n$(2) : $$($(4)_DEPS)\n' \
+ 		 '\nTAGS : $$($(4)_DEPS)\n' \
+ 		>> $(2)
+-	@$(PARSEROM) $(1) >> $(2)
++	@$(PERL) $(PARSEROM) $(1) >> $(2)
+ 
+ endef
+ 
+@@ -657,7 +657,7 @@
+ 	$(QM)$(ECHO) "  [LD] $@"
+ 	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
+ 		-Map $(BIN)/$*.tmp.map
+-	$(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
++	$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
+ 
+ # Keep intermediate object file (useful for debugging)
+ .PRECIOUS : $(BIN)/%.tmp
+@@ -714,7 +714,7 @@
+ 		echo "files are missing a licence declaration:" ;\
+ 		echo $(call unlicensed_deps_list,$<);\
+ 		exit 1,\
+-		$(LICENCE) $(call licence_list,$<))
++		$(PERL) $(LICENCE) $(call licence_list,$<))
+ 
+ # Extract compression information from intermediate object file
+ #
+@@ -941,7 +941,7 @@
+ CLEANUP	+= $(BIN)/symtab
+ 
+ symcheck : $(SYMTAB)
+-	$(SYMCHECK) $<
++	$(PERL) $(SYMCHECK) $<
+ 
+ endif # defined(BIN)
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/sysstat/default.nix b/nixpkgs/pkgs/os-specific/linux/sysstat/default.nix
new file mode 100644
index 000000000000..27b27ebffdd8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysstat/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, fetchurl, gettext, bzip2 }:
+
+stdenv.mkDerivation rec {
+  name = "sysstat-12.1.2";
+
+  src = fetchurl {
+    url = "http://perso.orange.fr/sebastien.godard/${name}.tar.xz";
+    sha256 = "0xiv70x4n24fcycvlq95lqgb3jwjxfzq61bnyqai57x54hhn46yp";
+  };
+
+  buildInputs = [ gettext ];
+
+  preConfigure = ''
+    export PATH_CP=$(type -tp cp)
+    export PATH_CHKCONFIG=/no-such-program
+    export BZIP=${bzip2.bin}/bin/bzip2
+    export SYSTEMCTL=systemctl
+  '';
+
+  makeFlags = "SYSCONFIG_DIR=$(out)/etc IGNORE_FILE_ATTRIBUTES=y CHOWN=true";
+  installTargets = "install_base install_nls install_man";
+
+  patches = [ ./install.patch ];
+
+  meta = {
+    homepage = http://sebastien.godard.pagesperso-orange.fr/;
+    description = "A collection of performance monitoring tools for Linux (such as sar, iostat and pidstat)";
+    license = stdenv.lib.licenses.gpl2Plus;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.eelco ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sysstat/install.patch b/nixpkgs/pkgs/os-specific/linux/sysstat/install.patch
new file mode 100644
index 000000000000..473fa30b98b4
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysstat/install.patch
@@ -0,0 +1,13 @@
+diff -rc sysstat-11.0.1/Makefile.in sysstat-11.0.1-new/Makefile.in
+*** sysstat-11.0.1/Makefile.in	2014-08-30 15:38:39.000000000 +0200
+--- sysstat-11.0.1-new/Makefile.in	2014-12-18 14:40:45.466349009 +0100
+***************
+*** 331,337 ****
+  install_base: all sa1 sa2 sysstat.sysconfig install_man install_nls \
+  	contrib/isag/isag
+  	mkdir -p $(DESTDIR)$(SA_LIB_DIR)
+- 	mkdir -p $(DESTDIR)$(SA_DIR)
+  ifeq ($(CLEAN_SA_DIR),y)
+  	find $(DESTDIR)$(SA_DIR) \( -name 'sar??' -o -name 'sa??' -o -name 'sar??.gz' -o -name 'sa??.gz' \) \
+  		-exec rm -f {} \;
+--- 331,336 ----
diff --git a/nixpkgs/pkgs/os-specific/linux/systemd-wait/default.nix b/nixpkgs/pkgs/os-specific/linux/systemd-wait/default.nix
new file mode 100644
index 000000000000..114f4c2444e6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/systemd-wait/default.nix
@@ -0,0 +1,25 @@
+{ python3Packages, fetchFromGitHub, lib }:
+
+python3Packages.buildPythonApplication rec {
+  pname = "systemd-wait";
+  version = "0.1+2018-10-05";
+
+  src = fetchFromGitHub {
+    owner = "Stebalien";
+    repo = pname;
+    rev = "bbb58dd4584cc08ad20c3888edb7628f28aee3c7";
+    sha256 = "1l8rd0wzf3m7fk0g1c8wc0csdisdfac0filhixpgp0ck9ignayq5";
+  };
+
+  propagatedBuildInputs = with python3Packages; [
+    dbus-python pygobject3
+  ];
+
+  meta = {
+    homepage = https://github.com/Stebalien/systemd-wait;
+    license = lib.licenses.gpl3;
+    description = "Wait for a systemd unit to enter a specific state";
+    maintainers = [ lib.maintainers.benley ];
+    platforms = lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix b/nixpkgs/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix
new file mode 100644
index 000000000000..2ff0e4cd38fd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/systemd/cryptsetup-generator.nix
@@ -0,0 +1,34 @@
+{ stdenv, systemd, cryptsetup }:
+
+systemd.overrideAttrs (p: {
+  version = p.version;
+  name = "systemd-cryptsetup-generator-${p.version}";
+
+  buildInputs = p.buildInputs ++ [ cryptsetup ];
+  outputs = [ "out" ];
+
+  buildPhase = ''
+    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 = ''
+    for prog in `find $out -type f -executable`; do
+      (patchelf --print-needed $prog | grep 'libsystemd-shared-.*\.so' > /dev/null) && (
+        patchelf --set-rpath `patchelf --print-rpath $prog`:"$out/lib/systemd" $prog
+      ) || true
+    done
+    # test it's OK
+    "$out"/lib/systemd/systemd-cryptsetup
+  '';
+
+  installPhase = ''
+    mkdir -p $out/lib/systemd/
+    cp systemd-cryptsetup $out/lib/systemd/systemd-cryptsetup
+    cp src/shared/*.so $out/lib/systemd/
+
+    mkdir -p $out/lib/systemd/system-generators/
+    cp systemd-cryptsetup-generator $out/lib/systemd/system-generators/systemd-cryptsetup-generator
+  '';
+})
diff --git a/nixpkgs/pkgs/os-specific/linux/systemd/default.nix b/nixpkgs/pkgs/os-specific/linux/systemd/default.nix
new file mode 100644
index 000000000000..d54972c055be
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/systemd/default.nix
@@ -0,0 +1,225 @@
+{ stdenv, lib, fetchFromGitHub, fetchpatch, fetchurl, pkgconfig, intltool, gperf, libcap, kmod
+, xz, pam, acl, libuuid, m4, utillinux, libffi
+, glib, kbd, libxslt, coreutils, libgcrypt, libgpgerror, libidn2, libapparmor
+, audit, lz4, bzip2, libmicrohttpd, pcre2
+, linuxHeaders ? stdenv.cc.libc.linuxHeaders
+, iptables, gnu-efi
+, gettext, docbook_xsl, docbook_xml_dtd_42, docbook_xml_dtd_45
+, ninja, meson, python3Packages, glibcLocales
+, patchelf
+, getent
+, buildPackages
+, withSelinux ? false, libselinux
+, withLibseccomp ? lib.any (lib.meta.platformMatch stdenv.hostPlatform) libseccomp.meta.platforms, libseccomp
+, withKexectools ? lib.any (lib.meta.platformMatch stdenv.hostPlatform) kexectools.meta.platforms, kexectools
+}:
+
+let
+  pythonLxmlEnv = buildPackages.python3Packages.python.withPackages ( ps: with ps; [ python3Packages.lxml ]);
+
+in stdenv.mkDerivation rec {
+  version = "239.20190219";
+  name = "systemd-${version}";
+
+  # When updating, use https://github.com/systemd/systemd-stable tree, not the development one!
+  # Also fresh patches should be cherry-picked from that tree to our current one.
+  src = fetchFromGitHub {
+    owner = "NixOS";
+    repo = "systemd";
+    rev = "nixos-v${version}";
+    sha256 = "0aczg25ih2gfjq810x8rw6rnpr6sw1lz6z0lvlyw2qphyih68b4x";
+  };
+
+  prePatch = let
+      # Upstream's maintenance branches are still too intrusive:
+      # https://github.com/systemd/systemd-stable/tree/v239-stable
+      patches-deb = fetchurl {
+        # This URL should point to a stable location that does not easily
+        # disappear.  In the past we were using `mirror://debian` but that
+        # eventually causes the files to disappear.  While that was a good sign
+        # for us to update our patch collection it does break reproducibility.
+        name = "systemd-debian-patches.tar.xz";
+        url = http://snapshot.debian.org/archive/debian/20190301T035241Z/pool/main/s/systemd/systemd_239-12%7Ebpo9%2B1.debian.tar.xz;
+        sha256 = "0v9f62gyfiw5icdrdlcvjcipsqrsm49w6n8bqp9nb8s2ih6rsfhg";
+      };
+      # Note that we skip debian-specific patches, i.e. ./debian/patches/debian/*
+    in ''
+      tar xf ${patches-deb}
+      patches="$patches $(cat debian/patches/series | grep -v '^debian/' | sed 's|^|debian/patches/|')"
+    '';
+
+  outputs = [ "out" "lib" "man" "dev" ];
+
+  nativeBuildInputs =
+    [ pkgconfig intltool gperf libxslt gettext docbook_xsl docbook_xml_dtd_42 docbook_xml_dtd_45
+      ninja meson
+      coreutils # meson calls date, stat etc.
+      glibcLocales
+      patchelf getent m4
+    ];
+  buildInputs =
+    [ linuxHeaders libcap kmod xz pam acl
+      /* cryptsetup */ libuuid glib libgcrypt libgpgerror libidn2
+      libmicrohttpd pcre2 ] ++
+      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.optional withSelinux libselinux;
+
+  #dontAddPrefix = true;
+
+  mesonFlags = [
+    "-Dloadkeys-path=${kbd}/bin/loadkeys"
+    "-Dsetfont-path=${kbd}/bin/setfont"
+    "-Dtty-gid=3" # tty in NixOS has gid 3
+    # "-Dtests=" # TODO
+    "-Dlz4=true"
+    "-Dhostnamed=true"
+    "-Dnetworkd=true"
+    "-Dsysusers=false"
+    "-Dtimedated=true"
+    "-Dtimesyncd=true"
+    "-Dfirstboot=false"
+    "-Dlocaled=true"
+    "-Dresolve=true"
+    "-Dsplit-usr=false"
+    "-Dlibcurl=false"
+    "-Dlibidn=false"
+    "-Dlibidn2=true"
+    "-Dquotacheck=false"
+    "-Dldconfig=false"
+    "-Dsmack=true"
+    "-Dsystem-uid-max=499" #TODO: debug why awking around in /etc/login.defs doesn't work
+    "-Dsystem-gid-max=499"
+    # "-Dtime-epoch=1"
+
+    (if stdenv.isAarch32 || stdenv.isAarch64 || !stdenv.hostPlatform.isEfi then "-Dgnu-efi=false" else "-Dgnu-efi=true")
+    "-Defi-libdir=${toString gnu-efi}/lib"
+    "-Defi-includedir=${toString gnu-efi}/include/efi"
+    "-Defi-ldsdir=${toString gnu-efi}/lib"
+
+    "-Dsysvinit-path="
+    "-Dsysvrcnd-path="
+
+    "-Dkill-path=${coreutils}/bin/kill"
+    "-Dkmod-path=${kmod}/bin/kmod"
+    "-Dsulogin-path=${utillinux}/bin/sulogin"
+    "-Dmount-path=${utillinux}/bin/mount"
+    "-Dumount-path=${utillinux}/bin/umount"
+  ];
+
+  preConfigure = ''
+    mesonFlagsArray+=(-Dntp-servers="0.nixos.pool.ntp.org 1.nixos.pool.ntp.org 2.nixos.pool.ntp.org 3.nixos.pool.ntp.org")
+    mesonFlagsArray+=(-Ddbuspolicydir=$out/etc/dbus-1/system.d)
+    mesonFlagsArray+=(-Ddbussessionservicedir=$out/share/dbus-1/services)
+    mesonFlagsArray+=(-Ddbussystemservicedir=$out/share/dbus-1/system-services)
+    mesonFlagsArray+=(-Dpamconfdir=$out/etc/pam.d)
+    mesonFlagsArray+=(-Drootprefix=$out)
+    mesonFlagsArray+=(-Drootlibdir=$lib/lib)
+    mesonFlagsArray+=(-Dpkgconfiglibdir=$dev/lib/pkgconfig)
+    mesonFlagsArray+=(-Dpkgconfigdatadir=$dev/share/pkgconfig)
+
+    export LC_ALL="en_US.UTF-8";
+    # FIXME: patch this in systemd properly (and send upstream).
+    # already fixed in f00929ad622c978f8ad83590a15a765b4beecac9: (u)mount
+    for i in src/remount-fs/remount-fs.c src/core/mount.c src/core/swap.c src/fsck/fsck.c units/emergency.service.in units/rescue.service.in src/journal/cat.c src/core/shutdown.c src/nspawn/nspawn.c src/shared/generator.c; do
+      test -e $i
+      substituteInPlace $i \
+        --replace /usr/bin/getent ${getent}/bin/getent \
+        --replace /sbin/swapon ${utillinux.bin}/sbin/swapon \
+        --replace /sbin/swapoff ${utillinux.bin}/sbin/swapoff \
+        --replace /sbin/fsck ${utillinux.bin}/sbin/fsck \
+        --replace /bin/echo ${coreutils}/bin/echo \
+        --replace /bin/cat ${coreutils}/bin/cat \
+        --replace /sbin/sulogin ${utillinux.bin}/sbin/sulogin \
+        --replace /usr/lib/systemd/systemd-fsck $out/lib/systemd/systemd-fsck \
+        --replace /bin/plymouth /run/current-system/sw/bin/plymouth # To avoid dependency
+    done
+
+    for i in tools/xml_helper.py tools/make-directive-index.py tools/make-man-index.py test/sys-script.py; do
+      substituteInPlace $i \
+        --replace "#!/usr/bin/env python" "#!${pythonLxmlEnv}/bin/python"
+    done
+
+    for i in src/basic/generate-gperfs.py src/resolve/generate-dns_type-gperf.py src/test/generate-sym-test.py ; do
+      substituteInPlace $i \
+        --replace "#!/usr/bin/env python" "#!${buildPackages.python3Packages.python}/bin/python"
+    done
+
+    substituteInPlace src/journal/catalog.c \
+      --replace /usr/lib/systemd/catalog/ $out/lib/systemd/catalog/
+  '';
+
+  # These defines are overridden by CFLAGS and would trigger annoying
+  # warning messages
+  postConfigure = ''
+    substituteInPlace config.h \
+      --replace "POLKIT_AGENT_BINARY_PATH" "_POLKIT_AGENT_BINARY_PATH" \
+      --replace "SYSTEMD_BINARY_PATH" "_SYSTEMD_BINARY_PATH" \
+      --replace "SYSTEMD_CGROUP_AGENT_PATH" "_SYSTEMD_CGROUP_AGENT_PATH"
+  '';
+
+  NIX_CFLAGS_COMPILE =
+    [ # Can't say ${polkit.bin}/bin/pkttyagent here because that would
+      # lead to a cyclic dependency.
+      "-UPOLKIT_AGENT_BINARY_PATH" "-DPOLKIT_AGENT_BINARY_PATH=\"/run/current-system/sw/bin/pkttyagent\""
+
+      # Set the release_agent on /sys/fs/cgroup/systemd to the
+      # currently running systemd (/run/current-system/systemd) so
+      # that we don't use an obsolete/garbage-collected release agent.
+      "-USYSTEMD_CGROUP_AGENT_PATH" "-DSYSTEMD_CGROUP_AGENT_PATH=\"/run/current-system/systemd/lib/systemd/systemd-cgroups-agent\""
+
+      "-USYSTEMD_BINARY_PATH" "-DSYSTEMD_BINARY_PATH=\"/run/current-system/systemd/lib/systemd/systemd\""
+    ];
+
+  doCheck = false; # fails a bunch of tests
+
+  postInstall = ''
+    # sysinit.target: Don't depend on
+    # systemd-tmpfiles-setup.service. This interferes with NixOps's
+    # send-keys feature (since sshd.service depends indirectly on
+    # sysinit.target).
+    mv $out/lib/systemd/system/sysinit.target.wants/systemd-tmpfiles-setup-dev.service $out/lib/systemd/system/multi-user.target.wants/
+
+    mkdir -p $out/example/systemd
+    mv $out/lib/{modules-load.d,binfmt.d,sysctl.d,tmpfiles.d} $out/example
+    mv $out/lib/systemd/{system,user} $out/example/systemd
+
+    rm -rf $out/etc/systemd/system
+
+    # Fix reference to /bin/false in the D-Bus services.
+    for i in $out/share/dbus-1/system-services/*.service; do
+      substituteInPlace $i --replace /bin/false ${coreutils}/bin/false
+    done
+
+    rm -rf $out/etc/rpm
+
+    # "kernel-install" shouldn't be used on NixOS.
+    find $out -name "*kernel-install*" -exec rm {} \;
+
+    # Keep only libudev and libsystemd in the lib output.
+    mkdir -p $out/lib
+    mv $lib/lib/security $lib/lib/libnss* $out/lib/
+  ''; # */
+
+  enableParallelBuilding = true;
+
+  # The interface version prevents NixOS from switching to an
+  # incompatible systemd at runtime.  (Switching across reboots is
+  # fine, of course.)  It should be increased whenever systemd changes
+  # in a backwards-incompatible way.  If the interface version of two
+  # systemd builds is the same, then we can switch between them at
+  # runtime; otherwise we can't and we need to reboot.
+  passthru.interfaceVersion = 2;
+
+  meta = with stdenv.lib; {
+    homepage = http://www.freedesktop.org/wiki/Software/systemd;
+    description = "A system and service manager for Linux";
+    license = licenses.lgpl21Plus;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.eelco ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/sysvinit/default.nix b/nixpkgs/pkgs/os-specific/linux/sysvinit/default.nix
new file mode 100644
index 000000000000..8549e7ccd546
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/sysvinit/default.nix
@@ -0,0 +1,45 @@
+{ stdenv, fetchurl, withoutInitTools ? false }:
+
+let version = "2.94"; in
+
+stdenv.mkDerivation {
+  name = (if withoutInitTools then "sysvtools" else "sysvinit") + "-" + version;
+
+  src = fetchurl {
+    url = "mirror://savannah/sysvinit/sysvinit-${version}.tar.xz";
+    sha256 = "05wshfgrijp3pi9rpfsa0yx4w3bf5v6hlwjqw79nlhz53xjca2by";
+  };
+
+  prePatch = ''
+    # Patch some minimal hard references, so halt/shutdown work
+    sed -i -e "s,/sbin/,$out/sbin/," src/halt.c src/init.c src/paths.h
+  '';
+
+  makeFlags = [ "SULOGINLIBS=-lcrypt" "ROOT=$(out)" "MANDIR=/share/man" ];
+
+  preInstall =
+    ''
+      substituteInPlace src/Makefile --replace /usr /
+    '';
+
+  postInstall = ''
+    mv $out/sbin/killall5 $out/bin
+    ln -sf killall5 $out/bin/pidof
+  ''
+    + stdenv.lib.optionalString withoutInitTools
+    ''
+      shopt -s extglob
+      rm -rf $out/sbin/!(sulogin)
+      rm -rf $out/include
+      rm -rf $out/share/man/man5
+      rm $(for i in $out/share/man/man8/*; do echo $i; done | grep -v 'pidof\|killall5')
+      rm $out/bin/wall $out/share/man/man1/wall.1
+    '';
+
+  meta = {
+    homepage = https://www.nongnu.org/sysvinit/;
+    description = "Utilities related to booting and shutdown";
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.gpl2Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/targetcli/default.nix b/nixpkgs/pkgs/os-specific/linux/targetcli/default.nix
new file mode 100644
index 000000000000..b8990484cb98
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/targetcli/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, python, fetchFromGitHub }:
+
+python.pkgs.buildPythonApplication rec {
+  pname = "targetcli";
+  version = "2.1.fb49";
+
+  src = fetchFromGitHub {
+    owner = "open-iscsi";
+    repo = "${pname}-fb";
+    rev = "v${version}";
+    sha256 = "093dmwc5g6yz4cdgpbfszmc97i7nd286w4x447dvg22hvwvjwqhh";
+  };
+
+  propagatedBuildInputs = with python.pkgs; [ configshell rtslib ];
+
+  meta = with stdenv.lib; {
+    description = "A command shell for managing the Linux LIO kernel target";
+    homepage = https://github.com/open-iscsi/targetcli-fb;
+    license = licenses.asl20;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tbs/default.nix b/nixpkgs/pkgs/os-specific/linux/tbs/default.nix
new file mode 100644
index 000000000000..fc4b38724a7d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tbs/default.nix
@@ -0,0 +1,63 @@
+{ stdenv, lib, fetchFromGitHub, kernel, kmod, perl, patchutils, perlPackages }:
+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 = ''
+    find $out/lib/modules/${kernel.modDirVersion} -name "*.ko" -exec xz {} \;
+  '';
+
+  meta = with lib; {
+    homepage = https://www.tbsdtv.com/;
+    description = "Linux driver for TBSDTV cards";
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ ck3d ];
+    priority = -1;
+    broken = stdenv.lib.versionAtLeast kernel.version "4.18";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/cdecls.patch b/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/cdecls.patch
new file mode 100644
index 000000000000..eee640e8a824
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/cdecls.patch
@@ -0,0 +1,31 @@
+__BEGIN_DECLS/__END_DECLS are BSD specific and not defined in musl
+glibc and uclibc had sys/cdefs.h doing it.
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+
+Index: tcp_wrappers_7.6/tcpd.h
+===================================================================
+--- tcp_wrappers_7.6.orig/tcpd.h
++++ tcp_wrappers_7.6/tcpd.h
+@@ -11,7 +11,9 @@
+ #include <netinet/in.h>
+ #include <stdio.h>
+ 
+-__BEGIN_DECLS
++#ifdef __cplusplus
++extern "C" {
++#endif
+ 
+ /* Structure to describe one communications endpoint. */
+ 
+@@ -252,6 +254,8 @@ extern char *fix_strtok();
+ extern char *my_strtok();
+ #endif
+ 
+-__END_DECLS
++#ifdef __cplusplus
++}
++#endif
+ 
+ #endif
diff --git a/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/default.nix b/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/default.nix
new file mode 100644
index 000000000000..5df7bb827aad
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/default.nix
@@ -0,0 +1,75 @@
+{ fetchurl, stdenv, libnsl }:
+
+let
+  vanillaVersion = "7.6.q";
+  patchLevel = "26";
+in stdenv.mkDerivation rec {
+  name = "tcp-wrappers-${version}";
+  version = "${vanillaVersion}-${patchLevel}";
+
+  src = fetchurl {
+    url = "mirror://debian/pool/main/t/tcp-wrappers/tcp-wrappers_${vanillaVersion}.orig.tar.gz";
+    sha256 = "0p9ilj4v96q32klavx0phw9va21fjp8vpk11nbh6v2ppxnnxfhwm";
+  };
+
+  debian = fetchurl {
+    url = "mirror://debian/pool/main/t/tcp-wrappers/tcp-wrappers_${version}.debian.tar.xz";
+    sha256 = "1dcdhi9lwzv7g19ggwxms2msq9fy14rl09rjqb10hwv0jix7z8j8";
+  };
+
+  prePatch = ''
+    tar -xaf $debian
+    patches="$(cat debian/patches/series | sed 's,^,debian/patches/,') $patches"
+
+    substituteInPlace Makefile --replace STRINGS STRINGDEFS
+    substituteInPlace debian/patches/13_shlib_weaksym --replace STRINGS STRINGDEFS
+  '';
+
+  # Fix __BEGIN_DECLS usage (even if it wasn't non-standard, this doesn't include sys/cdefs.h)
+  patches = [ ./cdecls.patch ];
+
+  postPatch = stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
+    substituteInPlace Makefile \
+      --replace '-DNETGROUP' '-DUSE_GETDOMAIN'
+  '';
+
+  buildInputs = [ libnsl ];
+
+  makeFlags = [ "REAL_DAEMON_DIR=$(out)/bin" "linux" "AR:=$(AR)" ];
+
+  installPhase = ''
+    mkdir -p "$out/bin"
+    cp -v safe_finger tcpd tcpdchk tcpdmatch try-from "$out/bin"
+
+    mkdir -p "$out/lib"
+    cp -v shared/lib*.so* "$out/lib"
+
+    mkdir -p "$out/include"
+    cp -v *.h "$out/include"
+
+    for i in 3 5 8;
+    do
+      mkdir -p "$out/man/man$i"
+      cp *.$i "$out/man/man$i" ;
+    done
+  '';
+
+  meta = {
+    description = "TCP Wrappers, a network logger, also known as TCPD or LOG_TCP";
+
+    longDescription = ''
+      Wietse Venema's network logger, also known as TCPD or LOG_TCP.
+      These programs log the client host name of incoming telnet, ftp,
+      rsh, rlogin, finger etc. requests.  Security options are: access
+      control per host, domain and/or service; detection of host name
+      spoofing or host address spoofing; booby traps to implement an
+      early-warning system.  The current version supports the System
+      V.4 TLI network programming interface (Solaris, DG/UX) in
+      addition to the traditional BSD sockets.
+    '';
+
+    homepage = ftp://ftp.porcupine.org/pub/security/index.html;
+    license = "BSD-style";
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/tcp-wrappers-7.6-headers.patch b/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/tcp-wrappers-7.6-headers.patch
new file mode 100644
index 000000000000..328a4a102618
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tcp-wrappers/tcp-wrappers-7.6-headers.patch
@@ -0,0 +1,295 @@
+--- a/options.c
++++ b/options.c
+@@ -34,6 +34,8 @@
+ 
+ /* System libraries. */
+ 
++#include <unistd.h>
++#include <stdlib.h>
+ #include <sys/types.h>
+ #include <sys/param.h>
+ #include <sys/socket.h>
+--- a/safe_finger.c
++++ b/safe_finger.c
+@@ -20,6 +20,11 @@
+ 
+ /* System libraries */
+ 
++#include <unistd.h>
++#include <fcntl.h>
++#include <stdlib.h>
++#include <sys/wait.h>
++#include <grp.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <signal.h>
+@@ -27,7 +31,7 @@
+ #include <ctype.h>
+ #include <pwd.h>
+ 
+-extern void exit();
++int pipe_stdin(char **argv);
+ 
+ /* Local stuff */
+ 
+--- a/scaffold.c
++++ b/scaffold.c
+@@ -10,6 +10,7 @@
+ 
+ /* System libraries. */
+ 
++#include <stdlib.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/socket.h>
+@@ -27,7 +27,4 @@
+ #endif
+ 
+-#ifndef INET6
+-extern char *malloc();
+-#endif
+ 
+ /* Application-specific. */
+--- a/shell_cmd.c
++++ b/shell_cmd.c
+@@ -14,6 +14,10 @@
+ 
+ /* System libraries. */
+ 
++#include <unistd.h>
++#include <stdlib.h>
++#include <fcntl.h>
++#include <sys/wait.h>
+ #include <sys/types.h>
+ #include <sys/param.h>
+ #include <signal.h>
+@@ -25,8 +25,6 @@
+ #include <syslog.h>
+ #include <string.h>
+ 
+-extern void exit();
+-
+ /* Local stuff. */
+ 
+ #include "tcpd.h"
+--- a/tcpdchk.c
++++ b/tcpdchk.c
+@@ -20,6 +20,8 @@
+ 
+ /* System libraries. */
+ 
++#include <unistd.h>
++#include <stdlib.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #ifdef INET6
+@@ -35,10 +36,7 @@
+ #include <netdb.h>
+ #include <string.h>
+ 
+-extern int errno;
+-extern void exit();
+-extern int optind;
+-extern char *optarg;
++int cidr_mask_addr(char *str);
+ 
+ #ifndef INADDR_NONE
+ #define INADDR_NONE     (-1)		/* XXX should be 0xffffffff */
+--- a/clean_exit.c
++++ b/clean_exit.c
+@@ -13,8 +13,8 @@
+ #endif
+ 
+ #include <stdio.h>
+-
+-extern void exit();
++#include <unistd.h>
++#include <stdlib.h>
+ 
+ #include "tcpd.h"
+ 
+--- a/hosts_access.c
++++ b/hosts_access.c
+@@ -23,6 +23,7 @@
+ 
+ /* System libraries. */
+ 
++#include <stdlib.h>
+ #include <sys/types.h>
+ #ifdef INT32_T
+     typedef uint32_t u_int32_t;
+@@ -43,8 +44,8 @@
+ #include <netdb.h>
+ #endif
+ 
+-extern char *fgets();
+-extern int errno;
++static int match_pattern_ylo(const char *s, const char *pattern);
++int cidr_mask_addr(char *str);
+ 
+ #ifndef	INADDR_NONE
+ #define	INADDR_NONE	(-1)		/* XXX should be 0xffffffff */
+--- a/inetcf.c
++++ b/inetcf.c
+@@ -9,15 +9,14 @@
+ static char sccsid[] = "@(#) inetcf.c 1.7 97/02/12 02:13:23";
+ #endif
+ 
++#include <stdlib.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <stdio.h>
+ #include <errno.h>
+ #include <string.h>
+ 
+-extern int errno;
+-extern void exit();
+-
++#include "scaffold.h"
+ #include "tcpd.h"
+ #include "inetcf.h"
+ 
+--- a/percent_x.c
++++ b/percent_x.c
+@@ -16,12 +16,12 @@
+ 
+ /* System libraries. */
+ 
++#include <unistd.h>
++#include <stdlib.h>
+ #include <stdio.h>
+ #include <syslog.h>
+ #include <string.h>
+ 
+-extern void exit();
+-
+ /* Local stuff. */
+ 
+ #include "tcpd.h"
+--- a/rfc931.c
++++ b/rfc931.c
+@@ -15,6 +15,7 @@
+ 
+ /* System libraries. */
+ 
++#include <unistd.h>
+ #include <stdio.h>
+ #include <syslog.h>
+ #include <sys/types.h>
+--- a/tcpd.c
++++ b/tcpd.c
+@@ -16,6 +16,7 @@
+ 
+ /* System libraries. */
+ 
++#include <unistd.h>
+ #include <sys/types.h>
+ #include <sys/param.h>
+ #include <sys/stat.h>
+@@ -39,6 +39,8 @@
+ #include "patchlevel.h"
+ #include "tcpd.h"
+ 
++void fix_options(struct request_info *request);
++
+ int     allow_severity = SEVERITY;	/* run-time adjustable */
+ int     deny_severity = LOG_WARNING;	/* ditto */
+ 
+--- a/tcpdmatch.c
++++ b/tcpdmatch.c
+@@ -19,6 +19,8 @@
+ 
+ /* System libraries. */
+ 
++#include <unistd.h>
++#include <stdlib.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/socket.h>
+@@ -30,9 +32,6 @@
+ #include <setjmp.h>
+ #include <string.h>
+ 
+-extern void exit();
+-extern int optind;
+-extern char *optarg;
+ 
+ #ifndef	INADDR_NONE
+ #define	INADDR_NONE	(-1)		/* XXX should be 0xffffffff */
+--- a/update.c
++++ b/update.c
+@@ -19,6 +19,7 @@
+ 
+ /* System libraries */
+ 
++#include <unistd.h>
+ #include <stdio.h>
+ #include <syslog.h>
+ #include <string.h>
+--- a/misc.c
++++ b/misc.c
+@@ -14,11 +14,10 @@
+ #include <arpa/inet.h>
+ #include <stdio.h>
+ #include <string.h>
++#include <stdlib.h>
+ 
+ #include "tcpd.h"
+ 
+-extern char *fgets();
+-
+ #ifndef	INADDR_NONE
+ #define	INADDR_NONE	(-1)		/* XXX should be 0xffffffff */
+ #endif
+--- a/fix_options.c
++++ b/fix_options.c
+@@ -32,6 +32,7 @@
+ 
+ /* fix_options - get rid of IP-level socket options */
+ 
++void
+ fix_options(request)
+ struct request_info *request;
+ {
+@@ -38,11 +38,8 @@
+ #ifdef IP_OPTIONS
+     unsigned char optbuf[BUFFER_SIZE / 3], *cp;
+     char    lbuf[BUFFER_SIZE], *lp;
+-#ifdef __GLIBC__
+-    size_t  optsize = sizeof(optbuf), ipproto;
+-#else
+-    int     optsize = sizeof(optbuf), ipproto;
+-#endif
++    socklen_t optsize = sizeof(optbuf);
++    int ipproto;
+     struct protoent *ip;
+     int     fd = request->fd;
+     unsigned int opt;
+--- a/socket.c
++++ b/socket.c
+@@ -95,11 +95,7 @@
+     static struct sockaddr_in client;
+     static struct sockaddr_in server;
+ #endif
+-#ifdef __GLIBC__
+-    size_t  len;
+-#else
+-    int     len;
+-#endif
++    socklen_t len;
+     char    buf[BUFSIZ];
+     int     fd = request->fd;
+ 
+@@ -430,11 +426,7 @@
+ #else
+     struct sockaddr_in sin;
+ #endif
+-#ifdef __GLIBC__
+-    size_t  size = sizeof(sin);
+-#else
+-    int     size = sizeof(sin);
+-#endif
++    socklen_t size;
+ 
+     /*
+      * Eat up the not-yet received datagram. Some systems insist on a
diff --git a/nixpkgs/pkgs/os-specific/linux/thunderbolt/default.nix b/nixpkgs/pkgs/os-specific/linux/thunderbolt/default.nix
new file mode 100644
index 000000000000..faf47c96a5e6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/thunderbolt/default.nix
@@ -0,0 +1,34 @@
+{ stdenv
+, boost
+, cmake
+, fetchFromGitHub
+, pkgconfig
+, txt2tags
+}:
+
+stdenv.mkDerivation rec {
+  name = "thunderbolt-${version}";
+  version = "0.9.3";
+  src = fetchFromGitHub {
+    owner = "01org";
+    repo = "thunderbolt-software-user-space";
+    rev = "v${version}";
+    sha256 = "02w1bfm7xvq0dzkhwqiq0camkzz9kvciyhnsis61c8vzp39cwx0x";
+  };
+
+  nativeBuildInputs = [ cmake pkgconfig txt2tags ];
+  buildInputs = [ boost ];
+
+  cmakeFlags = [
+    "-DUDEV_BIN_DIR=${placeholder "out"}/bin"
+    "-DUDEV_RULES_DIR=${placeholder "out"}/etc/udev/rules.d"
+  ];
+
+  meta = {
+    description = "Thunderbolt(TM) user-space components";
+    license = stdenv.lib.licenses.bsd3;
+    maintainers = [ stdenv.lib.maintainers.ryantrinkle ];
+    homepage = https://01.org/thunderbolt-sw;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tiptop/default.nix b/nixpkgs/pkgs/os-specific/linux/tiptop/default.nix
new file mode 100644
index 000000000000..3c833de8b0c3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tiptop/default.nix
@@ -0,0 +1,35 @@
+{ stdenv, fetchurl, fetchpatch, libxml2, ncurses, bison, flex }:
+
+stdenv.mkDerivation rec {
+  name = "tiptop-${version}";
+  version = "2.3.1";
+
+  src = fetchurl {
+    url = "${meta.homepage}/releases/${name}.tar.gz";
+    sha256 = "10j1138y3cj3hsmfz4w0bmk90523b0prqwi9nhb4z8xvjnf49i2i";
+  };
+
+  patches = [(fetchpatch {
+    name = "reproducibility.patch";
+    url = "https://salsa.debian.org/debian/tiptop/raw/debian/2.3.1-1/debian/patches/0001-fix-reproducibility-of-build-process.patch";
+    sha256 = "116l7n3nl9lj691i7j8x0d0za1i6zpqgghw5d70qfpb17c04cblp";
+  })];
+
+  postPatch = ''
+    substituteInPlace ./configure --replace -lcurses -lncurses
+  '';
+
+  nativeBuildInputs = [ flex bison ];
+  buildInputs = [ libxml2 ncurses ];
+
+  NIX_CFLAGS_COMPILE = [ "-I${libxml2.dev}/include/libxml2" ];
+
+  meta = with stdenv.lib; {
+    description = "Performance monitoring tool for Linux";
+    homepage = http://tiptop.gforge.inria.fr;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = [ maintainers.vcunat ];
+  };
+}
+
diff --git a/nixpkgs/pkgs/os-specific/linux/tiscamera/allow-pipeline-stop-in-trigger-mode.patch b/nixpkgs/pkgs/os-specific/linux/tiscamera/allow-pipeline-stop-in-trigger-mode.patch
new file mode 100644
index 000000000000..48a520f6ec3a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tiscamera/allow-pipeline-stop-in-trigger-mode.patch
@@ -0,0 +1,48 @@
+diff --git a/src/gstreamer-1.0/gsttcamsrc.cpp b/src/gstreamer-1.0/gsttcamsrc.cpp
+index d482e1e..e36afd8 100644
+--- a/src/gstreamer-1.0/gsttcamsrc.cpp
++++ b/src/gstreamer-1.0/gsttcamsrc.cpp
+@@ -1112,6 +1112,7 @@ bool gst_tcam_src_init_camera (GstTcamSrc* self)
+ 
+ static void gst_tcam_src_close_camera (GstTcamSrc* self)
+ {
++    GST_INFO("Closing device");
+     if (self->device != NULL)
+     {
+         self->device->dev->stop_stream();
+@@ -1156,7 +1157,7 @@ static gboolean gst_tcam_src_stop (GstBaseSrc* src)
+ 
+     self->device->dev->stop_stream();
+     gst_element_send_event(GST_ELEMENT(self), gst_event_new_eos());
+-    GST_DEBUG_OBJECT (self, "Stopped acquisition");
++    GST_DEBUG("Stopped acquisition");
+ 
+     return TRUE;
+ }
+@@ -1556,6 +1557,18 @@ static void gst_tcam_src_get_property (GObject* object,
+ }
+ 
+ 
++static gboolean gst_tcam_src_unlock (GstBaseSrc* src)
++{
++    GstTcamSrc* self = GST_TCAM_SRC(src);
++
++    self->is_running = FALSE;
++
++    self->cv.notify_all();
++
++    return TRUE;
++}
++
++
+ static void gst_tcam_src_class_init (GstTcamSrcClass* klass)
+ {
+     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+@@ -1616,6 +1629,7 @@ static void gst_tcam_src_class_init (GstTcamSrcClass* klass)
+     gstbasesrc_class->fixate = gst_tcam_src_fixate_caps;
+     gstbasesrc_class->start = gst_tcam_src_start;
+     gstbasesrc_class->stop = gst_tcam_src_stop;
++    gstbasesrc_class->unlock = gst_tcam_src_unlock;
+     gstbasesrc_class->negotiate = gst_tcam_src_negotiate;
+     gstbasesrc_class->get_times = gst_tcam_src_get_times;
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/tiscamera/default.nix b/nixpkgs/pkgs/os-specific/linux/tiscamera/default.nix
new file mode 100644
index 000000000000..53b6cbc3401a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tiscamera/default.nix
@@ -0,0 +1,98 @@
+{ lib
+, stdenv
+, fetchFromGitHub
+, cmake
+, pkgconfig
+, pcre
+, tinyxml
+, libusb1
+, libzip
+, glib
+, gobject-introspection
+, gst_all_1
+, libwebcam
+}:
+
+stdenv.mkDerivation rec {
+  pname = "tiscamera";
+  version = "0.9.1";
+  name = "${pname}-${version}";
+
+  src = fetchFromGitHub {
+    owner = "TheImagingSource";
+    repo = pname;
+    rev = "v-${name}";
+    sha256 = "143yp6bpzj3rqfnrcnlrcwggay37fg6rkphh4w9y9v7v4wllzf87";
+  };
+
+  nativeBuildInputs = [
+    cmake
+    pkgconfig
+  ];
+
+  buildInputs = [
+    pcre
+    tinyxml
+    libusb1
+    libzip
+    glib
+    gobject-introspection
+    gst_all_1.gstreamer
+    gst_all_1.gst-plugins-base
+    libwebcam
+  ];
+
+
+  cmakeFlags = [
+    "-DBUILD_ARAVIS=OFF" # For GigE support. Won't need it as our camera is usb.
+    "-DBUILD_GST_1_0=ON"
+    "-DBUILD_TOOLS=ON"
+    "-DBUILD_V4L2=ON"
+    "-DBUILD_LIBUSB=ON"
+  ];
+
+
+  patches = [
+    ./allow-pipeline-stop-in-trigger-mode.patch # To be removed next release.
+  ];
+
+  postPatch = ''
+    substituteInPlace ./data/udev/80-theimagingsource-cameras.rules \
+      --replace "/usr/bin/uvcdynctrl" "${libwebcam}/bin/uvcdynctrl" \
+      --replace "/path/to/tiscamera/uvc-extensions" "$out/share/uvcdynctrl/data/199e"
+
+    substituteInPlace ./src/BackendLoader.cpp \
+      --replace '"libtcam-v4l2.so"' "\"$out/lib/tcam-0/libtcam-v4l2.so\"" \
+      --replace '"libtcam-aravis.so"' "\"$out/lib/tcam-0/libtcam-aravis.so\"" \
+      --replace '"libtcam-libusb.so"' "\"$out/lib/tcam-0/libtcam-libusb.so\""
+  '';
+
+  preConfigure = ''
+    cmakeFlagsArray=(
+      $cmakeFlagsArray
+      "-DCMAKE_INSTALL_PREFIX=$out"
+      "-DTCAM_INSTALL_UDEV=$out/lib/udev/rules.d"
+      "-DTCAM_INSTALL_UVCDYNCTRL=$out/share/uvcdynctrl/data/199e"
+      "-DTCAM_INSTALL_GST_1_0=$out/lib/gstreamer-1.0"
+      "-DTCAM_INSTALL_GIR=$out/share/gir-1.0"
+      "-DTCAM_INSTALL_TYPELIB=$out/lib/girepository-1.0"
+      "-DTCAM_INSTALL_SYSTEMD=$out/etc/systemd/system"
+    )
+  '';
+
+
+  # There are gobject introspection commands launched as part of the build. Those have a runtime
+  # dependency on `libtcam` (which itself is built as part of this build). In order to allow
+  # that, we set the dynamic linker's path to point on the build time location of the library.
+  preBuild = ''
+    export LD_LIBRARY_PATH=$PWD/src:$LD_LIBRARY_PATH
+  '';
+
+  meta = with lib; {
+    description = "The Linux sources and UVC firmwares for The Imaging Source cameras";
+    homepage = https://github.com/TheImagingSource/tiscamera;
+    license = with licenses; [ asl20 ];
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ jraygauthier ];
+  };
+}
\ No newline at end of file
diff --git a/nixpkgs/pkgs/os-specific/linux/tmon/default.nix b/nixpkgs/pkgs/os-specific/linux/tmon/default.nix
new file mode 100644
index 000000000000..690eb8b2eabb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tmon/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, kernel, ncurses }:
+
+stdenv.mkDerivation {
+  name = "tmon-${kernel.version}";
+
+  inherit (kernel) src;
+
+  buildInputs = [ ncurses ];
+
+  configurePhase = ''
+    cd tools/thermal/tmon
+  '';
+
+  makeFlags = kernel.makeFlags ++ [ "INSTALL_ROOT=\"$(out)\"" "BINDIR=bin" ];
+  NIX_CFLAGS_LINK = "-lgcc_s";
+
+  enableParallelBuilding = true;
+
+  meta = with stdenv.lib; {
+    description = "Monitoring and Testing Tool for Linux kernel thermal subsystem";
+    homepage = https://www.kernel.org/;
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tomb/default.nix b/nixpkgs/pkgs/os-specific/linux/tomb/default.nix
new file mode 100644
index 000000000000..a43c53e02bbd
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tomb/default.nix
@@ -0,0 +1,44 @@
+{ stdenv, lib, fetchFromGitHub, gettext, zsh, pinentry, cryptsetup, gnupg, makeWrapper }:
+
+stdenv.mkDerivation rec {
+  name = "tomb-${version}";
+  version = "2.5";
+
+  src = fetchFromGitHub {
+    owner  = "dyne";
+    repo   = "Tomb";
+    rev    = "v${version}";
+    sha256 = "1wk1aanzfln88min29p5av2j8gd8vj5afbs2gvarv7lvx1vi7kh1";
+  };
+
+  nativeBuildInputs = [ makeWrapper ];
+
+  postPatch = ''
+    # if not, it shows .tomb-wrapped when running
+    substituteInPlace tomb \
+      --replace 'TOMBEXEC=$0' 'TOMBEXEC=tomb'
+  '';
+
+  buildPhase = ''
+    # manually patch the interpreter
+    sed -i -e "1s|.*|#!${zsh}/bin/zsh|g" tomb
+  '';
+
+  installPhase = ''
+    install -Dm755 tomb       $out/bin/tomb
+    install -Dm644 doc/tomb.1 $out/share/man/man1/tomb.1
+
+    ln -s ${gnupg}/bin/gpg $out/bin/gpg
+
+    wrapProgram $out/bin/tomb \
+      --prefix PATH : $out/bin:${lib.makeBinPath [ cryptsetup gettext pinentry ]}
+  '';
+
+  meta = with stdenv.lib; {
+    description = "File encryption on GNU/Linux";
+    homepage    = https://www.dyne.org/software/tomb/;
+    license     = licenses.gpl3;
+    maintainers = with maintainers; [ peterhoeg ];
+    platforms   = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tp_smapi/default.nix b/nixpkgs/pkgs/os-specific/linux/tp_smapi/default.nix
new file mode 100644
index 000000000000..13a5f2a2bffb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tp_smapi/default.nix
@@ -0,0 +1,48 @@
+{ stdenv, lib, fetchFromGitHub, kernel, writeScript, coreutils, gnugrep, jq, curl, common-updater-scripts, runtimeShell
+}:
+
+stdenv.mkDerivation rec {
+  name = "tp_smapi-${version}-${kernel.version}";
+  version = "0.43";
+
+  src = fetchFromGitHub {
+    owner = "evgeni";
+    repo = "tp_smapi";
+    rev = "tp-smapi/${version}";
+    sha256 = "1rjb0njckczc2mj05cagvj0lkyvmyk6bw7wkiinv81lw8m90g77g";
+    name = "tp-smapi-${version}";
+  };
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  hardeningDisable = [ "pic" ];
+
+  makeFlags = [
+    "KBASE=${kernel.dev}/lib/modules/${kernel.modDirVersion}"
+    "SHELL=${stdenv.shell}"
+    "HDAPS=1"
+  ];
+
+  installPhase = ''
+    install -v -D -m 644 thinkpad_ec.ko "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/firmware/thinkpad_ec.ko"
+    install -v -D -m 644 tp_smapi.ko "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/firmware/tp_smapi.ko"
+    install -v -D -m 644 hdaps.ko "$out/lib/modules/${kernel.modDirVersion}/kernel/drivers/firmware/hdapsd.ko"
+  '';
+
+  dontStrip = true;
+
+  enableParallelBuilding = true;
+
+  passthru.updateScript = import ./update.nix {
+    inherit stdenv lib writeScript coreutils gnugrep jq curl common-updater-scripts runtimeShell;
+  };
+
+  meta = {
+    description = "IBM ThinkPad hardware functions driver";
+    homepage = https://github.com/evgeni/tp_smapi;
+    license = stdenv.lib.licenses.gpl2;
+    maintainers = [ stdenv.lib.maintainers.garbas ];
+    # driver is only ment for linux thinkpads i think  bellow platforms should cover it.
+    platforms = [ "x86_64-linux" "i686-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tp_smapi/update.nix b/nixpkgs/pkgs/os-specific/linux/tp_smapi/update.nix
new file mode 100644
index 000000000000..b89912434ec5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tp_smapi/update.nix
@@ -0,0 +1,11 @@
+{ stdenv, lib, writeScript, coreutils, curl, gnugrep, jq, common-updater-scripts, runtimeShell }:
+
+writeScript "update-tp_smapi" ''
+#!${runtimeShell}
+PATH=${lib.makeBinPath [ common-updater-scripts coreutils curl gnugrep jq ]}
+
+tags=`curl -s https://api.github.com/repos/evgeni/tp_smapi/tags`
+latest_tag=`echo $tags | jq -r '.[] | .name' | grep -oP "^tp-smapi/\K.*" | sort --version-sort | tail -1`
+
+update-source-version linuxPackages.tp_smapi "$latest_tag"
+''
diff --git a/nixpkgs/pkgs/os-specific/linux/tpacpi-bat/default.nix b/nixpkgs/pkgs/os-specific/linux/tpacpi-bat/default.nix
new file mode 100644
index 000000000000..b4e584f2979b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tpacpi-bat/default.nix
@@ -0,0 +1,34 @@
+{ stdenv, fetchFromGitHub, perl, kmod, coreutils }:
+
+# Requires the acpi_call kernel module in order to run.
+stdenv.mkDerivation rec {
+  name = "tpacpi-bat-${version}";
+  version = "3.1";
+
+  src = fetchFromGitHub {
+    owner = "teleshoes";
+    repo = "tpacpi-bat";
+    rev = "v${version}";
+    sha256 = "0wbaz34z99gqx721alh5vmpxpj2yxg3x9m8jqyivfi1wfpwc2nd5";
+  };
+
+  buildInputs = [ perl ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp tpacpi-bat $out/bin
+  '';
+
+  postPatch = ''
+    substituteInPlace tpacpi-bat \
+      --replace modprobe ${kmod}/bin/modprobe \
+      --replace cat ${coreutils}/bin/cat
+  '';
+
+  meta = {
+    maintainers = [stdenv.lib.maintainers.orbekk];
+    platforms = stdenv.lib.platforms.linux;
+    description = "Tool to set battery charging thesholds on Lenovo Thinkpad";
+    license = stdenv.lib.licenses.gpl3Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/trace-cmd/default.nix b/nixpkgs/pkgs/os-specific/linux/trace-cmd/default.nix
new file mode 100644
index 000000000000..1d1712f6b476
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/trace-cmd/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchgit, asciidoc, docbook_xsl, libxslt }:
+
+stdenv.mkDerivation rec {
+  name    = "trace-cmd-${version}";
+  version = "2.6";
+
+  src = fetchgit {
+    url    = "git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git";
+    rev    = "refs/tags/trace-cmd-v${version}";
+    sha256 = "15d6b7l766h2mamqgphx6l6a33b1zn0yar2h7i6b24ph6kz3idxn";
+  };
+
+  buildInputs = [ asciidoc libxslt ];
+
+  configurePhase = "true";
+  buildPhase     = "make prefix=$out MANPAGE_DOCBOOK_XSL=${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl all doc";
+  installPhase   = "make prefix=$out install install_doc";
+
+  meta = {
+    description = "User-space tools for the Linux kernel ftrace subsystem";
+    license     = stdenv.lib.licenses.gpl2;
+    platforms   = stdenv.lib.platforms.linux;
+    maintainers = [ stdenv.lib.maintainers.thoughtpolice ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/trinity/default.nix b/nixpkgs/pkgs/os-specific/linux/trinity/default.nix
new file mode 100644
index 000000000000..54d9a9bafe97
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/trinity/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchFromGitHub }:
+
+stdenv.mkDerivation rec {
+  name = "trinity-${version}";
+  version = "1.8-git-2018-06-08";
+
+  src = fetchFromGitHub {
+    owner = "kernelslacker";
+    repo = "trinity";
+    rev = "1b2d43cb383cef86a05acb2df046ce5e9b17a7fe";
+    sha256 = "0dsq10vmd6ii1dnpaqhizk9p8mbd6mwgpmi13b11dxwxpcvbhlar";
+  };
+
+  # Fails on 32-bit otherwise
+  NIX_CFLAGS_COMPILE = [
+    "-Wno-error=int-to-pointer-cast"
+    "-Wno-error=pointer-to-int-cast"
+    "-Wno-error=incompatible-pointer-types"
+  ];
+
+  postPatch = ''
+    patchShebangs ./configure
+    patchShebangs ./scripts/
+  '';
+
+  enableParallelBuilding = true;
+
+  makeFlags = [ "DESTDIR=$(out)" ];
+
+  meta = with stdenv.lib; {
+    description = "A Linux System call fuzz tester";
+    homepage = https://codemonkey.org.uk/projects/trinity/;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.dezgeg ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/tunctl/default.nix b/nixpkgs/pkgs/os-specific/linux/tunctl/default.nix
new file mode 100644
index 000000000000..ded9ec0281db
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/tunctl/default.nix
@@ -0,0 +1,22 @@
+{stdenv, fetchurl}:
+
+stdenv.mkDerivation {
+  name = "tunctl-1.5";
+  src = fetchurl {
+    url = mirror://sourceforge/tunctl/tunctl-1.5.tar.gz;
+    sha256 = "aa2a6c4cc6bfacb11e0d9f62334a6638a0d435475c61230116f00b6af8b14fff";
+  };
+
+  makeFlags = [ "tunctl" ];
+  installPhase = ''
+    mkdir -p $out/bin
+    cp tunctl $out/bin
+  '';
+
+  meta = {
+    homepage = http://tunctl.sourceforge.net/;
+    description = "Utility to set up and maintain TUN/TAP network interfaces";
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/uclibc/default.nix b/nixpkgs/pkgs/os-specific/linux/uclibc/default.nix
new file mode 100644
index 000000000000..c07e063caa71
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/uclibc/default.nix
@@ -0,0 +1,114 @@
+{ stdenv, buildPackages
+, fetchurl, linuxHeaders, libiconvReal
+, extraConfig ? ""
+}:
+
+let
+  configParser = ''
+    function parseconfig {
+        set -x
+        while read LINE; do
+            NAME=`echo "$LINE" | cut -d \  -f 1`
+            OPTION=`echo "$LINE" | cut -d \  -f 2`
+
+            if test -z "$NAME"; then
+                continue
+            fi
+
+            echo "parseconfig: removing $NAME"
+            sed -i /^$NAME=/d .config
+
+            #if test "$OPTION" != n; then
+                echo "parseconfig: setting $NAME=$OPTION"
+                echo "$NAME=$OPTION" >> .config
+            #fi
+        done
+        set +x
+    }
+  '';
+
+  # UCLIBC_SUSV4_LEGACY defines 'tmpnam', needed for gcc libstdc++ builds.
+  nixConfig = ''
+    RUNTIME_PREFIX "/"
+    DEVEL_PREFIX "/"
+    UCLIBC_HAS_WCHAR y
+    UCLIBC_HAS_FTW y
+    UCLIBC_HAS_RPC y
+    DO_C99_MATH y
+    UCLIBC_HAS_PROGRAM_INVOCATION_NAME y
+    UCLIBC_SUSV4_LEGACY y
+    UCLIBC_HAS_THREADS_NATIVE y
+    KERNEL_HEADERS "${linuxHeaders}/include"
+  '' + stdenv.lib.optionalString (stdenv.isAarch32 && stdenv.buildPlatform != stdenv.hostPlatform) ''
+    CONFIG_ARM_EABI y
+    ARCH_WANTS_BIG_ENDIAN n
+    ARCH_BIG_ENDIAN n
+    ARCH_WANTS_LITTLE_ENDIAN y
+    ARCH_LITTLE_ENDIAN y
+    UCLIBC_HAS_FPU n
+  '';
+
+  version = "1.0.31";
+in
+
+stdenv.mkDerivation {
+  name = "uclibc-ng-${version}";
+  inherit version;
+
+  src = fetchurl {
+    url = "https://downloads.uclibc-ng.org/releases/${version}/uClibc-ng-${version}.tar.bz2";
+    # from "${url}.sha256";
+    sha256 = "0ba9yh7ir1jamrgc9x9v7zw0sw144f78q4vidiz6ynpr4dwbd5qm";
+  };
+
+  # 'ftw' needed to build acl, a coreutils dependency
+  configurePhase = ''
+    make defconfig
+    ${configParser}
+    cat << EOF | parseconfig
+    ${nixConfig}
+    ${extraConfig}
+    ${stdenv.hostPlatform.platform.uclibc.extraConfig or ""}
+    EOF
+    ( set +o pipefail; yes "" | make oldconfig )
+  '';
+
+  hardeningDisable = [ "stackprotector" ];
+
+  # Cross stripping hurts.
+  dontStrip = stdenv.hostPlatform != stdenv.buildPlatform;
+
+  depsBuildBuild = [ buildPackages.stdenv.cc ];
+
+  makeFlags = [
+    "ARCH=${stdenv.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
+  enableParallelBuilding = false;
+
+  installPhase = ''
+    mkdir -p $out
+    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
+  '';
+
+  passthru = {
+    # Derivations may check for the existance of this attribute, to know what to link to.
+    libiconv = libiconvReal;
+  };
+
+  meta = with stdenv.lib; {
+    homepage = "https://uclibc-ng.org";
+    description = "A small implementation of the C library";
+    maintainers = with maintainers; [ rasendubi ];
+    license = licenses.lgpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks-glue/default.nix b/nixpkgs/pkgs/os-specific/linux/udisks-glue/default.nix
new file mode 100644
index 000000000000..37af3c92ea53
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks-glue/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, fetchurl, pkgconfig, automake, autoconf, udisks1, dbus-glib, glib, libconfuse }:
+
+stdenv.mkDerivation {
+  name = "udisks-glue-1.3.5";
+
+  src = fetchurl {
+    url = "https://github.com/fernandotcl/udisks-glue/archive/release-1.3.5.tar.gz";
+    sha256 = "317d25bf249278dc8f6a5dcf18f760512427c772b9afe3cfe34e6e1baa258176";
+  };
+
+  nativeBuildInputs = [ pkgconfig automake autoconf ];
+  buildInputs = [ udisks1 dbus-glib glib libconfuse ];
+
+  preConfigure = "sh autogen.sh";
+
+  meta = {
+    homepage = https://github.com/fernandotcl/udisks-glue;
+    description = "A tool to associate udisks events to user-defined actions";
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [pSub];
+    license = stdenv.lib.licenses.bsd2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks/1-default.nix b/nixpkgs/pkgs/os-specific/linux/udisks/1-default.nix
new file mode 100644
index 000000000000..d48c21f6b52a
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks/1-default.nix
@@ -0,0 +1,44 @@
+{ stdenv, fetchurl, pkgconfig, sg3_utils, udev, glib, dbus, dbus-glib
+, polkit, parted, lvm2, libatasmart, intltool, libuuid, mdadm
+, libxslt, docbook_xsl, utillinux, libgudev }:
+
+stdenv.mkDerivation rec {
+  name = "udisks-1.0.5";
+
+  src = fetchurl {
+    url = "https://hal.freedesktop.org/releases/${name}.tar.gz";
+    sha256 = "0wbg3jrv8limdgvcygf4dqin3y6d30y9pcmmk711vq571vmq5v7j";
+  };
+
+  patches = [ ./purity.patch ./no-pci-db.patch ./glibc.patch ];
+
+  preConfigure =
+    ''
+      configureFlagsArray+=(--with-systemdsystemunitdir=$out/lib/systemd/system)
+    '';
+
+  postPatch =
+    ''
+      sed -e 's,/sbin/mdadm,${mdadm}&,g' -e "s,@slashlibdir@,$out/lib,g" -i data/80-udisks.rules
+
+      substituteInPlace src/main.c --replace \
+        "/sbin:/bin:/usr/sbin:/usr/bin" \
+        "${utillinux}/bin:${mdadm}/sbin:/var/run/current-system/sw/bin:/var/run/current-system/sw/bin"
+    '';
+
+  buildInputs =
+    [ sg3_utils udev glib dbus dbus-glib polkit parted libgudev
+      lvm2 libatasmart intltool libuuid libxslt docbook_xsl
+    ];
+
+  nativeBuildInputs = [ pkgconfig ];
+
+  configureFlags = [ "--localstatedir=/var" "--enable-lvm2" ];
+
+  meta = with stdenv.lib; {
+    homepage = http://www.freedesktop.org/wiki/Software/udisks;
+    description = "A daemon and command-line utility for querying and manipulating storage devices";
+    platforms = platforms.linux;
+    license = with licenses; [ gpl2 lgpl2Plus ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks/2-default.nix b/nixpkgs/pkgs/os-specific/linux/udisks/2-default.nix
new file mode 100644
index 000000000000..484697d42ea9
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks/2-default.nix
@@ -0,0 +1,78 @@
+{ stdenv, fetchFromGitHub, substituteAll, libtool, pkgconfig, gettext, gnused
+, gtk-doc, acl, systemd, glib, libatasmart, polkit, coreutils, bash, which
+, expat, libxslt, docbook_xsl, utillinux, mdadm, libgudev, libblockdev, parted
+, gobject-introspection, docbook_xml_dtd_412, docbook_xml_dtd_43, autoconf, automake
+, xfsprogs, f2fs-tools, dosfstools, e2fsprogs, btrfs-progs, exfat, nilfs-utils, ntfs3g
+}:
+
+let
+  version = "2.8.2";
+in stdenv.mkDerivation rec {
+  name = "udisks-${version}";
+
+  src = fetchFromGitHub {
+    owner = "storaged-project";
+    repo = "udisks";
+    rev = name;
+    sha256 = "000xf99id1f6w8l20jxm3f2g32v9wx68rzv6q2bwrfz6vmy76xwy";
+  };
+
+  outputs = [ "out" "man" "dev" "devdoc" ];
+
+  patches = [
+    (substituteAll {
+      src = ./fix-paths.patch;
+      bash = "${bash}/bin/bash";
+      blkid = "${utillinux}/bin/blkid";
+      false = "${coreutils}/bin/false";
+      mdadm = "${mdadm}/bin/mdadm";
+      sed = "${gnused}/bin/sed";
+      sh = "${bash}/bin/sh";
+      sleep = "${coreutils}/bin/sleep";
+      true = "${coreutils}/bin/true";
+    })
+    (substituteAll {
+      src = ./force-path.patch;
+      path = stdenv.lib.makeBinPath [ btrfs-progs coreutils dosfstools e2fsprogs exfat f2fs-tools nilfs-utils xfsprogs ntfs3g parted utillinux ];
+    })
+  ];
+
+  nativeBuildInputs = [
+    autoconf automake pkgconfig libtool gettext which gobject-introspection
+    gtk-doc libxslt docbook_xml_dtd_412 docbook_xml_dtd_43 docbook_xsl
+  ];
+
+  postPatch = stdenv.lib.optionalString stdenv.hostPlatform.isMusl ''
+      substituteInPlace udisks/udisksclient.c \
+        --replace 'defined( __GNUC_PREREQ)' 1 \
+        --replace '__GNUC_PREREQ(4,6)' 1
+  '';
+
+  buildInputs = [
+    expat libgudev libblockdev acl systemd glib libatasmart polkit
+  ];
+
+  preConfigure = "NOCONFIGURE=1 ./autogen.sh";
+
+  configureFlags = [
+    "--enable-gtk-doc"
+    "--localstatedir=/var"
+    "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
+    "--with-udevdir=$(out)/lib/udev"
+  ];
+
+  makeFlags = [
+    "INTROSPECTION_GIRDIR=$(dev)/share/gir-1.0"
+    "INTROSPECTION_TYPELIBDIR=$(out)/lib/girepository-1.0"
+  ];
+
+  doCheck = false; # fails
+
+  meta = with stdenv.lib; {
+    description = "A daemon, tools and libraries to access and manipulate disks, storage devices and technologies";
+    homepage = https://www.freedesktop.org/wiki/Software/udisks/;
+    license = licenses.gpl2Plus; # lgpl2Plus for the library, gpl2Plus for the tools & daemon
+    maintainers = with maintainers; [];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks/fix-paths.patch b/nixpkgs/pkgs/os-specific/linux/udisks/fix-paths.patch
new file mode 100644
index 000000000000..c2744c3b42e1
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks/fix-paths.patch
@@ -0,0 +1,131 @@
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -1,6 +1,6 @@
+ ## Process this file with automake to produce Makefile.in
+ 
+-SHELL = /bin/bash
++SHELL = @bash@
+ .SHELLFLAGS = -o pipefail -c
+ 
+ PYTHON ?= python3
+--- a/data/80-udisks2.rules
++++ b/data/80-udisks2.rules
+@@ -17,9 +17,9 @@
+ #
+ # TODO: file bug against mdadm(8) to have --export-prefix option that can be used with e.g. UDISKS_MD_MEMBER
+ #
+-SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="raid", ENV{ID_FS_TYPE}=="linux_raid_member", ENV{UDISKS_MD_MEMBER_LEVEL}=="", IMPORT{program}="/bin/sh -c '/sbin/mdadm --examine --export $tempnode | /bin/sed s/^MD_/UDISKS_MD_MEMBER_/g'"
++SUBSYSTEM=="block", ENV{ID_FS_USAGE}=="raid", ENV{ID_FS_TYPE}=="linux_raid_member", ENV{UDISKS_MD_MEMBER_LEVEL}=="", IMPORT{program}="@sh@ -c '@mdadm@ --examine --export $tempnode | @sed@ s/^MD_/UDISKS_MD_MEMBER_/g'"
+ 
+-SUBSYSTEM=="block", KERNEL=="md*", ENV{DEVTYPE}!="partition", IMPORT{program}="/bin/sh -c '/sbin/mdadm --detail --export $tempnode | /bin/sed s/^MD_/UDISKS_MD_/g'"
++SUBSYSTEM=="block", KERNEL=="md*", ENV{DEVTYPE}!="partition", IMPORT{program}="@sh@ -c '@mdadm@ --detail --export $tempnode | @sed@ s/^MD_/UDISKS_MD_/g'"
+ 
+ LABEL="udisks_probe_end"
+ 
+--- a/modules/zram/udiskslinuxmanagerzram.c
++++ b/modules/zram/udiskslinuxmanagerzram.c
+@@ -250,7 +250,7 @@
+ 
+       g_snprintf (tmp, 255, "zram%" G_GUINT64_FORMAT, i);
+       filename = g_build_filename (PACKAGE_ZRAMCONF_DIR, tmp, NULL);
+-      contents = g_strdup_printf ("#!/bin/bash\n\n"
++      contents = g_strdup_printf ("#!@bash@\n\n"
+                                   "ZRAM_NUM_STR=%" G_GUINT64_FORMAT "\n"
+                                   "ZRAM_DEV_SIZE=%" G_GUINT64_FORMAT "\n"
+                                   "SWAP=n\n",
+--- a/src/tests/install-udisks/runtest.sh
++++ b/src/tests/install-udisks/runtest.sh
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!@bash@
+ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ #
+--- a/src/tests/integration-test
++++ b/src/tests/integration-test
+@@ -414,7 +414,7 @@
+                 f.write('KERNEL=="sr*", ENV{DISK_EJECT_REQUEST}!="?*", '
+                         'ATTRS{model}=="scsi_debug*", '
+                         'ENV{ID_CDROM_MEDIA}=="?*", '
+-                        'IMPORT{program}="/sbin/blkid -o udev -p -u noraid $tempnode"\n')
++                        'IMPORT{program}="@blkid@ -o udev -p -u noraid $tempnode"\n')
+             # reload udev
+             subprocess.call('sync; pkill --signal HUP udevd || '
+                             'pkill --signal HUP systemd-udevd',
+@@ -1079,7 +1079,7 @@
+         self.assertFalse(os.access(f, os.X_OK))
+ 
+         f = os.path.join(mount_point, 'simple.exe')
+-        shutil.copy('/bin/bash', f)
++        shutil.copy('@bash@', f)
+         self.assertTrue(os.access(f, os.R_OK))
+         self.assertTrue(os.access(f, os.W_OK))
+         self.assertTrue(os.access(f, os.X_OK))
+@@ -1092,7 +1092,7 @@
+         self.assertFalse(os.access(f, os.X_OK))
+ 
+         f = os.path.join(mount_point, 'subdir', 'subdir.exe')
+-        shutil.copy('/bin/bash', f)
++        shutil.copy('@bash@', f)
+         self.assertTrue(os.access(f, os.R_OK))
+         self.assertTrue(os.access(f, os.W_OK))
+         self.assertTrue(os.access(f, os.X_OK))
+--- a/src/tests/storadectl/runtest.sh
++++ b/src/tests/storadectl/runtest.sh
+@@ -1,4 +1,4 @@
+-#!/bin/bash
++#!@bash@
+ # vim: dict+=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k
+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ #
+--- a/src/tests/test.c
++++ b/src/tests/test.c
+@@ -71,7 +71,7 @@
+ {
+   UDisksSpawnedJob *job;
+ 
+-  job = udisks_spawned_job_new ("/bin/true", NULL, getuid (), geteuid (), NULL, NULL);
++  job = udisks_spawned_job_new ("@true@", NULL, getuid (), geteuid (), NULL, NULL);
+   udisks_spawned_job_start (job);
+   _g_assert_signal_received (job, "completed", G_CALLBACK (on_completed_expect_success), NULL);
+   g_object_unref (job);
+@@ -84,10 +84,10 @@
+ {
+   UDisksSpawnedJob *job;
+ 
+-  job = udisks_spawned_job_new ("/bin/false", NULL, getuid (), geteuid (), NULL, NULL);
++  job = udisks_spawned_job_new ("@false@", NULL, getuid (), geteuid (), NULL, NULL);
+   udisks_spawned_job_start (job);
+   _g_assert_signal_received (job, "completed", G_CALLBACK (on_completed_expect_failure),
+-                             (gpointer) "Command-line `/bin/false' exited with non-zero exit status 1: ");
++                             (gpointer) "Command-line `@false@' exited with non-zero exit status 1: ");
+   g_object_unref (job);
+ }
+ 
+@@ -119,7 +119,7 @@
+ 
+   cancellable = g_cancellable_new ();
+   g_cancellable_cancel (cancellable);
+-  job = udisks_spawned_job_new ("/bin/true", NULL, getuid (), geteuid (), NULL, cancellable);
++  job = udisks_spawned_job_new ("@true@", NULL, getuid (), geteuid (), NULL, cancellable);
+   udisks_spawned_job_start (job);
+   _g_assert_signal_received (job, "completed", G_CALLBACK (on_completed_expect_failure),
+                              (gpointer) "Operation was cancelled (g-io-error-quark, 19)");
+@@ -145,7 +145,7 @@
+   GCancellable *cancellable;
+ 
+   cancellable = g_cancellable_new ();
+-  job = udisks_spawned_job_new ("/bin/sleep 0.5", NULL, getuid (), geteuid (), NULL, cancellable);
++  job = udisks_spawned_job_new ("@sleep@ 0.5", NULL, getuid (), geteuid (), NULL, cancellable);
+   udisks_spawned_job_start (job);
+   g_timeout_add (10, on_timeout, cancellable); /* 10 msec */
+   g_main_loop_run (loop);
+@@ -199,7 +199,7 @@
+ {
+   UDisksSpawnedJob *job;
+ 
+-  job = udisks_spawned_job_new ("/bin/sleep 1000", NULL, getuid (), geteuid (), NULL, NULL /* GCancellable */);
++  job = udisks_spawned_job_new ("@sleep@ 1000", NULL, getuid (), geteuid (), NULL, NULL /* GCancellable */);
+   udisks_spawned_job_start (job);
+   g_object_unref (job);
+ }
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks/force-path.patch b/nixpkgs/pkgs/os-specific/linux/udisks/force-path.patch
new file mode 100644
index 000000000000..16c7ea5322fa
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks/force-path.patch
@@ -0,0 +1,13 @@
+diff -ruN udisks-2.1.0.orig/src/main.c udisks-2.1.0/src/main.c
+--- udisks-2.1.0.orig/src/main.c	2013-04-02 10:43:41.629332135 +0000
++++ udisks-2.1.0/src/main.c	2013-04-02 11:04:55.635342823 +0000
+@@ -140,8 +140,7 @@
+         }
+     }
+ 
+-  if (g_getenv ("PATH") == NULL)
+-    g_setenv ("PATH", "/usr/bin:/bin:/usr/sbin:/sbin", TRUE);
++  g_setenv ("PATH", "@path@", TRUE);
+ 
+   udisks_notice ("udisks daemon version %s starting", PACKAGE_VERSION);
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks/glibc.patch b/nixpkgs/pkgs/os-specific/linux/udisks/glibc.patch
new file mode 100644
index 000000000000..85ef5208049d
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks/glibc.patch
@@ -0,0 +1,25 @@
+From 0aa652a7b257f98f9e8e7dc7b0ddc9bc62377d09 Mon Sep 17 00:00:00 2001
+From: Alexandre Rostovtsev <tetromino@gentoo.org>
+Date: Fri, 29 May 2015 21:09:39 -0400
+Subject: [PATCH] Bug 90778 - fix build with newer glibc versions
+
+https://bugs.freedesktop.org/show_bug.cgi?id=90778
+---
+ src/helpers/job-drive-detach.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/src/helpers/job-drive-detach.c b/src/helpers/job-drive-detach.c
+index eeafcab..d122a1f 100644
+--- a/src/helpers/job-drive-detach.c
++++ b/src/helpers/job-drive-detach.c
+@@ -18,6 +18,7 @@
+  *
+  */
+ 
++#include <sys/stat.h>
+ #include <stdio.h>
+ #include <string.h>
+ #include <errno.h>
+-- 
+2.4.2
+
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks/no-pci-db.patch b/nixpkgs/pkgs/os-specific/linux/udisks/no-pci-db.patch
new file mode 100644
index 000000000000..b323b515c40e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks/no-pci-db.patch
@@ -0,0 +1,13 @@
+Systemd no longer has the pci-db program.
+
+diff -ru -x '*~' udisks-1.0.4-orig/data/80-udisks.rules udisks-1.0.4/data/80-udisks.rules
+--- udisks-1.0.4-orig/data/80-udisks.rules	2011-08-25 23:31:20.000000000 +0200
++++ udisks-1.0.4/data/80-udisks.rules	2012-12-13 13:06:52.189650854 +0100
+@@ -3,7 +3,6 @@
+ 
+ # import names for PCI storage controllers
+ #
+-SUBSYSTEM=="pci", ACTION=="add|change", ENV{ID_MODEL_FROM_DATABASE}=="", ATTR{class}=="0x01*", IMPORT{program}="pci-db %p"
+ 
+ # Set eSATA port type for known eSATA CardBus adapters - first we want to ensure
+ # the device is on a cardbus controller (upper PCI device) - then we check
diff --git a/nixpkgs/pkgs/os-specific/linux/udisks/purity.patch b/nixpkgs/pkgs/os-specific/linux/udisks/purity.patch
new file mode 100644
index 000000000000..bf1121ddb659
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/udisks/purity.patch
@@ -0,0 +1,57 @@
+diff --git a/data/80-udisks.rules b/data/80-udisks.rules
+index 6720394..60b67ed 100644
+--- a/data/80-udisks.rules
++++ b/data/80-udisks.rules
+@@ -23,7 +23,7 @@ LABEL="ata_port_cardbus_end"
+ #  this is the case we can trigger a 'change' on the sas_expander device
+ #  when the bsg device appears)
+ #
+-SUBSYSTEM=="sas_expander", ACTION=="add|change", IMPORT{program}="udisks-probe-sas-expander /sys/%p"
++SUBSYSTEM=="sas_expander", ACTION=="add|change", IMPORT{program}="@slashlibdir@/udev/udisks-probe-sas-expander /sys/%p"
+ 
+ ##############################################################################################################
+ 
+@@ -54,7 +54,7 @@ ENV{DM_UDEV_DISABLE_DISK_RULES_FLAG}=="1", GOTO="udisks_end"
+ # import UDISKS_DM_* and UDISKS_LVM2_* properties - the long-term plan is to make the lvm2 and
+ # device-mapper packages provide this information
+ #
+-KERNEL=="dm-*", IMPORT{program}="udisks-dm-export %M %m"
++KERNEL=="dm-*", IMPORT{program}="@slashlibdir@/udev/udisks-dm-export %M %m"
+ 
+ # Make udevd synthesize a 'change' uevent when last opener of a rw-fd closes the fd - this
+ # should be part of the device-mapper rules
+@@ -63,7 +63,7 @@ KERNEL=="dm-*", OPTIONS+="watch"
+ ##############################################################################################################
+ # Probe LVM2 Physical Volumes - this will eventually be part of the LVM2 package
+ 
+-ENV{ID_FS_TYPE}=="LVM2_member", TEST=="/lib/udev/udisks-lvm-pv-export", IMPORT{program}="udisks-lvm-pv-export $env{ID_FS_UUID}"
++ENV{ID_FS_TYPE}=="LVM2_member", TEST=="@slashlibdir@/udev/udisks-lvm-pv-export", IMPORT{program}="@slashlibdir@/udev/udisks-lvm-pv-export $env{ID_FS_UUID}"
+ 
+ ##############################################################################################################
+ 
+@@ -85,7 +85,7 @@ KERNEL=="sr*", ENV{ID_CDROM_MEDIA_TRACK_COUNT_DATA}=="", GOTO="probe_parttable_e
+ 
+ # scan for partition tables both on whole-disk and partitions
+ #
+-IMPORT{program}="udisks-part-id $tempnode"
++IMPORT{program}="@slashlibdir@/udev/udisks-part-id $tempnode"
+ 
+ LABEL="probe_parttable_end"
+ 
+@@ -109,13 +109,13 @@ LABEL="md_end"
+ #
+ 
+ # USB ATA enclosures with a SAT layer
+-KERNEL=="sd*[!0-9]", ATTR{removable}=="0", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="disk", IMPORT{program}="udisks-probe-ata-smart $tempnode"
++KERNEL=="sd*[!0-9]", ATTR{removable}=="0", ENV{ID_BUS}=="usb", ENV{DEVTYPE}=="disk", IMPORT{program}="@slashlibdir@/udev/udisks-probe-ata-smart $tempnode"
+ 
+ # ATA disks driven by libata
+-KERNEL=="sd*[!0-9]", ATTR{removable}=="0", ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="disk", IMPORT{program}="udisks-probe-ata-smart $tempnode"
++KERNEL=="sd*[!0-9]", ATTR{removable}=="0", ENV{ID_BUS}=="ata", ENV{DEVTYPE}=="disk", IMPORT{program}="@slashlibdir@/udev/udisks-probe-ata-smart $tempnode"
+ 
+ # ATA disks connected via SAS (not driven by libata)
+-KERNEL=="sd*[!0-9]", ATTR{removable}=="0", ENV{ID_BUS}=="scsi", ENV{DEVTYPE}=="disk", ENV{ID_VENDOR}=="ATA", IMPORT{program}="udisks-probe-ata-smart $tempnode"
++KERNEL=="sd*[!0-9]", ATTR{removable}=="0", ENV{ID_BUS}=="scsi", ENV{DEVTYPE}=="disk", ENV{ID_VENDOR}=="ATA", IMPORT{program}="@slashlibdir@/udev/udisks-probe-ata-smart $tempnode"
+ 
+ 
+ # Example rule for tagging a device with a specific media type. Where and
diff --git a/nixpkgs/pkgs/os-specific/linux/undervolt/default.nix b/nixpkgs/pkgs/os-specific/linux/undervolt/default.nix
new file mode 100644
index 000000000000..a97cca4dfa76
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/undervolt/default.nix
@@ -0,0 +1,27 @@
+{ stdenv, fetchFromGitHub, python3Packages }:
+
+python3Packages.buildPythonApplication rec {
+  version = "0.2.9";
+  pname = "undervolt";
+
+  src = fetchFromGitHub {
+    owner = "georgewhewell";
+    repo = "undervolt";
+    rev = "${version}";
+    sha256 = "1d934lp8yczrfslmwff6fxzd4arja2vg00s5kwdr949bxpa6w59c";
+  };
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/georgewhewell/undervolt/;
+    description = "A program for undervolting Intel CPUs on Linux";
+
+    longDescription = ''
+      Undervolt is a program for undervolting Intel CPUs under Linux. It works in a similar
+      manner to the Windows program ThrottleStop (i.e, MSR 0x150). You can apply a fixed
+      voltage offset to one of 5 voltage planes, and override your systems temperature
+      target (CPU will throttle when this temperature is reached).
+    '';
+    license = licenses.gpl2;
+    platforms = [ "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/untie/default.nix b/nixpkgs/pkgs/os-specific/linux/untie/default.nix
new file mode 100644
index 000000000000..739bd4471927
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/untie/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, fetchurl }:
+
+stdenv.mkDerivation rec {
+  name = "untie-${version}";
+  version = "0.3";
+  src = fetchurl {
+    url = "http://guichaz.free.fr/untie/files/${name}.tar.bz2";
+    sha256 = "1334ngvbi4arcch462mzi5vxvxck4sy1nf0m58116d9xmx83ak0m";
+  };
+
+  makeFlags = "PREFIX=$(out)";
+
+  meta = with stdenv.lib; {
+    description = "A tool to run processes untied from some of the namespaces";
+    maintainers = with maintainers; [ raskin ];
+    platforms = platforms.linux;
+    license = licenses.gpl2Plus;
+  };
+
+  passthru = {
+    updateInfo = {
+      downloadPage = "http://guichaz.free.fr/untie";
+    };
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/upower/default.nix b/nixpkgs/pkgs/os-specific/linux/upower/default.nix
new file mode 100644
index 000000000000..0aaa31163ac5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/upower/default.nix
@@ -0,0 +1,41 @@
+{ stdenv, fetchurl, pkgconfig, dbus-glib
+, intltool, libxslt, docbook_xsl, udev, libgudev, libusb1
+, useSystemd ? true, systemd, gobject-introspection
+}:
+
+stdenv.mkDerivation rec {
+  name = "upower-0.99.9";
+
+  src = fetchurl {
+    url = https://gitlab.freedesktop.org/upower/upower/uploads/2282c7c0e53fb31816b824c9d1f547e8/upower-0.99.9.tar.xz;
+    sha256 = "046ix7j7hmb7ycv8v54668kjsrgjhzwxn299c1d87vdnkd38kfh1";
+  };
+
+  buildInputs =
+    [ dbus-glib intltool libxslt docbook_xsl udev libgudev libusb1 gobject-introspection ]
+    ++ stdenv.lib.optional useSystemd systemd;
+
+  nativeBuildInputs = [ pkgconfig ];
+
+  configureFlags =
+    [ "--with-backend=linux" "--localstatedir=/var"
+    ]
+    ++ stdenv.lib.optional useSystemd
+    [ "--with-systemdsystemunitdir=$(out)/etc/systemd/system"
+      "--with-systemdutildir=$(out)/lib/systemd"
+      "--with-udevrulesdir=$(out)/lib/udev/rules.d"
+    ];
+
+  NIX_CFLAGS_LINK = "-lgcc_s";
+
+  doCheck = false; # fails with "env: './linux/integration-test': No such file or directory"
+
+  installFlags = "historydir=$(TMPDIR)/foo";
+
+  meta = {
+    homepage = https://upower.freedesktop.org/;
+    description = "A D-Bus service for power management";
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.gpl2Plus;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/usbguard/default.nix b/nixpkgs/pkgs/os-specific/linux/usbguard/default.nix
new file mode 100644
index 000000000000..3df0023bd678
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/usbguard/default.nix
@@ -0,0 +1,66 @@
+{
+  stdenv, fetchurl, lib,
+  libxslt, pandoc, asciidoctor, pkgconfig,
+  dbus-glib, libcap_ng, libqb, libseccomp, polkit, protobuf, qtbase, qttools, qtsvg,
+  audit,
+  libgcrypt ? null,
+  libsodium ? null
+}:
+
+with stdenv.lib;
+
+assert libgcrypt != null -> libsodium == null;
+
+stdenv.mkDerivation rec {
+  version = "0.7.4";
+  name = "usbguard-${version}";
+
+  repo = "https://github.com/USBGuard/usbguard";
+
+  src = fetchurl {
+    url = "${repo}/releases/download/${name}/${name}.tar.gz";
+    sha256 = "1qkskd6q5cwlh2cpcsbzmmmgk6w63z0825wlb2sjwqq3kfgwjb3k";
+  };
+
+  nativeBuildInputs = [
+    libxslt
+    asciidoctor
+    pandoc # for rendering documentation
+    pkgconfig
+  ];
+
+  buildInputs = [
+    dbus-glib
+    libcap_ng
+    libqb
+    libseccomp
+    polkit
+    protobuf
+    audit
+
+    qtbase
+    qtsvg
+    qttools
+  ]
+  ++ (lib.optional (libgcrypt != null) libgcrypt)
+  ++ (lib.optional (libsodium != null) libsodium);
+
+  configureFlags = [
+    "--with-bundled-catch"
+    "--with-bundled-pegtl"
+    "--with-dbus"
+    "--with-gui-qt=qt5"
+    "--with-polkit"
+  ]
+  ++ (lib.optional (libgcrypt != null) "--with-crypto-library=gcrypt")
+  ++ (lib.optional (libsodium != null) "--with-crypto-library=sodium");
+
+  enableParallelBuilding = true;
+
+  meta = {
+    description = "The USBGuard software framework helps to protect your computer against BadUSB.";
+    homepage = "https://usbguard.github.io/";
+    license = licenses.gpl2;
+    maintainers = [ maintainers.tnias ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/usbip/default.nix b/nixpkgs/pkgs/os-specific/linux/usbip/default.nix
new file mode 100644
index 000000000000..497b5c191669
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/usbip/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, kernel, udev, autoconf, automake, libtool }:
+
+stdenv.mkDerivation rec {
+  name = "usbip-${kernel.name}";
+
+  src = kernel.src;
+
+  nativeBuildInputs = [ autoconf automake libtool ];
+  buildInputs = [ udev ];
+
+  preConfigure = ''
+    cd tools/usb/usbip
+    ./autogen.sh
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = https://github.com/torvalds/linux/tree/master/tools/usb/usbip;
+    description = "allows to pass USB device from server to client over the network";
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/usbutils/default.nix b/nixpkgs/pkgs/os-specific/linux/usbutils/default.nix
new file mode 100644
index 000000000000..85ef8a1a6ccb
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/usbutils/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, fetchurl, substituteAll, autoreconfHook, pkgconfig, libusb1, hwdata , python3 }:
+
+stdenv.mkDerivation rec {
+  name = "usbutils-010";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/usb/usbutils/${name}.tar.xz";
+    sha256 = "06aag4jfgsfjxk563xsp9ik9nadihmasrr37a1gb0vwqni5kdiv1";
+  };
+
+  patches = [
+    (substituteAll {
+      src = ./fix-paths.patch;
+      inherit hwdata;
+    })
+  ];
+
+  nativeBuildInputs = [ autoreconfHook pkgconfig ];
+  buildInputs = [ libusb1 python3 ];
+
+  outputs = [ "out" "man" "python" ];
+  postInstall = ''
+    moveToOutput "bin/lsusb.py" "$python"
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://www.linux-usb.org/;
+    description = "Tools for working with USB devices, such as lsusb";
+    license = licenses.gpl2Plus;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/usbutils/fix-paths.patch b/nixpkgs/pkgs/os-specific/linux/usbutils/fix-paths.patch
new file mode 100644
index 000000000000..d75c68505efc
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/usbutils/fix-paths.patch
@@ -0,0 +1,16 @@
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -51,11 +51,11 @@
+ 	usbreset.c
+ 
+ lsusb.py: $(srcdir)/lsusb.py.in
+-	sed 's|VERSION|$(VERSION)|g;s|@usbids@|$(datadir)/usb.ids|g' $< >$@
++	sed 's|VERSION|$(VERSION)|g;s|@usbids@|@hwdata@/share/hwdata/usb.ids|g' $< >$@
+ 	chmod 755 $@
+ 
+ lsusb.8: $(srcdir)/lsusb.8.in
+-	sed 's|VERSION|$(VERSION)|g;s|@usbids@|$(datadir)/usb.ids|g' $< >$@
++	sed 's|VERSION|$(VERSION)|g;s|@usbids@|@hwdata@/share/hwdata/usb.ids|g' $< >$@
+ 
+ usb-devices.1: $(srcdir)/usb-devices.1.in
+ 	sed 's|VERSION|$(VERSION)|g' $< >$@
diff --git a/nixpkgs/pkgs/os-specific/linux/usermount/default.nix b/nixpkgs/pkgs/os-specific/linux/usermount/default.nix
new file mode 100644
index 000000000000..94e5d998cd01
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/usermount/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchgit, pkgconfig, dbus, libnotify, udisks2, gdk_pixbuf }:
+
+stdenv.mkDerivation {
+  name = "usermount-0.1";
+
+  src = fetchgit {
+    url = "https://github.com/tom5760/usermount.git";
+    rev = "0d6aba3c1f8fec80de502f5b92fd8b28041cc8e4";
+    sha256 = "0gpp0vwiwr7kgbhh26jspv3255662mnvnav6g8i2h0qxar8hf8w2";
+  };
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [ dbus libnotify udisks2 gdk_pixbuf ];
+
+  NIX_CFLAGS_COMPILE = [ "-DENABLE_NOTIFICATIONS" ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    mv usermount $out/bin/
+  '';
+
+  meta = {
+    homepage = https://github.com/tom5760/usermount;
+    description = "A simple tool to automatically mount removable drives using UDisks2 and D-Bus";
+    license = stdenv.lib.licenses.mit;
+    platforms = stdenv.lib.platforms.linux;
+    maintainers = with stdenv.lib.maintainers; [ the-kenny ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/util-linux/default.nix b/nixpkgs/pkgs/os-specific/linux/util-linux/default.nix
new file mode 100644
index 000000000000..ec18c25ee665
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/util-linux/default.nix
@@ -0,0 +1,76 @@
+{ lib, stdenv, fetchurl, pkgconfig, zlib, shadow
+, ncurses ? null, perl ? null, pam, systemd ? null, minimal ? false }:
+
+let
+  version = lib.concatStringsSep "." ([ majorVersion ]
+    ++ lib.optional (patchVersion != "") patchVersion);
+  majorVersion = "2.33";
+  patchVersion = "1";
+
+in stdenv.mkDerivation rec {
+  name = "util-linux-${version}";
+
+  src = fetchurl {
+    url = "mirror://kernel/linux/utils/util-linux/v${majorVersion}/${name}.tar.xz";
+    sha256 = "08ggvgrb59m5jbq29950xxirsgv4xj3nwsc7vf82nyg1nvrxjjy1";
+  };
+
+  patches = [
+    ./rtcwake-search-PATH-for-shutdown.patch
+  ];
+
+  outputs = [ "bin" "dev" "out" "man" ];
+
+  postPatch = ''
+    patchShebangs tests/run.sh
+
+    substituteInPlace include/pathnames.h \
+      --replace "/bin/login" "${shadow}/bin/login"
+    substituteInPlace sys-utils/eject.c \
+      --replace "/bin/umount" "$out/bin/umount"
+  '';
+
+  # !!! It would be better to obtain the path to the mount helpers
+  # (/sbin/mount.*) through an environment variable, but that's
+  # somewhat risky because we have to consider that mount can setuid
+  # root...
+  configureFlags = [
+    "--enable-write"
+    "--enable-last"
+    "--enable-mesg"
+    "--disable-use-tty-group"
+    "--enable-fs-paths-default=/run/wrappers/bin:/var/run/current-system/sw/bin:/sbin"
+    "--disable-makeinstall-setuid" "--disable-makeinstall-chown"
+    (lib.withFeature (ncurses != null) "ncursesw")
+    (lib.withFeature (systemd != null) "systemd")
+    (lib.withFeatureAs (systemd != null)
+       "systemdsystemunitdir" "$(bin)/lib/systemd/system/")
+  ] ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform)
+       "scanf_cv_type_modifier=ms"
+  ;
+
+  makeFlags = "usrbin_execdir=$(bin)/bin usrsbin_execdir=$(bin)/sbin";
+
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs =
+    [ zlib pam ]
+    ++ lib.filter (p: p != null) [ ncurses systemd perl ];
+
+  doCheck = false; # "For development purpose only. Don't execute on production system!"
+
+  postInstall = ''
+    rm "$bin/bin/su" # su should be supplied by the su package (shadow)
+  '' + lib.optionalString minimal ''
+    rm -rf $out/share/{locale,doc,bash-completion}
+  '';
+
+  enableParallelBuilding = true;
+
+  meta = with lib; {
+    homepage = https://www.kernel.org/pub/linux/utils/util-linux/;
+    description = "A set of system utilities for Linux";
+    license = licenses.gpl2; # also contains parts under more permissive licenses
+    platforms = platforms.linux;
+    priority = 6; # lower priority than coreutils ("kill") and shadow ("login" etc.) packages
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/util-linux/rtcwake-search-PATH-for-shutdown.patch b/nixpkgs/pkgs/os-specific/linux/util-linux/rtcwake-search-PATH-for-shutdown.patch
new file mode 100644
index 000000000000..5f38861bf68b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/util-linux/rtcwake-search-PATH-for-shutdown.patch
@@ -0,0 +1,27 @@
+Search $PATH for the shutdown binary instead of hard-coding /sbin/shutdown,
+which isn't valid on NixOS (and a compatibility link on most other modern
+distros anyway).
+
+  -- nckx <github@tobias.gr>
+--- a/include/pathnames.h
++++ b/include/pathnames.h
+@@ -53,7 +53,7 @@
+ #ifndef _PATH_LOGIN
+ #define _PATH_LOGIN		"/bin/login"
+ #endif
+-#define _PATH_SHUTDOWN		"/sbin/shutdown"
++#define _PATH_SHUTDOWN   "shutdown"
+
+ #define _PATH_TERMCOLORS_DIRNAME "terminal-colors.d"
+ #define _PATH_TERMCOLORS_DIR	"/etc/" _PATH_TERMCOLORS_DIRNAME
+--- a/sys-utils/rtcwake.c
++++ b/sys-utils/rtcwake.c
+@@ -575,7 +575,7 @@ int main(int argc, char **argv)
+ 		arg[i++] = "now";
+ 		arg[i]   = NULL;
+ 		if (!ctl.dryrun) {
+-			execv(arg[0], arg);
++			execvp(arg[0], arg);
+ 			warn(_("failed to execute %s"), _PATH_SHUTDOWN);
+ 			rc = EXIT_FAILURE;
+ 		}
diff --git a/nixpkgs/pkgs/os-specific/linux/uvcdynctrl/default.nix b/nixpkgs/pkgs/os-specific/linux/uvcdynctrl/default.nix
new file mode 100644
index 000000000000..1a40ec50c999
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/uvcdynctrl/default.nix
@@ -0,0 +1,30 @@
+{ stdenv, fetchFromGitHub, cmake, pkgconfig, libxml2 }:
+
+stdenv.mkDerivation rec {
+  version = "0.3.0";
+  name = "uvcdynctrl-${version}";
+
+  src = fetchFromGitHub {
+    owner = "cshorler";
+    repo = "webcam-tools";
+    rev = "bee2ef3c9e350fd859f08cd0e6745871e5f55cb9";
+    sha256 = "0s15xxgdx8lnka7vi8llbf6b0j4rhbjl6yp0qxaihysf890xj73s";
+  };
+
+  nativeBuildInputs = [ cmake pkgconfig ];
+  buildInputs = [ libxml2 ];
+
+  prePatch = ''
+    substituteInPlace uvcdynctrl/CMakeLists.txt \
+      --replace "/etc/udev" "$out/etc/udev" \
+      --replace "/lib/udev" "$out/lib/udev"
+  '';
+
+  meta = with stdenv.lib; {
+    description = "A simple interface for devices supported by the linux UVC driver";
+    homepage = http://guvcview.sourceforge.net;
+    license = licenses.gpl3Plus;
+    maintainers = [ maintainers.puffnfresh ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/v4l-utils/default.nix b/nixpkgs/pkgs/os-specific/linux/v4l-utils/default.nix
new file mode 100644
index 000000000000..2a9d42988b5b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/v4l-utils/default.nix
@@ -0,0 +1,51 @@
+{ stdenv, lib, fetchurl, pkgconfig, perl
+, libjpeg, udev
+, withUtils ? true
+, withGUI ? true, alsaLib, libX11, qtbase, libGLU
+}:
+
+# See libv4l in all-packages.nix for the libs only (overrides alsa, libX11 & QT)
+
+stdenv.mkDerivation rec {
+  name = "v4l-utils-${version}";
+  version = "1.16.2";
+
+  src = fetchurl {
+    url = "https://linuxtv.org/downloads/v4l-utils/${name}.tar.bz2";
+    sha256 = "0iwfdp4ghzd6l9qg5545032vwmqy2rnhk0xf1g9mad67l74hhckc";
+  };
+
+  outputs = [ "out" "dev" ];
+
+  configureFlags =
+    if withUtils then [
+      "--with-udevdir=${placeholder "out"}/lib/udev"
+    ] else [
+      "--disable-v4l-utils"
+    ];
+
+  postFixup = ''
+    # Create symlink for V4l1 compatibility
+    ln -s "$dev/include/libv4l1-videodev.h" "$dev/include/videodev.h"
+  '';
+
+  nativeBuildInputs = [ pkgconfig perl ];
+
+  buildInputs = [ udev ] ++ lib.optionals (withUtils && withGUI) [ alsaLib libX11 qtbase libGLU ];
+
+  propagatedBuildInputs = [ libjpeg ];
+
+  NIX_CFLAGS_COMPILE = lib.optional (withUtils && withGUI) "-std=c++11";
+
+  postPatch = ''
+    patchShebangs .
+  '';
+
+  meta = with stdenv.lib; {
+    description = "V4L utils and libv4l, provide common image formats regardless of the v4l device";
+    homepage = https://linuxtv.org/projects.php;
+    license = licenses.lgpl21Plus;
+    maintainers = with maintainers; [ codyopel ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/v4l2loopback/default.nix b/nixpkgs/pkgs/os-specific/linux/v4l2loopback/default.nix
new file mode 100644
index 000000000000..2e22b99a95f3
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/v4l2loopback/default.nix
@@ -0,0 +1,37 @@
+{ stdenv, fetchFromGitHub, kernel, kmod }:
+
+stdenv.mkDerivation rec {
+  name = "v4l2loopback-${version}-${kernel.version}";
+  version = "0.12.0";
+
+  src = fetchFromGitHub {
+    owner = "umlaeute";
+    repo = "v4l2loopback";
+    rev = "v${version}";
+    sha256 = "1rf8dvabksxb2sj14j32h7n7pw7byqfnpqs4m4afj3398y9y23c4";
+  };
+
+  hardeningDisable = [ "format" "pic" ];
+
+  preBuild = ''
+    substituteInPlace Makefile --replace "modules_install" "INSTALL_MOD_PATH=$out modules_install"
+    sed -i '/depmod/d' Makefile
+    export PATH=${kmod}/sbin:$PATH
+  '';
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+  buildInputs = [ kmod ];
+
+  makeFlags = [
+    "KERNELRELEASE=${kernel.modDirVersion}"
+    "KERNEL_DIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+  ];
+
+  meta = with stdenv.lib; {
+    description = "A kernel module to create V4L2 loopback devices";
+    homepage = https://github.com/umlaeute/v4l2loopback;
+    license = licenses.gpl2;
+    maintainers = [ maintainers.domenkozar ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/v86d/default.nix b/nixpkgs/pkgs/os-specific/linux/v86d/default.nix
new file mode 100644
index 000000000000..073a6ded998b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/v86d/default.nix
@@ -0,0 +1,40 @@
+{ stdenv, fetchurl
+, kernel, klibc
+}:
+
+stdenv.mkDerivation rec {
+  name = "v86d-${version}-${kernel.version}";
+  version = "0.1.10";
+
+  src = fetchurl {
+    url = "https://github.com/mjanusz/v86d/archive/v86d-${version}.tar.gz";
+    sha256 = "1flnpp8rc945cxr6jr9dlm8mi8gr181zrp2say4269602s1a4ymg";
+  };
+
+  patchPhase = ''
+    patchShebangs configure
+  '';
+
+  configureFlags = [ "--with-klibc" "--with-x86emu" ];
+
+  hardeningDisable = [ "stackprotector" ];
+
+  makeFlags = [
+    "KDIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
+    "DESTDIR=$(out)"
+  ];
+
+  configurePhase = ''
+    ./configure $configureFlags
+  '';
+
+  buildInputs = [ klibc ];
+
+  meta = with stdenv.lib; {
+    description = "A daemon to run x86 code in an emulated environment";
+    homepage = https://github.com/mjanusz/v86d;
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ codyopel ];
+    platforms = [ "i686-linux" "x86_64-linux" ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/virtualbox/default.nix b/nixpkgs/pkgs/os-specific/linux/virtualbox/default.nix
new file mode 100644
index 000000000000..9e2dee099cec
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/virtualbox/default.nix
@@ -0,0 +1,33 @@
+{ stdenv, virtualbox, kernel }:
+
+stdenv.mkDerivation {
+  name = "virtualbox-modules-${virtualbox.version}-${kernel.version}";
+  src = virtualbox.modsrc;
+  hardeningDisable = [
+    "fortify" "pic" "stackprotector"
+  ];
+
+  nativeBuildInputs = kernel.moduleBuildDependencies;
+
+  patches = [
+    ./fix_kerndir.patch
+    ./fix_kbuild.patch
+  ];
+
+  KERN_DIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
+  INCLUDE_BASE = "${virtualbox.modsrc}";
+
+  makeFlags = [
+    "-C ${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+    "INSTALL_MOD_PATH=$(out)"
+  ];
+  preBuild = "makeFlagsArray+=(\"M=$(pwd)\")";
+  buildFlags = [ "modules" ];
+  installTargets = [ "modules_install" ];
+
+  enableParallelBuilding = true;
+
+  meta = virtualbox.meta // {
+    description = virtualbox.meta.description + " (kernel modules)";
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kbuild.patch b/nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kbuild.patch
new file mode 100644
index 000000000000..242a905c1a05
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kbuild.patch
@@ -0,0 +1,85 @@
+diff --git a/vboxdrv/Makefile b/vboxdrv/Makefile
+index e262c61..4af8dac 100644
+--- a/vboxdrv/Makefile
++++ b/vboxdrv/Makefile
+@@ -131,7 +131,7 @@ ifdef VBOX_WITH_NATIVE_DTRACE
+  MOD_OBJS += SUPDrvDTrace.o
+ endif
+
+-MOD_INCL  = $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
++MOD_INCL  = $(addprefix -I$(INCLUDE_BASE)/$(MOD_NAME),/ /include /r0drv/linux)
+ ifdef VBOX_WITH_NATIVE_DTRACE
+  MOD_INCL += -I/usr/include/linux -I/usr/include
+ endif
+@@ -157,7 +157,7 @@ ifdef VBOX_WITH_TEXT_MODMEM_HACK
+ endif
+
+ # build defs
+-MOD_CFLAGS = -include $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h \
++MOD_CFLAGS = -include include/VBox/SUPDrvMangling.h \
+	-fno-omit-frame-pointer -fno-pie
+
+ include $(obj)/Makefile.include.footer
+diff --git a/vboxnetadp/Makefile b/vboxnetadp/Makefile
+index e262c61..4af8dac 100644
+--- a/vboxnetadp/Makefile
++++ b/vboxnetadp/Makefile
+@@ -34,7 +34,7 @@ MOD_OBJS += math/gcc/divdi3.o \
+	math/gcc/umoddi3.o
+ endif
+
+-MOD_INCL = $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
++MOD_INCL = $(addprefix -I$(INCLUDE_BASE)/$(MOD_NAME),/ /include /r0drv/linux)
+ MOD_DEFS = -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX \
+	    -DRT_WITH_VBOX -DVBOX_WITH_HARDENING \
+	    -Wno-declaration-after-statement
+@@ -59,6 +59,6 @@ ifdef VBOX_USE_INSERT_PAGE
+ endif
+
+ # build defs
+-MOD_CFLAGS = -include $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h -fno-pie
++MOD_CFLAGS = -include include/VBox/SUPDrvMangling.h -fno-pie
+
+ include $(obj)/Makefile.include.footer
+diff --git a/vboxnetflt/Makefile b/vboxnetflt/Makefile
+index e262c61..4af8dac 100644
+--- a/vboxnetflt/Makefile
++++ b/vboxnetflt/Makefile
+@@ -38,7 +38,7 @@ MOD_OBJS += math/gcc/divdi3.o \
+	math/gcc/umoddi3.o
+ endif
+
+-MOD_INCL = $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
++MOD_INCL = $(addprefix -I$(INCLUDE_BASE)/$(MOD_NAME),/ /include /r0drv/linux)
+ MOD_DEFS = -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 \
+	-DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DVBOX_WITH_HARDENING \
+	-Wno-declaration-after-statement
+@@ -63,6 +63,6 @@ ifdef VBOX_USE_INSERT_PAGE
+ endif
+
+ # build defs
+-MOD_CFLAGS = -include $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h -fno-pie
++MOD_CFLAGS = -include include/VBox/SUPDrvMangling.h -fno-pie
+
+ include $(obj)/Makefile.include.footer
+diff --git a/vboxpci/Makefile b/vboxpci/Makefile
+index e262c61..4af8dac 100644
+--- a/vboxpci/Makefile
++++ b/vboxpci/Makefile
+@@ -38,7 +38,7 @@ MOD_OBJS += math/gcc/divdi3.o       \
+	math/gcc/umoddi3.o
+ endif
+
+-MOD_INCL = $(addprefix -I$(KBUILD_EXTMOD),/ /include /r0drv/linux)
++MOD_INCL = $(addprefix -I$(INCLUDE_BASE)/$(MOD_NAME),/ /include /r0drv/linux)
+ MOD_DEFS = -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX \
+	-DRT_WITH_VBOX -DVBOX_WITH_HARDENING
+ ifeq ($(BUILD_TARGET_ARCH),amd64)
+@@ -60,6 +60,6 @@ ifdef VBOX_USE_INSERT_PAGE
+ endif
+
+ # build defs
+-MOD_CFLAGS = -include $(KBUILD_EXTMOD)/include/VBox/SUPDrvMangling.h -fno-pie
++MOD_CFLAGS = -include include/VBox/SUPDrvMangling.h -fno-pie
+
+ include $(obj)/Makefile.include.footer
diff --git a/nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kerndir.patch b/nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kerndir.patch
new file mode 100644
index 000000000000..70ddbbb2ebd5
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/virtualbox/fix_kerndir.patch
@@ -0,0 +1,48 @@
+diff --git a/vboxdrv/Makefile.include.header b/vboxdrv/Makefile.include.header
+index 8df1eb4d25..5a3e5604e7 100644
+--- a/vboxdrv/Makefile.include.header
++++ b/vboxdrv/Makefile.include.header
+@@ -117,7 +117,6 @@ else # neq($(KERNELRELEASE),)
+ endif # neq($(KERNELRELEASE),)
+
+ # Kernel build folder
+-KERN_DIR := /lib/modules/$(KERN_VER)/build
+ ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
+  $(error Error: unable to find the headers of the Linux kernel to build against. \
+           Specify KERN_VER=<version> and run Make again)
+diff --git a/vboxnetadp/Makefile.include.header b/vboxnetadp/Makefile.include.header
+index 8df1eb4d25..5a3e5604e7 100644
+--- a/vboxnetadp/Makefile.include.header
++++ b/vboxnetadp/Makefile.include.header
+@@ -117,7 +117,6 @@ else # neq($(KERNELRELEASE),)
+ endif # neq($(KERNELRELEASE),)
+
+ # Kernel build folder
+-KERN_DIR := /lib/modules/$(KERN_VER)/build
+ ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
+  $(error Error: unable to find the headers of the Linux kernel to build against. \
+           Specify KERN_VER=<version> and run Make again)
+diff --git a/vboxnetflt/Makefile.include.header b/vboxnetflt/Makefile.include.header
+index 8df1eb4d25..5a3e5604e7 100644
+--- a/vboxnetflt/Makefile.include.header
++++ b/vboxnetflt/Makefile.include.header
+@@ -117,7 +117,6 @@ else # neq($(KERNELRELEASE),)
+ endif # neq($(KERNELRELEASE),)
+
+ # Kernel build folder
+-KERN_DIR := /lib/modules/$(KERN_VER)/build
+ ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
+  $(error Error: unable to find the headers of the Linux kernel to build against. \
+           Specify KERN_VER=<version> and run Make again)
+diff --git a/vboxpci/Makefile.include.header b/vboxpci/Makefile.include.header
+index 8df1eb4d25..5a3e5604e7 100644
+--- a/vboxpci/Makefile.include.header
++++ b/vboxpci/Makefile.include.header
+@@ -117,7 +117,6 @@ else # neq($(KERNELRELEASE),)
+ endif # neq($(KERNELRELEASE),)
+
+ # Kernel build folder
+-KERN_DIR := /lib/modules/$(KERN_VER)/build
+ ifneq ($(shell if test -d $(KERN_DIR); then echo yes; fi),yes)
+  $(error Error: unable to find the headers of the Linux kernel to build against. \
+           Specify KERN_VER=<version> and run Make again)
diff --git a/nixpkgs/pkgs/os-specific/linux/wireguard/default.nix b/nixpkgs/pkgs/os-specific/linux/wireguard/default.nix
new file mode 100644
index 000000000000..02e08bec7ad7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/wireguard/default.nix
@@ -0,0 +1,32 @@
+{ stdenv, kernel, wireguard-tools, perl }:
+
+# module requires Linux >= 3.10 https://www.wireguard.io/install/#kernel-requirements
+assert stdenv.lib.versionAtLeast kernel.version "3.10";
+
+stdenv.mkDerivation rec {
+  name = "wireguard-${version}";
+  inherit (wireguard-tools) src version;
+
+  preConfigure = ''
+    cd src
+    sed -i '/depmod/,+1d' Makefile
+  '';
+
+  hardeningDisable = [ "pic" ];
+
+  KERNELDIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
+  INSTALL_MOD_PATH = "\${out}";
+
+  NIX_CFLAGS = ["-Wno-error=cpp"];
+
+  nativeBuildInputs = [ perl ] ++ kernel.moduleBuildDependencies;
+
+  buildFlags = [ "module" ];
+  installTargets = [ "module-install" ];
+
+  meta = with stdenv.lib; {
+    inherit (wireguard-tools.meta) homepage license maintainers;
+    description = "Kernel module for the WireGuard secure network tunnel";
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/wireless-tools/default.nix b/nixpkgs/pkgs/os-specific/linux/wireless-tools/default.nix
new file mode 100644
index 000000000000..687bb7647cf8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/wireless-tools/default.nix
@@ -0,0 +1,24 @@
+{stdenv, fetchurl}:
+
+stdenv.mkDerivation rec {
+  pname = "wireless-tools";
+  version = "30.pre9";
+
+  src = fetchurl {
+    url = "http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.${version}.tar.gz";
+    sha256 = "0qscyd44jmhs4k32ggp107hlym1pcyjzihiai48xs7xzib4wbndb";
+  };
+
+  makeFlags = [
+    "PREFIX=${placeholder "out"}"
+    "CC:=$(CC)"
+    "AR:=$(AR)"
+    "RANLIB:=$(RANLIB)"
+    "LDCONFIG=:"
+  ];
+
+  meta = {
+    platforms = stdenv.lib.platforms.linux;
+    license = stdenv.lib.licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/wpa_supplicant/default.nix b/nixpkgs/pkgs/os-specific/linux/wpa_supplicant/default.nix
new file mode 100644
index 000000000000..8b8c23739c22
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/wpa_supplicant/default.nix
@@ -0,0 +1,112 @@
+{ stdenv, fetchpatch, fetchurl, openssl, pkgconfig, libnl
+, dbus, readline ? null, pcsclite ? null
+}:
+
+with stdenv.lib;
+stdenv.mkDerivation rec {
+  version = "2.7";
+
+  name = "wpa_supplicant-${version}";
+
+  src = fetchurl {
+    url = "https://w1.fi/releases/${name}.tar.gz";
+    sha256 = "0x1hqyahq44jyla8jl6791nnwrgicrhidadikrnqxsm2nw36pskn";
+  };
+
+  # TODO: Patch epoll so that the dbus actually responds
+  # TODO: Figure out how to get privsep working, currently getting SIGBUS
+  extraConfig = ''
+    CONFIG_AP=y
+    CONFIG_LIBNL32=y
+    CONFIG_EAP_FAST=y
+    CONFIG_EAP_PWD=y
+    CONFIG_EAP_PAX=y
+    CONFIG_EAP_SAKE=y
+    CONFIG_EAP_GPSK=y
+    CONFIG_EAP_GPSK_SHA256=y
+    CONFIG_WPS=y
+    CONFIG_WPS_ER=y
+    CONFIG_WPS_NFS=y
+    CONFIG_EAP_IKEV2=y
+    CONFIG_EAP_EKE=y
+    CONFIG_HT_OVERRIDES=y
+    CONFIG_VHT_OVERRIDES=y
+    CONFIG_ELOOP=eloop
+    #CONFIG_ELOOP_EPOLL=y
+    CONFIG_L2_PACKET=linux
+    CONFIG_IEEE80211W=y
+    CONFIG_TLS=openssl
+    CONFIG_TLSV11=y
+    #CONFIG_TLSV12=y see #8332
+    CONFIG_IEEE80211R=y
+    CONFIG_DEBUG_SYSLOG=y
+    #CONFIG_PRIVSEP=y
+    CONFIG_IEEE80211N=y
+    CONFIG_IEEE80211AC=y
+    CONFIG_INTERNETWORKING=y
+    CONFIG_HS20=y
+    CONFIG_P2P=y
+    CONFIG_TDLS=y
+    CONFIG_BGSCAN_SIMPLE=y
+  '' + optionalString (pcsclite != null) ''
+    CONFIG_EAP_SIM=y
+    CONFIG_EAP_AKA=y
+    CONFIG_EAP_AKA_PRIME=y
+    CONFIG_PCSC=y
+  '' + optionalString (dbus != null) ''
+    CONFIG_CTRL_IFACE_DBUS=y
+    CONFIG_CTRL_IFACE_DBUS_NEW=y
+    CONFIG_CTRL_IFACE_DBUS_INTRO=y
+  '' + (if readline != null then ''
+    CONFIG_READLINE=y
+  '' else ''
+    CONFIG_WPA_CLI_EDIT=y
+  '');
+
+  preBuild = ''
+    for manpage in wpa_supplicant/doc/docbook/wpa_supplicant.conf* ; do
+      substituteInPlace "$manpage" --replace /usr/share/doc $out/share/doc
+    done
+    cd wpa_supplicant
+    cp -v defconfig .config
+    echo "$extraConfig" >> .config
+    cat -n .config
+    substituteInPlace Makefile --replace /usr/local $out
+    export NIX_CFLAGS_COMPILE="$NIX_CFLAGS_COMPILE \
+      -I$(echo "${stdenv.lib.getDev libnl}"/include/libnl*/) \
+      -I${stdenv.lib.getDev pcsclite}/include/PCSC/"
+  '';
+
+  buildInputs = [ openssl libnl dbus readline pcsclite ];
+
+  nativeBuildInputs = [ pkgconfig ];
+
+  patches = [
+    (fetchpatch {
+      name = "build-fix.patch";
+      url = "https://gitweb.gentoo.org/repo/gentoo.git/plain/net-wireless/wpa_supplicant/files/wpa_supplicant-2.7-fix-undefined-remove-ie.patch?id=e0288112138a70a8acc3ae0196772fd7ccb677ce";
+      sha256 = "0ysazfcyn195mvkb1v10mgzzmpmqgv5kwqxwzfbsfhzq5bbaihld";
+    })
+  ];
+
+  postInstall = ''
+    mkdir -p $out/share/man/man5 $out/share/man/man8
+    cp -v "doc/docbook/"*.5 $out/share/man/man5/
+    cp -v "doc/docbook/"*.8 $out/share/man/man8/
+    mkdir -p $out/etc/dbus-1/system.d $out/share/dbus-1/system-services $out/etc/systemd/system
+    cp -v "dbus/"*service $out/share/dbus-1/system-services
+    sed -e "s@/sbin/wpa_supplicant@$out&@" -i "$out/share/dbus-1/system-services/"*
+    cp -v dbus/dbus-wpa_supplicant.conf $out/etc/dbus-1/system.d
+    cp -v "systemd/"*.service $out/etc/systemd/system
+    rm $out/share/man/man8/wpa_priv.8
+    install -Dm444 wpa_supplicant.conf $out/share/doc/wpa_supplicant/wpa_supplicant.conf.example
+  '';
+
+  meta = with stdenv.lib; {
+    homepage = http://hostap.epitest.fi/wpa_supplicant/;
+    description = "A tool for connecting to WPA and WPA2-protected wireless networks";
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ marcweber ];
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/wpa_supplicant/gui.nix b/nixpkgs/pkgs/os-specific/linux/wpa_supplicant/gui.nix
new file mode 100644
index 000000000000..891de61c0170
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/wpa_supplicant/gui.nix
@@ -0,0 +1,32 @@
+{ stdenv, qtbase, qmake, inkscape, imagemagick, wpa_supplicant }:
+
+stdenv.mkDerivation {
+  name = "wpa_gui-${wpa_supplicant.version}";
+
+  inherit (wpa_supplicant) src;
+
+  buildInputs = [ qtbase ];
+  nativeBuildInputs = [ qmake inkscape imagemagick ];
+
+  prePatch = ''
+    cd wpa_supplicant/wpa_gui-qt4
+  '';
+
+  postBuild = ''
+    make -C icons
+  '';
+
+  postInstall = ''
+    mkdir -pv $out/{bin,share/applications,share/icons}
+    cp -v wpa_gui $out/bin
+    cp -v wpa_gui.desktop $out/share/applications
+    cp -av icons/hicolor $out/share/icons
+  '';
+
+  meta = with stdenv.lib; {
+    description = "Qt-based GUI for wpa_supplicant";
+    homepage = http://hostap.epitest.fi/wpa_supplicant/;
+    license = licenses.bsd3;
+    platforms = platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/x86_energy_perf_policy/default.nix b/nixpkgs/pkgs/os-specific/linux/x86_energy_perf_policy/default.nix
new file mode 100644
index 000000000000..b4997714ceaf
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/x86_energy_perf_policy/default.nix
@@ -0,0 +1,25 @@
+{ stdenv, kernel }:
+
+stdenv.mkDerivation {
+  name = "x86_energy_perf_policy-${kernel.version}";
+
+  src = kernel.src;
+
+  postPatch = ''
+    cd tools/power/x86/x86_energy_perf_policy
+    sed -i 's,/usr,,g' Makefile
+  '';
+
+  preInstall = ''
+    mkdir -p $out/bin $out/share/man/man8
+  '';
+
+  makeFlags = [ "DESTDIR=$(out)" ];
+
+  meta = with stdenv.lib; {
+    description = "Set the energy versus performance policy preference bias on recent X86 processors";
+    homepage = https://www.kernel.org/;
+    license = licenses.gpl2;
+    platforms = [ "i686-linux" "x86_64-linux" ]; # x86-specific
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/x86info/default.nix b/nixpkgs/pkgs/os-specific/linux/x86info/default.nix
new file mode 100644
index 000000000000..7911a2172ba0
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/x86info/default.nix
@@ -0,0 +1,40 @@
+{stdenv, fetchurl, pciutils, python}:
+
+stdenv.mkDerivation rec {
+  version = "1.30";
+  name = "x86info-${version}";
+
+  src = fetchurl {
+    url = "http://codemonkey.org.uk/projects/x86info/${name}.tgz";
+    sha256 = "0a4lzka46nabpsrg3n7akwr46q38f96zfszd73xcback1s2hjc7y";
+  };
+
+  preConfigure = ''
+    patchShebangs .
+
+    # ignore warnings
+    sed -i 's/-Werror -Wall//' Makefile
+  '';
+
+  buildInputs = [ pciutils python ];
+
+  installPhase = ''
+    mkdir -p $out/bin
+    cp x86info lsmsr $out/bin
+  '';
+
+  meta = {
+    description = "Identification utility for the x86 series of processors";
+    longDescription =
+    ''
+      x86info will identify all Intel/AMD/Centaur/Cyrix/VIA CPUs. It leverages
+      the cpuid kernel module where possible.  it supports parsing model specific
+      registers (MSRs) via the msr kernel module.  it will approximate processor
+      frequency, and identify the cache sizes and layout. 
+    '';
+    platforms = [ "i686-linux" "x86_64-linux" ];
+    license = stdenv.lib.licenses.gpl2;
+    homepage = http://codemonkey.org.uk/projects/x86info/;
+    maintainers = with stdenv.lib.maintainers; [jcumming];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/xf86-input-mtrack/default.nix b/nixpkgs/pkgs/os-specific/linux/xf86-input-mtrack/default.nix
new file mode 100644
index 000000000000..2897e9200fd7
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/xf86-input-mtrack/default.nix
@@ -0,0 +1,42 @@
+{
+  stdenv
+, fetchurl
+, utilmacros
+, pkgconfig
+, mtdev
+, xorgserver
+, xorgproto
+, pixman
+, autoreconfHook
+}:
+
+stdenv.mkDerivation {
+  name = "xf86-input-mtrack-0.3.0";
+
+  buildInputs = [
+    utilmacros
+    pkgconfig
+    mtdev
+    xorgserver
+    xorgproto
+    pixman
+    autoreconfHook
+  ];
+
+  CFLAGS = "-I${pixman}/include/pixman-1";
+
+  src = fetchurl {
+    name = "xf86-input-mtrack.tar.gz";
+    url = "https://github.com/BlueDragonX/xf86-input-mtrack/tarball/v0.3.0";
+    sha256 = "174rdw7gv0wsnjgmwpx4pgjn1zfbylflda4k2dzff6phzxj9yl6v";
+  };
+
+  meta = {
+    homepage = https://github.com/BlueDragonX/xf86-input-mtrack;
+
+    description = "An Xorg driver for multitouch trackpads";
+
+    license = stdenv.lib.licenses.gpl2;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/xf86-input-multitouch/default.nix b/nixpkgs/pkgs/os-specific/linux/xf86-input-multitouch/default.nix
new file mode 100644
index 000000000000..71242348f681
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/xf86-input-multitouch/default.nix
@@ -0,0 +1,48 @@
+{ stdenv
+, fetchgit
+, mtdev
+, pixman
+, xorg
+, libpciaccess
+}:
+
+stdenv.mkDerivation {
+  name = "xf86-input-multitouch-20110312";
+
+  src = fetchgit {
+    url = http://bitmath.org/git/multitouch.git;
+    rev = "4d87c041f6a232aa30528d70d4b9946d1824b4ed";
+    sha256 = "1jh52d3lkmchn5xdbz4qn50d30nild1zxvfbvwwl2rbmphs5ww6y";
+  };
+
+  # Configuration from http://bitmath.org/code/multitouch/
+  confFile = ''
+    Section "InputClass"
+        MatchIsTouchpad "true"
+        Identifier "Multitouch Touchpad"
+        Driver "multitouch"
+    EndSection
+  '';
+
+  buildInputs = with xorg; [
+    mtdev xorgproto libpciaccess libxcb
+  ];
+
+  buildPhase = ''
+    make INCLUDE="$NIX_CFLAGS_COMPILE -I${xorg.xorgserver.dev}/include/xorg -I${pixman}/include/pixman-1 -Iinclude"
+  '';
+
+  installPhase = ''
+    make DESTDIR="$out" LIBDIR="lib" install
+    mkdir -p $out/include/xorg
+    echo -n "$confFile" > $out/include/xorg/10-multitouch.conf
+  '';
+
+  meta = {
+    homepage = http://bitmath.org/code/multitouch/;
+
+    description = "Brings multitouch gestures to the Linux desktop";
+
+    license = stdenv.lib.licenses.gpl2;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/xf86-input-wacom/default.nix b/nixpkgs/pkgs/os-specific/linux/xf86-input-wacom/default.nix
new file mode 100644
index 000000000000..ac095ffaf89b
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/xf86-input-wacom/default.nix
@@ -0,0 +1,31 @@
+{ stdenv, fetchurl
+, xorgproto, libX11, libXext, libXi, libXrandr, libXrender
+, ncurses, pkgconfig, xorgserver, udev, libXinerama, pixman }:
+
+stdenv.mkDerivation rec {
+  name = "xf86-input-wacom-0.36.0";
+
+  src = fetchurl {
+    url = "mirror://sourceforge/linuxwacom/${name}.tar.bz2";
+    sha256 = "1xi39hl8ddgj9m7m2k2ll2r3wh0k0aq45fvrsv43651bhz9cbrza";
+  };
+
+  buildInputs = [ xorgproto libX11 libXext libXi libXrandr libXrender
+    ncurses pkgconfig xorgserver udev libXinerama pixman ];
+
+  preConfigure = ''
+    mkdir -p $out/share/X11/xorg.conf.d
+    configureFlags="--with-xorg-module-dir=$out/lib/xorg/modules
+    --with-sdkdir=$out/include/xorg --with-xorg-conf-dir=$out/share/X11/xorg.conf.d"
+  '';
+
+  CFLAGS = "-I${pixman}/include/pixman-1";
+
+  meta = with stdenv.lib; {
+    maintainers = [ maintainers.goibhniu ];
+    description = "Wacom digitizer driver for X11";
+    homepage = http://linuxwacom.sourceforge.net;
+    license = licenses.gpl2;
+    platforms = platforms.linux; # Probably, works with other unices as well
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/xf86-video-nested/default.nix b/nixpkgs/pkgs/os-specific/linux/xf86-video-nested/default.nix
new file mode 100644
index 000000000000..14d2b249fc08
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/xf86-video-nested/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchgit, autoreconfHook, xorgproto, libX11, libXext
+, pixman, pkgconfig, utilmacros, xorgserver
+}:
+
+stdenv.mkDerivation {
+  name = "xf86-video-nested-2012-06-15";
+
+  src = fetchgit {
+    url = git://anongit.freedesktop.org/xorg/driver/xf86-video-nested;
+    rev = "ad48dc6eb98776a8a886f26f31c0110352fa1da4";
+    sha256 = "0r5k9rk8mq4j51a310qvvfmhhz8a0cmcwr8pl8mkwfsgcpwxbpfg";
+  };
+
+  buildInputs =
+    [ autoreconfHook xorgproto libX11 libXext pixman
+      pkgconfig utilmacros xorgserver
+    ];
+
+  hardeningDisable = [ "fortify" ];
+
+  CFLAGS = "-I${pixman}/include/pixman-1";
+
+  meta = {
+    homepage = https://cgit.freedesktop.org/xorg/driver/xf86-video-nested;
+    description = "A driver to run Xorg on top of Xorg or something else";
+    maintainers = [ stdenv.lib.maintainers.goibhniu ];
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/xsensors/default.nix b/nixpkgs/pkgs/os-specific/linux/xsensors/default.nix
new file mode 100644
index 000000000000..5f7bca097bf6
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/xsensors/default.nix
@@ -0,0 +1,23 @@
+{ stdenv, lib, fetchurl, gtk2, pkgconfig, lm_sensors }:
+
+stdenv.mkDerivation rec {
+  name = "xsensors-${version}";
+  version = "0.70";
+  src = fetchurl {
+    url = "http://www.linuxhardware.org/xsensors/xsensors-${version}.tar.gz";
+    sha256 = "1siplsfgvcxamyqf44h71jx6jdfmvhfm7mh0y1q8ps4zs6pj2zwh";
+  };
+  nativeBuildInputs = [ pkgconfig ];
+  buildInputs = [
+    gtk2 lm_sensors
+  ];
+  patches = [
+    ./remove-unused-variables.patch
+    ./replace-deprecated-gtk.patch
+  ];
+  meta = with lib; {
+    license = licenses.gpl2;
+    platforms = platforms.linux;
+    maintainers = with maintainers; [ cstrahan ];
+  };
+}
diff --git a/nixpkgs/pkgs/os-specific/linux/xsensors/remove-unused-variables.patch b/nixpkgs/pkgs/os-specific/linux/xsensors/remove-unused-variables.patch
new file mode 100644
index 000000000000..7da97a0e56e8
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/xsensors/remove-unused-variables.patch
@@ -0,0 +1,39 @@
+Author: Nanley Chery <nanleychery@gmail.com>
+From: Jean Delvare <khali@linux-fr.org>
+Subject: Remove declared, but unused variables
+Bug-Debian: http://bugs.debian.org/625435
+---
+--- a/src/gui.c
++++ b/src/gui.c
+@@ -257,10 +257,9 @@
+ 
+ /* Start the sensor info update timer. */
+ gint start_timer( GtkWidget *widget, gpointer data ) {
+-    gint timer;
+ 
+     /* Setup timer for updates. */
+-    timer = g_timeout_add( update_time * 1000, 
++    g_timeout_add( update_time * 1000,
+                              (GtkFunction) update_sensor_data, 
+ 			     (gpointer) data );
+ 
+@@ -287,7 +286,7 @@
+ 
+     /* feature data */
+     updates *head = NULL;
+-    updates *current = NULL, *prev = NULL;
++    updates *current = NULL;
+ 
+     const sensors_feature *feature;
+ 
+@@ -347,10 +346,8 @@
+             new_node->pbar = featpbar;
+ 
+             if ( head == NULL ) {
+-                prev = head;
+                 head = current = new_node;
+             } else {
+-                prev = current;
+                 current = current->next = new_node;
+             }
+ 
diff --git a/nixpkgs/pkgs/os-specific/linux/xsensors/replace-deprecated-gtk.patch b/nixpkgs/pkgs/os-specific/linux/xsensors/replace-deprecated-gtk.patch
new file mode 100644
index 000000000000..fed4c7dc4c95
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/xsensors/replace-deprecated-gtk.patch
@@ -0,0 +1,168 @@
+Author: Nanley Chery <nanleychery@gmail.com>
+Subject: Update deprecated gtk casts and replace deprecated function calls with their analogous cairo counterparts.
+Bug-Debian: http://bugs.debian.org/622005
+Bug-Debian: http://bugs.debian.org/610321
+---
+--- a/src/gui.c
++++ b/src/gui.c
+@@ -27,10 +27,10 @@
+ GtkWidget *mainwindow = NULL;
+ 
+ GdkColor colorWhite = { 0, 0xFFFF, 0xFFFF, 0xFFFF };
+-    
+-GdkColormap *cmap = NULL;
+ 
+-GdkPixmap *theme = NULL;
++GdkPixbuf *theme = NULL;
++
++cairo_surface_t *surface = NULL;
+ 
+ /* Destroy the main window. */
+ gint destroy_gui( GtkWidget *widget, gpointer data ) {
+@@ -76,17 +76,16 @@
+     }
+ }
+ 
+-static void draw_digits( GtkWidget *widget, const gchar *digits, int highLow )
++static void draw_digits( GtkWidget *widget, cairo_t *cr, const gchar *digits, int highLow )
+ {
+     const gchar *digit = digits;
+     int pos = 0, x = 0, y = 0, w = 0;
+ 
+     while ( *digit ) {
+         get_pm_location( *digit, &x, &y, &w );
+-        gdk_draw_drawable( widget->window,
+-                           widget->style->fg_gc[ GTK_WIDGET_STATE
+-                           (widget) ], theme, x, y + highLow,
+-                           pos, 0, w, 30 );
++        cairo_set_source_surface (cr, surface, pos-x, 0-(y + highLow));
++		cairo_rectangle(cr, pos, 0, w, 30);
++		cairo_fill(cr);
+         pos += w;
+         digit++;
+     }
+@@ -102,6 +101,8 @@
+ 
+     gchar result[7];
+ 
++    cairo_t *cr = gdk_cairo_create(widget->window);
++
+ #ifdef DEBUG_XSENSORS
+     printf( "area.width = %d, area.height = %d\n", event->area.width,
+             event->area.height );
+@@ -117,13 +118,11 @@
+ 
+             /* Display the digits */
+             if ( g_snprintf( result, 6, "%5.0f", current->curvalue ) >= 0 )
+-               draw_digits( widget, result, highLow );
++               draw_digits( widget, cr, result, highLow );
+ 
+             /* Display RPM */
+-            gdk_draw_drawable( widget->window, 
+-                               widget->style->fg_gc[ GTK_WIDGET_STATE 
+-                               (widget) ], theme, 0, 120 + highLow, 
+-                               90, 0, 57, 30 );
++            cairo_set_source_surface (cr, surface, 90-0, 0-(120 + highLow));
++     	    cairo_rectangle(cr, 90, 0, 57, 30);
+             break;
+         case TEMP:
+             if ( current->curvalue > current->curmax )
+@@ -134,17 +133,15 @@
+ 
+             /* Display the digits */
+             if ( g_snprintf( result, 7, "%6.1f", current->curvalue ) >= 0 )
+-               draw_digits( widget, result, highLow );
++               draw_digits( widget, cr, result, highLow );
+ 
+             /* Display degree symbol */
+             if ( tf == FALSE )
+                 x = 0;
+             else
+                 x = 57;
+-            gdk_draw_drawable( widget->window, 
+-                             widget->style->fg_gc[ GTK_WIDGET_STATE 
+-                             (widget) ], theme, x, 60 + highLow, 
+-                             96, 0, 57, 30 );
++            cairo_set_source_surface (cr, surface, 96-x, 0-(60 + highLow));
++     	    cairo_rectangle(cr, 96, 0, 57, 30);
+             
+             break;
+         case VOLT:
+@@ -154,20 +151,17 @@
+             
+             /* Display the digits */
+             if ( g_snprintf( result, 7, "%6.2f", current->curvalue ) >= 0 )
+-               draw_digits( widget, result, highLow );
++               draw_digits( widget, cr, result, highLow );
+ 
+             /* Display V */
+-            gdk_draw_drawable( widget->window, 
+-                             widget->style->fg_gc[ GTK_WIDGET_STATE 
+-                             (widget) ], theme, 114, 60 + highLow, 
+-                             96, 0, 57, 30 );
+-
+-
++            cairo_set_source_surface (cr, surface, 96-114, 0-(60 + highLow));
++     	    cairo_rectangle(cr, 96, 0, 57, 30);
+             break;
+         default:
+             break;
+     }
+-            
++    cairo_fill(cr);
++    cairo_destroy(cr);
+     return TRUE;
+ }
+ 
+@@ -260,7 +254,7 @@
+ 
+     /* Setup timer for updates. */
+     g_timeout_add( update_time * 1000,
+-                             (GtkFunction) update_sensor_data, 
++                             (GSourceFunc) update_sensor_data,
+ 			     (gpointer) data );
+ 
+     return SUCCESS;
+@@ -460,8 +454,6 @@
+     g_signal_connect( G_OBJECT (mainwindow), "delete_event",
+                       G_CALLBACK (destroy_gui), NULL );
+ 
+-    /* Graphics needed for drawing info. */
+-    cmap = gtk_widget_get_colormap( mainwindow );
+ 
+     /* Set up the image file used for displaying characters. */
+     if ( imagefile == NULL ) {
+@@ -481,12 +473,10 @@
+                        "Image file not found in either location!  Exiting!\n" );
+                 exit( 1 );
+             } else {
+-                theme = gdk_pixmap_colormap_create_from_xpm( NULL, cmap,
+-                        NULL, NULL, "./images/default.xpm" );
++                theme = gdk_pixbuf_new_from_file("./images/default.xpm", NULL );
+             }
+         } else {
+-            theme = gdk_pixmap_colormap_create_from_xpm( NULL, cmap,
+-                    NULL, NULL, imagefile );
++            theme = gdk_pixbuf_new_from_file(imagefile, NULL );
+         }
+     } else {
+         if ( stat( imagefile, &sbuf ) != 0 ) {
+@@ -495,11 +485,15 @@
+                     "Image file not found in specified location!  Exiting!\n" );
+             exit( 1 );
+         } else {
+-            theme = gdk_pixmap_colormap_create_from_xpm( NULL, cmap,
+-                    NULL, NULL, imagefile );
++            theme = gdk_pixbuf_new_from_file(imagefile, NULL );
+         }
+     }
+-    
++    surface = cairo_image_surface_create_for_data(gdk_pixbuf_get_pixels(theme),
++                                        CAIRO_FORMAT_RGB24,
++										gdk_pixbuf_get_width(theme),
++										gdk_pixbuf_get_height(theme),
++										gdk_pixbuf_get_rowstride(theme));
++
+     /* Create notebook for sensors. */
+     notebook = gtk_notebook_new( );
+     gtk_widget_modify_bg( notebook, GTK_STATE_NORMAL, &colorWhite );
diff --git a/nixpkgs/pkgs/os-specific/linux/zfs/default.nix b/nixpkgs/pkgs/os-specific/linux/zfs/default.nix
new file mode 100644
index 000000000000..28a4836bf00e
--- /dev/null
+++ b/nixpkgs/pkgs/os-specific/linux/zfs/default.nix
@@ -0,0 +1,200 @@
+{ stdenv, fetchFromGitHub, autoreconfHook, utillinux, nukeReferences, coreutils
+, perl, fetchpatch
+, configFile ? "all"
+
+# Userspace dependencies
+, zlib, libuuid, python3, attr, openssl
+, libtirpc
+, nfs-utils
+, gawk, gnugrep, gnused, systemd
+
+# Kernel dependencies
+, kernel ? null, spl ? null
+}:
+
+with stdenv.lib;
+let
+  buildKernel = any (n: n == configFile) [ "kernel" "all" ];
+  buildUser = any (n: n == configFile) [ "user" "all" ];
+
+  common = { version
+    , sha256
+    , extraPatches
+    , spl
+    , rev ? "zfs-${version}"
+    , isUnstable ? false
+    , isLegacyCrypto ? false
+    , incompatibleKernelVersion ? null }:
+    if buildKernel &&
+      (incompatibleKernelVersion != null) &&
+        versionAtLeast kernel.version incompatibleKernelVersion then
+       throw ''
+         Linux v${kernel.version} is not yet supported by zfsonlinux v${version}.
+         ${stdenv.lib.optionalString (!isUnstable) "Try zfsUnstable or set the NixOS option boot.zfs.enableUnstable."}
+       ''
+    else stdenv.mkDerivation rec {
+      name = "zfs-${configFile}-${version}${optionalString buildKernel "-${kernel.version}"}";
+
+      src = fetchFromGitHub {
+        owner = "zfsonlinux";
+        repo = "zfs";
+        inherit rev sha256;
+      };
+
+      patches = extraPatches;
+
+      postPatch = optionalString buildKernel ''
+        patchShebangs scripts
+      '' + optionalString stdenv.hostPlatform.isMusl ''
+        substituteInPlace config/user-libtirpc.m4 \
+          --replace /usr/include/tirpc ${libtirpc}/include/tirpc
+      '';
+
+      nativeBuildInputs = [ autoreconfHook nukeReferences ]
+        ++ optional buildKernel (kernel.moduleBuildDependencies ++ [ perl ]);
+      buildInputs =
+           optionals buildKernel [ spl ]
+        ++ optionals buildUser [ zlib libuuid python3 attr ]
+        ++ optionals (buildUser && (isUnstable || isLegacyCrypto)) [ openssl ]
+        ++ optional stdenv.hostPlatform.isMusl [ libtirpc ];
+
+      # for zdb to get the rpath to libgcc_s, needed for pthread_cancel to work
+      NIX_CFLAGS_LINK = "-lgcc_s";
+
+      hardeningDisable = [ "fortify" "stackprotector" "pic" ];
+
+      preConfigure = ''
+        substituteInPlace ./module/zfs/zfs_ctldir.c   --replace "umount -t zfs"           "${utillinux}/bin/umount -t zfs"
+        substituteInPlace ./module/zfs/zfs_ctldir.c   --replace "mount -t zfs"            "${utillinux}/bin/mount -t zfs"
+        substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/umount"             "${utillinux}/bin/umount"
+        substituteInPlace ./lib/libzfs/libzfs_mount.c --replace "/bin/mount"              "${utillinux}/bin/mount"
+        substituteInPlace ./lib/libshare/nfs.c        --replace "/usr/sbin/exportfs"      "${nfs-utils}/bin/exportfs"
+        substituteInPlace ./cmd/ztest/ztest.c         --replace "/usr/sbin/ztest"         "$out/sbin/ztest"
+        substituteInPlace ./cmd/ztest/ztest.c         --replace "/usr/sbin/zdb"           "$out/sbin/zdb"
+        substituteInPlace ./config/user-systemd.m4    --replace "/usr/lib/modules-load.d" "$out/etc/modules-load.d"
+        substituteInPlace ./config/zfs-build.m4       --replace "\$sysconfdir/init.d"     "$out/etc/init.d"
+        substituteInPlace ./etc/zfs/Makefile.am       --replace "\$(sysconfdir)"          "$out/etc"
+        substituteInPlace ./cmd/zed/Makefile.am       --replace "\$(sysconfdir)"          "$out/etc"
+        substituteInPlace ./module/Makefile.in        --replace "/bin/cp"                 "cp"
+        substituteInPlace ./etc/systemd/system/zfs-share.service.in \
+          --replace "/bin/rm " "${coreutils}/bin/rm "
+
+        for f in ./udev/rules.d/*
+        do
+          substituteInPlace "$f" --replace "/lib/udev/vdev_id" "$out/lib/udev/vdev_id"
+        done
+        substituteInPlace ./cmd/vdev_id/vdev_id \
+          --replace "PATH=/bin:/sbin:/usr/bin:/usr/sbin" \
+          "PATH=${makeBinPath [ coreutils gawk gnused gnugrep systemd ]}"
+
+        ./autogen.sh
+        configureFlagsArray+=("--libexecdir=$out/libexec")
+      '';
+
+      configureFlags = [
+        "--with-config=${configFile}"
+        "--with-python=${python3.interpreter}"
+      ] ++ optionals buildUser [
+        "--with-dracutdir=$(out)/lib/dracut"
+        "--with-udevdir=$(out)/lib/udev"
+        "--with-systemdunitdir=$(out)/etc/systemd/system"
+        "--with-systemdpresetdir=$(out)/etc/systemd/system-preset"
+        "--with-systemdgeneratordir=$(out)/lib/systemd/system-generator"
+        "--with-mounthelperdir=$(out)/bin"
+        "--sysconfdir=/etc"
+        "--localstatedir=/var"
+        "--enable-systemd"
+      ] ++ optionals buildKernel [
+        "--with-linux=${kernel.dev}/lib/modules/${kernel.modDirVersion}/source"
+        "--with-linux-obj=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build"
+      ] ++ optionals (buildKernel && spl != null) [
+        "--with-spl=${spl}/libexec/spl"
+      ];
+
+      enableParallelBuilding = true;
+
+      installFlags = [
+        "sysconfdir=\${out}/etc"
+        "DEFAULT_INITCONF_DIR=\${out}/default"
+      ];
+
+      postInstall = ''
+        # Prevent kernel modules from depending on the Linux -dev output.
+        nuke-refs $(find $out -name "*.ko")
+      '' + optionalString buildUser ''
+        # Remove provided services as they are buggy
+        rm $out/etc/systemd/system/zfs-import-*.service
+
+        sed -i '/zfs-import-scan.service/d' $out/etc/systemd/system/*
+
+        for i in $out/etc/systemd/system/*; do
+        substituteInPlace $i --replace "zfs-import-cache.service" "zfs-import.target"
+        done
+
+        # Fix pkgconfig.
+        ln -s ../share/pkgconfig $out/lib/pkgconfig
+
+        # Remove tests because they add a runtime dependency on gcc
+        rm -rf $out/share/zfs/zfs-tests
+      '';
+
+      outputs = [ "out" ] ++ optionals buildUser [ "lib" "dev" ];
+
+      meta = {
+        description = "ZFS Filesystem Linux Kernel module";
+        longDescription = ''
+          ZFS is a filesystem that combines a logical volume manager with a
+          Copy-On-Write filesystem with data integrity detection and repair,
+          snapshotting, cloning, block devices, deduplication, and more.
+        '';
+        homepage = http://zfsonlinux.org/;
+        license = licenses.cddl;
+        platforms = platforms.linux;
+        maintainers = with maintainers; [ jcumming wizeman fpletz globin ];
+      };
+    };
+in {
+  # also check if kernel version constraints in
+  # ./nixos/modules/tasks/filesystems/zfs.nix needs
+  # to be adapted
+  zfsStable = common {
+    # comment/uncomment if breaking kernel versions are known
+    # incompatibleKernelVersion = "4.20";
+
+    # this package should point to the latest release.
+    version = "0.7.13";
+
+    sha256 = "1l77bq7pvc54vl15pnrjd0njgpf00qjzy0x85dpfh5jxng84x1fb";
+
+    extraPatches = [
+      # in case this gets out of date, just send Mic92 a pull request!
+      (fetchpatch {
+        url = "https://github.com/Mic92/zfs/commit/cf23c1d38bfc698a8a729fc0c5f9ca41591f4d95.patch";
+        sha256 = "14v3x9ipvg2qd1vyf70nv909jd5zdxlsw5y8k60pfyvwm7g80wr5";
+      })
+    ];
+
+    inherit spl;
+  };
+
+  zfsUnstable = common rec {
+    # comment/uncomment if breaking kernel versions are known
+    # incompatibleKernelVersion = "4.19";
+
+    # this package should point to a version / git revision compatible with the latest kernel release
+    version = "0.8.0-rc3";
+
+    sha256 = "0wmkis0q2gbj7sgx3ipxngbgzjcf7ay353v3mglf2ay50q4da5i7";
+    isUnstable = true;
+
+    extraPatches = [
+      # in case this gets out of date, just send Mic92 a pull request!
+      (fetchpatch {
+        url = "https://github.com/Mic92/zfs/commit/bc29b5783da0af2c80c85126a1831ce1d52bfb69.patch";
+        sha256 = "1sdcr1w2jp3djpwlf1f91hrxxmc34q0jl388smdkxh5n5bpw5gzw";
+      })
+    ];
+
+    spl = null;
+  };
+}