Refactor arch package building a bit, to make it easier to test

This commit is contained in:
Brian Picciano 2024-11-03 15:23:43 +01:00
parent 6ac473edcb
commit 932c8e2244
5 changed files with 60 additions and 47 deletions

View File

@ -65,7 +65,7 @@ in rec {
''; '';
}; };
vendorHash = "sha256-R+8uCjWnWCDG7WLuSnjKnVfZwYSbjKqMPqJfMnnj6G0="; vendorHash = "sha256-xAm2DqgXpZEErjASSZQoEH9GPwFbBh4h2cY4FWzPVZM=";
subPackages = [ subPackages = [
"./cmd/entrypoint" "./cmd/entrypoint"
@ -118,41 +118,9 @@ in rec {
''; '';
}; };
appimagetool = pkgs.callPackage ./nix/appimagetool.nix {};
appImage = pkgs.stdenv.mkDerivation {
name = "isle-AppImage";
src = appDir;
nativeBuildInputs = [
appimagetool
];
ARCH = pkgs.stdenv.hostPlatform.parsed.cpu.name;
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
cp -rL "$src" isle.AppDir
chmod +w isle.AppDir -R
export VERSION=debug
# https://github.com/probonopd/go-appimage/issues/155
unset SOURCE_DATE_EPOCH
appimagetool ./isle.AppDir
mv Isle-* "$out"
'';
};
appImageBin = pkgs.runCommand "isle-AppImage-bin" {} ''
mkdir -p "$out"/bin
cp ${appImage} "$out"/bin/isle
'';
tests = pkgs.writeScript "isle-tests" '' tests = pkgs.writeScript "isle-tests" ''
export PATH=${pkgs.lib.makeBinPath [ export PATH=${pkgs.lib.makeBinPath [
appImageBin build.appImage
pkgs.busybox pkgs.busybox
pkgs.yq-go pkgs.yq-go
pkgs.jq pkgs.jq
@ -181,4 +149,37 @@ in rec {
pkgs.go pkgs.go
]; ];
}; };
build = rec {
appImage = pkgs.stdenv.mkDerivation {
name = "isle-AppImage";
src = appDir;
nativeBuildInputs = [
(pkgsNative.callPackage ./nix/appimagetool.nix {})
];
ARCH = pkgs.stdenv.hostPlatform.parsed.cpu.name;
builder = builtins.toFile "build.sh" ''
source $stdenv/setup
cp -rL "$src" isle.AppDir
chmod +w isle.AppDir -R
export VERSION=debug
# https://github.com/probonopd/go-appimage/issues/155
unset SOURCE_DATE_EPOCH
appimagetool ./isle.AppDir
mkdir -p "$out"/bin
mv Isle-* "$out"/bin/isle
'';
};
archPkg = ((import ./dist/linux/arch) {
inherit hostSystem releaseName appImage;
pkgs = pkgsNative;
});
};
} }

View File

@ -1,6 +1,5 @@
{ {
pkgs, pkgs,
buildSystem,
hostSystem, hostSystem,
releaseName, releaseName,
appImage, appImage,
@ -70,7 +69,7 @@ in
cp $pkgbuild PKGBUILD cp $pkgbuild PKGBUILD
tar -cf src.tar.zst --zstd --mode=a+rX,u+w -C root . tar -cf src.tar.zst --zstd --mode=a+rX,u+w -C root .
cp "$src" isle cp "$src"/bin/isle isle
PKGEXT=".pkg.tar.zst" CARCH="${cpuArch}" makepkg \ PKGEXT=".pkg.tar.zst" CARCH="${cpuArch}" makepkg \
--nodeps \ --nodeps \

View File

@ -18,7 +18,7 @@ You can build an AppImage for your current system by running the following from
the project's root: the project's root:
``` ```
nix-build -A appImageBin nix-build -A build.appImage
``` ```
The resulting binary can be found under `result/bin`. The resulting binary can be found under `result/bin`.
@ -28,7 +28,20 @@ The resulting binary can be found under `result/bin`.
An AppImage can be cross-compiled by passing the `hostSystem` argument: An AppImage can be cross-compiled by passing the `hostSystem` argument:
``` ```
nix-build --argstr hostSystem "x86_64-linux" -A appImageBin nix-build --argstr hostSystem "x86_64-linux" -A build.appImage
``` ```
Supported system strings are enumerated in `nix/pkgs.nix`. Supported system strings are enumerated in `nix/pkgs.nix`.
## Alternative Build Targets
Besides AppImage, Isle supports building alternative package types which are
targetted at different specific operating systems. Each of these has its own
`build.*` target.
* AppImage (all OSs): `nix-build -A build.appImage`
* Arch Linux package: `nix-build -A build.archPkg`
All targets theoretically support passing in a `hostSystem` argument to
cross-compile to a different architecture or OS, but some targets may not make
sense with some `hostSystem` values.

View File

@ -1,3 +1,5 @@
# TODO this is currently broken, garage is using builtins.currentSystem for some
# reason.
{ {
description = "isle provides the foundation for an autonomous community cloud infrastructure"; description = "isle provides the foundation for an autonomous community cloud infrastructure";
@ -16,7 +18,7 @@
}; };
in in
defaultAttrs.appImage defaultAttrs.build.appImage
); );
pkgsForBuildSystem = (buildSystem: { pkgsForBuildSystem = (buildSystem: {

View File

@ -12,24 +12,22 @@
mkRelease = hostSystem: let mkRelease = hostSystem: let
appImage = ((import ./default.nix) { build = ((import ./default.nix) {
inherit buildSystem hostSystem releaseName revision; inherit buildSystem hostSystem releaseName revision;
}).appImage; }).build;
archPkg = ((import ./dist/linux/arch) {
inherit pkgs buildSystem hostSystem releaseName appImage;
});
in pkgs.stdenv.mkDerivation { in pkgs.stdenv.mkDerivation {
name = "isle-release-${hostSystem}"; name = "isle-release-${hostSystem}";
inherit releaseName hostSystem; inherit releaseName hostSystem;
inherit appImage archPkg;
appImage = build.appImage;
archPkg = build.archPkg;
builder = builtins.toFile "build.sh" '' builder = builtins.toFile "build.sh" ''
source $stdenv/setup source $stdenv/setup
mkdir -p "$out"/ mkdir -p "$out"/
cp "$appImage" "$out"/isle-$releaseName-$hostSystem.AppImage cp "$appImage"/bin/isle "$out"/isle-$releaseName-$hostSystem.AppImage
cp "$archPkg"/*.tar.zst "$out"/isle-$releaseName-$hostSystem.pkg.tar.zst cp "$archPkg"/*.tar.zst "$out"/isle-$releaseName-$hostSystem.pkg.tar.zst
''; '';
}; };