mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 09:05:58 -05:00
refactor(shell): use create-simple-derivations helper
This commit is contained in:
@@ -4,20 +4,9 @@
|
||||
snowfall-lib,
|
||||
snowfall-config,
|
||||
}:
|
||||
let
|
||||
inherit (core-inputs.flake-utils-plus.lib) filterPackages;
|
||||
inherit (core-inputs.nixpkgs.lib)
|
||||
assertMsg
|
||||
foldl
|
||||
mapAttrs
|
||||
callPackageWith
|
||||
;
|
||||
|
||||
user-shells-root = snowfall-lib.fs.get-snowfall-file "shells";
|
||||
in
|
||||
{
|
||||
shell = {
|
||||
## Create flake output packages.
|
||||
## Create flake output shells.
|
||||
## Example Usage:
|
||||
## ```nix
|
||||
## create-shells { inherit channels; src = ./my-shells; overrides = { inherit another-shell; }; alias = { default = "another-shell"; }; }
|
||||
@@ -27,41 +16,7 @@ in
|
||||
## { another-shell = ...; my-shell = ...; default = ...; }
|
||||
## ```
|
||||
#@ Attrs -> Attrs
|
||||
create-shells =
|
||||
{
|
||||
channels,
|
||||
src ? user-shells-root,
|
||||
pkgs ? channels.nixpkgs,
|
||||
overrides ? { },
|
||||
alias ? { },
|
||||
}:
|
||||
let
|
||||
user-shells = snowfall-lib.fs.get-default-nix-files-recursive src;
|
||||
create-shell-metadata =
|
||||
shell:
|
||||
let
|
||||
extra-inputs = pkgs // {
|
||||
inherit channels;
|
||||
lib = snowfall-lib.internal.system-lib;
|
||||
inputs = snowfall-lib.flake.without-src user-inputs;
|
||||
namespace = snowfall-config.namespace;
|
||||
};
|
||||
in
|
||||
{
|
||||
# We are building flake outputs based on file paths. Nix doesn't allow this
|
||||
# so we have to explicitly discard the string's path context to use it as an attribute name.
|
||||
name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory shell);
|
||||
drv = callPackageWith extra-inputs shell { };
|
||||
};
|
||||
shells-metadata = builtins.map create-shell-metadata user-shells;
|
||||
merge-shells =
|
||||
shells: metadata:
|
||||
shells
|
||||
// {
|
||||
${metadata.name} = metadata.drv;
|
||||
};
|
||||
shells = snowfall-lib.attrs.merge-with-aliases merge-shells shells-metadata alias // overrides;
|
||||
in
|
||||
filterPackages pkgs.stdenv.hostPlatform.system shells;
|
||||
create-shells = args:
|
||||
snowfall-lib.internal.create-simple-derivations (args // { type = "shells"; });
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user