Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer managing the nix services to determinate-nixd (builds on top of #50) #53

Open
wants to merge 6 commits into
base: graham/fh-469-using-determinate-nix-darwin-in-away-where-nix-darwin-doesnt
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion modules/nix-darwin-unmanaged.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
{ lib, ... }: {
{ lib, pkgs, ... }:
let
failWithoutDeterminateMessage = ''
if ! /usr/local/bin/determinate-nixd status > /dev/null 2>&1 ; then
echo "Determinate is not installed."
echo "Download and install the Determinate package before activating the nix-darwin module."
echo ""
echo "https://docs.determinate.systems/get-started"
exit 1
fi
'';
in {
# Disable some modules that conflict with determinate-nixd.
disabledModules = [
# Wants to add an outdated Nix to the environment, manage nix.conf, manage the
Expand Down Expand Up @@ -72,4 +83,25 @@

# Determinate.pkg can handle fixing build users itself.
config.system.checks.verifyBuildUsers = false;


### Help the user migrate from managed to unmanaged

# Scenario: user has an upstream Nix installation that they want to transition to Determinate
config.system.activationScripts.preActivation.text = lib.mkBefore failWithoutDeterminateMessage;
config.system.activationScripts.preUserActivation.text = lib.mkBefore failWithoutDeterminateMessage;

# Scenario: user has previously used the "default" determinate module before we went to an unmanaged nix.
#
# The symlinks defeat nix-darwin's activation-time unload/update/reload logic for launchd services.
# Because the symlink points to the file, they have the same content, nix-darwin won't try to update or reload the service.
#
# It also defeats nix-darwin's deletion logic, which will delete any LaunchDaemon that was managed by the previously active generation and is not present in the now-activating generation.
# Since the file will now exist in the new profile's LaunchDaemons directory, it will not be deleted.
config.environment.launchDaemons."systems.determinate.nix-store.plist".source = pkgs.runCommand "nix-store-ln" {} ''
ln -s /Library/LaunchDaemons/systems.determinate.nix-store.plist $out
'';
config.environment.launchDaemons."systems.determinate.nix-daemon.plist".source = pkgs.runCommand "nix-daemon-ln" {} ''
ln -s /Library/LaunchDaemons/systems.determinate.nix-daemon.plist $out
'';
}
Loading