feat: internal namespacing and callPackageWith for better ux

This commit is contained in:
Jake Hamilton 2023-01-15 14:52:52 -08:00
parent 0ba4256dbd
commit 7def9101de
No known key found for this signature in database
GPG key ID: 9762169A1B35EA68
7 changed files with 70 additions and 60 deletions

View file

@ -4,13 +4,13 @@
}:
let
inherit (core-inputs.flake-utils-plus.lib) filterPackages;
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs;
inherit (core-inputs.flake-utils-plus.lib) filterPackages allSystems;
inherit (core-inputs.nixpkgs.lib) assertMsg foldl mapAttrs filterAttrs callPackageWith;
user-packages-root = snowfall-lib.fs.get-snowfall-file "packages";
in
{
package = {
package = rec {
# Create flake output packages.
# Type: Attrs -> Attrs
# Usage: create-packages { inherit channels; src = ./my-packages; overrides = { inherit another-package; }; alias.default = "another-package"; }
@ -21,17 +21,26 @@ in
, pkgs ? channels.nixpkgs
, overrides ? { }
, alias ? { }
, package-namespace ? "internal"
}:
let
user-packages = snowfall-lib.fs.get-default-nix-files-recursive src;
create-package-metadata = package: {
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package);
drv = pkgs.callPackage package {
inherit channels;
lib = snowfall-lib.internal.system-lib;
inputs = snowfall-lib.flake.without-src user-inputs;
create-package-metadata = package:
let
namespaced-packages = {
${package-namespace} = packages-without-aliases;
};
extra-inputs = pkgs // namespaced-packages // {
inherit channels;
lib = snowfall-lib.internal.system-lib;
pkgs = pkgs // namespaced-packages;
inputs = snowfall-lib.flake.without-snowfall-inputs user-inputs;
};
in
{
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package);
drv = callPackageWith extra-inputs package { };
};
};
packages-metadata = builtins.map create-package-metadata user-packages;
merge-packages = packages: metadata:
packages // {