2022-01-25 10:47:31 +03:00
|
|
|
# First draft of this flake include a large amount of cruft to be compatible
|
|
|
|
# with both pre and post Nix 2.6 APIs.
|
|
|
|
#
|
|
|
|
# The expected state is to support bundlers of the form:
|
|
|
|
# bundlers.<system>.<name> = drv: some-drv;
|
|
|
|
|
2021-10-31 21:15:16 +03:00
|
|
|
{
|
2022-01-25 06:39:21 +03:00
|
|
|
description = "Example bundlers";
|
2021-10-31 21:15:16 +03:00
|
|
|
|
|
|
|
inputs.nix-utils.url = "github:juliosueiras-nix/nix-utils";
|
2022-01-25 06:39:21 +03:00
|
|
|
inputs.nix-bundle.url = "github:matthewbauer/nix-bundle";
|
2021-10-31 21:15:16 +03:00
|
|
|
|
2022-01-25 06:39:21 +03:00
|
|
|
outputs = { self, nixpkgs, nix-bundle, nix-utils }: let
|
|
|
|
# System types to support.
|
|
|
|
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
|
2021-10-31 21:15:16 +03:00
|
|
|
|
2022-01-25 06:39:21 +03:00
|
|
|
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
|
|
|
|
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
2021-10-31 21:15:16 +03:00
|
|
|
|
2022-01-25 06:39:21 +03:00
|
|
|
# Nixpkgs instantiated for supported system types.
|
|
|
|
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
|
2021-10-31 21:15:16 +03:00
|
|
|
|
2022-01-25 10:47:31 +03:00
|
|
|
# Backwards compatibility helper for pre Nix2.6 bundler API
|
2022-12-28 23:02:26 +03:00
|
|
|
program = p: with builtins; with (protect p); "${outPath}/bin/${
|
2022-01-25 10:47:31 +03:00
|
|
|
if p?meta && p.meta?mainProgram then
|
2022-01-25 06:39:21 +03:00
|
|
|
meta.mainProgram
|
2022-01-25 10:47:31 +03:00
|
|
|
else (parseDrvName (unsafeDiscardStringContext p.name)).name
|
2022-01-25 06:39:21 +03:00
|
|
|
}";
|
2022-12-28 23:02:26 +03:00
|
|
|
|
|
|
|
protect = drv: if drv?outPath then drv else throw "provided installable is not a derivation and not coercible to an outPath";
|
2022-01-25 06:39:21 +03:00
|
|
|
in {
|
2022-06-17 13:57:48 +03:00
|
|
|
defaultBundler = builtins.listToAttrs (map (system: {
|
|
|
|
name = system;
|
2022-12-28 23:02:26 +03:00
|
|
|
value = drv: self.bundlers.${system}.toArx (protect drv);
|
2022-06-17 13:57:48 +03:00
|
|
|
}) supportedSystems)
|
|
|
|
# Backwards compatibility helper for pre Nix2.6 bundler API
|
|
|
|
// {__functor = s: nix-bundle.bundlers.nix-bundle;};
|
2022-01-25 06:39:21 +03:00
|
|
|
|
2022-01-25 10:47:31 +03:00
|
|
|
bundlers = let n =
|
|
|
|
(forAllSystems (system: {
|
|
|
|
# Backwards compatibility helper for pre Nix2.6 bundler API
|
|
|
|
toArx = drv: (nix-bundle.bundlers.nix-bundle ({
|
|
|
|
program = if drv?program then drv.program else (program drv);
|
|
|
|
inherit system;
|
|
|
|
})) // (if drv?program then {} else {name=
|
|
|
|
(builtins.parseDrvName drv.name).name;});
|
2022-01-25 06:39:21 +03:00
|
|
|
|
|
|
|
toRPM = drv: nix-utils.bundlers.rpm {inherit system; program=program drv;};
|
|
|
|
|
|
|
|
toDEB = drv: nix-utils.bundlers.deb {inherit system; program=program drv;};
|
|
|
|
|
2022-01-25 10:47:31 +03:00
|
|
|
toDockerImage = {...}@drv:
|
|
|
|
(nixpkgs.legacyPackages.${system}.dockerTools.buildLayeredImage {
|
2022-12-28 21:54:28 +03:00
|
|
|
name = drv.name or drv.pname or "image";
|
2022-01-25 06:39:21 +03:00
|
|
|
tag = "latest";
|
2022-12-28 23:02:26 +03:00
|
|
|
contents = if drv?outPath then drv else throw "provided installable is not a derivation and not coercible to an outPath";
|
2022-01-25 10:47:31 +03:00
|
|
|
});
|
2021-10-31 21:15:16 +03:00
|
|
|
|
2022-01-25 06:39:21 +03:00
|
|
|
toBuildDerivation = drv:
|
2022-02-08 10:20:04 +03:00
|
|
|
(import ./report/default.nix {
|
2022-12-28 23:02:26 +03:00
|
|
|
drv = protect drv;
|
2022-01-25 06:39:21 +03:00
|
|
|
pkgs = nixpkgsFor.${system};}).buildtimeDerivations;
|
|
|
|
|
|
|
|
toReport = drv:
|
2022-02-08 10:20:04 +03:00
|
|
|
(import ./report/default.nix {
|
2022-12-28 23:02:26 +03:00
|
|
|
drv = protect drv;
|
2022-01-25 06:39:21 +03:00
|
|
|
pkgs = nixpkgsFor.${system};}).runtimeReport;
|
|
|
|
|
|
|
|
identity = drv: drv;
|
2022-01-25 10:47:31 +03:00
|
|
|
}
|
|
|
|
));
|
|
|
|
in with builtins;
|
|
|
|
# Backwards compatibility helper for pre Nix2.6 bundler API
|
|
|
|
listToAttrs (map
|
|
|
|
(name: {
|
|
|
|
inherit name;
|
2022-02-04 16:39:14 +03:00
|
|
|
value = builtins.trace "The bundler API has been updated to require the form `bundlers.<system>.<name>`. The previous API will be deprecated in Nix 2.7. See `https://github.com/NixOS/nix/pull/5456/`"
|
|
|
|
({system,program}@drv: self.bundlers.${system}.${name}
|
2022-01-25 10:47:31 +03:00
|
|
|
(drv // {
|
|
|
|
name = baseNameOf drv.program;
|
|
|
|
outPath = dirOf (dirOf drv.program);
|
2022-02-04 16:39:14 +03:00
|
|
|
}));
|
2022-01-25 10:47:31 +03:00
|
|
|
})
|
|
|
|
(attrNames n.x86_64-linux))
|
|
|
|
//
|
|
|
|
n;
|
2022-01-25 06:39:21 +03:00
|
|
|
};
|
2021-10-31 21:15:16 +03:00
|
|
|
}
|