Add deb package building

This commit is contained in:
Brian Picciano 2024-12-20 12:49:01 +01:00
parent 86db5fb5ba
commit aa593ceae3
5 changed files with 106 additions and 21 deletions

View File

@ -168,5 +168,11 @@ in rec {
pkgs = pkgsNative; pkgs = pkgsNative;
appDir = appDir { systemRoot = "/"; }; appDir = appDir { systemRoot = "/"; };
}); });
debPkg = ((import ./dist/linux/deb) {
inherit hostSystem releaseName;
pkgs = pkgsNative;
appDir = appDir { systemRoot = "/"; };
});
}; };
} }

View File

@ -11,7 +11,7 @@
pkgname=isle pkgname=isle
pkgver=${builtins.replaceStrings ["-"] ["_"] releaseName} pkgver=${builtins.replaceStrings ["-"] ["_"] releaseName}
pkgrel=0 pkgrel=0
pkgdesc="The foundation for an autonomous community cloud infrastructure." pkgdesc="The foundation for an autonomous community cloud infrastructure"
arch=('${cpuArch}') arch=('${cpuArch}')
url="https://code.betamike.com/micropelago/isle" url="https://code.betamike.com/micropelago/isle"
license=('AGPL-3.0-or-later') license=('AGPL-3.0-or-later')
@ -25,6 +25,10 @@
} }
''; '';
linuxRoot = (import ../default.nix).buildRoot {
inherit pkgs appDir;
};
in in
pkgs.stdenv.mkDerivation { pkgs.stdenv.mkDerivation {
name = "isle-arch-pkg-${releaseName}-${cpuArch}"; name = "isle-arch-pkg-${releaseName}-${cpuArch}";
@ -37,30 +41,13 @@ in
]; ];
inherit pkgbuild; inherit pkgbuild;
src = appDir; src = linuxRoot;
defaultDaemonYml = ../../../go/daemon/daecommon/daemon.yml;
systemdService = ../isle.service;
dontUnpack = true; dontUnpack = true;
buildPhase = '' buildPhase = ''
cp -rL "$src" root tar -cf src.tar.zst --zstd --mode=a+rX,u+w -C "$src" .
chmod -R +w root
mkdir -p root/etc/isle/
cp "$defaultDaemonYml" root/etc/isle/daemon.yml
mkdir -p root/usr/lib/sysusers.d/
cat >root/usr/lib/sysusers.d/isle.conf <<EOF
u isle - "isle Daemon"
EOF
mkdir -p root/usr/lib/systemd/system
cp "$systemdService" root/usr/lib/systemd/system/isle.service
cp $pkgbuild PKGBUILD cp $pkgbuild PKGBUILD
tar -cf src.tar.zst --zstd --mode=a+rX,u+w -C root .
PKGEXT=".pkg.tar.zst" CARCH="${cpuArch}" makepkg \ PKGEXT=".pkg.tar.zst" CARCH="${cpuArch}" makepkg \
--nodeps \ --nodeps \
--config ${pkgs.pacman}/etc/makepkg.conf --config ${pkgs.pacman}/etc/makepkg.conf

72
dist/linux/deb/default.nix vendored Normal file
View File

@ -0,0 +1,72 @@
{
pkgs,
hostSystem,
releaseName,
appDir,
}: let
debArch = builtins.getAttr hostSystem {
"x86_64-linux" = "amd64";
"aarch64-linux" = "arm64";
"armv6l-linux" = "armhf";
"i686-linux" = "i386";
};
control = pkgs.writeTextDir "DEBIAN/control" ''
Package: isle
Version: ${releaseName}
Section: net
Priority: optional
Architecture: ${debArch}
Maintainer: Brian Picciano <me@mediocregopher.com>
Description: The foundation for an autonomous community cloud infrastructure
Homepage: https://code.betamike.com/micropelago/isle
'';
postinst = pkgs.writeTextDir "DEBIAN/postinst" ''
#!/bin/sh
systemctl daemon-reload
systemd-sysusers /usr/lib/sysusers.d/isle.conf
'';
postrm = pkgs.writeTextDir "DEBIAN/postrm" ''
#!/bin/sh
systemctl daemon-reload
'';
linuxRoot = (import ../default.nix).buildRoot {
inherit pkgs appDir;
};
root = pkgs.buildEnv {
name = "isle-deb-pkg-root";
paths = [
linuxRoot
control
postinst
postrm
];
};
in pkgs.stdenv.mkDerivation {
name = "isle-deb-pkg-${releaseName}-${debArch}";
nativeBuildInputs = [
pkgs.zstd
pkgs.dpkg
];
src = root;
buildPhase = ''
cp -rL "$src" root
chmod +w -R root
chmod +x root/DEBIAN/post*
dpkg-deb \
--root-owner-group \
-Z zstd \
-b root isle_${releaseName}_${debArch}.deb
'';
installPhase = ''
mkdir -p "$out"
cp *.deb "$out"
'';
}

18
dist/linux/default.nix vendored Normal file
View File

@ -0,0 +1,18 @@
{
buildRoot = { pkgs, appDir}: pkgs.runCommand "isle-linux-root" {} ''
mkdir -p "$out"
cp -r ${appDir}/usr "$out"/
chmod +w -R "$out"/usr
mkdir -p "$out"/etc/isle
cp "${../../go/daemon/daecommon/daemon.yml}" "$out"/etc/isle/daemon.yml
mkdir -p "$out"/usr/lib/sysusers.d/
cat >"$out"/usr/lib/sysusers.d/isle.conf <<EOF
u isle - "isle Daemon"
EOF
mkdir -p "$out"/usr/lib/systemd/system
cp "${./isle.service}" "$out"/usr/lib/systemd/system/isle.service
'';
}

View File

@ -22,13 +22,15 @@
appImage = build.appImage; appImage = build.appImage;
archPkg = build.archPkg; archPkg = build.archPkg;
debPkg = build.debPkg;
builder = builtins.toFile "build.sh" '' builder = builtins.toFile "build.sh" ''
source $stdenv/setup source $stdenv/setup
mkdir -p "$out"/ mkdir -p "$out"/
cp "$appImage"/bin/isle "$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"/* "$out"/
cp "$debPkg"/* "$out"/
''; '';
}; };