refactor: reduce duplication and improve consistency across hosts

- Centralize home-manager _module.args in profiles/nixos.nix via sharedModules
- Add lib/secrets.nix with mkSyncthingSecrets helper for DRY secret definitions
- Move syncthing device IDs to lib/constants.nix
- Standardize hostname handling (Darwin hosts now use hostname arg)
- Add missing networking.hostName to tahani
- Fix redundant string interpolations
This commit is contained in:
2025-12-23 14:13:47 +00:00
parent 4f93e60f3c
commit 1d8a0c660c
14 changed files with 95 additions and 85 deletions

View File

@@ -2,7 +2,7 @@
inputs, inputs,
pkgs, pkgs,
user, user,
constants, hostname,
... ...
}: { }: {
imports = [ imports = [
@@ -18,8 +18,8 @@
inputs.sops-nix.darwinModules.sops inputs.sops-nix.darwinModules.sops
]; ];
networking.hostName = "chidi"; networking.hostName = hostname;
networking.computerName = "Chidi"; networking.computerName = hostname;
home-manager.users.${user} = { home-manager.users.${user} = {
imports = [ imports = [

View File

@@ -1,18 +1,14 @@
{user, ...}: { {
user,
hostname,
...
}: let
secrets = import ../../lib/secrets.nix;
in {
sops.age.keyFile = "/Users/${user}/.config/sops/age/keys.txt"; sops.age.keyFile = "/Users/${user}/.config/sops/age/keys.txt";
sops.secrets = { sops.secrets = secrets.mkSyncthingSecrets {
chidi-syncthing-cert = { inherit hostname user;
sopsFile = ../../secrets/chidi-syncthing-cert; isDarwin = true;
format = "binary";
owner = user;
path = "/Users/${user}/.config/syncthing/cert.pem";
};
chidi-syncthing-key = {
sopsFile = ../../secrets/chidi-syncthing-key;
format = "binary";
owner = user;
path = "/Users/${user}/.config/syncthing/key.pem";
};
}; };
} }

View File

@@ -1,6 +1,7 @@
{ {
inputs, inputs,
user, user,
hostname,
... ...
}: { }: {
imports = [ imports = [
@@ -16,8 +17,8 @@
inputs.sops-nix.darwinModules.sops inputs.sops-nix.darwinModules.sops
]; ];
networking.hostName = "jason"; networking.hostName = hostname;
networking.computerName = "Jason"; networking.computerName = hostname;
home-manager.users.${user} = { home-manager.users.${user} = {
imports = [ imports = [

View File

@@ -1,20 +1,16 @@
{user, ...}: { {
user,
hostname,
...
}: let
secrets = import ../../lib/secrets.nix;
in {
sops.age.keyFile = "/Users/${user}/.config/sops/age/keys.txt"; sops.age.keyFile = "/Users/${user}/.config/sops/age/keys.txt";
sops.age.sshKeyPaths = []; sops.age.sshKeyPaths = [];
sops.gnupg.sshKeyPaths = []; sops.gnupg.sshKeyPaths = [];
sops.secrets = { sops.secrets = secrets.mkSyncthingSecrets {
jason-syncthing-cert = { inherit hostname user;
sopsFile = ../../secrets/jason-syncthing-cert; isDarwin = true;
format = "binary";
owner = user;
path = "/Users/${user}/.config/syncthing/cert.pem";
};
jason-syncthing-key = {
sopsFile = ../../secrets/jason-syncthing-key;
format = "binary";
owner = user;
path = "/Users/${user}/.config/syncthing/key.pem";
};
}; };
} }

View File

@@ -3,7 +3,6 @@
hostname, hostname,
inputs, inputs,
user, user,
constants,
... ...
}: { }: {
imports = [ imports = [
@@ -23,11 +22,6 @@
]; ];
home-manager.users.${user} = { home-manager.users.${user} = {
pkgs,
lib,
...
}: {
_module.args = {inherit user constants inputs;};
imports = [ imports = [
inputs.nixvim.homeModules.nixvim inputs.nixvim.homeModules.nixvim
../../profiles/bash.nix ../../profiles/bash.nix

View File

@@ -3,7 +3,6 @@
hostname, hostname,
inputs, inputs,
user, user,
constants,
... ...
}: { }: {
imports = [ imports = [
@@ -25,11 +24,6 @@
]; ];
home-manager.users.${user} = { home-manager.users.${user} = {
pkgs,
lib,
...
}: {
_module.args = {inherit user constants inputs;};
imports = [ imports = [
inputs.nixvim.homeModules.nixvim inputs.nixvim.homeModules.nixvim
../../profiles/bash.nix ../../profiles/bash.nix

View File

@@ -2,7 +2,7 @@
inputs, inputs,
pkgs, pkgs,
user, user,
constants, hostname,
... ...
}: { }: {
imports = [ imports = [
@@ -20,11 +20,6 @@
]; ];
home-manager.users.${user} = { home-manager.users.${user} = {
pkgs,
lib,
...
}: {
_module.args = {inherit user constants inputs;};
imports = [ imports = [
inputs.nixvim.homeModules.nixvim inputs.nixvim.homeModules.nixvim
../../profiles/atuin.nix ../../profiles/atuin.nix
@@ -60,4 +55,6 @@
}; };
virtualisation.docker.enable = true; virtualisation.docker.enable = true;
networking.hostName = hostname;
} }

View File

@@ -1,17 +1,16 @@
{user, ...}: { {
sops.secrets = { user,
tahani-syncthing-cert = { hostname,
sopsFile = ../../secrets/tahani-syncthing-cert; ...
format = "binary"; }: let
owner = user; secrets = import ../../lib/secrets.nix;
path = "/home/${user}/.config/syncthing/cert.pem"; in {
}; sops.secrets =
tahani-syncthing-key = { secrets.mkSyncthingSecrets {
sopsFile = ../../secrets/tahani-syncthing-key; inherit hostname user;
format = "binary"; isDarwin = false;
owner = user; }
path = "/home/${user}/.config/syncthing/key.pem"; // {
};
tahani-paperless-password = { tahani-paperless-password = {
sopsFile = ../../secrets/tahani-paperless-password; sopsFile = ../../secrets/tahani-paperless-password;
format = "binary"; format = "binary";

View File

@@ -11,4 +11,10 @@
nixos = "25.11"; nixos = "25.11";
homeManager = "25.11"; homeManager = "25.11";
}; };
syncthingDeviceIds = {
tahani = "6B7OZZF-TEAMUGO-FBOELXP-Z4OY7EU-5ZHLB5T-V6Z3UDB-Q2DYR43-QBYW6QM";
jason = "42II2VO-QYPJG26-ZS3MB2I-AOPVZ67-JJNSE76-U54CO5Y-634A5OG-ECU4YQA";
chidi = "N7W6SUT-QO6J4BE-T3Y65SM-OFGYGNV-TGYBJPX-JVN4Z72-AENZ247-KWXOQA6";
};
} }

25
lib/secrets.nix Normal file
View File

@@ -0,0 +1,25 @@
{
mkSyncthingSecrets = {
hostname,
user,
isDarwin,
}: let
homeDir =
if isDarwin
then "/Users/${user}"
else "/home/${user}";
in {
"${hostname}-syncthing-cert" = {
sopsFile = ../secrets/${hostname}-syncthing-cert;
format = "binary";
owner = user;
path = "${homeDir}/.config/syncthing/cert.pem";
};
"${hostname}-syncthing-key" = {
sopsFile = ../secrets/${hostname}-syncthing-key;
format = "binary";
owner = user;
path = "${homeDir}/.config/syncthing/key.pem";
};
};
}

View File

@@ -53,7 +53,7 @@
}; };
users.users.${user} = { users.users.${user} = {
name = "${user}"; name = user;
home = "/Users/${user}"; home = "/Users/${user}";
isHidden = false; isHidden = false;
shell = pkgs.fish; shell = pkgs.fish;

View File

@@ -2,6 +2,7 @@
pkgs, pkgs,
user, user,
constants, constants,
inputs,
... ...
}: { }: {
security.sudo.enable = true; security.sudo.enable = true;
@@ -9,8 +10,12 @@
system.stateVersion = constants.stateVersions.nixos; system.stateVersion = constants.stateVersions.nixos;
time.timeZone = "UTC"; time.timeZone = "UTC";
home-manager.sharedModules = [
{_module.args = {inherit user constants inputs;};}
];
nix = { nix = {
settings.trusted-users = ["${user}"]; settings.trusted-users = [user];
gc.dates = "weekly"; gc.dates = "weekly";
nixPath = ["nixos-config=/home/${user}/.local/share/src/nixos-config:/etc/nixos"]; nixPath = ["nixos-config=/home/${user}/.local/share/src/nixos-config:/etc/nixos"];
}; };

View File

@@ -41,7 +41,6 @@
''; '';
}; };
}; };
# Antigravity Google models (for opencode-antigravity-auth plugin)
provider = { provider = {
google = { google = {
models = { models = {
@@ -128,10 +127,6 @@
}; };
}; };
# oh-my-opencode configuration
# - Disables built-in google_auth (using antigravity plugin instead)
# - Oracle uses Zen API (opencode/gpt-5.2) instead of ChatGPT subscription
# - Frontend/document/multimodal agents use Antigravity Gemini models
home.file.".config/opencode/oh-my-opencode.json".text = builtins.toJSON { home.file.".config/opencode/oh-my-opencode.json".text = builtins.toJSON {
"$schema" = "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json"; "$schema" = "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json";
google_auth = false; google_auth = false;

View File

@@ -1,6 +1,7 @@
{ {
user, user,
pkgs, pkgs,
constants,
... ...
}: let }: let
isDarwin = pkgs.stdenv.isDarwin; isDarwin = pkgs.stdenv.isDarwin;
@@ -12,36 +13,37 @@
if isDarwin if isDarwin
then "staff" then "staff"
else "users"; else "users";
deviceIds = constants.syncthingDeviceIds;
in { in {
services.syncthing = { services.syncthing = {
enable = true; enable = true;
openDefaultPorts = !isDarwin; openDefaultPorts = !isDarwin;
dataDir = "${homeDir}/.local/share/syncthing"; dataDir = "${homeDir}/.local/share/syncthing";
configDir = "${homeDir}/.config/syncthing"; configDir = "${homeDir}/.config/syncthing";
user = "${user}"; user = user;
group = group; inherit group;
guiAddress = "0.0.0.0:8384"; guiAddress = "0.0.0.0:8384";
overrideFolders = true; overrideFolders = true;
overrideDevices = true; overrideDevices = true;
settings = { settings = {
devices = { devices = {
"tahani" = { tahani = {
id = "6B7OZZF-TEAMUGO-FBOELXP-Z4OY7EU-5ZHLB5T-V6Z3UDB-Q2DYR43-QBYW6QM"; id = deviceIds.tahani;
addresses = ["tcp://tahani:22000"]; addresses = ["tcp://tahani:22000"];
}; };
"jason" = { jason = {
id = "42II2VO-QYPJG26-ZS3MB2I-AOPVZ67-JJNSE76-U54CO5Y-634A5OG-ECU4YQA"; id = deviceIds.jason;
addresses = ["tcp://jason:22000"]; addresses = ["tcp://jason:22000"];
}; };
"chidi" = { chidi = {
id = "N7W6SUT-QO6J4BE-T3Y65SM-OFGYGNV-TGYBJPX-JVN4Z72-AENZ247-KWXOQA6"; id = deviceIds.chidi;
addresses = ["tcp://chidi:22000"]; addresses = ["tcp://chidi:22000"];
}; };
}; };
folders = { folders = {
"nixos-config" = { nixos-config = {
path = "${homeDir}/nixos-config"; path = "${homeDir}/nixos-config";
devices = ["tahani" "jason" "chidi"]; devices = ["tahani" "jason" "chidi"];
}; };