I’m looking for a way to run a maintained and initialization script whenever the user rebuilds their system (or reboots, or activates their env, etc).
However, my script requires access to rsync in order to work.
What can I use to accomplish this in activationScripts?
Can I:
- require a package dependency via my config?
- Turn my shell script into a shellScriptApplication, and call that script from activationScripts?
- Some secret third thing
Umm… just use string antiquotes to include the full store path of the binary in the script?
More specifically, use string interpolation, as the nix manual explains:
''
echo blah
${lib.getExe pkgs.whatever} --flag1 --flag2
${lib.getExe' pkgs.whateverWithMultipleBinaries "binary"} --flag3 arg4
''
rsync only has one binary which matches the pname, so getExe will suffice here.
Please do not use activation scripts for this. Just make a systemd service. Happening again on rebuild is what sysinit-reactivation.target is for. Activation scripts should have been deprecated long ago.
5 Likes
That also lets you use path for convenient binary access. A more fully worked example:
{ pkgs, ... }: {
systemd.services.my-init-script = {
wantedBy = [
"sysinit-reactivation.target"
];
path = [
pkgs.whatever
];
script = ''
whatever do something --now
'';
serviceConfig.Type = "oneshot";
};
}
1 Like
I’m going to try this– thanks for the tip about that target.