style(flake)!: manually import lib flake module

- Also make `lib` an `internal` option
- Unify let blocks and move them under `imports`
  (makes it clear where `config.lib` comes from)
- Fix a minor typo
This commit is contained in:
reo101 2024-09-07 20:49:14 +03:00
parent 1baef9b78c
commit 31f9e7dbef
Signed by: reo101
GPG key ID: 675AA7EF13964ACB
9 changed files with 96 additions and 82 deletions

View file

@ -5,9 +5,9 @@ let
and and
hasFiles hasFiles
hasDirectories hasDirectories
configuration-type-to-outputs-modules; configuration-type-to-outputs-modules
in ;
let
# `pkgs` with flake's overlays # `pkgs` with flake's overlays
# NOTE: done here to avoid infinite recursion # NOTE: done here to avoid infinite recursion
pkgs' = system: pkgs' = system:

View file

@ -1,21 +1,19 @@
{ lib, config, self, inputs, withSystem, ... }: { lib, config, self, inputs, withSystem, ... }:
let
inherit (config.lib)
and
hasFiles
hasDirectories
recurseDir
kebabToCamel
configuration-type-to-outputs-modules;
in
{ {
imports = [ imports = [
../lib
./default-generators.nix ./default-generators.nix
]; ];
options = let options = let
inherit (lib) types; inherit (lib)
types
;
inherit (config.lib)
recurseDir
kebabToCamel
;
in { in {
auto.configurations = lib.mkOption { auto.configurations = lib.mkOption {
description = '' description = ''

View file

@ -6,9 +6,12 @@
]; ];
options = let options = let
inherit (lib) types; inherit (lib)
types
;
in { in {
lib = lib.mkOption { lib = lib.mkOption {
internal = true;
type = types.unspecified; type = types.unspecified;
}; };
}; };

View file

@ -1,14 +1,13 @@
{ lib, config, self, inputs, ... }: { lib, config, self, inputs, ... }:
let
inherit (config.lib)
and
eq
hasFiles
;
in
{ {
config.lib = rec { config.lib = let
inherit (config.lib)
and
eq
hasFiles
;
in rec {
# Try to passthru `inputs` by default # Try to passthru `inputs` by default
defaultThingHandle = { raw, thingType }: name: result: let defaultThingHandle = { raw, thingType }: name: result: let
thing = thing =

View file

@ -1,21 +1,24 @@
{ lib, config, self, inputs, ... }: { lib, config, self, inputs, ... }:
let
inherit (config.lib)
createThings
kebabToCamel;
in
let
# Modules helpers
createModules = baseDir:
createThings {
inherit baseDir;
thingType = "module";
};
in
{ {
imports = [
../lib
];
options = let options = let
inherit (lib) types; inherit (lib)
types
;
inherit (config.lib)
createThings
kebabToCamel
;
createModules = baseDir:
createThings {
inherit baseDir;
thingType = "module";
};
in { in {
auto.modules = lib.mkOption { auto.modules = lib.mkOption {
description = '' description = ''
@ -76,7 +79,6 @@ in
(createModules dir); (createModules dir);
}; };
}; };
config = {};
})); }));
# TODO: put in a more visible place # TODO: put in a more visible place
default = { default = {

View file

@ -1,19 +1,23 @@
{ lib, config, self, inputs, ... }: { lib, config, self, inputs, ... }:
let
inherit (config.lib)
createThings;
in
let
createOverlays = baseDir:
createThings {
inherit baseDir;
thingType = "overlay";
};
in
{ {
imports = [
../lib
];
options = let options = let
inherit (lib) types; inherit (lib)
types
;
inherit (config.lib)
createThings
;
createOverlays = baseDir:
createThings {
inherit baseDir;
thingType = "overlay";
};
in { in {
auto.overlays = lib.mkOption { auto.overlays = lib.mkOption {
description = '' description = ''

View file

@ -1,23 +1,27 @@
{ lib, config, self, inputs, ... }: { lib, config, self, inputs, ... }:
let
inherit (config.lib)
createThings;
in
let
createPackages = baseDir:
createThings {
inherit baseDir;
thingType = "package";
raw = false;
extras.systems = {
default = lib.const true;
};
};
in
{ {
imports = [
../lib
];
options = let options = let
inherit (lib) types; inherit (lib)
types
;
inherit (config.lib)
createThings
;
createPackages = baseDir:
createThings {
inherit baseDir;
thingType = "package";
raw = false;
extras.systems = {
default = lib.const true;
};
};
in { in {
auto.packages = lib.mkOption { auto.packages = lib.mkOption {
description = '' description = ''

View file

@ -4,7 +4,7 @@
perSystem = { system, ... }: { perSystem = { system, ... }: {
_module.args.pkgs = import inputs.nixpkgs { _module.args.pkgs = import inputs.nixpkgs {
inherit system; inherit system;
# WARN: not including `self.packages` overylay # WARN: not including `self.packages` overlay
# because it causes an infinite recursion # because it causes an infinite recursion
overlays = lib.attrValues self.overlays ++ [ overlays = lib.attrValues self.overlays ++ [
inputs.neovim-nightly-overlay.overlays.default inputs.neovim-nightly-overlay.overlays.default

View file

@ -1,23 +1,27 @@
{ lib, config, self, inputs, ... }: { lib, config, self, inputs, ... }:
let
inherit (config.lib)
createThings;
in
let
createDevShells = baseDir:
createThings {
inherit baseDir;
thingType = "devShell";
raw = false;
extras.systems = {
default = lib.const true;
};
};
in
{ {
imports = [
../lib
];
options = let options = let
inherit (lib) types; inherit (lib)
types
;
inherit (config.lib)
createThings
;
createDevShells = baseDir:
createThings {
inherit baseDir;
thingType = "devShell";
raw = false;
extras.systems = {
default = lib.const true;
};
};
in { in {
auto.devShells = lib.mkOption { auto.devShells = lib.mkOption {
description = '' description = ''