modules: create modules to hold global variables

This commit is contained in:
Anthony Rodriguez 2024-12-18 09:23:33 +01:00
parent 0e6ec0157b
commit e98a15db1d
Signed by: nezia
GPG key ID: EE3BE97C040A86CE
3 changed files with 71 additions and 1 deletions

View file

@ -1,3 +1,7 @@
{ {
imports = [./theme]; imports = [
./systemVars.nix
./homeVars.nix
./theme
];
} }

31
modules/homeVars.nix Normal file
View file

@ -0,0 +1,31 @@
{
config,
lib,
options,
...
}: let
inherit (lib) mkIf mkOption;
inherit (lib.types) str;
in {
options.local.homeVars = {
fullName = mkOption {
type = str;
description = "your full name (used for git commits and user description)";
default = null;
};
email = mkOption {
type = str;
description = "your email (used for git commits)";
default = null;
};
};
config.assertions = mkIf (!config.local.systemVars.isServer) [
{
assertion = options.local.homeVars.fullName.isDefined;
}
{
assertion = options.local.homeVars.email.isDefined;
}
];
}

35
modules/systemVars.nix Normal file
View file

@ -0,0 +1,35 @@
{
lib,
options,
...
}: let
inherit (lib) mkOption;
inherit (lib.types) bool str;
in {
options.local.systemVars = {
hostName = mkOption {
type = str;
description = "hostname for the current host";
default = null;
};
username = mkOption {
type = str;
description = "username for the home directory";
default = null;
};
isServer = mkOption {
type = bool;
description = "whether or not this host is a server";
default = false;
};
};
config.assertions = [
{
assertion = options.local.systemVars.hostName.isDefined;
}
{
assertion = options.local.systemVars.username.isDefined;
}
];
}