-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
130 lines (130 loc) · 3.27 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
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
{
name,
pkgs ? import <nixpkgs> { },
src,
buildroot ? (
builtins.fetchGit {
url = "https://gitlab.com/buildroot.org/buildroot.git";
ref = "2024.08";
rev = "769d71ae84c7a3d43ee92a1d126b2937713cc811";
}
),
defconfig,
lockfile,
nativeBuildInputs ? [ ],
extraHashes ? { },
}:
let
inherit (pkgs) stdenv;
makeFHSEnv = pkgs.buildFHSEnv {
name = "make-fhs";
runScript = "make";
targetPkgs =
pkgs:
with pkgs;
[
bc
cpio
file
perl
rsync
unzip
util-linux
wget
which
]
++ nativeBuildInputs;
};
buildDir = "/build/br";
buildrootMake = "${makeFHSEnv}/bin/make-fhs --silent BR2_EXTERNAL=$PWD O=${buildDir} -C ${buildroot}";
devShell = (makeFHSEnv.overrideAttrs { runScript = "bash"; }).env.overrideAttrs {
shellHook = ''
alias make="${buildrootMake}"
echo -e "The 'make' command is aliased to use relevant Buildroot flags.\nUse \\make to call the original make command."
'';
};
buildrootBase = {
inherit src;
configurePhase = ''
mkdir -p ${buildDir}
${buildrootMake} ${defconfig}
'';
hardeningDisable = [ "format" ];
};
lockedPackageInputs =
let
lockedInputs = builtins.fromJSON (builtins.readFile lockfile);
symlinkCommands = builtins.map (
file:
let
lockedAttrs = lockedInputs.${file};
input = pkgs.fetchurl {
name = file;
urls = lockedInputs.${file}.uris;
hash = "${lockedAttrs.algo}:${lockedAttrs.checksum}";
};
in
"ln -s ${input} $out/'${file}'"
) (builtins.attrNames lockedInputs);
in
stdenv.mkDerivation {
name = "${name}-sources";
dontUnpack = true;
dontConfigure = true;
buildPhase = "mkdir $out";
installPhase = pkgs.lib.concatStringsSep "\n" symlinkCommands;
};
extraHashesFile = (pkgs.formats.json { }).generate "hashes.json" extraHashes;
in
rec {
inherit devShell;
packageInputs = lockedPackageInputs;
packageInfo = stdenv.mkDerivation (
buildrootBase
// {
name = "${name}-packageinfo.json";
buildPhase = ''
${buildrootMake} show-info > packageinfo.json
'';
installPhase = ''
cp packageinfo.json $out
'';
}
);
lockFile = pkgs.stdenv.mkDerivation {
name = "${name}-buildroot.lock";
buildInputs = with pkgs; [ python3 ];
dontUnpack = true;
dontConfigure = true;
dontInstall = true;
buildPhase = ''
python3 ${./make-package-lock.py} --hashes ${extraHashesFile} --buildroot ${buildroot} --input ${packageInfo} --output $out
'';
};
build = stdenv.mkDerivation (
buildrootBase
// {
inherit name;
outputs = [
"out"
"sdk"
];
buildPhase = ''
export BR2_DL_DIR=/build/source/downloads
mkdir -p $BR2_DL_DIR
for lockedInput in ${lockedPackageInputs}/*; do
ln -s $lockedInput "$BR2_DL_DIR/$(basename $lockedInput)"
done
${buildrootMake}
${buildrootMake} sdk
'';
installPhase = ''
mkdir $out $sdk
cp -r output/images $out/
cp -r output/host $sdk
sh $sdk/host/relocate-sdk.sh
'';
dontFixup = true;
}
);
}