Dotfiles managed with Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: reorganize modules into darwin/ and home/ directories

+81 -7
auto-upgrade.nix darwin/auto-upgrade.nix
+62 -2
flake.nix
··· 2 2 description = "Personal cross-platform dotfiles flake"; 3 3 4 4 inputs = { 5 + # Base package set used by every target system. 5 6 nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 7 + 8 + # macOS system configuration framework. 6 9 nix-darwin.url = "github:nix-darwin/nix-darwin/master"; 7 10 nix-darwin.inputs.nixpkgs.follows = "nixpkgs"; 11 + 12 + # User-level configuration framework shared by macOS and Linux. 8 13 home-manager.url = "github:nix-community/home-manager"; 9 14 home-manager.inputs.nixpkgs.follows = "nixpkgs"; 10 15 16 + # Overlay for a newer Neovim package in the shared package set. 11 17 neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay"; 12 18 }; 13 19 14 20 outputs = inputs@{ self, nixpkgs, nix-darwin, home-manager, ... }: 15 21 let 22 + # Reuse helper functions from nixpkgs throughout the flake. 16 23 lib = nixpkgs.lib; 24 + 25 + # Decide whether a host should be built with nix-darwin or standalone 26 + # Home Manager based on its target system string. 17 27 isDarwin = host: lib.hasSuffix "darwin" host.system; 28 + 29 + # Fill in default paths so every host entry has the same shape, even when 30 + # `homeDirectory` or `flakeDirectory` are omitted in `hosts.nix`. 31 + # { 32 + # system 33 + # username 34 + # homeDirectory 35 + # flakeDirectory 36 + # } 18 37 mkHost = host: 19 38 let 20 39 homeDirectory = host.homeDirectory or ( ··· 28 47 inherit homeDirectory; 29 48 flakeDirectory = host.flakeDirectory or "${homeDirectory}/.dot"; 30 49 }; 50 + 51 + # Load the host inventory and normalize each entry once up front. 31 52 hosts = lib.mapAttrs (_: host: mkHost host) (import ./hosts.nix); 53 + 54 + # Import nixpkgs for one target system with the repo's shared policy. 32 55 mkPkgs = system: import nixpkgs { 33 56 inherit system; 34 57 config.allowUnfree = true; 35 58 }; 59 + 60 + # Shared Home Manager module wiring reused by both standalone Home 61 + # Manager configs and the Home Manager module embedded in nix-darwin. 36 62 mkHomeModule = host: { 37 - imports = [ ./home.nix ]; 63 + # Import the Home Manager module tree from `home/default.nix`. 64 + imports = [ ./home ]; 38 65 home = { 39 66 inherit (host) username homeDirectory; 40 67 }; 41 68 }; 69 + 70 + # Build a standalone Home Manager configuration for non-Darwin hosts. 42 71 mkHome = _: host: home-manager.lib.homeManagerConfiguration { 43 72 pkgs = mkPkgs host.system; 44 73 extraSpecialArgs = { ··· 46 75 }; 47 76 modules = [ (mkHomeModule host) ]; 48 77 }; 78 + 79 + # Build a nix-darwin system for macOS hosts and attach the same Home 80 + # Manager module so user config stays defined in one place. 49 81 mkDarwin = hostName: host: nix-darwin.lib.darwinSystem { 50 82 system = host.system; 83 + 84 + # `specialArgs` is an escape hatch from the Nix module system 85 + # (defined in nixpkgs `lib/modules.nix` -> `lib.evalModules`). 86 + # It passes arbitrary values directly into every module's function 87 + # argument list before option evaluation begins. 88 + # 89 + # There is no predefined list of allowed keys: you invent the names 90 + # here and destructure them in the receiving module: 91 + # 92 + # # darwin/default.nix 93 + # { config, pkgs, hostName, flakeDirectory, username, ... }: { ... } 94 + # 95 + # Values passed here: 96 + # self - the flake's own output set 97 + # hostName - the attribute name from `darwinConfigurations` 98 + # flakeDirectory - absolute path where the flake lives on disk 99 + # username - primary user account name 100 + # homeDirectory - absolute path to the user's home directory 51 101 specialArgs = { 52 102 inherit self hostName; 53 103 inherit (host) flakeDirectory username homeDirectory; 54 104 }; 105 + 55 106 modules = [ 56 - ./macos.nix 107 + ./darwin 57 108 home-manager.darwinModules.home-manager 58 109 { 59 110 home-manager.useGlobalPkgs = true; 60 111 home-manager.useUserPackages = true; 112 + # `extraSpecialArgs` is the home-manager equivalent of 113 + # `specialArgs`: arbitrary values forwarded into every home-manager 114 + # module's function arguments. 115 + # Here we pass the full `inputs` attrset so that modules in 116 + # `home/default.nix` can reference other flake inputs (e.g. 117 + # overlays, plugins) without those inputs having to be declared 118 + # as options. 61 119 home-manager.extraSpecialArgs = { 62 120 inherit inputs; 63 121 }; ··· 66 124 ]; 67 125 }; 68 126 in { 127 + # Export only Darwin hosts as nix-darwin configurations. 69 128 darwinConfigurations = lib.mapAttrs mkDarwin (lib.filterAttrs (_: host: isDarwin host) hosts); 70 129 130 + # Export only non-Darwin hosts as standalone Home Manager configs. 71 131 homeConfigurations = lib.mapAttrs mkHome (lib.filterAttrs (_: host: !isDarwin host) hosts); 72 132 }; 73 133 }
+1 -1
home.nix home/default.nix
··· 5 5 import ./packages/shared.nix { 6 6 inherit pkgs inputs; 7 7 } 8 - ++ lib.optionals pkgs.stdenv.isDarwin (import ./packages/macos.nix { 8 + ++ lib.optionals pkgs.stdenv.isDarwin (import ./packages/darwin.nix { 9 9 inherit pkgs; 10 10 }); 11 11
+16 -3
justfile
··· 1 1 current_host := `if [ "$(uname -s)" = "Darwin" ]; then scutil --get LocalHostName; else hostname -s; fi` 2 - current_flake := "path:.#{{current_host}}" 3 2 4 3 alias drs := switch 5 4 alias hms := hm-switch ··· 8 7 just -l 9 8 10 9 build: 11 - printf 'Using host %s\n' "{{current_host}}"; if [ "$(uname -s)" = "Darwin" ]; then darwin-rebuild build --flake "{{current_flake}}"; else home-manager build --flake "{{current_flake}}"; fi 10 + #!/usr/bin/env bash 11 + printf 'Using host %s\n' "{{current_host}}" 12 + if [ "$(uname -s)" = "Darwin" ] 13 + then 14 + darwin-rebuild build --flake ".#{{current_host}}" 15 + else 16 + home-manager build --flake ".#{{current_host}}" 17 + fi 12 18 13 19 switch: 14 - printf 'Using host %s\n' "{{current_host}}"; if [ "$(uname -s)" = "Darwin" ]; then sudo darwin-rebuild switch --flake "{{current_flake}}"; else home-manager switch --flake "{{current_flake}}"; fi 20 + #!/usr/bin/env bash 21 + printf 'Using host %s\n' "{{current_host}}" 22 + if [ "$(uname -s)" = "Darwin" ] 23 + then 24 + darwin-rebuild switch --flake ".#{{current_host}}" 25 + else 26 + home-manager switch --flake ".#{{current_host}}" 27 + fi 15 28 16 29 hm-build target: 17 30 home-manager build --flake path:.#{{target}}
+2 -1
macos.nix darwin/default.nix
··· 24 24 25 25 casks = [ 26 26 "aldente" 27 + "biscuit" 27 28 "brave-browser" 28 29 "nikitabobko/tap/aerospace" 29 30 "codexbar" ··· 37 38 ]; 38 39 39 40 onActivation = { 40 - cleanup = "none"; 41 + cleanup = "zap"; 41 42 autoUpdate = true; 42 43 upgrade = true; 43 44 };
packages/macos.nix home/packages/darwin.nix
packages/shared.nix home/packages/shared.nix