refactor(modules/lib): move more options to it
Some checks failed
/ check (push) Failing after 4s
/ check-renovaterc (push) Successful in 3s
/ build-packages (push) Has been skipped
/ build-vm (push) Has been skipped
/ report-size (push) Has been skipped

This should keep all my custom options in the same place.
This commit is contained in:
Jalil David Salamé Messina 2025-04-21 23:10:27 +02:00
parent e71ab67615
commit bb1b491abc
Signed by: jalil
GPG key ID: F016B9E770737A0B
3 changed files with 27 additions and 28 deletions

View file

@ -1,7 +1,8 @@
{ lib, pkgs, ... }@attrs:
let
osConfig = attrs.osConfig or null;
inherit (lib) types;
inherit (import ../lib.nix { inherit lib; }) mkExtraPackagesOption;
osConfig = attrs.osConfig or null;
fromOs =
let
get =
@ -11,22 +12,6 @@ let
path: default: if osConfig == null then default else get path osConfig;
fromConfig = path: default: fromOs ([ "jconfig" ] ++ path) default;
mkExtraPackagesOption =
name: defaultPkgsPath:
let
text = lib.strings.concatMapStringsSep " " (
pkgPath: "pkgs." + (lib.strings.concatStringsSep "." pkgPath)
) defaultPkgsPath;
defaultText = lib.literalExpression "[ ${text} ]";
default = builtins.map (pkgPath: lib.attrsets.getAttrFromPath pkgPath pkgs) defaultPkgsPath;
in
lib.mkOption {
description = "Extra ${name} Packages.";
type = types.listOf types.package;
inherit default defaultText;
example = [ ];
};
identity.options = {
email = lib.mkOption {
description = "Primary email address";

View file

@ -1,7 +1,4 @@
{ lib }:
let
inherit (lib) types;
in
{
# Like mkEnableOption but defaults to true
mkDisableOption =
@ -20,8 +17,31 @@ in
}:
lib.mkOption {
inherit description;
type = types.path;
type = lib.types.path;
default = builtins.fetchurl { inherit url sha256; };
defaultText = lib.literalMD "![${description}](${url})";
};
# Like `lib.mkEnableOption` but default to disabled
mkDisableOption =
desc:
lib.mkEnableOption desc
// {
default = true;
example = false;
};
# Like `lib.mkPackageOption` but for a list of packages.
mkExtraPackagesOption =
name: defaultPkgsPath:
let
text = lib.strings.concatMapStringsSep " " (
pkgPath: "pkgs." + (lib.strings.concatStringsSep "." pkgPath)
) defaultPkgsPath;
in
lib.mkOption {
description = "Extra ${name} Packages.";
type = lib.types.listOf lib.types.package;
default = builtins.map (pkgPath: lib.attrsets.getAttrFromPath pkgPath pkgs) defaultPkgsPath;
defaultText = lib.literalExpression "[ ${text} ]";
example = [ ];
};
}

View file

@ -1,13 +1,7 @@
{ lib, ... }:
let
inherit (lib) mkEnableOption mkOption types;
mkDisableOption =
desc:
mkEnableOption desc
// {
default = true;
example = false;
};
inherit (import ../lib.nix { inherit lib; }) mkDisableOption;
in
{
options.jhome.nvim = {