From e98a15db1d449c7a8993abac2ede6fdb5fe84958 Mon Sep 17 00:00:00 2001 From: Anthony Rodriguez Date: Wed, 18 Dec 2024 09:23:33 +0100 Subject: [PATCH] modules: create modules to hold global variables --- modules/default.nix | 6 +++++- modules/homeVars.nix | 31 +++++++++++++++++++++++++++++++ modules/systemVars.nix | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 modules/homeVars.nix create mode 100644 modules/systemVars.nix diff --git a/modules/default.nix b/modules/default.nix index eecd825..a7c1dc4 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,3 +1,7 @@ { - imports = [./theme]; + imports = [ + ./systemVars.nix + ./homeVars.nix + ./theme + ]; } diff --git a/modules/homeVars.nix b/modules/homeVars.nix new file mode 100644 index 0000000..3b2688c --- /dev/null +++ b/modules/homeVars.nix @@ -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; + } + ]; +} diff --git a/modules/systemVars.nix b/modules/systemVars.nix new file mode 100644 index 0000000..cb8d169 --- /dev/null +++ b/modules/systemVars.nix @@ -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; + } + ]; +}