Merge pull request #300 from Lykos153/feature/bundlers

Add option perSystem.<>.bundlers
This commit is contained in:
Robert Hensing 2025-08-05 21:05:37 +02:00 committed by GitHub
commit 8f8bb951b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 0 deletions

View file

@ -83,6 +83,18 @@ rec {
};
};
bundlersExample = mkFlake
{ inputs.self = { }; }
{
imports = [ flake-parts.flakeModules.bundlers ];
systems = [ "a" "b" ];
perSystem = { system, ... }: {
packages.hello = pkg system "hello";
bundlers.toTarball = drv: pkg system "tarball-${drv.name}";
bundlers.toAppImage = drv: pkg system "appimage-${drv.name}";
};
};
modulesFlake = mkFlake
{
inputs.self = { };
@ -251,6 +263,9 @@ rec {
};
};
assert bundlersExample.bundlers.a.toTarball (pkg "a" "hello") == pkg "a" "tarball-hello";
assert bundlersExample.bundlers.b.toAppImage (pkg "b" "hello") == pkg "b" "appimage-hello";
# - exported package becomes part of overlay.
# - perSystem is invoked for the right system, when system is non-memoized
assert nixpkgsWithEasyOverlay.hello == pkg "x86_64-linux" "hello";

28
extras/bundlers.nix Normal file
View file

@ -0,0 +1,28 @@
{ lib
, flake-parts-lib
, ...
}:
let
inherit
(lib)
mkOption
types
;
inherit
(flake-parts-lib)
mkTransposedPerSystemModule
;
in
mkTransposedPerSystemModule {
name = "bundlers";
option = mkOption {
type = types.lazyAttrsOf (types.functionTo types.package);
default = { };
description = ''
An attribute set of bundlers to be used by [`nix bundle`](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-bundle.html).
`nix bundle --bundler .#<name>` <derivation> will bundle <derivation> using the bundler `bundlers.<name>`.
'';
};
file = ./bundlers.nix;
}

View file

@ -50,6 +50,7 @@
flakeModules = ./extras/flakeModules.nix;
modules = ./extras/modules.nix;
partitions = ./extras/partitions.nix;
bundlers = ./extras/bundlers.nix;
};
in
lib.mkFlake { inherit inputs; } {