a flake module to ease creating and managing multiple hosts in your nix flake.

refactor: use native builders

+3 -48
+3 -48
lib.nix
··· 22 22 mapAttrs 23 23 filterAttrs 24 24 mkDefault 25 - evalModules 26 25 mergeAttrs 27 26 assertMsg 28 27 ; ··· 91 90 ... 92 91 }: 93 92 let 94 - # create the modulesPath based on the system, we need 95 - modulesPath = if class == "darwin" then "${nix-darwin}/modules" else "${nixpkgs}/nixos/modules"; 96 - 97 - # we need to import the module list for our system 98 - # this is either the nixos modules list provided by nixpkgs 99 - # or the darwin modules list provided by nix darwin 100 - baseModules = import "${modulesPath}/module-list.nix"; 93 + evalHost = if class == "darwin" then nix-darwin.lib.darwinSystem else nixpkgs.lib.nixosSystem; 101 94 102 - eval = evalModules { 95 + eval = evalHost { 103 96 # we use recursiveUpdate such that users can "override" the specialArgs 104 97 # 105 98 # This should only be used for special arguments that need to be evaluated ··· 113 106 # even though self is just the same as `inputs.self` 114 107 # we still pass this as some people will use this 115 108 self 116 - 117 - # we need to set this because some modules require it sadly 118 - # you may also recall `modulesPath + /installer/scan/not-detected.nix` 119 - modulesPath 120 109 ; 121 110 } specialArgs; 122 111 123 - # A nominal type for modules. When set and non-null, this adds a check to 124 - # make sure that only compatible modules are imported. 125 - class = classToND class; 126 - 127 112 modules = concatLists [ 128 - # bring in all of our base modules 129 - baseModules 130 - 131 113 # import our host system paths 132 114 ( 133 115 if path != null then ··· 159 141 ); 160 142 }) 161 143 162 - # some modules to have these arguments, like documentation.nix 163 - # <https://github.com/NixOS/nixpkgs/blob/9692553cb583e8dca46b66ab76c0eb2ada1a4098/nixos/modules/misc/documentation.nix> 164 - (singleton { 165 - _module.args = { 166 - inherit baseModules; 167 - 168 - # this should in the future be the modules that the user added without baseModules 169 - modules = [ ]; 170 - 171 - # TODO: remove in 25.05 172 - # https://github.com/NixOS/nixpkgs/blob/9692553cb583e8dca46b66ab76c0eb2ada1a4098/nixos/lib/eval-config.nix#L38 173 - extraModules = [ ]; 174 - }; 175 - }) 176 - 177 144 # here we make some basic assumptions about the system the person is using 178 145 # like the system type and the hostname 179 146 (singleton { ··· 200 167 # without supplying an upstream nixpkgs source, nix-darwin will not be able to build 201 168 # and will complain and log an error demanding that you must set this value 202 169 nixpkgs.source = mkDefault nixpkgs; 203 - 204 - system = { 205 - # i don't quite know why this is set but upstream does it so i will too 206 - checks.verifyNixPath = false; 207 - 208 - # we use these values to keep track of what upstream revision we are on, this also 209 - # prevents us from recreating docs for the same configuration build if nothing has changed 210 - darwinVersionSuffix = ".${nix-darwin.shortRev or nix-darwin.dirtyShortRev or "dirty"}"; 211 - darwinRevision = nix-darwin.rev or nix-darwin.dirtyRev or "dirty"; 212 - }; 213 170 })) 214 171 215 172 # import any additional modules that the user has provided ··· 222 179 else 223 180 assert assertMsg (nix-darwin != null) "nix-darwin must be set when class is darwin"; 224 181 { 225 - darwinConfigurations.${name} = eval // { 226 - system = eval.config.system.build.toplevel; 227 - }; 182 + darwinConfigurations.${name} = eval; 228 183 }; 229 184 230 185 foldAttrsRecursive = foldl' (acc: attrs: recursiveUpdate acc attrs) { };