This is an equivalent of the `nix.enable` option from NixOS
and Home Manager. On NixOS, it mostly serves to allow building
fixed‐configuration systems without any Nix installation at
all. It should work for that purpose with nix-darwin too, and the
implementation is largely the same, but the main use case is more
similar to the Home Manager option: to allow the use of nix-darwin
with an unmanaged system installation of Nix, including when there
is another service expecting to manage it, as with Determinate.
By providing an escape hatch to opt out of Nix management entirely,
this will also allow us to consolidate and simplify our existing Nix
installation management, by being more opinionated about things like
taking ownership of the daemon and the build users. Porting one option
from NixOS lets us drop two that only ever existed in nix-darwin and
reduce overall complexity.
We already put `/nix/var/nix/profiles/default/bin` on the `$PATH`,
and whatever `nix.package` is set to already gets installed into
`/run/current-system/sw/bin`, so this is pointless.
Using `grep -v` without `-z` will return 0 even if there is a match
found as all the non-matching lines will be matched. Instead of using
`grep -vqz`, `(! grep ...)` is more readable.
The brackets are necessary as `! grep` will not trigger `set -e`[0], so we
run it inside a subshell to use its non-zero exit code.
[0]: https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#The-Set-Builtin
This change updates the usage description of darwin-rebuild.sh as
follows:
* Add options:
--print-build-logs / -L
--no-registries
--commit-lock-file
--no-write-lock-file
--override-input
* Specify that --no-flake and the flake related options are
mutually exclusive.
* Specify that --keep-going and -k are aliases.
* Specify that --keep-failed and -K are aliases.
* Correct the description of --update-input; only one value follows.
The --no-build-hook argument remains undocumented, like for nix.
The version of sudo on macOS 10.13 High Sierra does not support the
`--preserve-env=LIST` option syntax, which is used here to preserve
PATH.
Override sudo with a shell function that checks for the availability of
this option syntax, and do not pass PATH otherwise.
Also move the prefix env command in the sudo invocations into the new
sudo function.
Signed-off-by: Rafael Kitover <rkitover@gmail.com>