Simplify user config

work
sloane ess 2024-07-19 20:59:11 -04:00
parent a07217278b
commit 6cf8344ed9
11 changed files with 64 additions and 101 deletions

View File

@ -3,15 +3,15 @@
flake.darwinModules = { flake.darwinModules = {
home = home =
let let
inherit (config.users) me; inherit (config.me) username;
in in
{ {
home-manager.users.${me} = { home-manager.users.${username} = {
imports = [ self.homeModules.darwin ]; imports = [ self.homeModules.darwin ];
}; };
users.users.${me} = { users.users.${username} = {
name = me; name = username;
home = "/Users/${me}"; home = "/Users/${username}";
}; };
}; };

View File

@ -71,9 +71,9 @@
inputs.pre-commit.flakeModule inputs.pre-commit.flakeModule
./darwin ./darwin
./home ./home
./me
./nixos ./nixos
./templates ./templates
./users
]; ];
flake = { flake = {
nixosConfigurations = { nixosConfigurations = {

View File

@ -1,13 +1,13 @@
{ flake, ... }: { flake, ... }:
let let
inherit (flake.config.users) me'; inherit (flake.config) me;
in in
{ {
programs.git = { programs.git = {
enable = true; enable = true;
userEmail = me'.email; userEmail = me.email;
userName = me'.name; userName = me.name;
extraConfig = { extraConfig = {
help.autocorrect = "prompt"; help.autocorrect = "prompt";

View File

@ -1,6 +1,6 @@
{ flake, pkgs, ... }: { flake, pkgs, ... }:
let let
inherit (flake.config.users) me me'; inherit (flake.config) me;
tomlFormat = pkgs.formats.toml { }; tomlFormat = pkgs.formats.toml { };
in in
{ {
@ -10,9 +10,9 @@ in
# hardcode .config because pijul doesn't support XDG (yet?) # hardcode .config because pijul doesn't support XDG (yet?)
".config/pijul/config.toml".source = tomlFormat.generate "pijul-config" { ".config/pijul/config.toml".source = tomlFormat.generate "pijul-config" {
author = { author = {
name = me; name = me.username;
full_name = me'.name; full_name = me.name;
inherit (me') email; inherit (me) email;
}; };
}; };
}; };

9
me/config.nix Normal file
View File

@ -0,0 +1,9 @@
{
name = "sloane ess";
username = "sloane";
email = "sloane@sloane.lol";
sshKeys = [
# secretive
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKTVoMVtHSvosU9SCam4S5RTP0R2V09vqw5Xiuff+x4J7NtUxsBhqIrkPSfJHSbYlBKITX5RFyFBo5mtsTa95v0= sloane"
];
}

33
me/default.nix Normal file
View File

@ -0,0 +1,33 @@
{ lib, ... }:
let
userSubmodule = lib.types.submodule {
options = {
name = lib.mkOption {
type = lib.types.str;
description = ''
full name
'';
};
username = lib.mkOption {
type = lib.types.str;
description = ''
user account name
'';
};
email = lib.mkOption { type = lib.types.str; };
sshKeys = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = ''
SSH public keys
'';
};
};
};
in
{
options.me = lib.mkOption { type = userSubmodule; };
# TODO: currently multiplexing this on the work branch
# how can we vary the config username based on the hostname?
# e.g. https://github.com/srid/nixos-flake/discussions/22#discussioncomment-5909499
config.me = import ./config.nix;
}

View File

@ -8,15 +8,15 @@
home = home =
let let
inherit (config.users) me; inherit (config.me) username;
in in
{ {
home-manager.users.${me} = { home-manager.users.${username} = {
imports = [ self.homeModules.linux ]; imports = [ self.homeModules.linux ];
}; };
users.users.${me} = { users.users.${username} = {
name = me; name = username;
home = "/home/${me}"; home = "/home/${username}";
isNormalUser = true; isNormalUser = true;
}; };
}; };

View File

@ -42,7 +42,7 @@
# wipe out the registry for purity, cf. https://github.com/MatthewCroughan/nixcfg/commit/ce86bee2755127a4fdaca91e5e037d3fe625cba9 # wipe out the registry for purity, cf. https://github.com/MatthewCroughan/nixcfg/commit/ce86bee2755127a4fdaca91e5e037d3fe625cba9
flake-registry = builtins.toFile "empty-flake-registry.json" ''{"flakes":[],"version":2}''; flake-registry = builtins.toFile "empty-flake-registry.json" ''{"flakes":[],"version":2}'';
trusted-users = [ trusted-users = [
flake.config.users.me flake.config.me.username
"root" "root"
"@admin" "@admin"
"@wheel" "@wheel"

View File

@ -3,11 +3,11 @@
# remote access # remote access
users.users = users.users =
let let
inherit (flake.config.users) me me'; inherit (flake.config) me;
myKeys = me'.sshKeys; myKeys = me.sshKeys;
in in
{ {
root.openssh.authorizedKeys.keys = myKeys; root.openssh.authorizedKeys.keys = myKeys;
${me}.openssh.authorizedKeys.keys = myKeys; ${me.username}.openssh.authorizedKeys.keys = myKeys;
}; };
} }

View File

@ -1,24 +0,0 @@
{
me = "sloane";
users = {
sloane = {
name = "sloane ess";
username = "sloane";
email = "sloane@sloane.lol";
sshKeys = [
# secretive
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBKTVoMVtHSvosU9SCam4S5RTP0R2V09vqw5Xiuff+x4J7NtUxsBhqIrkPSfJHSbYlBKITX5RFyFBo5mtsTa95v0= sloane"
];
};
sloane-work = {
name = "Sloane Ess";
username = "sloane";
email = "sloane@yelp.com";
sshKeys = [
# secretive
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBLWD/lvxFOdmE48MUKdigYZOAc3bSIyPxW4M7frWe8Nks9cr58Z/1btvUUmAK+u+J6gw5g+Mt9X0uwR7KPQlavg= sloane"
"ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBOkqyHm9fBDXChdmNgbhxd2U1IpkiD4xjC8AVOvil+uEeKYqDi5mF3oeAGYJrV6BRc7hEO+DQP60pN0wI5tMoYE= yelp"
];
};
};
}

View File

@ -1,55 +0,0 @@
{ config, lib, ... }:
let
userSubmodule = lib.types.submodule {
options = {
name = lib.mkOption {
type = lib.types.str;
description = ''
full name
'';
};
username = lib.mkOption {
type = lib.types.str;
description = ''
user account name
'';
};
email = lib.mkOption { type = lib.types.str; };
sshKeys = lib.mkOption {
type = lib.types.listOf lib.types.str;
description = ''
SSH public keys
'';
};
};
};
usersSubmodule = lib.types.submodule {
options = {
users = lib.mkOption { type = lib.types.attrsOf userSubmodule; };
me = lib.mkOption {
type = lib.types.str;
description = ''
The name of the user that represents me.
Admin user in all contexts.
Should be a key into the `users` attribute set.
'';
};
me' = lib.mkOption {
type = userSubmodule;
description = ''
The rest of the user data for `me`.
'';
readOnly = true;
};
};
};
in
{
# TODO: can we hack in an assertion that `me` is a key in `users`?
options.users = lib.mkOption { type = usersSubmodule; };
config.users = (import ./config.nix) // {
me' = lib.mkDefault config.users.users.${config.users.me};
};
}