[M7] flake: distribution bundles + non-NixOS wrapper

This commit is contained in:
2026-05-17 12:29:30 +00:00
parent 1f63984b60
commit fdf97861a4
3 changed files with 311 additions and 4 deletions

View File

@@ -4,18 +4,39 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
bundlers.url = "github:NixOS/bundlers";
bundlers.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, flake-utils }:
outputs = { self, nixpkgs, flake-utils, bundlers }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
# exec::run shells out to these at runtime; wrap the binary so
# they're reachable even outside a nix develop shell.
cargoxxRuntimePath = pkgs.lib.makeBinPath [
pkgs.nix
pkgs.cmake
pkgs.ninja
pkgs.curl
pkgs.git
];
# Defaults applied to the bundled `nix` so it works on hosts
# that don't already have nix set up (Arch/Debian/Fedora users
# who install our .pkg.tar.zst / .deb / .rpm). Multi-user mode
# would expect a `nixbld` group and a running daemon
cargoxxNixConfig = ''
experimental-features = nix-command flakes
build-users-group =
'';
cargoxx-bin = pkgs.gcc15Stdenv.mkDerivation {
pname = "cargoxx";
version = "0.1.0";
src = ./.;
nativeBuildInputs = [ pkgs.cmake pkgs.ninja ];
nativeBuildInputs = [ pkgs.cmake pkgs.ninja pkgs.makeWrapper ];
buildInputs = [ pkgs.sqlite pkgs.reproc pkgs.catch2_3 ];
configurePhase = ''
cmake -S build -B build/release -G Ninja \
@@ -27,6 +48,9 @@
installPhase = ''
mkdir -p $out/bin
cp build/release/cargoxx $out/bin/
wrapProgram $out/bin/cargoxx \
--prefix PATH : ${cargoxxRuntimePath} \
--set-default NIX_CONFIG ${pkgs.lib.escapeShellArg cargoxxNixConfig}
'';
hardeningDisable = [ "all" ];
};
@@ -103,8 +127,54 @@
'';
hardeningDisable = [ "all" ];
};
bundlers-sys = bundlers.bundlers.${system};
# Arch's pacman expects a tar.zst archive containing a
# `.PKGINFO` metadata file plus the file tree rooted at /.
# We ship the entire closure under /nix/store; /usr/bin/cargoxx
# is a symlink to the in-store wrapper.
toArchPkg = drv:
let
pname = drv.pname or drv.name;
version = drv.version or "0";
mainProgram = drv.meta.mainProgram or pname;
in pkgs.runCommand "${pname}-${version}-1-x86_64.pkg.tar.zst" {
nativeBuildInputs = [ pkgs.libarchive pkgs.coreutils ];
closureInfo = pkgs.closureInfo { rootPaths = [ drv ]; };
} ''
stage=$(mktemp -d)
mkdir -p $stage/nix/store $stage/usr/bin
for p in $(cat $closureInfo/store-paths); do
cp -a "$p" $stage/nix/store/
done
ln -s ${drv}/bin/${mainProgram} $stage/usr/bin/${mainProgram}
installed_size=$(du -sk $stage | cut -f1)
cat > $stage/.PKGINFO <<EOF
pkgname = ${pname}
pkgver = ${version}-1
pkgdesc = ${drv.meta.description or pname}
builddate = 0
packager = nix-build
size = $installed_size
arch = x86_64
EOF
( cd $stage && bsdtar --zstd -cf $out .PKGINFO nix usr )
'';
in {
packages.default = cargoxx-bin;
packages.appimage = bundlers-sys.toAppImage cargoxx-bin;
packages.dockerImage = bundlers-sys.toDockerImage cargoxx-bin;
packages.deb = bundlers-sys.toDEB cargoxx-bin;
packages.rpm = bundlers-sys.toRPM cargoxx-bin;
packages.archpkg = toArchPkg cargoxx-bin;
# Reusable packaging functions, all of the shape `drv -> drv`.
# Mirror the `to*` naming used by github:NixOS/bundlers.
lib.toAppImage = bundlers-sys.toAppImage;
lib.toDockerImage = bundlers-sys.toDockerImage;
lib.toDEB = bundlers-sys.toDEB;
lib.toRPM = bundlers-sys.toRPM;
lib.toArchPkg = toArchPkg;
lib.buildCppPackage = buildCppPackage;
devShells.default = pkgs.gcc15Stdenv.mkDerivation {
name = "cargoxx-dev";