refactor: simplify 'user' options

This commit is contained in:
2026-04-21 13:59:03 +02:00
parent 38818e7508
commit 6a30a431f8
24 changed files with 94 additions and 139 deletions

View File

@@ -12,7 +12,7 @@ let
imports = [ ../hosts/${hostname} ];
deployment = {
targetHost = self.nixosConfigurations.${hostname}.config.ssh.publicHostname;
targetUser = self.nixosConfigurations.${hostname}.config.ssh.username;
targetUser = self.nixosConfigurations.${hostname}.config.host.username;
buildOnTarget = builtins.any (t: t != "local" && t != "arm") tags;
inherit tags;
};

View File

@@ -5,9 +5,6 @@
...
}:
let
username = "hektor";
in
{
imports = [
inputs.sops-nix.homeManagerModules.sops
@@ -57,8 +54,8 @@ in
home = {
stateVersion = "25.05";
inherit username;
homeDirectory = "/home/${username}";
username = "hektor";
homeDirectory = "/home/${config.home.username}";
};
targets.genericLinux.nixGL = {

View File

@@ -6,13 +6,19 @@
}:
{
options.nixgl.wrap = lib.mkOption {
options = {
host.username = lib.mkOption {
type = lib.types.str;
default = config.home.username;
};
nixgl.wrap = lib.mkOption {
type = lib.types.functionTo lib.types.package;
default = if config.lib ? nixGL then config.lib.nixGL.wrap else lib.id;
readOnly = true;
};
options.wrapApp = lib.mkOption {
wrapApp = lib.mkOption {
type = lib.types.raw;
default =
pkg: flags:
@@ -27,4 +33,5 @@
pkg;
readOnly = true;
};
};
}

View File

@@ -51,31 +51,17 @@ in
../../modules/yubikey
];
home-manager.users.${config.host.username} = import ../../home/hosts/andromache {
inherit
inputs
config
pkgs
lib
;
};
home-manager.users.${config.host.username} = import ../../home/hosts/andromache;
ssh.username = config.host.username;
ssh.authorizedHosts = [ "astyanax" ];
secrets = {
inherit (config.host) username;
nixSigningKey.enable = true;
};
secrets.nixSigningKey.enable = true;
tailscale.enable = true;
docker.user = config.host.username;
docker.enable = true;
hcloud = {
enable = true;
inherit (config.host) username;
};
hcloud.enable = true;
disko.devices = {
disk.data = {
@@ -107,7 +93,6 @@ in
my.yubikey = {
enable = false;
inherit (config.host) username;
keys = [
{
handle = "<KeyHandle1>";

View File

@@ -47,26 +47,15 @@ in
../../modules/yubikey
];
home-manager.users.${config.host.username} = import ../../home/hosts/astyanax {
inherit
inputs
config
pkgs
lib
;
};
home-manager.users.${config.host.username} = import ../../home/hosts/astyanax;
ssh.username = config.host.username;
ssh.authorizedHosts = [ "andromache" ];
secrets = {
inherit (config.host) username;
nixSigningKey.enable = true;
};
secrets.nixSigningKey.enable = true;
tailscale.enable = true;
docker.user = config.host.username;
nfc.user = config.host.username;
docker.enable = true;
nfc.enable = true;
desktop.ly.enable = true;
audio.automation.enable = true;

View File

@@ -12,7 +12,6 @@
];
ssh = {
inherit (config.host) username;
publicHostname = config.host.name;
authorizedHosts = [
"andromache"

View File

@@ -13,7 +13,6 @@
];
ssh = {
inherit (config.host) username;
publicHostname = config.host.name;
authorizedHosts = [
"andromache"

View File

@@ -19,7 +19,6 @@
networking.hostName = config.host.name;
ssh = {
inherit (config.host) username;
publicHostname = "server.hektormisplon.xyz";
authorizedHosts = [
"andromache"
@@ -27,7 +26,7 @@
];
};
docker.user = config.host.username;
docker.enable = true;
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";

View File

@@ -1,7 +1,6 @@
{
inputs,
config,
pkgs,
...
}:
{
@@ -29,13 +28,7 @@
../../modules/x
];
home-manager.users.${config.host.username} = import ../../home/hosts/vm {
inherit inputs config pkgs;
};
ssh.username = config.host.username;
secrets.username = config.host.username;
home-manager.users.${config.host.username} = import ../../home/hosts/vm;
disko = {
devices.disk.main = {

View File

@@ -12,10 +12,15 @@ let
in
{
imports = [
../modules/common/host.nix
../modules/ssh
];
ssh.username = username;
host = {
inherit username;
name = "orange-pi";
};
ssh.authorizedHosts = [
"andromache"
"astyanax"

View File

@@ -12,10 +12,15 @@ let
in
{
imports = [
../modules/common/host.nix
../modules/ssh
];
ssh.username = username;
host = {
inherit username;
name = "raspberry-pi";
};
ssh.authorizedHosts = [
"andromache"
"astyanax"

View File

@@ -1,7 +1,8 @@
{ config, myUtils, ... }:
let
inherit (config.secrets) sopsDir username;
inherit (config.secrets) sopsDir;
inherit (config.host) username;
owner = config.users.users.${username}.name;
in
{

View File

@@ -1,7 +1,8 @@
{ config, myUtils, ... }:
let
inherit (config.secrets) sopsDir username;
inherit (config.secrets) sopsDir;
inherit (config.host) username;
owner = config.users.users.${username}.name;
in
{

View File

@@ -73,6 +73,11 @@ in
myUtils
;
};
sharedModules = [
{
host.username = lib.mkDefault config.host.username;
}
];
};
};
}

View File

@@ -2,29 +2,17 @@
let
cfg = config.docker;
inherit (config.host) username;
in
{
options.docker = {
enable = lib.mkEnableOption "docker";
rootless = lib.mkOption {
type = lib.types.bool;
default = false;
};
user = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
};
config = lib.mkMerge [
{
warnings = lib.flatten [
(lib.optional (
cfg.rootless && cfg.user != null
) "'virtualisation.docker.user' is ignored when rootless mode is enabled")
(lib.optional (
!cfg.rootless && cfg.user == null
) "'virtualisation.docker.user' is not set (no user is added to the docker group)")
];
}
(lib.mkIf cfg.rootless {
virtualisation.docker = {
enable = false;
@@ -34,11 +22,9 @@ in
};
};
})
(lib.mkIf (!cfg.rootless && cfg.user != null) {
virtualisation.docker = {
enable = true;
};
users.users.${cfg.user}.extraGroups = [ "docker" ];
(lib.mkIf (cfg.enable && !cfg.rootless) {
virtualisation.docker.enable = true;
users.users.${username}.extraGroups = [ "docker" ];
})
];
}

View File

@@ -4,7 +4,7 @@
}:
let
inherit (config.secrets) username;
inherit (config.host) username;
owner = config.users.users.${username}.name;
in
{

View File

@@ -7,25 +7,22 @@
let
cfg = config.hcloud;
inherit (config.host) username;
inherit (config.secrets) sopsDir;
in
{
options.hcloud = {
enable = lib.mkEnableOption "hcloud CLI configuration";
username = lib.mkOption {
type = lib.types.str;
description = "Username for hcloud CLI configuration";
};
};
config = lib.mkIf cfg.enable {
sops.secrets = myUtils.mkSopsSecrets sopsDir "hcloud" [ "api-token" ] {
owner = config.users.users.${cfg.username}.name;
owner = config.users.users.${username}.name;
};
sops.templates."hcloud/cli.toml" = {
owner = config.users.users.${cfg.username}.name;
path = "/home/${cfg.username}/.config/hcloud/cli.toml";
owner = config.users.users.${username}.name;
path = "/home/${username}/.config/hcloud/cli.toml";
content = ''
active_context = "server"

View File

@@ -2,15 +2,13 @@
let
cfg = config.nfc;
inherit (config.host) username;
in
{
options.nfc = {
user = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
enable = lib.mkEnableOption "NFC device access";
};
};
config = lib.mkIf (cfg.user != null) {
users.users.${cfg.user}.extraGroups = [ "dialout" ];
config = lib.mkIf cfg.enable {
users.users.${username}.extraGroups = [ "dialout" ];
};
}

View File

@@ -9,8 +9,9 @@
let
cfg = config.secrets;
inherit (config.host) username;
inherit (cfg) sopsDir;
owner = config.users.users.${cfg.username}.name;
owner = config.users.users.${username}.name;
mkSopsSecrets = myUtils.mkSopsSecrets sopsDir;
in
{
@@ -18,10 +19,6 @@ in
options = {
secrets = {
username = lib.mkOption {
type = lib.types.str;
};
sopsDir = lib.mkOption {
type = lib.types.str;
default = "${toString inputs.nix-secrets}/secrets";
@@ -43,7 +40,7 @@ in
# ```
# age-plugin-yubikey --identity > <keyfile-path>
# ```
age.keyFile = "/home/${cfg.username}/.config/sops/age/keys.txt";
age.keyFile = "/home/${username}/.config/sops/age/keys.txt";
secrets = lib.mkMerge [
(mkSopsSecrets "email" [ "personal" "work" ] { inherit owner; })

View File

@@ -1,14 +1,14 @@
{ lib, config, ... }:
let
inherit (config.host) username;
in
{
options.ssh = {
authorizedHosts = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
};
username = lib.mkOption {
type = lib.types.str;
default = "h";
};
publicHostname = lib.mkOption {
type = lib.types.str;
default = "";
@@ -16,7 +16,7 @@
};
# auto generate authorized_keys from `authorizedHosts`
config.users.users.${config.ssh.username}.openssh.authorizedKeys.keys = lib.flatten (
config.users.users.${username}.openssh.authorizedKeys.keys = lib.flatten (
map (
hostname:
let

View File

@@ -1,6 +1,6 @@
{ lib, config, ... }:
let
inherit (config.ssh) username;
inherit (config.host) username;
in
{
# auto extract SSH keys

View File

@@ -7,23 +7,18 @@
with lib;
let
cfg = config.my.syncthing;
inherit (config.host) username;
in
{
options.my.syncthing.username = mkOption {
type = types.str;
default = "h";
};
config = {
users.groups.${cfg.username} = { };
users.users.${cfg.username}.extraGroups = [ cfg.username ];
users.groups.${username} = { };
users.users.${username}.extraGroups = [ username ];
services.syncthing = {
enable = true;
user = cfg.username;
group = cfg.username;
configDir = "/home/${cfg.username}/.local/state/syncthing";
user = username;
group = username;
configDir = "/home/${username}/.local/state/syncthing";
openDefaultPorts = true;
};
};

View File

@@ -1,7 +1,8 @@
{ config, myUtils, ... }:
let
inherit (config.secrets) sopsDir username;
inherit (config.secrets) sopsDir;
inherit (config.host) username;
owner = config.users.users.${username}.name;
in
{

View File

@@ -9,18 +9,14 @@ with lib;
let
cfg = config.my.yubikey;
inherit (config.host) username;
formatKey = key: ":${key.handle},${key.userKey},${key.coseType},${key.options}";
authfileContent = username: keys: username + lib.concatMapStrings formatKey keys;
authfileContent = u: keys: u + lib.concatMapStrings formatKey keys;
in
{
options.my.yubikey = {
enable = mkEnableOption "yubiKey U2F authentication";
username = mkOption {
type = types.str;
default = "h";
};
origin = mkOption {
type = types.str;
default = "pam://yubi";
@@ -61,7 +57,7 @@ in
interactive = true;
cue = true;
inherit (cfg) origin;
authfile = pkgs.writeText "u2f-mappings" (authfileContent cfg.username cfg.keys);
authfile = pkgs.writeText "u2f-mappings" (authfileContent username cfg.keys);
};
};
services = {