feat(home): My module

This commit is contained in:
punkfairie 2024-11-15 17:44:46 -08:00
parent 5f7cfe4858
commit 6ef9ec385a
Signed by: punkfairie
GPG key ID: A509E8F77FB9D696
3 changed files with 73 additions and 73 deletions

View file

@ -1,4 +0,0 @@
{ namespace, lib, ... }:
{
}

View file

@ -0,0 +1,73 @@
{
namespace,
lib,
config,
...
}:
let
inherit (lib)
mkOption
types
mkDefault
mkIf
;
in
{
options.${namespace}.my = rec {
name = mkOption {
type = with types; str;
default = config.snowfallorg.user.name or "marley";
description = "Your username, for use as your login name.";
};
username = mkOption {
type = with types; str;
default = name;
description = "Your username, for external profiles.";
};
fullName = mkOption {
type = with types; str;
default = name;
description = "Your full name, for display purposes.";
};
email = mkOption {
type = with types; nullOr str;
default = null;
description = "Your email";
};
git.name = mkOption {
type = with types; str;
default = name;
description = "Your git committer name.";
};
git.email = mkOption {
type = with types; nullOr str;
default = email;
description = "Your git committer email.";
};
};
config =
let
cfg = config.${namespace}.my;
in
{
assertions = [
{
assertion = cfg.name != null;
message = "${namespace}.my.name must be set.";
}
];
home.username = mkDefault cfg.name;
programs.git = mkIf config.programs.git.enable {
userName = mkDefault cfg.git.name;
userEmail = mkDefault cfg.git.email;
};
};
}

View file

@ -1,69 +0,0 @@
{
lib,
config,
pkgs,
...
}:
with lib;
{
options = {
me = rec {
name = mkOption {
type = types.str;
default = builtins.getEnv "HOME";
defaultText =
# nix
literalExpression ''
builtins.getEnv "HOME"
'';
description = ''
Your username, for use as your home folder and login name.
'';
};
username = mkOption {
type = types.str;
default = name;
defaultText = literalMD "{option}`home.me.name`";
description = ''
Your username, for external profiles.
'';
};
email = mkOption {
type = with types; nullOr str;
default = null;
description = ''
Your email.
'';
};
git.name = mkOption {
type = with types; nullOr str;
default = null;
description = ''
Your git committer name.
'';
};
git.email = mkOption {
type = with types; nullOr str;
default = email;
defaultText = literalMD "{option}`home.me.email`";
description = ''
Your git committer email.
'';
};
};
};
config =
let
cfg = config.me;
homeDir = if pkgs.stdenv.isDarwin then "Users" else "home";
in
{
home.username = cfg.name;
home.homeDirectory = "/${homeDir}/${cfg.name}";
};
}