11.stylix/stylix/autoload.nix
NAHO 5b9710eee9
treewide: remove optional builtins prefixes from prelude functions (#1915)
Remove optional builtins prefixes from prelude functions by running:

    builtins=(
      abort
      baseNameOf
      break
      derivation
      derivationStrict
      dirOf
      false
      fetchGit
      fetchMercurial
      fetchTarball
      fetchTree
      fromTOML
      import
      isNull
      map
      null
      placeholder
      removeAttrs
      scopedImport
      throw
      toString
      true
    )

    fd --type file --exec-batch sed --in-place --regexp-extended "
      s/\<builtins\.($(
          printf '%s\n' "${builtins[@]}" |
            paste --delimiter '|' --serial -
      ))\>/\1/g
    "

    nix fmt

This patch is heavily inspired by [1] ("treewide: remove optional
builtins prefixes from prelude functions").

[1]: https://github.com/NixOS/nixpkgs/pull/444432

Link: https://github.com/nix-community/stylix/pull/1915

Reviewed-by: Daniel Thwaites <danth@danth.me>
Reviewed-by: awwpotato <awwpotato@voidq.com>
2025-09-28 11:09:21 +02:00

62 lines
2 KiB
Nix

{ lib }:
# string -> [ path ]
# List include path for either nixos modules or hm modules
platform:
builtins.concatLists (
lib.mapAttrsToList (
target: kind:
let
file = ../modules/${target}/${platform}.nix;
module = import file;
# Detect whether the file's value has an argument named `mkTarget`
useMkTarget =
builtins.isFunction module && (builtins.functionArgs module) ? mkTarget;
# NOTE: `mkTarget` cannot be distributed normally through the module system
# due to issues of infinite recursion.
mkTarget = import ./mk-target.nix;
in
lib.optional (kind == "directory" && builtins.pathExists file) (
if useMkTarget then
{ config, ... }@args:
let
# Based on `lib.modules.applyModuleArgs`
#
# Apply `mkTarget` as a special arg without actually using `specialArgs`,
# which cannot be defined from within a configuration.
context =
name: ''while evaluating the module argument `${name}' in "${toString file}":'';
extraArgs = lib.pipe module [
builtins.functionArgs
(lib.flip removeAttrs [ "mkTarget" ])
(builtins.mapAttrs (
name: _:
builtins.addErrorContext (context name) (
args.${name} or config._module.args.${name}
)
))
];
in
{
key = file;
_file = file;
imports = [
(module (
args
// extraArgs
// {
inherit mkTarget;
config = lib.recursiveUpdate config {
stylix = throw "stylix: unguarded `config.stylix` accessed while using mkTarget";
lib.stylix.colors = throw "stylix: unguarded `config.lib.stylix.colors` accessed while using mkTarget";
};
}
))
];
}
else
file
)
) (builtins.readDir ../modules)
)