From 9610667c25f4e480e1f8b1359345a2b8506b4090 Mon Sep 17 00:00:00 2001 From: Niccolo Borgioli Date: Mon, 27 Jan 2025 23:46:38 +0100 Subject: [PATCH] decouple all config from host --- darwin.nix | 70 +++++++++++++++++++++++++++ flake.nix | 121 +++++++++++----------------------------------- home.nix | 7 +-- hosts/default.nix | 1 + hosts/mac14.nix | 2 +- hosts/mac16.nix | 2 +- hosts/sflx.nix | 5 ++ 7 files changed, 110 insertions(+), 98 deletions(-) create mode 100644 darwin.nix create mode 100644 hosts/sflx.nix diff --git a/darwin.nix b/darwin.nix new file mode 100644 index 0000000..2f0a7a6 --- /dev/null +++ b/darwin.nix @@ -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"; +} diff --git a/flake.nix b/flake.nix index 9c974ff..e71f548 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "Example nix-darwin system flake"; + description = "Personal Nix configuration"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; @@ -12,106 +12,41 @@ }; outputs = - inputs@{ + { self, nix-darwin, nixpkgs, home-manager, }: let - name = "mbp"; hosts = import ./hosts; - configuration = - { 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"; - }; + inherit (builtins) listToAttrs; in { - darwinConfigurations."${name}" = nix-darwin.lib.darwinSystem { - modules = [ - ( - { config, ... }: - { - config._module.args = { inherit hosts; }; - } - ) - configuration - home-manager.darwinModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.users.niccoloborgioli = import ./home.nix; - } - ]; - }; - - # Expose the package set, including overlays, for convenience. - # darwinPackages = self.darwinConfigurations."${name}".pkgs; + darwinConfigurations = listToAttrs ( + map (host: { + name = host.hostName; + value = nix-darwin.lib.darwinSystem { + modules = [ + # Make `host` available as module arg. + ( + { config, ... }: + { + config._module.args = { inherit host; }; + } + ) + # configuration + (import ./darwin.nix { flake = self; }) + home-manager.darwinModules.home-manager + { + home-manager.backupFileExtension = "backup"; + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.${host.username} = import ./home.nix { inherit host; }; + } + ]; + }; + }) hosts + ); }; } diff --git a/home.nix b/home.nix index 10ad108..bd7ce46 100644 --- a/home.nix +++ b/home.nix @@ -1,11 +1,12 @@ -{ pkgs, ... }@args: +{ host }: +{ pkgs, ... }: { # https://nix-community.github.io/home-manager home.stateVersion = "25.05"; # Please read the comment before changing. programs.home-manager.enable = true; - home.username = "niccoloborgioli"; - home.homeDirectory = "/Users/niccoloborgioli"; + home.username = host.username; + home.homeDirectory = "/Users/${host.username}"; home.packages = [ ] ++ (import ./home/shared.nix { inherit pkgs; }) ++ (import ./home/sflx.nix { inherit pkgs; }); diff --git a/hosts/default.nix b/hosts/default.nix index 90f15c4..d29267f 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,4 +1,5 @@ [ (import ./mac14.nix) (import ./mac16.nix) + (import ./sflx.nix) ] diff --git a/hosts/mac14.nix b/hosts/mac14.nix index 2ec45ff..c19b3ec 100644 --- a/hosts/mac14.nix +++ b/hosts/mac14.nix @@ -1,5 +1,5 @@ { username = "cupcakearmy"; hostName = "mac14"; - system = "aarch64-darwin"; + platform = "aarch64-darwin"; } diff --git a/hosts/mac16.nix b/hosts/mac16.nix index 527a24f..d1a88cc 100644 --- a/hosts/mac16.nix +++ b/hosts/mac16.nix @@ -1,5 +1,5 @@ { username = "niccoloborgioli"; hostName = "mac16"; - system = "aarch64-darwin"; + platform = "aarch64-darwin"; } diff --git a/hosts/sflx.nix b/hosts/sflx.nix new file mode 100644 index 0000000..b638d03 --- /dev/null +++ b/hosts/sflx.nix @@ -0,0 +1,5 @@ +{ + username = "niccoloborgioli"; + hostName = "sflx"; + platform = "aarch64-darwin"; +}