Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions pkgs/os-specific/linux/kernel/common-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ with stdenv.lib;

# Bump the maximum number of CPUs to support systems like EC2 x1.*
# instances and Xeon Phi.
${optionalString (stdenv.system == "x86_64-linux" || stdenv.system == "aarch64-linux") ''
${optionalString (stdenv.hostPlatform.system == "x86_64-linux" || stdenv.hostPlatform.system == "aarch64-linux") ''
NR_CPUS 384
''}

Expand Down Expand Up @@ -347,11 +347,12 @@ with stdenv.lib;
SECURITY_SELINUX_BOOTPARAM_VALUE 0 # Disable SELinux by default
SECURITY_YAMA? y # Prevent processes from ptracing non-children processes
DEVKMEM n # Disable /dev/kmem
${if versionOlder version "3.14" then ''
CC_STACKPROTECTOR? y # Detect buffer overflows on the stack
'' else ''
CC_STACKPROTECTOR_REGULAR? y
''}
${optionalString (! stdenv.hostPlatform.isArm)
(if versionOlder version "3.14" then ''
CC_STACKPROTECTOR? y # Detect buffer overflows on the stack
'' else ''
CC_STACKPROTECTOR_REGULAR? y
'')}
${optionalString (versionAtLeast version "3.12") ''
USER_NS y # Support for user namespaces
''}
Expand Down
63 changes: 16 additions & 47 deletions pkgs/os-specific/linux/kernel/generic.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, perl, buildLinux
{ stdenv, buildPackages, perl, buildLinux

, # The kernel source tarball.
src
Expand All @@ -23,7 +23,8 @@
# symbolic name and `patch' is the actual patch. The patch may
# optionally be compressed with gzip or bzip2.
kernelPatches ? []
, ignoreConfigErrors ? stdenv.platform.name != "pc"
, ignoreConfigErrors ? hostPlatform.platform.name != "pc" ||
hostPlatform != stdenv.buildPlatform
, extraMeta ? {}
, hostPlatform
, ...
Expand All @@ -43,14 +44,12 @@ let
netfilterRPFilter = true;
} // features) kernelPatches;

configWithPlatform = kernelPlatform: import ./common-config.nix {
inherit stdenv version kernelPlatform extraConfig;
config = import ./common-config.nix {
inherit stdenv version extraConfig;
kernelPlatform = hostPlatform;
features = kernelFeatures; # Ensure we know of all extra patches, etc.
};

config = configWithPlatform stdenv.platform;
configCross = configWithPlatform hostPlatform.platform;

kernelConfigFun = baseConfig:
let
configFromPatches =
Expand All @@ -65,31 +64,15 @@ let

kernelConfig = kernelConfigFun config;

depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ perl ];

platformName = stdenv.platform.name;
kernelBaseConfig = stdenv.platform.kernelBaseConfig;
kernelTarget = stdenv.platform.kernelTarget;
autoModules = stdenv.platform.kernelAutoModules;
preferBuiltin = stdenv.platform.kernelPreferBuiltin or false;
arch = stdenv.platform.kernelArch;

crossAttrs = let
cp = hostPlatform.platform;
in {
arch = cp.kernelArch;
platformName = cp.name;
kernelBaseConfig = cp.kernelBaseConfig;
kernelTarget = cp.kernelTarget;
autoModules = cp.kernelAutoModules;

# Just ignore all options that don't apply (We are lazy).
ignoreConfigErrors = true;

kernelConfig = kernelConfigFun configCross;

inherit (kernel.crossDrv) src patches preUnpack;
};
platformName = hostPlatform.platform.name;
kernelBaseConfig = hostPlatform.platform.kernelBaseConfig;
kernelTarget = hostPlatform.platform.kernelTarget;
autoModules = hostPlatform.platform.kernelAutoModules;
preferBuiltin = hostPlatform.platform.kernelPreferBuiltin or false;
arch = hostPlatform.platform.kernelArch;

prePatch = kernel.prePatch + ''
# Patch kconfig to print "###" after every question so that
Expand All @@ -103,7 +86,7 @@ let
cd $buildRoot

# Get a basic config file for later refinement with $generateConfig.
make -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch
make HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc -C ../$sourceRoot O=$PWD $kernelBaseConfig ARCH=$arch

# Create the config file.
echo "generating kernel configuration..."
Expand All @@ -118,28 +101,14 @@ let
};

kernel = buildLinux {
inherit version modDirVersion src kernelPatches stdenv extraMeta;

configfile = configfile.nativeDrv or configfile;

crossConfigfile = configfile.crossDrv or configfile;
inherit version modDirVersion src kernelPatches stdenv extraMeta configfile;

config = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };

crossConfig = { CONFIG_MODULES = "y"; CONFIG_FW_LOADER = "m"; };
};

passthru = {
features = kernelFeatures;
passthru = kernel.passthru // (removeAttrs passthru [ "passthru" ]);
};

addPassthru' = lib.extendDerivation true passthru;

nativeDrv = addPassthru' kernel.nativeDrv;

crossDrv = addPassthru' kernel.crossDrv;

in if kernel ? crossDrv
then nativeDrv // { inherit nativeDrv crossDrv; }
else addPassthru' kernel
in lib.extendDerivation true passthru kernel
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-4.13.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:

import ./generic.nix (args // rec {
version = "4.13.16";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-4.14.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:

with stdenv.lib;

Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-4.4.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:

import ./generic.nix (args // rec {
version = "4.4.111";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-4.9.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, ... } @ args:

import ./generic.nix (args // rec {
version = "4.9.76";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-beagleboard.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:

let
modDirVersion = "4.9.61";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:

with stdenv.lib;

Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-mptcp.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:

import ./generic.nix (rec {
mptcpVersion = "0.93";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-rpi.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ... } @ args:

let
modDirVersion = "4.9.59";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-samus-4.12.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchFromGitHub, perl, buildLinux, ncurses, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchFromGitHub, perl, buildLinux, ncurses, ... } @ args:

import ./generic.nix (args // rec {
version = "4.12.2";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-testing-bcachefs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchgit, perl, buildLinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchgit, perl, buildLinux, ... } @ args:

import ./generic.nix (args // rec {
version = "4.11.2017.08.23";
Expand Down
2 changes: 1 addition & 1 deletion pkgs/os-specific/linux/kernel/linux-testing.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ stdenv, hostPlatform, fetchurl, perl, buildLinux, libelf, utillinux, ... } @ args:
{ stdenv, buildPackages, hostPlatform, fetchurl, perl, buildLinux, libelf, utillinux, ... } @ args:

import ./generic.nix (args // rec {
version = "4.15-rc8";
Expand Down
48 changes: 16 additions & 32 deletions pkgs/os-specific/linux/kernel/manual-config.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ runCommand, nettools, bc, perl, gmp, libmpc, mpfr, kmod, openssl
, libelf ? null
, utillinux ? null
{ buildPackages, runCommand, nettools, bc, perl, gmp, libmpc, mpfr, openssl
, libelf
, utillinux
, writeTextFile, ubootTools
, hostPlatform
}:
Expand All @@ -26,19 +26,11 @@ in {
src,
# Any patches
kernelPatches ? [],
# Patches for native compiling only
nativeKernelPatches ? [],
# Patches for cross compiling only
crossKernelPatches ? [],
# The native kernel .config file
# The kernel .config file
configfile,
# The cross kernel .config file
crossConfigfile ? configfile,
# Manually specified nixexpr representing the config
# If unspecified, this will be autodetected from the .config
config ? stdenv.lib.optionalAttrs allowImportFromDerivation (readConfig configfile),
# Cross-compiling config
crossConfig ? if allowImportFromDerivation then (readConfig crossConfigfile) else config,
# Use defaultMeta // extraMeta
extraMeta ? {},
# Whether to utilize the controversial import-from-derivation feature to parse the config
Expand All @@ -61,8 +53,8 @@ let

commonMakeFlags = [
"O=$(buildRoot)"
] ++ stdenv.lib.optionals (stdenv.platform ? kernelMakeFlags)
stdenv.platform.kernelMakeFlags;
] ++ stdenv.lib.optionals (hostPlatform.platform ? kernelMakeFlags)
hostPlatform.platform.kernelMakeFlags;

drvAttrs = config_: platform: kernelPatches: configfile:
let
Expand Down Expand Up @@ -105,7 +97,7 @@ let
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|= ${kmod}/bin/depmod|'
sed -i Makefile -e 's|= depmod|= ${buildPackages.kmod}/bin/depmod|'
'';

configurePhase = ''
Expand Down Expand Up @@ -211,7 +203,7 @@ let
find -empty -type d -delete

# Remove reference to kmod
sed -i Makefile -e 's|= ${kmod}/bin/depmod|= depmod|'
sed -i Makefile -e 's|= ${buildPackages.kmod}/bin/depmod|= depmod|'
'' else optionalString installsFirmware ''
make firmware_install $makeFlags "''${makeFlagsArray[@]}" \
$installFlags "''${installFlagsArray[@]}"
Expand Down Expand Up @@ -239,34 +231,26 @@ in

assert stdenv.lib.versionAtLeast version "4.14" -> libelf != null;
assert stdenv.lib.versionAtLeast version "4.15" -> utillinux != null;
stdenv.mkDerivation ((drvAttrs config stdenv.platform (kernelPatches ++ nativeKernelPatches) configfile) // {
stdenv.mkDerivation ((drvAttrs config hostPlatform.platform kernelPatches configfile) // {
name = "linux-${version}";

enableParallelBuilding = true;

depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ perl bc nettools openssl gmp libmpc mpfr ]
++ optional (stdenv.platform.kernelTarget == "uImage") ubootTools
++ optional (stdenv.hostPlatform.platform.kernelTarget == "uImage") buildPackages.ubootTools
++ optional (stdenv.lib.versionAtLeast version "4.14") libelf
++ optional (stdenv.lib.versionAtLeast version "4.15") utillinux
;

hardeningDisable = [ "bindnow" "format" "fortify" "stackprotector" "pic" ];

makeFlags = commonMakeFlags ++ [
"ARCH=${stdenv.platform.kernelArch}"
"HOSTCC=${buildPackages.stdenv.cc.targetPrefix}gcc"
"ARCH=${stdenv.hostPlatform.platform.kernelArch}"
] ++ stdenv.lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) [
"CROSS_COMPILE=${stdenv.cc.targetPrefix}"
];

karch = stdenv.platform.kernelArch;

crossAttrs = let cp = hostPlatform.platform; in
(drvAttrs crossConfig cp (kernelPatches ++ crossKernelPatches) crossConfigfile) // {
makeFlags = commonMakeFlags ++ [
"ARCH=${cp.kernelArch}"
"CROSS_COMPILE=$(crossConfig)-"
];

karch = cp.kernelArch;

nativeBuildInputs = optional (cp.kernelTarget == "uImage") ubootTools;
};
karch = hostPlatform.platform.kernelArch;
})
18 changes: 4 additions & 14 deletions pkgs/os-specific/linux/kernel/perf.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ lib, stdenv, kernel, elfutils, python, perl, newt, slang, asciidoc, xmlto, makeWrapper
, docbook_xsl, docbook_xml_dtd_45, libxslt, flex, bison, pkgconfig, libunwind, binutils
, libiberty, libaudit
, libiberty, libaudit, libbfd
, zlib, withGtk ? false, gtk2 ? null }:

with lib;
Expand All @@ -11,7 +11,7 @@ assert versionAtLeast kernel.version "3.12";
stdenv.mkDerivation {
name = "perf-linux-${kernel.version}";

inherit (kernel) src;
inherit (kernel) src makeFlags;

preConfigure = ''
cd tools/perf
Expand All @@ -21,10 +21,9 @@ stdenv.mkDerivation {
'';

# perf refers both to newt and slang
# binutils is required for libbfd.
nativeBuildInputs = [ asciidoc xmlto docbook_xsl docbook_xml_dtd_45 libxslt
flex bison libiberty libaudit makeWrapper pkgconfig ];
buildInputs = [ elfutils python perl newt slang libunwind binutils zlib ] ++
flex bison libiberty libaudit makeWrapper pkgconfig python perl ];
buildInputs = [ elfutils newt slang libunwind libbfd zlib ] ++
stdenv.lib.optional withGtk gtk2;

# Note: we don't add elfutils to buildInputs, since it provides a
Expand All @@ -47,15 +46,6 @@ stdenv.mkDerivation {
--prefix PATH : "${binutils}/bin"
'';

crossAttrs = {
/* I don't want cross-python or cross-perl -
I don't know if cross-python even works */
propagatedBuildInputs = [ elfutils.crossDrv newt.crossDrv ];
makeFlags = "CROSS_COMPILE=${stdenv.cc.targetPrefix}";
elfutils = elfutils.crossDrv;
inherit (kernel.crossDrv) src patches;
};

meta = {
homepage = https://perf.wiki.kernel.org/;
description = "Linux tools to profile with performance counters";
Expand Down