save progress

This commit is contained in:
2025-01-07 19:17:44 -05:00
parent 20a02e8cab
commit 5badd8e774
6 changed files with 142 additions and 93 deletions

173
flake.nix
View File

@@ -1,11 +1,17 @@
{ {
description = "Example Darwin system flake"; description = "Example multi-host, multi-user Darwin system flake with hostVars/userVars, using let-bindings and strict commas";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
nix-darwin.url = "github:LnL7/nix-darwin"; nix-darwin.url = "github:LnL7/nix-darwin";
nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; nix-darwin.inputs.nixpkgs.follows = "nixpkgs";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew"; nix-homebrew.url = "github:zhaofengli-wip/nix-homebrew";
homebrew-core = { homebrew-core = {
url = "github:homebrew/homebrew-core"; url = "github:homebrew/homebrew-core";
@@ -19,80 +25,79 @@
url = "github:homebrew/homebrew-bundle"; url = "github:homebrew/homebrew-bundle";
flake = false; flake = false;
}; };
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = inputs@{ self, nix-darwin, nix-homebrew, home-manager, ... }: outputs = inputs@{ self, nix-darwin, home-manager, ... }:
let let
username = "stephen"; ###################################
# 1. Host variables
###################################
hostVars = {
host1 = {
hostname = "swaphb-mba"; hostname = "swaphb-mba";
arch = "aarch64-darwin";
};
host2 = {
hostname = "example";
arch = "aarch64-darwin";
};
};
###################################
# 2. User variables
###################################
userVars = {
userA = {
username = "stephen";
homeDirectory = "/Users/stephen";
shell = "zsh";
};
userB = {
username = "example";
homeDirectory = "/Users/example";
shell = "fish";
};
};
###################################
# 3. Base Darwin config function
###################################
baseDarwinConfig = hostKey:
{ config, pkgs, ... }:
{
nixpkgs.hostPlatform = hostVars.${hostKey}.arch;
# Minimal Darwin system config (minus environment.systemPackages/services)
configuration = { pkgs, lib, inputs, ... }: {
# Some general Darwin/Nix configuration
nix.extraOptions = '' nix.extraOptions = ''
experimental-features = nix-command flakes experimental-features = nix-command flakes
''; '';
# This can stay here or move to modules/darwin/services.nix
# services.nix-daemon.enable = true;
# Enable the nix-darwin module system.
nix.package = pkgs.nix; nix.package = pkgs.nix;
# Necessary for using flakes on this system.
nix.settings.experimental-features = "nix-command flakes"; nix.settings.experimental-features = "nix-command flakes";
# zsh, fish, etc.
programs.zsh.enable = true;
programs.bash.interactiveShellInit = ''
source /home/${username}/.config/op/plugins.sh
'';
system.configurationRevision = self.rev or self.dirtyRev or null; system.configurationRevision = self.rev or self.dirtyRev or null;
system.defaults = { nixpkgs.config.allowUnfree = true;
# ... nixpkgs.config.allowBroken = true;
};
system.stateVersion = 4;
nixpkgs.hostPlatform = "aarch64-darwin";
nixpkgs.config = {
allowUnfree = true;
allowBroken = true;
};
};
# Minimal home-manager config (minus dotfiles)
homeconfig = { pkgs, lib, ... }: {
home.stateVersion = "24.05";
programs.home-manager.enable = true;
home.packages = with pkgs; [ ];
home.sessionVariables = {
EDITOR = "nano";
};
home.homeDirectory = lib.mkForce "/Users/${username}";
}; };
in in
{ {
darwinConfigurations."${hostname}" = nix-darwin.lib.darwinSystem { ###################################
modules = # 4. Host 1: swaphb-mba
[ ###################################
# Main Darwin config darwinConfigurations."${hostVars.host1.hostname}" = let
configuration host1Base = baseDarwinConfig "host1";
in
# The official nix-homebrew module from your flake inputs nix-darwin.lib.darwinSystem {
nix-homebrew.darwinModules.nix-homebrew modules = [
host1Base,
./modules/darwin/homebrew.nix,
./modules/darwin/services.nix,
./modules/darwin/nixpackages.nix,
inputs.nix-homebrew.darwinModules.nix-homebrew,
{ {
nix-homebrew = { nix-homebrew = {
enable = true; enable = true;
enableRosetta = true; enableRosetta = true;
user = "${username}"; user = userVars.userA.username;
taps = { taps = {
"homebrew/homebrew-core" = inputs.homebrew-core; "homebrew/homebrew-core" = inputs.homebrew-core;
"homebrew/homebrew-cask" = inputs.homebrew-cask; "homebrew/homebrew-cask" = inputs.homebrew-cask;
@@ -101,29 +106,59 @@
autoMigrate = true; autoMigrate = true;
mutableTaps = false; mutableTaps = false;
}; };
} },
home-manager.darwinModules.home-manager {
# Our own modules for Darwin-level configs
./modules/darwin/homebrew.nix
./modules/darwin/nixpackages.nix
./modules/darwin/services.nix
# Home Manager
home-manager.darwinModules.home-manager
{
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
home-manager.verbose = true; home-manager.verbose = true;
home-manager.users.${username} = {
home-manager.users.${userVars.userA.username} = {
home.homeDirectory = userVars.userA.homeDirectory;
programs.zsh.enable = (userVars.userA.shell == "zsh");
programs.fish.enable = (userVars.userA.shell == "fish");
imports = [ imports = [
homeconfig ./modules/home/${userVars.userA.username}/dotfiles.nix
./modules/home/dotfiles.nix
]; ];
}; };
} }
]; ];
}; };
darwinPackages = self.darwinConfigurations."${hostname}".pkgs; ###################################
# 5. Host 2: example
###################################
darwinConfigurations."${hostVars.host2.hostname}" = let
host2Base = baseDarwinConfig "host2";
in
nix-darwin.lib.darwinSystem {
modules = [
host2Base,
./modules/darwin/homebrew.nix,
./modules/darwin/services.nix,
./modules/darwin/nixpackages.nix,
home-manager.darwinModules.home-manager {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.verbose = true;
home-manager.users.${userVars.userB.username} = {
home.homeDirectory = userVars.userB.homeDirectory;
programs.zsh.enable = (userVars.userB.shell == "zsh");
programs.fish.enable = (userVars.userB.shell == "fish");
imports = [
./modules/home/${userVars.userB.username}/dotfiles.nix
];
}; };
} }
];
};
###################################
# 6. (Optional) Expose packages
###################################
darwinPackages = {
"${hostVars.host1.hostname}" = self.darwinConfigurations."${hostVars.host1.hostname}".pkgs;
"${hostVars.host2.hostname}" = self.darwinConfigurations."${hostVars.host2.hostname}".pkgs;
};
}
}

View File

@@ -21,6 +21,7 @@
"teleport-connect" "teleport-connect"
"utm" "utm"
"localsend" "localsend"
"joplin"
]; ];
masApps = { masApps = {
"1Password for Safari" = 1569813296; "1Password for Safari" = 1569813296;

View File

View File

@@ -0,0 +1,13 @@
{ config, pkgs, lib, ... }:
{
home.file.".gitconfig".text = ''
[user]
name = "User B"
email = "userA@example.com"
'';
home.file.".zshrc".text = ''
# userA's custom zsh config
'';
}

View File