mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 09:05:58 -05:00
93 lines
2.9 KiB
Nix
93 lines
2.9 KiB
Nix
{
|
|
core-inputs,
|
|
user-inputs,
|
|
snowfall-lib,
|
|
snowfall-config,
|
|
}:
|
|
let
|
|
inherit (builtins) baseNameOf;
|
|
inherit (core-inputs.nixpkgs.lib)
|
|
foldl
|
|
mapAttrs
|
|
hasSuffix
|
|
isFunction
|
|
splitString
|
|
tail
|
|
;
|
|
|
|
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
|
|
in
|
|
{
|
|
module = {
|
|
## Create flake output modules.
|
|
## Example Usage:
|
|
## ```nix
|
|
## create-modules { src = ./my-modules; overrides = { inherit another-module; }; alias = { default = "another-module" }; }
|
|
## ```
|
|
## Result:
|
|
## ```nix
|
|
## { another-module = ...; my-module = ...; default = ...; }
|
|
## ```
|
|
#@ Attrs -> Attrs
|
|
create-modules =
|
|
{
|
|
src ? "${user-modules-root}/nixos",
|
|
overrides ? { },
|
|
alias ? { },
|
|
}:
|
|
let
|
|
user-modules = snowfall-lib.fs.get-default-nix-files-recursive src;
|
|
create-module-metadata = module: {
|
|
name = snowfall-lib.path.get-relative-module-path src module;
|
|
path = module;
|
|
};
|
|
modules-metadata = builtins.map create-module-metadata user-modules;
|
|
merge-modules =
|
|
modules: metadata:
|
|
modules
|
|
// {
|
|
# NOTE: home-manager *requires* modules to specify named arguments or it will not
|
|
# pass values in. For this reason we must specify things like `pkgs` as a named attribute.
|
|
${metadata.name} =
|
|
args@{ pkgs, ... }:
|
|
let
|
|
system = args.system or args.pkgs.stdenv.hostPlatform.system;
|
|
target = args.target or system;
|
|
|
|
format =
|
|
let
|
|
virtual-system-type = snowfall-lib.system.get-virtual-system-type target;
|
|
in
|
|
if virtual-system-type != "" then
|
|
virtual-system-type
|
|
else if snowfall-lib.system.is-darwin target then
|
|
"darwin"
|
|
else
|
|
"linux";
|
|
|
|
# Replicates the specialArgs from Snowfall Lib's system builder.
|
|
modified-args = args // {
|
|
inherit system target format;
|
|
virtual = args.virtual or (snowfall-lib.system.get-virtual-system-type target != "");
|
|
systems = args.systems or { };
|
|
|
|
lib = snowfall-lib.internal.system-lib;
|
|
|
|
inputs = snowfall-lib.flake.without-src user-inputs;
|
|
namespace = snowfall-config.namespace;
|
|
};
|
|
imported-user-module = import metadata.path;
|
|
user-module =
|
|
if isFunction imported-user-module then
|
|
imported-user-module modified-args
|
|
else
|
|
imported-user-module;
|
|
in
|
|
user-module // { _file = metadata.path; };
|
|
};
|
|
modules = snowfall-lib.attrs.merge-with-aliases merge-modules modules-metadata alias // overrides;
|
|
in
|
|
modules;
|
|
};
|
|
}
|