home-manager/state: refactor and add paths and ports sub-option

Similarly structured to the NixOS module to make it consistent, yay.
This commit is contained in:
Gabriel Arazas 2024-07-31 21:47:48 +08:00
parent ae06921d64
commit f6c70a278b
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
8 changed files with 124 additions and 42 deletions

View File

@ -60,7 +60,7 @@ in
topdirs = "~/Downloads ~/Documents ~/library"; topdirs = "~/Downloads ~/Documents ~/library";
"skippedNames+" = "skippedNames+" =
let let
inherit (config.state) ignoreDirectories; inherit (config.state.paths) ignoreDirectories;
in in
lib.concatStringsSep " " ignoreDirectories; lib.concatStringsSep " " ignoreDirectories;

View File

@ -10,7 +10,7 @@ in
config = lib.mkIf cfg.enable (lib.mkMerge [ config = lib.mkIf cfg.enable (lib.mkMerge [
{ {
state.ignoreDirectories = [ state.paths.ignoreDirectories = [
"node_modules" # For Node projects. "node_modules" # For Node projects.
"result" # For Nix builds. "result" # For Nix builds.
"target" # For Rust builds. "target" # For Rust builds.

View File

@ -1,7 +1,7 @@
{ {
imports = [ imports = [
./extra-arguments.nix ./extra-arguments.nix
./state.nix ./state
./suites/desktop.nix ./suites/desktop.nix
./suites/dev.nix ./suites/dev.nix
./suites/editors.nix ./suites/editors.nix

View File

@ -1,37 +0,0 @@
{ lib, ... }:
{
options.state = lib.mkOption {
type = lib.types.submodule {
freeformType = with lib.types; attrsOf anything;
options = {
ignoreDirectories = lib.mkOption {
type = with lib.types; listOf str;
description = ''
A state variable holding a list of directory names to be excluded
in processes involving walking through directories (e.g., desktop
indexing).
'';
default = [ ];
example = [
"node_modules"
".direnv"
];
};
};
};
description = ''
A set of values to be held in the home-manager configuration. Pretty much
used for anything that requires consistency or deduplicate the source of
truth for module values.
'';
example = {
sampleValue = 10;
dev.ignoreDirectories = [
".git"
"node_modules"
".direnv"
];
};
};
}

View File

@ -0,0 +1,28 @@
{ lib, ... }:
{
imports = [
./ports.nix
./paths.nix
];
options.state = lib.mkOption {
type = lib.types.submodule {
freeformType = with lib.types; attrsOf anything;
default = { };
};
description = ''
A set of values to be held in the home-manager configuration. Pretty much
used for anything that requires consistency or deduplicate the source of
truth for module values.
'';
example = {
sampleValue = 10;
paths.ignoreDirectories = [
".git"
"node_modules"
".direnv"
];
};
};
}

View File

@ -0,0 +1,27 @@
{ lib, ... }:
{
options.state =
let
pathsSubmodule = { lib, ... }: {
options = {
paths = lib.mkOption {
type = with lib.types; attrsOf (listOf path);
default = { };
description = ''
Set of paths to hold as a single source of truth for path-related
settings throughout the whole home environment.
'';
example = lib.literalExpression ''
{
ignoreDirectories = [ "''${config.home.homeDirectory}/Nodes" ];
ignorePaths = [ ".gitignore" "node_modules" "result" ];
}
'';
};
};
};
in lib.mkOption {
type = lib.type.submodule pathsSubmodule;
};
}

View File

@ -0,0 +1,64 @@
{ lib, ... }:
let
supportedProtocols = [ "tcp" "udp" ];
in
{
options.state =
let
portRangeType = {
options = {
from = lib.mkOption {
type = lib.types.port;
description = ''
The start of the range of TCP/UDP ports to be taken over.
'';
};
to = lib.mkOption {
type = lib.types.port;
description = ''
The end of the range of TCP/UDP ports to be taken over.
'';
};
};
};
portValueModule = { lib, ... }: {
options = {
protocols = lib.mkOption {
type = with lib.types; listOf (enum supportedProtocols);
description = ''
Indicates the type of protocol of the service.
'';
default = [ "tcp" "udp" ];
example = [ "tcp" ];
};
value = lib.mkOption {
type = with lib.types; either port (submodule portRangeType);
description = ''
The port number itself.
'';
};
};
};
portsSubmodule = { lib, ... }: {
options = {
ports = lib.mkOption {
type = with lib.types; attrsOf (submodule portValueModule);
default = { };
example = lib.literalExpression ''
{
gonic.value = 4629;
mopidy.value = 6034;
}
'';
};
};
};
in lib.mkOption {
type = lib.types.submodule portsSubmodule;
};
}

View File

@ -20,7 +20,7 @@ in {
({ ({
# Contains a dev-adjacent list of directory names to be ignored usually # Contains a dev-adjacent list of directory names to be ignored usually
# used in walking through directories. # used in walking through directories.
state.ignoreDirectories = [ state.paths.ignoreDirectories = [
".git" ".git"
".direnv" ".direnv"
]; ];
@ -171,7 +171,7 @@ in {
programs.eza = { programs.eza = {
enable = true; enable = true;
extraOptions = let extraOptions = let
ignoreDirectories = lib.concatStringsSep "|" config.state.ignoreDirectories; ignoreDirectories = lib.concatStringsSep "|" config.state.paths.ignoreDirectories;
in [ in [
"--group-directories-first" "--group-directories-first"
"--header" "--header"