From 3d70922a859a0404d255bab218d855ce64b9b0e8 Mon Sep 17 00:00:00 2001 From: Nico Date: Sat, 3 May 2025 16:15:58 +1000 Subject: [PATCH] nix: start darwin configuration preparation for macOS --- flake.lock | 21 +++++++++++++++ flake.nix | 23 +++++++++++++++- hosts/faye/conf.nix | 6 +++++ modules/darwin/applications.nix | 48 +++++++++++++++++++++++++++++++++ modules/darwin/desktop.nix | 47 ++++++++++++++++++++++++++++++++ modules/darwin/hardware.nix | 35 ++++++++++++++++++++++++ modules/darwin/nix.nix | 34 +++++++++++++++++++++++ 7 files changed, 213 insertions(+), 1 deletion(-) create mode 100644 hosts/faye/conf.nix create mode 100644 modules/darwin/applications.nix create mode 100644 modules/darwin/desktop.nix create mode 100644 modules/darwin/hardware.nix create mode 100644 modules/darwin/nix.nix diff --git a/flake.lock b/flake.lock index 4eaee97..4400930 100644 --- a/flake.lock +++ b/flake.lock @@ -125,6 +125,26 @@ "type": "github" } }, + "nix-darwin": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1732420287, + "narHash": "sha256-CzvYF4x6jUh/+NEEIFrIY5t1W/N3IA2bNZJiMXu9GTo=", + "owner": "LnL7", + "repo": "nix-darwin", + "rev": "3c52583b99666a349a6219dc1f0dd07d75c82d6a", + "type": "github" + }, + "original": { + "owner": "LnL7", + "repo": "nix-darwin", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1731676054, @@ -187,6 +207,7 @@ "root": { "inputs": { "lanzaboote": "lanzaboote", + "nix-darwin": "nix-darwin", "nixpkgs": "nixpkgs" } }, diff --git a/flake.nix b/flake.nix index 60d5df1..d9665b8 100644 --- a/flake.nix +++ b/flake.nix @@ -6,9 +6,11 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; lanzaboote.url = "github:nix-community/lanzaboote/v0.4.1"; lanzaboote.inputs.nixpkgs.follows = "nixpkgs"; + nix-darwin.url = "github:LnL7/nix-darwin"; + nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, lanzaboote, ... }@inputs: { + outputs = { self, nixpkgs, lanzaboote, nix-darwin, ... }@inputs: { nixosConfigurations.pluto = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = [ @@ -34,5 +36,24 @@ ./hosts/pluto/hardware-configuration.nix ]; }; + + darwinConfigurations.faye = nix-darwin.lib.darwinSystem { + system = "aarch64-darwin"; + modules = [ + ./modules/applications.nix + ./modules/firefox.nix + ./modules/fonts.nix + ./modules/games.nix + ./modules/nix.nix + ./modules/shell.nix + + ./modules/darwin/applications.nix + ./modules/darwin/desktop.nix + ./modules/darwin/hardware.nix + ./modules/darwin/nix.nix + + ./hosts/faye/conf.nix + ]; + }; }; } diff --git a/hosts/faye/conf.nix b/hosts/faye/conf.nix new file mode 100644 index 0000000..6049ca5 --- /dev/null +++ b/hosts/faye/conf.nix @@ -0,0 +1,6 @@ +{ config, lib, pkgs, ... }: + +{ + networking.hostName = "faye"; + networking.computerName = "faye"; +} diff --git a/modules/darwin/applications.nix b/modules/darwin/applications.nix new file mode 100644 index 0000000..3455944 --- /dev/null +++ b/modules/darwin/applications.nix @@ -0,0 +1,48 @@ +{ config, lib, pkgs, ... }: + +{ + # dock + system.defaults.dock.autohide = true; + system.defaults.dock.autohide-delay = 0.2; + system.defaults.dock.autohide-time-modifier = 0.2; + system.defaults.dock.mineffect = "scale"; + system.defaults.dock.orientation = "left"; + system.defaults.dock.show-recents = true; + system.defaults.dock.tilesize = 48; + system.defaults.dock.persistent-apps = [ + "${pkgs.firefox}/Applications/Firefox.app" + "${pkgs.kitty}/Applications/Kitty.app" + "/System/Applications/Finder.app" + ]; + + # finder + system.defaults.finder = { + AppleShowAllExtensions = true; + AppleShowAllFiles = true; + FXEnableExtensionChangeWarning = false; + FXPreferredViewStyle = "clmv"; + FXRemoveOldTrashItems = true; + NewWindowTarget = "Home"; + ShowStatusBar = true; + _FXShowPosixPathInTitle = true; + _FXSortFoldersFirst = true; + + CreateDesktop = true; # desktop icons + ShowHardDrivesOnDesktop = true; + ShowExternalHardDrivesOnDesktop = true; + ShowMountedServersOnDesktop = true; + ShowRemovableMediaOnDesktop = true; + }; + + # activity monitor + system.defaults.ActivityMonitor = { + IconType = 0; + OpenMainWindow = true; + ShowCategory = 100; + SortColumn = "CPUUsage"; + SortDirection = 0; + }; + + # hotkey daemon + services.skhd.enable = true; +} diff --git a/modules/darwin/desktop.nix b/modules/darwin/desktop.nix new file mode 100644 index 0000000..b129f85 --- /dev/null +++ b/modules/darwin/desktop.nix @@ -0,0 +1,47 @@ +{ config, lib, pkgs, ... }: + +{ + + # appearance + system.defaults.NSGlobalDomain.AppleInterfaceStyle = "Dark"; + system.defaults.NSGlobalDomain.AppleShowScrollBars = "WhenScrolling"; + system.defaults.WindowManager.EnableStandardClickToShowDesktop = true; + system.startup.chime = true; + + system.defaults.NSGlobalDomain.NSDisableAutomaticTermination = true; + system.defaults.NSGlobalDomain.NSDocumentSaveNewDocumentsToCloud = false; + + # login + system.defaults.loginwindow.GuestEnabled = false; + system.defaults.screensaver.askForPassword = true; + + # control center + # 18 = show in menubar, 24 = put in control center + system.defaults.controlcenter = { + Display = 18; + FocusModes = 18; + NowPlaying = 18; + Sound = 18; + + Bluetooth = 24; + AirDrop = 24; + + BatteryShowPercentage = true; + }; + + # clock + system.defaults.menuExtraClock = { + Show24Hour = false; + ShowAMPM = true; + ShowDayOfMonth = true; + ShowDayOfWeek = true; + }; + + # mission control + system.defaults.dock.expose-animation-duration = 0.2; + + # spaces + system.defaults.dock.mru-spaces = false; # dont rearange spaces based on usage + system.defaults.spaces.spans-displays = true; # displays have different spaces + system.defaults.NSGlobalDomain.AppleSpacesSwitchOnActivate = true; +} diff --git a/modules/darwin/hardware.nix b/modules/darwin/hardware.nix new file mode 100644 index 0000000..9080131 --- /dev/null +++ b/modules/darwin/hardware.nix @@ -0,0 +1,35 @@ +{ config, lib, pkgs, ... }: + +{ + power = { + sleep.computer = "never"; + sleep.display = 5; + }; + + security.pam.enableSudoTouchIdAuth = true; + + networking.dns = [ + "1.1.1.1" + ]; + + # keyboard + system.defaults.NSGlobalDomain = { + KeyRepeat = 1; + NSAutomaticCapitalizationEnabled = false; + NSAutomaticDashSubstitutionEnabled = false; + NSAutomaticInlinePredictionEnabled = true; + NSAutomaticPeriodSubstitutionEnabled = false; + NSAutomaticQuoteSubstitutionEnabled = false; + NSAutomaticSpellingCorrectionEnabled = false; + }; + + system.keyboard.remapCapsLockToControl = true; + system.keyboard.swapLeftCtrlAndFn = true; + system.defaults.NSGlobalDomain.ApplePressAndHoldEnabled = false; + + system.defaults.hitoolbox.AppleFnUsageType = "Do Nothing"; + + # mouse + system.defaults.".GlobalPreferences"."com.apple.mouse.scaling" = -1.0; # mouse acceleration + +} diff --git a/modules/darwin/nix.nix b/modules/darwin/nix.nix new file mode 100644 index 0000000..0182024 --- /dev/null +++ b/modules/darwin/nix.nix @@ -0,0 +1,34 @@ +{ config, lib, pkgs, ... }: + +{ + # auto upgrade nix package and the daemon service. + services.nix-daemon.enable = true; + + # nix auto garbage collection + nix.gc = { + automatic = true; + interval = { Weekday = 0; Hour = 0; Minute = 0; }; + options = "--delete-older-than 7d"; + }; + + # make nix applications use alias instead of symlinks for compatability + system.activationScripts.applications.text = let + env = pkgs.buildEnv { + name = "system-applications"; + paths = config.environment.systemPackages; + pathsToLink = "/Applications"; + }; + in + pkgs.lib.mkForce '' + # Set up applications. + echo "setting up /Applications..." >&2 + rm -rf /Applications/Nix\ Apps + mkdir -p /Applications/Nix\ Apps + find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + | + while read -r src; do + app_name=$(basename "$src") + echo "copying $src" >&2 + ${pkgs.mkalias}/bin/mkalias "$src" "/Applications/Nix Apps/$app_name" + done + ''; +}