-
Notifications
You must be signed in to change notification settings - Fork 408
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
Support arbitrary keys in system.activationScripts
#664
base: master
Are you sure you want to change the base?
Conversation
9f7b510
to
b08ea88
Compare
I had a failing First, it's complaining that The It then waits for I'm guessing the I reworked the code to check |
This changes nix-darwin's behavior to match NixOS's handling of this option. Each key can specify a list of dependencies to control ordering, and every element of `system.activationScripts` will be used. This also introduces `system.userActivationScripts`, again mirroring NixOS, and moves the user-level keys from `system.activationScripts`. Care is taken to continue handling legacy keys such as `system.activationScripts.{preActivation,preUserActivation,postActivation,...}` with the same behavior they have already had. Previously, the `org.nixos.activate-system` launchd daemon only ran the `etc` and `keyboard` activation scripts. This change adds a new `onlyOnRebuild` setting to existing keys to preserve that behavior. Newly defined keys will run at both rebuild and boot time, matching NixOS's behavior. Fixes LnL7#663.
b08ea88
to
eaa350d
Compare
I was looking for the same feature and was surprised that someone already supported it 😅 Your solution works for my use-case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general I tried to keep compatibility with existing modules, however I intentionally excluded activation scripts from the public api for external modules. It would be nice if the module system provided better functionality for this but everything is global and thus accessible in all modules.
Allowing any imported code to do arbitrary things as root already doesn't seem like the best idea in the first place and while initially implementing the darwin modules I clearly noticed that almost none of the existing activation logic from NixOS could be reused as it's written with the assumption that it has full control over the entire system. Unlike with NixOS there's no way to rollback if activation breaks something for the host system.
Currently I've just worked around this by |
I believe this PR preserves full compatibility with existing modules; users can still set exactly the same activation script keys and they will have exactly the same functionality, and they can also do the NixOS thing and define new activation script keys. I agree it's a potentially dangerous interface, but you're already exposing the interface with (BTW, the motivation for this is that I was starting to work on #618 and I found that there wasn't an easy way to add the required |
I mostly agree with that, since everything is global there is indeed no way to actually prevent this. However currently at least insures that the included module was actually written with darwin in mind. The current changes would allow the following. {
imports = [ <nixpkgs/nixos/missing-functionality.nix> ];
config = {
something.enable = true;
};
} I would at least like this case like this to fail, one option could be to simply rename the option for activation snippets. This will still catch unintended use while enabling dynamic snippets and ordering both internally and for modules written for darwin specifically. |
Seems reasonable; how about something like P.S. I wish everything wasn't global. I wish we had proper static checks. :( |
(Home Manager uses |
If you're okay with renaming it, we could name it |
To clarify I'm ok with the changes if they don't remain under the same option as NixOS. For preActivation/postActivation we can use |
I don't believe |
Yeah, could be that the implementation is a bit too simple to cover this case. But the same idea can be implemented using conditions and the warnings module. |
This changes nix-darwin's behavior to match NixOS's handling of this option. Each key can specify a list of dependencies to control ordering, and every element of
system.activationScripts
will be used.This also introduces
system.userActivationScripts
, again mirroring NixOS, and moves the user-level keys fromsystem.activationScripts
.Care is taken to continue handling legacy keys such as
system.activationScripts.{preActivation,preUserActivation,postActivation,...}
with the same behavior they have already had.Previously, the
org.nixos.activate-system
launchd daemon only ran theetc
andkeyboard
activation scripts. This change adds a newonlyOnRebuild
setting to existing keys to preserve that behavior. Newly defined keys will run at both rebuild and boot time, matching NixOS's behavior.Fixes #663.