Skip to content

Commit 85b8fb9

Browse files
Add multi-user support for different machines (#208)
## Summary - Add per-host `username` option allowing different usernames per machine - Create work machine host config (`CB14957.local`) with username `cohnesor` - Update all modules to use dynamic username from `myconfig.constants.username` - Update standalone home-manager configs to accept username as argument ## Changes - `modules/config/hosts.nix` - Added `username` option with default - `modules/config/constants.nix` - Username derives from host config - `modules/config/user.nix` - Fixed hardcoded usernames - `modules/features/engineer.nix` - Dynamic NordVPN users and nh flake path - `hosts/mac-nix/default.nix` - Uses dynamic username pattern - `hosts/CB14957.local/default.nix` - New work machine config - `.config/home-manager/*` - Updated to support multiple users ## Usage ```bash # Personal machines (use default username) darwin-rebuild switch --flake .#Conners-MacBook-Air # Work machine darwin-rebuild switch --flake .#CB14957.local ``` ## Test plan - [ ] Verify `nix flake check` passes - [ ] Test rebuild on personal machine - [ ] Test rebuild on work machine <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added browser integration with selectable extensions and a new browser input for home configurations. * Introduced a firefox-addons input and applied its overlay across platforms. * **Chores** * Extended system configuration support for additional macOS and Linux hosts. * Made user/home settings configurable per-host (dynamic usernames and platform-specific home paths). * Centralized and parameterized user-related options for flexible multi-machine deployments. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> ---------
1 parent 5e934cc commit 85b8fb9

13 files changed

Lines changed: 250 additions & 70 deletions

File tree

.config/home-manager/flake.nix

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
description = "Home Manager configuration of connerohnesorge";
2+
description = "Home Manager configuration";
33

44
inputs = {
55
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
@@ -17,17 +17,38 @@
1717
...
1818
}: {
1919
homeConfigurations = {
20-
# macOS configuration
20+
# Personal macOS configuration
2121
"connerohnesorge@Conners-MacBook-Air.local" = home-manager.lib.homeManagerConfiguration {
22-
pkgs = nixpkgs.legacyPackages.aarch64-darwin; # Assuming M1/M2 Mac, use x86_64-darwin for Intel
22+
pkgs = nixpkgs.legacyPackages.aarch64-darwin;
23+
extraSpecialArgs = {username = "connerohnesorge";};
2324
modules = [
2425
./home-darwin.nix
2526
];
2627
};
2728

28-
# Linux configuration
29+
# Work macOS configuration
30+
"cohnesor@CB14957.local" = home-manager.lib.homeManagerConfiguration {
31+
pkgs = nixpkgs.legacyPackages.aarch64-darwin;
32+
extraSpecialArgs = {username = "cohnesor";};
33+
modules = [
34+
./home-darwin.nix
35+
];
36+
};
37+
38+
# Personal Linux configuration
2939
"connerohnesorge" = home-manager.lib.homeManagerConfiguration {
3040
pkgs = nixpkgs.legacyPackages.x86_64-linux;
41+
extraSpecialArgs = {username = "connerohnesorge";};
42+
modules = [
43+
stylix.homeManagerModules.stylix
44+
./home.nix
45+
];
46+
};
47+
48+
# Work Linux configuration (if needed)
49+
"cohnesor" = home-manager.lib.homeManagerConfiguration {
50+
pkgs = nixpkgs.legacyPackages.x86_64-linux;
51+
extraSpecialArgs = {username = "cohnesor";};
3152
modules = [
3253
stylix.homeManagerModules.stylix
3354
./home.nix

.config/home-manager/home-darwin.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
config,
33
pkgs,
44
lib,
5+
username ? "connerohnesorge",
56
...
67
}: {
78
home = {
8-
username = "connerohnesorge";
9-
homeDirectory = "/home/connerohnesorge";
9+
inherit username;
10+
homeDirectory = "/Users/${username}";
1011

1112
# You should not change this value, even if you update Home Manager. If you do
1213
# want to update the value, then make sure to first check the Home Manager

.config/home-manager/home.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
pkgs,
44
lib,
55
stylix,
6+
username ? "connerohnesorge",
67
...
78
}: {
89
home = {
9-
username = "connerohnesorge";
10-
homeDirectory = "/home/connerohnesorge";
10+
inherit username;
11+
homeDirectory = "/home/${username}";
1112

1213
# You should not change this value, even if you update Home Manager. If you do
1314
# want to update the value, then make sure to first check the Home Manager

flake.lock

Lines changed: 34 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@
33

44
inputs = {
55
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6-
zen-browser.url = "github:connerohnesorge/zen-browser-flake";
6+
zen-browser = {
7+
url = "github:0xc000022070/zen-browser-flake";
8+
inputs.nixpkgs.follows = "nixpkgs";
9+
inputs.home-manager.follows = "home-manager";
10+
};
11+
12+
firefox-addons = {
13+
url = "github:connerohnesorge/nur-expressions?dir=pkgs/firefox-addons";
14+
inputs.nixpkgs.follows = "nixpkgs";
15+
};
16+
717
proton-authenticator.url = "github:connerohnesorge/proton-authenticator-flake?ref=0494e1b70724861b4f8e2fb314b744e0591dfbb5";
818
proton-authenticator.inputs.nixpkgs.follows = "nixpkgs";
919

@@ -141,7 +151,8 @@
141151
flake = let
142152
mkConfigurations = moduleSystem:
143153
denix.lib.configurations {
144-
homeManagerUser = "connerohnesorge";
154+
# homeManagerUser is set dynamically per-host via myconfig.host.username
155+
# See modules/config/constants.nix and modules/config/home.nix
145156
inherit moduleSystem;
146157

147158
paths = [./hosts ./modules ./rices];

hosts/CB14957.local/default.nix

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{
2+
delib,
3+
inputs,
4+
pkgs,
5+
config,
6+
lib,
7+
...
8+
}: let
9+
system = "aarch64-darwin";
10+
in
11+
delib.host {
12+
name = "CB14957.local";
13+
14+
# Work machine username
15+
username = "cohnesor";
16+
17+
rice = "empty";
18+
type = "laptop";
19+
20+
home.home.stateVersion = "24.11";
21+
homeManagerSystem = system;
22+
23+
myconfig = {
24+
features = {
25+
engineer.enable = true;
26+
};
27+
programs = {
28+
dx.enable = true;
29+
catls.enable = true;
30+
convert_img.enable = true;
31+
};
32+
};
33+
34+
nixos = {
35+
imports = [
36+
inputs.determinate.nixosModules.default
37+
];
38+
nixpkgs.hostPlatform = "x86_64-linux";
39+
nixpkgs.config.allowUnfree = true;
40+
nixpkgs.config.allowUnsupportedSystem = true;
41+
system.stateVersion = "24.11";
42+
43+
# Minimal file system configuration to prevent assertion failures
44+
fileSystems."/" = {
45+
device = "/dev/disk/by-label/nixos";
46+
fsType = "ext4";
47+
};
48+
49+
boot.loader.systemd-boot.enable = true;
50+
boot.loader.efi.canTouchEfiVariables = true;
51+
};
52+
53+
darwin = {myconfig, ...}: {
54+
imports = [
55+
# inputs.determinate.darwinModules.default
56+
];
57+
58+
nixpkgs = {
59+
hostPlatform = system;
60+
config.allowUnfree = true;
61+
};
62+
nix.enable = false;
63+
programs = {
64+
direnv = {
65+
enable = true;
66+
nix-direnv = {
67+
enable = true;
68+
package = pkgs.nix-direnv;
69+
};
70+
};
71+
ssh = {
72+
extraConfig = ''
73+
SetEnv TERM=xterm-256color
74+
'';
75+
};
76+
};
77+
system = {
78+
stateVersion = 5;
79+
primaryUser = myconfig.constants.username;
80+
defaults = {
81+
dock.autohide = true;
82+
83+
trackpad = {
84+
Clicking = true;
85+
TrackpadThreeFingerDrag = true;
86+
Dragging = true;
87+
};
88+
};
89+
};
90+
91+
environment = {
92+
systemPackages = [
93+
# Macos Only
94+
pkgs.aerospace
95+
pkgs.raycast
96+
pkgs.xcodes
97+
# Shared
98+
];
99+
shells = [pkgs.zsh];
100+
101+
pathsToLink = ["/share/qemu"];
102+
etc."containers/containers.conf.d/99-gvproxy-path.conf".text = ''
103+
[engine]
104+
helper_binaries_dir = ["${pkgs.gvproxy}/bin"]
105+
'';
106+
};
107+
users.users.${myconfig.constants.username} = {
108+
home = "/Users/${myconfig.constants.username}";
109+
};
110+
111+
security.pam.services.sudo_local.touchIdAuth = true;
112+
};
113+
}

hosts/mac-nix/default.nix

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ in
4646
boot.loader.efi.canTouchEfiVariables = true;
4747
};
4848

49-
darwin = {
49+
darwin = {myconfig, ...}: {
5050
imports = [
5151
# inputs.determinate.darwinModules.default
5252
];
@@ -73,7 +73,7 @@ in
7373
};
7474
system = {
7575
stateVersion = 5;
76-
primaryUser = "connerohnesorge";
76+
primaryUser = myconfig.constants.username;
7777
defaults = {
7878
dock.autohide = true;
7979

@@ -101,8 +101,8 @@ in
101101
helper_binaries_dir = ["${pkgs.gvproxy}/bin"]
102102
'';
103103
};
104-
users.users.connerohnesorge = {
105-
home = "/Users/connerohnesorge";
104+
users.users.${myconfig.constants.username} = {
105+
home = "/Users/${myconfig.constants.username}";
106106
};
107107

108108
security.pam.services.sudo_local.touchIdAuth = true;

modules/config/constants.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ delib.module {
1616
name = "constants";
1717

1818
options.constants = with delib; {
19-
# Primary username for the system (used for account creation and home directory)
20-
username = readOnly (strOption "connerohnesorge");
19+
# Primary username for the system (derived from host configuration)
20+
# This allows different usernames per machine (e.g., "connerohnesorge" locally, "cohnesor" at work)
21+
username = strOption "connerohnesorge";
2122

2223
# Full display name for the user (used in Git commits and system identification)
2324
userfullname = readOnly (strOption "Conner Ohnesorge");
2425

2526
# Primary email address (used for Git commits, SSH keys, and notifications)
2627
useremail = readOnly (strOption "connerohnesorge@outlook.com");
2728
};
29+
30+
# Derive username from host configuration
31+
myconfig.always = {myconfig, ...}: {
32+
constants.username = myconfig.host.username;
33+
};
2834
}

0 commit comments

Comments
 (0)