-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
188 lines (161 loc) · 5.06 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
{
description = "A flake for the REX project";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs, ... }:
let
system = "x86_64-linux";
basePkgs = import nixpkgs {
inherit system;
};
remoteNixpkgsPatches = [
{
meta.description = "cc-wrapper: remove -nostdlibinc";
url = "https://github.com/chinrw/nixpkgs/commit/0016d524d02035187216a6df9fff1dbffadfa81b.patch";
sha256 = "sha256-kYTSw+8vByZcCHXfVeWqi0/XVNjo8YJSey03k/+uxvw=";
}
{
meta.description = "cc-wrapper: disable warn about cross-compile";
url = "https://github.com/chinrw/nixpkgs/commit/3a6374fce7c048a86e7ff56671b1dbc4974757a9.patch";
sha256 = "sha256-pxgls4+wn5wekkQH8etdoYV3mAY8omviZ/MOu9sekE8";
}
];
patchedNixpkgsSrc = basePkgs.applyPatches {
name = "nixpkgs-patched";
src = basePkgs.path;
patches = map basePkgs.fetchpatch remoteNixpkgsPatches;
};
patchedBindgen =
(self: super: {
rust-bindgen-unwrapped = super.rust-bindgen-unwrapped.overrideAttrs (finalAttrs: oldAttrs: {
src = super.fetchFromGitHub {
owner = "rust-lang";
repo = "rust-bindgen";
rev = "20aa65a0b9edfd5f8ab3e038197da5cb2c52ff18";
sha256 = "sha256-OrwPpXXfbkeS7SAmZDZDUXZV4BfSF3e/58LJjedY1vA=";
};
cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
inherit (finalAttrs) pname src version;
hash = finalAttrs.cargoHash;
};
cargoHash = "sha256-e94pwjeGOv/We6uryQedj7L41dhCUc2wzi/lmKYnEMA=";
});
});
patchedPkgs = import patchedNixpkgsSrc {
inherit system;
overlays = [ patchedBindgen ];
};
pkgs = import nixpkgs {
inherit system;
# overlays = [ overrideLLVM ];
};
wrapCC = cc: pkgs.wrapCCWith {
inherit cc;
extraBuildCommands = ''
# Remove the line that contains "-nostdlibinc"
sed -i 's|-nostdlibinc||g' "$out/nix-support/cc-cflags"
echo " -resource-dir=${pkgs.llvmPackages.clang}/resource-root" >> "$out/nix-support/cc-cflags"
echo > "$out/nix-support/add-local-cc-cflags-before.sh"
'';
};
# wrappedClang = wrapCC pkgs.llvmPackages.clang.cc;
# lib = nixpkgs.lib;
# Use unwrapped clang & lld to avoid warnings about multi-target usage
rexPackages = with pkgs; [
# Kernel builds
autoconf
bc
binutils
bison
cmake
diffutils
elfutils
elfutils.dev
fakeroot
findutils
flex
gcc
glibc.dev
getopt
gnumake
ncurses
openssl.dev
pahole
pkg-config
xz.dev
zlib
zlib.dev
ninja
patchedPkgs.rust-bindgen
pahole
strace
zstd
eza
perf-tools
# linuxKernel.packages.linux_latest.perf
# Clang kernel builds
patchedPkgs.llvmPackages.clang
# wrappedClang
# llvmPackages.libcxxStdenv
lld
mold
# llvmPackages.bintools
qemu
busybox
perf-tools
# for llvm/Demangle/Demangle.h
libllvm
libllvm.dev
libgcc
libclang.lib
libclang.dev
# meson deps
meson
curl
perl
bear # generate compile commands
rsync # for make headers_install
gdb
# bmc deps
iproute2
memcached
python3
zoxide # in case host is using zoxide
openssh # q-script ssh support
];
# (pkgs.buildFHSEnv.override { stdenv = pkgs.llvmPackages.stdenv; })
fhs = (pkgs.buildFHSEnv.override { stdenv = pkgs.llvmPackages.stdenv; })
{
name = "rex-env";
targetPkgs = pkgs: rexPackages;
runScript = "bash";
profile = ''
export LD_LIBRARY_PATH=${pkgs.libgcc.lib}/lib:$LD_LIBRARY_PATH
export NIX_ENFORCE_NO_NATIVE=0
export PATH=$(realpath "./build/rust-dist/bin"):$PATH
export RUST_BACKTRACE=1
'';
};
in
{
devShells."${system}" = {
default = fhs.env;
rex = pkgs.mkShell {
packages = rexPackages;
# Disable default hardening flags. These are very confusing when doing
# development and they break builds of packages/systems that don't
# expect these flags to be on. Automatically enables stuff like
# FORTIFY_SOURCE, -Werror=format-security, -fPIE, etc. See:
# - https://nixos.org/manual/nixpkgs/stable/#sec-hardening-in-nixpkgs
# - https://nixos.wiki/wiki/C#Hardening_flags
hardeningDisable = [ "all" ];
shellHook = ''
export LD_LIBRARY_PATH=${pkgs.libgcc.lib}/lib:$LD_LIBRARY_PATH
echo "loading rex env"
export NIX_ENFORCE_NO_NATIVE=0
'';
};
};
};
}