diff --git a/modules/hm/options.nix b/modules/hm/options.nix index e274f52..8ce3629 100644 --- a/modules/hm/options.nix +++ b/modules/hm/options.nix @@ -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"; diff --git a/modules/lib.nix b/modules/lib.nix index 3e3a288..776e641 100644 --- a/modules/lib.nix +++ b/modules/lib.nix @@ -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 = [ ]; + }; } diff --git a/modules/nixvim/options.nix b/modules/nixvim/options.nix index 292a80e..8b37eac 100644 --- a/modules/nixvim/options.nix +++ b/modules/nixvim/options.nix @@ -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 = {