-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
116 lines (100 loc) · 3.83 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
{
inputs = {
# a better way of using the latest stable version of nixpkgs
# without specifying specific release
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz";
};
outputs = { self, nixpkgs, ... }:
let
# helpers for producing system-specific outputs
supportedSystems = [
"aarch64-linux"
"riscv64-linux"
"x86_64-linux"
];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f rec {
pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
linux_latest_with_llvm = prev.linux_latest.override {
stdenv = llvmPkgs.stdenv;
};
})
];
};
llvmPkgs = pkgs.llvmPackages;
# this gets the "major version" of LLVM, eg "16" or "17"
llvmVersion = builtins.elemAt (builtins.splitVersion llvmPkgs.clang.version) 0;
commonInputs = with pkgs; [
# for a better kernel developer workflow
b4
dt-schema
neovim
yamllint
# for "make menuconfig"
pkg-config
ncurses
# testing the built kernel in a VM using QEMU
debootstrap # fur creating ze rootfs
gdb
qemu_kvm
# extra utilities _I_ find useful
bat
broot
choose
fd
ripgrep
# formatting this flake
nixfmt
];
});
globalBuildFlags = {
# build related flags (for the script)
CLEAN_BUILD = 0;
INSTALL_ZE_KERNEL = 1;
};
in
{
devShells = forEachSupportedSystem ({ pkgs, commonInputs, llvmPkgs, llvmVersion, ... }: rec {
default = withLLVM;
#default = withGNU;
withLLVM = (pkgs.mkShell.override { stdenv = llvmPkgs.stdenv; }) {
inputsFrom = [ pkgs.linux_latest_with_llvm ];
packages = commonInputs
++ [ pkgs.rustup ]
# for some reason, `llvmPkgs.stdenv` does not have `lld` or actually `bintools`
++ [ llvmPkgs.bintools ];
# Disable '-fno-strict-overflow' compiler flag because it causes the build to fail with the following error:
# clang-16: error: argument unused during compilation: '-fno-strict-overflow' [-Werror,-Wunused-command-line-argument]
hardeningDisable = [ "strictoverflow" ];
env = rec {
# just in case you want to disable building with the LLVM toolchain
# **DO NOT SET THIS TO '0'**
# **COMMENT IT OUT INSTEAD**
# because, for some reason, setting `LLVM` to '0' still counts... :/
LLVM = 1;
# build related flags (for the script)
BUILD_WITH_RUST = 1;
# needed by Rust bindgen
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ llvmPkgs.libclang.lib ];
# because `grep gcc "$(nix-store -r $(command -v clang))/nix-support/libcxx-cxxflags"` matches
# but `grep clang "$(nix-store -r $(command -v clang))/nix-support/libcxx-cxxflags"` **DOES NOT MATCH**
KCFLAGS = "-isystem ${LIBCLANG_PATH}/clang/${llvmVersion}/include";
} // globalBuildFlags;
# **ONLY UNCOMMENT THIS IF YOU ARE _NOT_ USING HOME-MANAGER AND GET LOCALE ERRORS/WARNINGS**
# If you are using home-manager, then add the following to your ~/.bashrc
# `source $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh`
#LOCALE_ARCHIVE_2_27 = "${pkgs.glibcLocales}/lib/locale/locale-archive";
};
withGNU = pkgs.mkShell {
inputsFrom = [ pkgs.linux_latest ];
packages = commonInputs;
env = {
# build related flags (for the script)
BUILD_WITH_RUST = 0;
} // globalBuildFlags;
};
});
};
}