erikarvstedt / extra-container

Run declarative NixOS containers without full system rebuilds
MIT License
218 stars 16 forks source link

Container start/stop scripts (host side) #32

Closed milabs closed 1 year ago

milabs commented 1 year ago

Hello,

It would be nice to have the ability to add start/stop commands for the container, executed on the host side.

For example, in a project I've working on I have to add some iptables rules once container started.

erikarvstedt commented 1 year ago

This can be achieved like so:

{
  containers.demo = {
    config = ...;
  };

  # Commands executed on the host
  systemd.services."container@demo" = {
    preStart = "...";
    postStart = "...";
    preStop = "...";
    postStop = "...";
  };
}

This pattern is used internally by extra-container, e.g. for implementing enableWAN.

milabs commented 1 year ago

Wow, thanks. Haven't found that by myself.