On EC2 boxes, NixOS sets up an amazon-init service that reconfigures the machine on startup via
I’d like to be able to run this service but only the first time the machine boots up. Any ideas on how to accomplish this?
I toyed with the idea of tweaking the service to only run if a path exists (ConditionPathExists) and touching a file on
ExecStartPost, but this will only work on the 2nd boot (because the machine starts up with a script that doesn’t include my tweaks).
You can set a “touch” in the user-data configuration’s activation script.
Or using ConditionPathExists with an exclamation mark will negate it.
Isn’t that what I described in the last paragraph of my question though? I feel like I’m missing something otherwise!
I can’t change the
amazon-init service in my
userData because that will change the init service after it runs (causing it to be run twice).
but this will only work on the 2nd boot (because the machine starts up with a script that doesn’t include my tweaks).
Have the new configuration set:
systemd.services.amazon-init.enable = false;
Subsequent boots should not start that service.
Perhaps create another service that performs the touch. That can be a “one-shot” and prevent amazon-init from running (because you also modify it after the first boot).
- amazon-init starts
- new configuration is loaded
- one-shot service does a touch
- modify amazon-init to expect that touch’d file
- modified amazon-init does not find required file
These are great ideas. I love the simplicity of 1), and I think it should work. I’ll try it out.
PS: I ended up going with 2) because NixOS didn’t like disabling amazon-init while it was still running.