-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathflake.nix
162 lines (137 loc) · 3.89 KB
/
flake.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
neovim-flake.url = "github:jordanisaacs/neovim-flake";
};
outputs = {
self,
nixpkgs,
neovim-flake,
}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
# Flake options
enableBPF = true;
enableRust = true;
enableEditor = true;
enableGdb = true;
useRustForLinux = false;
buildLib = pkgs.callPackage ./build {};
linuxConfigs = pkgs.callPackage ./configs/kernel.nix {inherit enableBPF enableRust useRustForLinux enableGdb;};
inherit (linuxConfigs) kernelArgs kernelConfig;
# Config file derivation
configfile = buildLib.buildKernelConfig {
inherit
(kernelConfig)
generateConfigFlags
structuredExtraConfig
enableRust
;
inherit kernel nixpkgs;
};
# Kernel derivation
kernelDrv = buildLib.buildKernel {
inherit
(kernelArgs)
src
modDirVersion
version
enableRust
enableGdb
kernelPatches
;
inherit configfile nixpkgs;
};
linuxDev = pkgs.linuxPackagesFor kernelDrv;
kernel = linuxDev.kernel;
buildRustModule = buildLib.buildRustModule {inherit kernel;};
buildCModule = buildLib.buildCModule {inherit kernel;};
modules = [cModule] ++ pkgs.lib.optional enableRust rustModule;
initramfs = buildLib.buildInitramfs {
inherit kernel modules;
extraBin =
{
strace = "${pkgs.strace}/bin/strace";
}
// pkgs.lib.optionalAttrs enableBPF {
stackcount = "${pkgs.bcc}/bin/stackcount";
};
storePaths = [pkgs.foot.terminfo] ++ pkgs.lib.optionals enableBPF [pkgs.bcc pkgs.python3];
};
runQemu = buildLib.buildQemuCmd {inherit kernel initramfs enableGdb;};
runGdb = buildLib.buildGdbCmd {inherit kernel modules;};
neovimPkg =
(neovim-flake.lib.neovimConfiguration {
inherit pkgs;
modules = [
(pkgs.callPackage ./configs/editor.nix {inherit enableRust;})
];
})
.neovim;
cModule = buildCModule {
name = "helloworld";
src = ./modules/helloworld;
};
rustModule = buildRustModule {
name = "rust-out-of-tree";
src =
if useRustForLinux
then ./modules/rfl_rust
else ./modules/rust;
};
ebpf-stacktrace = pkgs.stdenv.mkDerivation {
name = "ebpf-stacktrace";
src = ./ebpf/ebpf_stacktrace;
installPhase = ''
runHook preInstall
mkdir $out
cp ./helloworld $out/
cp ./helloworld_dbg $out/
cp runit.sh $out/
runHook postInstall
'';
meta.platforms = ["x86_64-linux"];
};
genRustAnalyzer =
pkgs.writers.writePython3Bin
"generate-rust-analyzer"
{}
(builtins.readFile ./scripts/generate_rust_analyzer.py);
devShell = let
nativeBuildInputs = with pkgs;
[
bear # for compile_commands.json, use bear -- make
runQemu
git
gdb
qemu
pahole
# static analysis
flawfinder
cppcheck
sparse
rustc
]
++ lib.optional enableGdb runGdb
++ lib.optional enableEditor neovimPkg
++ lib.optionals enableRust [cargo rustfmt genRustAnalyzer];
buildInputs = [pkgs.nukeReferences kernel.dev];
in
pkgs.mkShell {
inherit buildInputs nativeBuildInputs;
KERNEL = kernel.dev;
KERNEL_VERSION = kernel.modDirVersion;
RUST_LIB_SRC = pkgs.rustPlatform.rustLibSrc;
};
in {
lib = {
builders = import ./build/default.nix;
};
packages.${system} = {
inherit initramfs kernel cModule ebpf-stacktrace rustModule genRustAnalyzer;
kernelConfig = configfile;
};
devShells.${system}.default = devShell;
};
}