8.nix-darwin/modules/system
Robert Hensing acf6b46011 system.build: Treat as variables, make lazy
This fixes an unnecessary evaluation dependency that prevented the
custom and much appreciated primaryUser error from popping up.

Specifically:

       … while evaluating the option `system.build':

       … while evaluating definitions from `/nix/store/lc6n4bhxj9255kzfn9pnpx65583a8cgc-source/modules/environment':

       … while evaluating definitions from `/nix/store/lc6n4bhxj9255kzfn9pnpx65583a8cgc-source/modules/nix':

       … while evaluating the option `environment.darwinConfig':

       … while evaluating the option `system.primaryUserHome':

       error: expected a string but found null: null
       at /nix/store/lc6n4bhxj9255kzfn9pnpx65583a8cgc-source/modules/system/primary-user.nix:26:30:
           25|       default =
           26|         config.users.users.${config.system.primaryUser}.home or "/Users/${config.system.primaryUser}";
             |                              ^
           27|     };

While it did have some indication as to the cause, it lets the good
error message go to waste.

**Context**

`lazyAttrsOf` is the better choice when you use an attrset as individual
variables instead of in aggregate (e.g. `attrNames`, `toJSON`).

The reason is that an expression like `a.b` is strict in `a`, which
entails the evaluating the _whole_ set of attribute _names_ in `a`.
In the `attrsOf` this means evaluating all `mkIf` conditions, which
in turn also means evaluating all the regular definitions to the
smallest degree (WHNF) to determine that they're not `mkIf`s.

`lazyAttrsOf` simply assumes that all attributes aren't `mkIf false`,
and throws an error in the attribute value if necessary.
This would be a problem with `toJSON` and such, but is completely
fine when the attributes are treated as variables of a lazy program,
as is the case here.

**NixOS**

NixOS made `system.build` a submodule with a `freeformType`, allowing
the things inside of it to be declared, and for them to have niceties
like documentation and merging behavior.
nix-darwin could probably adopt this.
2025-05-23 12:00:51 +02:00
..
defaults defaults: add com.apple.iCal for managing Calendar.app 2025-05-16 12:52:49 +10:00
activation-scripts.nix activation-scripts: move createRun after checks 2025-05-16 16:34:31 +01:00
applications.nix applications: use system.primaryUser for the legacy path 2025-05-16 16:31:17 +01:00
base.nix activation-scripts: get rid of user activation 2025-05-16 16:34:31 +01:00
checks.nix checks: make nixPath check more helpful 2025-05-16 16:34:31 +01:00
default.nix system.build: Treat as variables, make lazy 2025-05-23 12:00:51 +02:00
defaults-write.nix defaults: move userDefaults to system activation 2025-05-16 16:31:17 +01:00
etc.nix etc: merge etcChecks into checks 2025-05-16 16:34:31 +01:00
keyboard.nix (feature) Add swapLeftCtrlAndFn 2024-08-05 13:00:32 +02:00
launchd.nix launchd: move userLaunchd to system activation 2025-05-16 16:29:17 +01:00
nvram.nix treewide: remove lib.mdDoc 2024-04-19 04:05:50 +02:00
patches.nix system: replace for f in $(ls ...) with for f in .../* 2024-11-07 17:20:00 +11:00
primary-user.nix Update repo link 2025-05-17 12:14:14 -04:00
shells.nix users: allow shell to be managed by macOS 2024-10-27 21:52:41 +11:00
startup.nix treewide: remove lib.mdDoc 2024-04-19 04:05:50 +02:00
version.nix Docs: Fix references to NixOS 2025-03-06 16:24:46 +01:00