mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 09:05:58 -05:00
refactor: standardize on formatter
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
{ core-inputs
|
||||
, user-inputs
|
||||
, snowfall-lib
|
||||
, snowfall-config
|
||||
}:
|
||||
|
||||
let
|
||||
{
|
||||
core-inputs,
|
||||
user-inputs,
|
||||
snowfall-lib,
|
||||
snowfall-config,
|
||||
}: let
|
||||
inherit (core-inputs.nixpkgs.lib) assertMsg foldl filterAttrs const;
|
||||
in
|
||||
rec {
|
||||
in rec {
|
||||
flake = rec {
|
||||
## Remove the `self` attribute from an attribute set.
|
||||
## Example Usage:
|
||||
@@ -19,7 +17,7 @@ rec {
|
||||
## { x = true; }
|
||||
## ```
|
||||
#@ Attrs -> Attrs
|
||||
without-self = flake-inputs: builtins.removeAttrs flake-inputs [ "self" ];
|
||||
without-self = flake-inputs: builtins.removeAttrs flake-inputs ["self"];
|
||||
|
||||
## Remove the `src` attribute from an attribute set.
|
||||
## Example Usage:
|
||||
@@ -31,7 +29,7 @@ rec {
|
||||
## { x = true; }
|
||||
## ```
|
||||
#@ Attrs -> Attrs
|
||||
without-src = flake-inputs: builtins.removeAttrs flake-inputs [ "src" ];
|
||||
without-src = flake-inputs: builtins.removeAttrs flake-inputs ["src"];
|
||||
|
||||
## Remove the `src` and `self` attributes from an attribute set.
|
||||
## Example Usage:
|
||||
@@ -57,22 +55,22 @@ rec {
|
||||
#@ Attrs -> Attrs
|
||||
without-snowfall-options = flake-options:
|
||||
builtins.removeAttrs
|
||||
flake-options
|
||||
[
|
||||
"systems"
|
||||
"modules"
|
||||
"overlays"
|
||||
"packages"
|
||||
"outputs-builder"
|
||||
"outputsBuilder"
|
||||
"packagesPrefix"
|
||||
"hosts"
|
||||
"channels-config"
|
||||
"templates"
|
||||
"package-namespace"
|
||||
"alias"
|
||||
"snowfall"
|
||||
];
|
||||
flake-options
|
||||
[
|
||||
"systems"
|
||||
"modules"
|
||||
"overlays"
|
||||
"packages"
|
||||
"outputs-builder"
|
||||
"outputsBuilder"
|
||||
"packagesPrefix"
|
||||
"hosts"
|
||||
"channels-config"
|
||||
"templates"
|
||||
"package-namespace"
|
||||
"alias"
|
||||
"snowfall"
|
||||
];
|
||||
|
||||
## Transform an attribute set of inputs into an attribute set where the values are the inputs' `lib` attribute. Entries without a `lib` attribute are removed.
|
||||
## Example Usage:
|
||||
@@ -84,80 +82,80 @@ rec {
|
||||
## { x = nixpkgs.lib; }
|
||||
## ```
|
||||
#@ Attrs -> Attrs
|
||||
get-libs = attrs:
|
||||
let
|
||||
# @PERF(jakehamilton): Replace filter+map with a fold.
|
||||
attrs-with-libs = filterAttrs
|
||||
(name: value: builtins.isAttrs (value.lib or null))
|
||||
attrs;
|
||||
libs =
|
||||
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
||||
in
|
||||
get-libs = attrs: let
|
||||
# @PERF(jakehamilton): Replace filter+map with a fold.
|
||||
attrs-with-libs =
|
||||
filterAttrs
|
||||
(name: value: builtins.isAttrs (value.lib or null))
|
||||
attrs;
|
||||
libs =
|
||||
builtins.mapAttrs (name: input: input.lib) attrs-with-libs;
|
||||
in
|
||||
libs;
|
||||
};
|
||||
|
||||
mkFlake = full-flake-options:
|
||||
let
|
||||
package-namespace = full-flake-options.package-namespace or snowfall-config.namespace or "internal";
|
||||
custom-flake-options = flake.without-snowfall-options full-flake-options;
|
||||
alias = full-flake-options.alias or { };
|
||||
homes = snowfall-lib.home.create-homes (full-flake-options.homes or { });
|
||||
systems = snowfall-lib.system.create-systems {
|
||||
systems = (full-flake-options.systems or { });
|
||||
homes = (full-flake-options.homes or { });
|
||||
mkFlake = full-flake-options: let
|
||||
package-namespace = full-flake-options.package-namespace or snowfall-config.namespace or "internal";
|
||||
custom-flake-options = flake.without-snowfall-options full-flake-options;
|
||||
alias = full-flake-options.alias or {};
|
||||
homes = snowfall-lib.home.create-homes (full-flake-options.homes or {});
|
||||
systems = snowfall-lib.system.create-systems {
|
||||
systems = full-flake-options.systems or {};
|
||||
homes = full-flake-options.homes or {};
|
||||
};
|
||||
hosts = snowfall-lib.attrs.merge-shallow [(full-flake-options.systems.hosts or {}) systems homes];
|
||||
templates = snowfall-lib.template.create-templates {
|
||||
overrides = full-flake-options.templates or {};
|
||||
alias = alias.templates or {};
|
||||
};
|
||||
nixos-modules = snowfall-lib.module.create-modules {
|
||||
src = snowfall-lib.fs.get-snowfall-file "modules/nixos";
|
||||
overrides = full-flake-options.modules.nixos or {};
|
||||
alias = alias.modules.nixos or {};
|
||||
};
|
||||
darwin-modules = snowfall-lib.module.create-modules {
|
||||
src = snowfall-lib.fs.get-snowfall-file "modules/darwin";
|
||||
overrides = full-flake-options.modules.darwin or {};
|
||||
alias = alias.modules.darwin or {};
|
||||
};
|
||||
home-modules = snowfall-lib.module.create-modules {
|
||||
src = snowfall-lib.fs.get-snowfall-file "modules/home";
|
||||
overrides = full-flake-options.modules.home or {};
|
||||
alias = alias.modules.home or {};
|
||||
};
|
||||
overlays = snowfall-lib.overlay.create-overlays {
|
||||
inherit package-namespace;
|
||||
extra-overlays = full-flake-options.extra-exported-overlays or {};
|
||||
};
|
||||
|
||||
outputs-builder = channels: let
|
||||
user-outputs-builder =
|
||||
full-flake-options.outputs-builder
|
||||
or full-flake-options.outputsBuilder
|
||||
or (const {});
|
||||
user-outputs = user-outputs-builder channels;
|
||||
packages = snowfall-lib.package.create-packages {
|
||||
inherit channels package-namespace;
|
||||
overrides = (full-flake-options.packages or {}) // (user-outputs.packages or {});
|
||||
alias = alias.packages or {};
|
||||
};
|
||||
hosts = snowfall-lib.attrs.merge-shallow [ (full-flake-options.systems.hosts or { }) systems homes ];
|
||||
templates = snowfall-lib.template.create-templates {
|
||||
overrides = (full-flake-options.templates or { });
|
||||
alias = alias.templates or { };
|
||||
};
|
||||
nixos-modules = snowfall-lib.module.create-modules {
|
||||
src = snowfall-lib.fs.get-snowfall-file "modules/nixos";
|
||||
overrides = (full-flake-options.modules.nixos or { });
|
||||
alias = alias.modules.nixos or { };
|
||||
};
|
||||
darwin-modules = snowfall-lib.module.create-modules {
|
||||
src = snowfall-lib.fs.get-snowfall-file "modules/darwin";
|
||||
overrides = (full-flake-options.modules.darwin or { });
|
||||
alias = alias.modules.darwin or { };
|
||||
};
|
||||
home-modules = snowfall-lib.module.create-modules {
|
||||
src = snowfall-lib.fs.get-snowfall-file "modules/home";
|
||||
overrides = (full-flake-options.modules.home or { });
|
||||
alias = alias.modules.home or { };
|
||||
};
|
||||
overlays = snowfall-lib.overlay.create-overlays {
|
||||
inherit package-namespace;
|
||||
extra-overlays = full-flake-options.extra-exported-overlays or { };
|
||||
shells = snowfall-lib.shell.create-shells {
|
||||
inherit channels;
|
||||
overrides = (full-flake-options.shells or {}) // (user-outputs.devShells or {});
|
||||
alias = alias.shells or {};
|
||||
};
|
||||
|
||||
outputs-builder = channels:
|
||||
let
|
||||
user-outputs-builder =
|
||||
full-flake-options.outputs-builder
|
||||
or full-flake-options.outputsBuilder
|
||||
or (const { });
|
||||
user-outputs = user-outputs-builder channels;
|
||||
packages = snowfall-lib.package.create-packages {
|
||||
inherit channels package-namespace;
|
||||
overrides = (full-flake-options.packages or { }) // (user-outputs.packages or { });
|
||||
alias = alias.packages or { };
|
||||
};
|
||||
shells = snowfall-lib.shell.create-shells {
|
||||
inherit channels;
|
||||
overrides = (full-flake-options.shells or { }) // (user-outputs.devShells or { });
|
||||
alias = alias.shells or { };
|
||||
};
|
||||
outputs = {
|
||||
inherit packages;
|
||||
|
||||
outputs = {
|
||||
inherit packages;
|
||||
devShells = shells;
|
||||
};
|
||||
in
|
||||
snowfall-lib.attrs.merge-deep [user-outputs outputs];
|
||||
|
||||
devShells = shells;
|
||||
};
|
||||
in
|
||||
snowfall-lib.attrs.merge-deep [ user-outputs outputs ];
|
||||
|
||||
flake-options = custom-flake-options // {
|
||||
flake-options =
|
||||
custom-flake-options
|
||||
// {
|
||||
inherit hosts templates;
|
||||
inherit (user-inputs) self;
|
||||
|
||||
@@ -168,29 +166,30 @@ rec {
|
||||
darwinModules = darwin-modules;
|
||||
homeModules = home-modules;
|
||||
|
||||
channelsConfig = full-flake-options.channels-config or { };
|
||||
channelsConfig = full-flake-options.channels-config or {};
|
||||
|
||||
channels.nixpkgs.overlaysBuilder = snowfall-lib.overlay.create-overlays-builder {
|
||||
inherit package-namespace;
|
||||
extra-overlays = full-flake-options.overlays or [ ];
|
||||
extra-overlays = full-flake-options.overlays or [];
|
||||
};
|
||||
|
||||
outputsBuilder = outputs-builder;
|
||||
|
||||
_snowfall = {
|
||||
config = snowfall-config;
|
||||
raw-config = full-flake-options.snowfall or { };
|
||||
raw-config = full-flake-options.snowfall or {};
|
||||
user-lib = snowfall-lib.internal.user-lib;
|
||||
};
|
||||
};
|
||||
|
||||
flake-utils-plus-outputs =
|
||||
core-inputs.flake-utils-plus.lib.mkFlake flake-options;
|
||||
flake-utils-plus-outputs =
|
||||
core-inputs.flake-utils-plus.lib.mkFlake flake-options;
|
||||
|
||||
flake-outputs =
|
||||
flake-utils-plus-outputs // {
|
||||
inherit overlays;
|
||||
};
|
||||
in
|
||||
flake-outputs =
|
||||
flake-utils-plus-outputs
|
||||
// {
|
||||
inherit overlays;
|
||||
};
|
||||
in
|
||||
flake-outputs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user