MatthewCroughan / nixinate

Another NixOS Deployment Tool - Nixinate your systems 🕶️
MIT License
240 stars 32 forks source link

Add locking via flock(1) #25

Closed MatthewCroughan closed 2 years ago

MatthewCroughan commented 2 years ago

If two Nixinate deployments were executed in parallel, it would cause two activation scripts to run in parallel which can cause failure.

It is not clear whether the correct solution is to use flock via Nixinate, or whether nixos-rebuild or even the activation script should be implementing the locking. Either way, this PR solves the problem from Nixinate's point of view by adding "advisory" file descriptor based locks on the filesystem via /dev/shm.

Also of note is the fact that I have to figure out a way to make flock work with the hermetic = true argument, before it can be merged. Otherwise, it would be a dependency which prevents support for other platforms. It is otherwise an impurity that is expected on the remote side.

Helpful references