|
1 | | -inputs: |
2 | | -{ lib, config, pkgs, ... }: |
| 1 | +{ lib, options, ... }: |
3 | 2 | let |
4 | | - inherit (import ./shared.nix inputs) |
5 | | - commonNixSettingsModule |
6 | | - restrictedNixSettingsModule |
7 | | - mkPreferable |
8 | | - ; |
9 | | -in |
10 | | -{ |
11 | | - imports = [ |
12 | | - commonNixSettingsModule |
13 | | - restrictedNixSettingsModule |
14 | | - ]; |
15 | | - |
16 | | - config = { |
17 | | - # Make Nix use the Nix daemon |
18 | | - nix.useDaemon = true; |
19 | | - |
20 | | - # Make sure that the user can't enable the nix-daemon in their own nix-darwin config |
21 | | - services.nix-daemon.enable = lib.mkForce false; |
22 | | - |
23 | | - system.activationScripts.nix-daemon = lib.mkForce { enable = false; text = ""; }; |
24 | | - system.activationScripts.launchd.text = lib.mkBefore '' |
25 | | - if test -e /Library/LaunchDaemons/org.nixos.nix-daemon.plist; then |
26 | | - echo "Unloading org.nixos.nix-daemon" |
27 | | - launchctl bootout system /Library/LaunchDaemons/org.nixos.nix-daemon.plist || true |
28 | | - mv /Library/LaunchDaemons/org.nixos.nix-daemon.plist /Library/LaunchDaemons/.before-determinate-nixd.org.nixos.nix-daemon.plist.skip |
29 | | - fi |
| 3 | + postMigrationInstructions = '' |
| 4 | + You have successfully migrated your Determinate installation. |
| 5 | + Please remove `determinate.darwinModules.default` from your |
| 6 | + nix-darwin configuration, and ensure that you have nix-darwin’s own |
| 7 | + Nix installation management disabled by setting: |
30 | 8 |
|
31 | | - if test -e /Library/LaunchDaemons/org.nixos.darwin-store.plist; then |
32 | | - echo "Unloading org.nixos.darwin-store" |
33 | | - launchctl bootout system /Library/LaunchDaemons/org.nixos.darwin-store.plist || true |
34 | | - mv /Library/LaunchDaemons/org.nixos.darwin-store.plist /Library/LaunchDaemons/.before-determinate-nixd.org.nixos.darwin-store.plist.skip |
35 | | - fi |
| 9 | + nix.enable = false; |
36 | 10 |
|
37 | | - install -d -m 755 -o root -g wheel /usr/local/bin |
38 | | - cp ${inputs.self.packages.${pkgs.stdenv.system}.default}/bin/determinate-nixd /usr/local/bin/.determinate-nixd.next |
39 | | - chmod +x /usr/local/bin/.determinate-nixd.next |
40 | | - mv /usr/local/bin/.determinate-nixd.next /usr/local/bin/determinate-nixd |
41 | | - ''; |
| 11 | + Then run `darwin-rebuild switch` again. |
| 12 | + ''; |
| 13 | +in |
| 14 | +{ |
| 15 | + config = |
| 16 | + # Check if nix-darwin is new enough for the `nix.enable` option. |
| 17 | + if options.nix.enable.visible or true then |
| 18 | + { |
| 19 | + nix.enable = false; |
42 | 20 |
|
43 | | - launchd.daemons.determinate-nixd-store.serviceConfig = { |
44 | | - Label = "systems.determinate.nix-store"; |
45 | | - RunAtLoad = true; |
| 21 | + system.activationScripts.checks.text = lib.mkBefore '' |
| 22 | + if [[ ! -e /usr/local/bin/determinate-nixd ]]; then |
| 23 | + printf >&2 '\e[1;31merror: Determinate not installed, aborting activation\e[0m\n' |
| 24 | + printf >&2 'The Determinate nix-darwin module is no longer necessary. To install\n' |
| 25 | + printf >&2 'Determinate, remove `determinate.darwinModules.default` from your\n' |
| 26 | + printf >&2 'configuration and follow the installation installations at\n' |
| 27 | + printf >&2 '<https://docs.determinate.systems/getting-started/individuals>.\n' |
| 28 | + exit 2 |
| 29 | + fi |
46 | 30 |
|
47 | | - StandardErrorPath = lib.mkForce "/var/log/determinate-nix-init.log"; |
48 | | - StandardOutPath = lib.mkForce "/var/log/determinate-nix-init.log"; |
| 31 | + # Hack: Detect the version of the `.plist` set up by the old |
| 32 | + # version of the module. |
| 33 | + if grep -- '--nix-bin' /Library/LaunchDaemons/systems.determinate.nix-daemon.plist >/dev/null; then |
| 34 | + printf >&2 '\e[1;31merror: Determinate needs migration, aborting activation\e[0m\n' |
| 35 | + printf >&2 'Determinate now manages the Nix installation independently of the\n' |
| 36 | + printf >&2 'nix-darwin module.\n' |
| 37 | + printf >&2 '\n' |
| 38 | + printf >&2 'Please download and run the macOS installer from\n' |
| 39 | + printf >&2 '<https://docs.determinate.systems/getting-started/individuals> and then\n' |
| 40 | + printf >&2 'run `darwin-rebuild switch` again to migrate your installation.\n' |
| 41 | + exit 2 |
| 42 | + fi |
49 | 43 |
|
50 | | - ProgramArguments = lib.mkForce [ |
51 | | - "/usr/local/bin/determinate-nixd" |
52 | | - "--nix-bin" |
53 | | - "${config.nix.package}/bin" |
54 | | - "init" |
55 | | - ]; |
56 | | - }; |
| 44 | + if [[ ! -e /run/current-system/Library/LaunchDaemons/systems.determinate.nix-daemon.plist ]]; then |
| 45 | + printf >&2 '\e[1;31merror: deprecated Determinate module present, aborting activation\e[0m\n' |
| 46 | + printf >&2 '%s' ${lib.escapeShellArg postMigrationInstructions} |
| 47 | + exit 2 |
| 48 | + fi |
| 49 | + ''; |
57 | 50 |
|
58 | | - launchd.daemons.determinate-nixd.serviceConfig = { |
59 | | - Label = "systems.determinate.nix-daemon"; |
| 51 | + system.activationScripts.extraActivation.text = lib.mkBefore '' |
| 52 | + # Hack: Make sure nix-darwin doesn’t clobber the Determinate |
| 53 | + # launchd daemons after they become unmanaged. |
60 | 54 |
|
61 | | - StandardErrorPath = lib.mkForce "/var/log/determinate-nix-daemon.log"; |
62 | | - StandardOutPath = lib.mkForce "/var/log/determinate-nix-daemon.log"; |
| 55 | + determinateDaemonsStash=$(mktemp -d --suffix=determinate-daemons) |
| 56 | + cp -a /Library/LaunchDaemons/systems.determinate.{nix-daemon,nix-store}.plist "$determinateDaemonsStash" |
63 | 57 |
|
64 | | - ProgramArguments = lib.mkForce [ |
65 | | - "/usr/local/bin/determinate-nixd" |
66 | | - "--nix-bin" |
67 | | - "${config.nix.package}/bin" |
68 | | - "daemon" |
69 | | - ]; |
| 58 | + # shellcheck disable=SC2317 |
| 59 | + restoreDeterminateDaemons() { |
| 60 | + printf >&2 'restoring Determinate daemons...\n' |
| 61 | + mv "$determinateDaemonsStash"/*.plist /Library/LaunchDaemons |
| 62 | + rmdir "$determinateDaemonsStash" |
| 63 | + launchctl load -w /Library/LaunchDaemons/systems.determinate.nix-daemon.plist |
| 64 | + launchctl load -w /Library/LaunchDaemons/systems.determinate.nix-store.plist |
| 65 | + printf >&2 '\n' |
| 66 | + printf >&2 '%s' ${lib.escapeShellArg postMigrationInstructions} |
| 67 | + } |
70 | 68 |
|
71 | | - Sockets = { |
72 | | - "determinate-nixd.socket" = { |
73 | | - # We'd set `SockFamily = "Unix";`, but nix-darwin automatically sets it with SockPathName |
74 | | - SockPassive = true; |
75 | | - SockPathName = "/var/run/determinate-nixd.socket"; |
76 | | - }; |
| 69 | + trap restoreDeterminateDaemons EXIT |
| 70 | + ''; |
| 71 | + } |
| 72 | + else |
| 73 | + { |
| 74 | + assertions = [ |
| 75 | + { |
| 76 | + assertion = false; |
| 77 | + message = '' |
| 78 | + Determinate now manages the Nix installation independently of |
| 79 | + the nix-darwin module. |
77 | 80 |
|
78 | | - "nix-daemon.socket" = { |
79 | | - # We'd set `SockFamily = "Unix";`, but nix-darwin automatically sets it with SockPathName |
80 | | - SockPassive = true; |
81 | | - SockPathName = "/var/run/nix-daemon.socket"; |
82 | | - }; |
83 | | - }; |
84 | | - |
85 | | - SoftResourceLimits = { |
86 | | - NumberOfFiles = mkPreferable 1048576; |
87 | | - NumberOfProcesses = mkPreferable 1048576; |
88 | | - Stack = mkPreferable 67108864; |
89 | | - }; |
90 | | - HardResourceLimits = { |
91 | | - NumberOfFiles = mkPreferable 1048576; |
92 | | - NumberOfProcesses = mkPreferable 1048576; |
93 | | - Stack = mkPreferable 67108864; |
| 81 | + Please download and run the macOS installer from |
| 82 | + <https://docs.determinate.systems/getting-started>, |
| 83 | + update nix-darwin, and then run `darwin-rebuild switch` |
| 84 | + again to migrate your installation. |
| 85 | + ''; |
| 86 | + } |
| 87 | + ]; |
94 | 88 | }; |
95 | | - }; |
96 | | - }; |
97 | 89 | } |
0 commit comments