Add locking via flock(1) #25

Merged
MatthewCroughan merged 2 commits from mc/flocking into master 2022-09-12 17:58:39 +00:00
MatthewCroughan commented 2022-08-19 04:39:14 +00:00 (Migrated from github.com)

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
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 - https://www.baeldung.com/linux/file-locking
Sign in to join this conversation.
No description provided.