decouple all config from host

This commit is contained in:
Niccolo Borgioli 2025-01-27 23:46:38 +01:00
parent 646aaeefe4
commit 9610667c25
7 changed files with 110 additions and 98 deletions

70
darwin.nix Normal file
View File

@ -0,0 +1,70 @@
{ flake }:
{ pkgs, host, ... }:
{
nix.settings.experimental-features = "nix-command flakes";
# Set Git commit hash for darwin-version.
system.configurationRevision = flake.rev or flake.dirtyRev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 5;
nixpkgs.hostPlatform = host.platform;
nixpkgs.config.allowUnfree = true;
# Nix Darwin
# https://daiderd.com/nix-darwin/manual/index.html
# Security
system.defaults.screensaver.askForPassword = true;
system.defaults.screensaver.askForPasswordDelay = 0;
system.defaults.loginwindow.GuestEnabled = false;
# Dock
system.defaults.dock.autohide = true;
system.defaults.dock.orientation = "left";
system.defaults.dock.show-recents = false;
system.defaults.dock.persistent-apps = [
"/Applications/Arc.app"
"/Applications/Ghostty.app"
"/Applications/VSCodium.app"
"/Applications/Spotify.app"
"/System/Applications/System Settings.app"
];
system.defaults.dock.persistent-others = [ ];
# Input devices
system.keyboard.enableKeyMapping = true;
system.keyboard.remapCapsLockToEscape = true;
system.defaults.NSGlobalDomain.InitialKeyRepeat = 25;
system.defaults.NSGlobalDomain.KeyRepeat = 2;
system.defaults.NSGlobalDomain."com.apple.mouse.tapBehavior" = 1;
system.defaults.NSGlobalDomain."com.apple.trackpad.scaling" = 0.875;
system.defaults.trackpad.Dragging = true;
# Finder
system.defaults.finder.AppleShowAllExtensions = true;
system.defaults.finder.ShowPathbar = true;
# Other
system.startup.chime = false;
users.users.${host.username} = {
home = "/Users/${host.username}";
shell = pkgs.fish;
};
programs.fish.enable = true;
homebrew = {
enable = true;
casks = import ./cask.nix;
taps = [ "lihaoyun6/tap" ];
onActivation = {
autoUpdate = true;
cleanup = "zap";
};
};
# Home Manager
home-manager.backupFileExtension = "backup";
}

121
flake.nix
View File

@ -1,5 +1,5 @@
{ {
description = "Example nix-darwin system flake"; description = "Personal Nix configuration";
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
@ -12,106 +12,41 @@
}; };
outputs = outputs =
inputs@{ {
self, self,
nix-darwin, nix-darwin,
nixpkgs, nixpkgs,
home-manager, home-manager,
}: }:
let let
name = "mbp";
hosts = import ./hosts; hosts = import ./hosts;
configuration = inherit (builtins) listToAttrs;
{ pkgs, ... }:
{
nix.settings.experimental-features = "nix-command flakes";
# Set Git commit hash for darwin-version.
system.configurationRevision = self.rev or self.dirtyRev or null;
# Used for backwards compatibility, please read the changelog before changing.
# $ darwin-rebuild changelog
system.stateVersion = 5;
nixpkgs.hostPlatform = "aarch64-darwin";
nixpkgs.config.allowUnfree = true;
# Nix Darwin
# https://daiderd.com/nix-darwin/manual/index.html
# Security
system.defaults.screensaver.askForPassword = true;
system.defaults.screensaver.askForPasswordDelay = 0;
system.defaults.loginwindow.GuestEnabled = false;
# Dock
system.defaults.dock.autohide = true;
system.defaults.dock.orientation = "left";
system.defaults.dock.show-recents = false;
system.defaults.dock.persistent-apps = [
"/Applications/Arc.app"
"/Applications/Ghostty.app"
"/Applications/VSCodium.app"
"/Applications/Spotify.app"
"/System/Applications/System Settings.app"
];
system.defaults.dock.persistent-others = [ ];
# Input devices
system.keyboard.enableKeyMapping = true;
system.keyboard.remapCapsLockToEscape = true;
system.defaults.NSGlobalDomain.InitialKeyRepeat = 25;
system.defaults.NSGlobalDomain.KeyRepeat = 2;
system.defaults.NSGlobalDomain."com.apple.mouse.tapBehavior" = 1;
system.defaults.NSGlobalDomain."com.apple.trackpad.scaling" = 0.875;
system.defaults.trackpad.Dragging = true;
# Finder
system.defaults.finder.AppleShowAllExtensions = true;
system.defaults.finder.ShowPathbar = true;
# Other
system.startup.chime = false;
users.users."niccoloborgioli" = {
home = "/Users/niccoloborgioli";
shell = pkgs.fish;
};
programs.fish.enable = true;
homebrew = {
enable = true;
casks = import ./cask.nix;
taps = [ "lihaoyun6/tap" ];
onActivation = {
autoUpdate = true;
cleanup = "zap";
};
};
# Home Manager
home-manager.backupFileExtension = "backup";
};
in in
{ {
darwinConfigurations."${name}" = nix-darwin.lib.darwinSystem { darwinConfigurations = listToAttrs (
modules = [ map (host: {
( name = host.hostName;
{ config, ... }: value = nix-darwin.lib.darwinSystem {
{ modules = [
config._module.args = { inherit hosts; }; # Make `host` available as module arg.
} (
) { config, ... }:
configuration {
home-manager.darwinModules.home-manager config._module.args = { inherit host; };
{ }
home-manager.useGlobalPkgs = true; )
home-manager.useUserPackages = true; # configuration
home-manager.users.niccoloborgioli = import ./home.nix; (import ./darwin.nix { flake = self; })
} home-manager.darwinModules.home-manager
]; {
}; home-manager.backupFileExtension = "backup";
home-manager.useGlobalPkgs = true;
# Expose the package set, including overlays, for convenience. home-manager.useUserPackages = true;
# darwinPackages = self.darwinConfigurations."${name}".pkgs; home-manager.users.${host.username} = import ./home.nix { inherit host; };
}
];
};
}) hosts
);
}; };
} }

View File

@ -1,11 +1,12 @@
{ pkgs, ... }@args: { host }:
{ pkgs, ... }:
{ {
# https://nix-community.github.io/home-manager # https://nix-community.github.io/home-manager
home.stateVersion = "25.05"; # Please read the comment before changing. home.stateVersion = "25.05"; # Please read the comment before changing.
programs.home-manager.enable = true; programs.home-manager.enable = true;
home.username = "niccoloborgioli"; home.username = host.username;
home.homeDirectory = "/Users/niccoloborgioli"; home.homeDirectory = "/Users/${host.username}";
home.packages = home.packages =
[ ] ++ (import ./home/shared.nix { inherit pkgs; }) ++ (import ./home/sflx.nix { inherit pkgs; }); [ ] ++ (import ./home/shared.nix { inherit pkgs; }) ++ (import ./home/sflx.nix { inherit pkgs; });

View File

@ -1,4 +1,5 @@
[ [
(import ./mac14.nix) (import ./mac14.nix)
(import ./mac16.nix) (import ./mac16.nix)
(import ./sflx.nix)
] ]

View File

@ -1,5 +1,5 @@
{ {
username = "cupcakearmy"; username = "cupcakearmy";
hostName = "mac14"; hostName = "mac14";
system = "aarch64-darwin"; platform = "aarch64-darwin";
} }

View File

@ -1,5 +1,5 @@
{ {
username = "niccoloborgioli"; username = "niccoloborgioli";
hostName = "mac16"; hostName = "mac16";
system = "aarch64-darwin"; platform = "aarch64-darwin";
} }

5
hosts/sflx.nix Normal file
View File

@ -0,0 +1,5 @@
{
username = "niccoloborgioli";
hostName = "sflx";
platform = "aarch64-darwin";
}