Skip to content

Commit

Permalink
Merge pull request #42 from pedorich-n/builder-improvements
Browse files Browse the repository at this point in the history
builder: Improve phases
  • Loading branch information
astro authored May 30, 2024
2 parents 51b0d65 + 55e5056 commit 05c3605
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ pkgs.stdenv.mkDerivation {
) allRequiredPackages
);
in ''
runHook preConfigure
${installPackages}
echo "src imagebuilder file:packages" > repositories.conf
Expand All @@ -98,6 +100,15 @@ pkgs.stdenv.mkDerivation {
ln -s $file $(basename $file)
done
fi
'' + lib.optionalString (files != null) ''
# copy files to avoid making etc read-only
cp -r --no-preserve=all ${files} files
'' + lib.optionalString (lib.versionOlder release "19") ''
# Hack around broken check for gcc
touch staging_dir/host/.prereq-build
'' + ''
runHook postConfigure
'';

nativeBuildInputs = with pkgs; [
Expand All @@ -106,28 +117,32 @@ pkgs.stdenv.mkDerivation {
bash perl python3 dtc
] ++ lib.optional (!lib.versionAtLeast release "21" && release != "snapshot") python2;

buildPhase = let
makeArgs = lib.concatStringsSep " " [
"-j$NIX_BUILD_CORES"
"DISABLED_SERVICES='${lib.concatStringsSep " " disabledServices}'"
"PACKAGES='${lib.concatStringsSep " " packages}'"
"PROFILE='${profile}'"
"SHELL='${pkgs.runtimeShell}'"
(lib.optionalString (files != null) "FILES='./files'")
(lib.optionalString (rootFsPartSize != null) "ROOTFS_PARTSIZE=${toString rootFsPartSize}")
(lib.optionalString (extraImageName != null) "EXTRA_IMAGE_NAME='${extraImageName}'")
];

in lib.optionalString (lib.versionOlder release "19") ''
# Hack around broken check for gcc
touch staging_dir/host/.prereq-build
'' + lib.optionalString (files != null) ''
# copy files to avoid making etc read-only
cp -r --no-preserve=all ${files} files
'' + ''
make image ${makeArgs}
'';

buildFlags = [
".DEFAULT_GOAL=image"
];

preBuild =
let
mkBuildFlagsArray = flags: lib.concatStringsSep " " (lib.mapAttrsToList (name: value: ''${name}="${builtins.toString value}"'') flags);

flags = {
PROFILE = profile;
PACKAGES = lib.concatStringsSep " " packages;
} // lib.optionalAttrs (disabledServices != [ ]) {
DISABLED_SERVICES = lib.concatStringsSep " " disabledServices;
} // lib.optionalAttrs (files != null) {
FILES = "./files";
} // lib.optionalAttrs (rootFsPartSize != null) {
ROOTFS_PARTSIZE = rootFsPartSize;
} // lib.optionalAttrs (extraImageName != null) {
EXTRA_IMAGE_NAME = extraImageName;
};
in
''
buildFlagsArray+=(${mkBuildFlagsArray flags})
'';

installPhase = ''
mkdir -p $out/nix-support
pushd bin/targets/${target}/${variant}
Expand Down

0 comments on commit 05c3605

Please sign in to comment.