refactor(shell): use create-simple-derivations helper

This commit is contained in:
anntnzrb
2025-10-08 23:28:36 -05:00
parent db72aa1e33
commit a8025edb45

View File

@@ -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"; });
};
}