-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
90 lines (71 loc) · 2 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
{ stdenv
, buildPackages
, lib
, writeText
, autokernel
, python3
# needed for kernels >=4.16
, bison ? null
, flex ? null
# needed for kernels >=5.2
, pahole ? null
}:
{ pname
, version
, src
, patches ? [ ]
, makeFlags ? [ ]
, baseConfig ? stdenv.hostPlatform.linux-kernel.baseConfig
, configOptions ? { }
, extraConfigOptions ? { }
}:
assert (lib.versionAtLeast version "4.16") -> (bison != null && flex != null);
assert (lib.versionAtLeast version "5.2") -> (pahole != null);
let
configOptions' =
if configOptions == { }
then import ./config.nix { inherit stdenv lib version; }
else configOptions;
configEval = lib.evalModules {
modules = [
(import ./module.nix)
{ settings = configOptions'; }
{ settings = extraConfigOptions; }
];
};
# FIXME: Respect baseConfig
autokernelScript = writeText "${pname}-${version}-autokernel.lua" (''
load_kconfig_unchecked(kernel_dir .. "/arch/x86/configs/x86_64_defconfig")
'' + configEval.config.autokernelConfig);
autokernelConfig = writeText "${pname}-${version}-autokernel.toml" ''
[config]
script = "${autokernelScript}"
'';
in
stdenv.mkDerivation {
pname = "${pname}-config";
inherit version src patches makeFlags;
depsBuildBuild = [ buildPackages.stdenv.cc ];
nativeBuildInputs = [ autokernel python3 ]
++ lib.optionals (lib.versionAtLeast version "4.16") [ bison flex ]
++ lib.optionals (lib.versionAtLeast version "5.2") [ pahole ];
dontConfigure = true;
enableParallelBuilding = true;
buildPhase = ''
runHook preBuild
export HOSTCC=$CC_FOR_BUILD
export HOSTCXX=$CXX_FOR_BUILD
export HOSTAR=$AR_FOR_BUILD
export HOSTLD=$LD_FOR_BUILD
export RUST_BACKTRACE=1
autokernel --kernel-dir "." --config "${autokernelConfig}" generate-config
runHook postBuild
'';
installPhase = ''
runHook preInstall
mv .config $out
runHook postInstall
'';
dontFixup = true;
passthru = { inherit baseConfig configOptions extraConfigOptions autokernelScript; };
}