From 464b0bd5fe9f16a64a8875703b58633711ab6de1 Mon Sep 17 00:00:00 2001 From: Spotlight Date: Thu, 29 May 2025 01:54:38 -0500 Subject: [PATCH] darwin: Merge shared configuration between hosts --- flake.lock | 6 +- hosts/darwin/shared/common.nix | 36 +++++++++++ hosts/darwin/shared/java.nix | 30 +++++++++ .../spotlights-mac-pro/configuration.nix | 61 +----------------- .../spotlights-macbook-air/configuration.nix | 63 ++----------------- 5 files changed, 76 insertions(+), 120 deletions(-) create mode 100644 hosts/darwin/shared/common.nix create mode 100644 hosts/darwin/shared/java.nix diff --git a/flake.lock b/flake.lock index 3c0ece3..01f566a 100644 --- a/flake.lock +++ b/flake.lock @@ -92,11 +92,11 @@ ] }, "locked": { - "lastModified": 1748455938, - "narHash": "sha256-mQ/iNzPra2WtDQ+x2r5IadcWNr0m3uHvLMzJkXKAG/8=", + "lastModified": 1748489961, + "narHash": "sha256-uGnudxMoQi2c8rpPoHXuQSm80NBqlOiNF4xdT3hhzLM=", "owner": "nix-community", "repo": "home-manager", - "rev": "02077149e2921014511dac2729ae6dadb4ec50e2", + "rev": "95c988cf08e9a5a8fe7cc275d5e3f24e9e87bd51", "type": "github" }, "original": { diff --git a/hosts/darwin/shared/common.nix b/hosts/darwin/shared/common.nix new file mode 100644 index 0000000..775c560 --- /dev/null +++ b/hosts/darwin/shared/common.nix @@ -0,0 +1,36 @@ +{ pkgs, ... }: { + imports = [ + ./java.nix + ]; + + # We'd like to use Vim globally. + environment = { + systemPackages = [ + pkgs.vim + ]; + variables.EDITOR = "${pkgs.vim}/bin/vim"; + }; + + # Similarly, we'd like to use zsh. + programs.zsh.enable = true; + + # We make the assumption our user is named `spot`. + users.users.spot = { + description = "Spotlight Deveaux"; + home = "/Users/spot"; + shell = pkgs.zsh; + }; + + nix = { + # Keep the latest version of Nix. + package = pkgs.nix; + settings = { + # Necessary for using flakes on this system. + experimental-features = "nix-command flakes"; + + # Include Garnix + substituters = [ "https://cache.garnix.io" ]; + trusted-public-keys = [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ]; + }; + }; +} diff --git a/hosts/darwin/shared/java.nix b/hosts/darwin/shared/java.nix new file mode 100644 index 0000000..e02b20b --- /dev/null +++ b/hosts/darwin/shared/java.nix @@ -0,0 +1,30 @@ +{ pkgs, ... }: { + # Install the latest JDK, and latest LTS JDK. + # Per https://github.com/LnL7/nix-darwin/issues/663, + # nix-darwin only supports a few specific named activation scripts. + # We'll leverage `extraActivation` to symlink our JDKs. + # TODO(spotlightishere): Migrate to explicit scripts when possible + system.activationScripts.extraActivation.text = '' + ############## + # Latest JDK # + ############## + # Regardless of version, we'd like the latest JDK available. + + # Remove the symlink if it doesn't already exist. + rm -f /Library/Java/JavaVirtualMachines/zulu-latest.jdk + + # We should only have a single JDK present within our package, + # but let's limit `find` regardless. + JDK_LOCATION="$(find "${pkgs.jdk24}" -name "*.jdk" | head -n1)" + + # Symlink! + ln -sf "$JDK_LOCATION" "/Library/Java/JavaVirtualMachines/zulu-latest.jdk" + + ########## + # JDK 21 # + ########## + # We'd also like the latest LTS version of the JDK available. + rm -f /Library/Java/JavaVirtualMachines/zulu-21.jdk + ln -sf "${pkgs.jdk21}/zulu-21.jdk" "/Library/Java/JavaVirtualMachines/zulu-21.jdk" + ''; +} diff --git a/hosts/darwin/spotlights-mac-pro/configuration.nix b/hosts/darwin/spotlights-mac-pro/configuration.nix index d4a782e..0f2c98d 100644 --- a/hosts/darwin/spotlights-mac-pro/configuration.nix +++ b/hosts/darwin/spotlights-mac-pro/configuration.nix @@ -1,66 +1,11 @@ { lib, pkgs, system, ... }: { - environment = { - # We'll use Vim globally. - systemPackages = [ - pkgs.vim - ]; - variables.EDITOR = "${pkgs.vim}/bin/vim"; - }; - - # Per https://github.com/LnL7/nix-darwin/issues/663, - # nix-darwin only supports a few specific named activation scripts. - # We'll leverage `extraActivation` to symlink our JDKs. - system.activationScripts.extraActivation.text = '' - ############## - # Latest JDK # - ############## - # Regardless of version, we'd like the latest JDK available. - - # Remove the symlink if it doesn't already exist. - rm -f /Library/Java/JavaVirtualMachines/zulu-latest.jdk - - # We should only have a single JDK present within our package, - # but let's limit `find` regardless. - JDK_LOCATION="$(find "${pkgs.jdk24}" -name "*.jdk" | head -n1)" - - # Symlink! - ln -sf "$JDK_LOCATION" "/Library/Java/JavaVirtualMachines/zulu-latest.jdk" - - ########## - # JDK 21 # - ########## - # We'd also like the latest LTS version of the JDK available. - rm -f /Library/Java/JavaVirtualMachines/zulu-21.jdk - ln -sf "${pkgs.jdk21}/zulu-21.jdk" "/Library/Java/JavaVirtualMachines/zulu-21.jdk" - ''; - - # Auto upgrade the nix package. - nix = { - # Keep the latest version of Nix. - package = pkgs.nix; - settings = { - # Necessary for using flakes on this system. - experimental-features = "nix-command flakes"; - - # Include Garnix - substituters = [ "https://cache.garnix.io" ]; - trusted-public-keys = [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ]; - }; - }; - - # Create /etc/zshrc that loads the nix-darwin environment. - programs.zsh.enable = true; + imports = [ + ../shared/common.nix + ]; # Used for backwards compatibility, please read the changelog before changing. # $ darwin-rebuild changelog system.stateVersion = 6; nixpkgs.hostPlatform = lib.mkDefault "x86_64-darwin"; - - # Our singular user! - users.users.spot = { - description = "Spotlight Deveaux"; - home = "/Users/spot"; - shell = pkgs.zsh; - }; } diff --git a/hosts/darwin/spotlights-macbook-air/configuration.nix b/hosts/darwin/spotlights-macbook-air/configuration.nix index d6f59ae..95c891f 100644 --- a/hosts/darwin/spotlights-macbook-air/configuration.nix +++ b/hosts/darwin/spotlights-macbook-air/configuration.nix @@ -1,66 +1,11 @@ { lib, pkgs, system, ... }: { - environment = { - # We'll use Vim globally. - systemPackages = [ - pkgs.vim - ]; - variables.EDITOR = "${pkgs.vim}/bin/vim"; - }; - - # Per https://github.com/LnL7/nix-darwin/issues/663, - # nix-darwin only supports a few specific named activation scripts. - # We'll leverage `extraActivation` to symlink our JDKs. - system.activationScripts.extraActivation.text = '' - ############## - # Latest JDK # - ############## - # Regardless of version, we'd like the latest JDK available. - - # Remove the symlink if it doesn't already exist. - rm -f /Library/Java/JavaVirtualMachines/zulu-latest.jdk - - # We should only have a single JDK present within our package, - # but let's limit `find` regardless. - JDK_LOCATION="$(find "${pkgs.jdk24}" -name "*.jdk" | head -n1)" - - # Symlink! - ln -sf "$JDK_LOCATION" "/Library/Java/JavaVirtualMachines/zulu-latest.jdk" - - ########## - # JDK 21 # - ########## - # We'd also like the latest LTS version of the JDK available. - rm -f /Library/Java/JavaVirtualMachines/zulu-21.jdk - ln -sf "${pkgs.jdk21}/zulu-21.jdk" "/Library/Java/JavaVirtualMachines/zulu-21.jdk" - ''; - - # Auto upgrade the nix package. - nix = { - # Keep the latest version of Nix. - package = pkgs.nix; - settings = { - # Necessary for using flakes on this system. - experimental-features = "nix-command flakes"; - - # Include Garnix - substituters = [ "https://cache.garnix.io" ]; - trusted-public-keys = [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ]; - }; - }; - - # Create /etc/zshrc that loads the nix-darwin environment. - programs.zsh.enable = true; + imports = [ + ../shared/common.nix + ]; # Used for backwards compatibility, please read the changelog before changing. # $ darwin-rebuild changelog - system.stateVersion = 4; + system.stateVersion = 6; nixpkgs.hostPlatform = lib.mkDefault "aarch64-darwin"; - - # Our singular user! - users.users.spot = { - description = "Spotlight Deveaux"; - home = "/Users/spot"; - shell = pkgs.zsh; - }; }