diff --git a/modules/system/boot/systemd-unit-options.nix b/modules/system/boot/systemd-unit-options.nix index ec769ad69f9..9aa9b2b4f3b 100644 --- a/modules/system/boot/systemd-unit-options.nix +++ b/modules/system/boot/systemd-unit-options.nix @@ -47,6 +47,15 @@ with pkgs.lib; ''; }; + partOf = mkOption { + default = []; + types = types.listOf types.string; + description = '' + If the specified units are stopped or restarted, then this + unit is stopped or restarted as well. + ''; + }; + wantedBy = mkOption { default = []; types = types.listOf types.string; diff --git a/modules/system/boot/systemd.nix b/modules/system/boot/systemd.nix index 51b65812b34..06019fa2a08 100644 --- a/modules/system/boot/systemd.nix +++ b/modules/system/boot/systemd.nix @@ -191,8 +191,9 @@ let ''} Requires=${concatStringsSep " " def.requires} Wants=${concatStringsSep " " def.wants} - Before=${concatStringsSep " " def.before} After=${concatStringsSep " " def.after} + Before=${concatStringsSep " " def.before} + PartOf=${concatStringsSep " " def.partOf} ${def.unitConfig} [Service] diff --git a/modules/system/upstart/upstart.nix b/modules/system/upstart/upstart.nix index c31314f1091..577efe17065 100644 --- a/modules/system/upstart/upstart.nix +++ b/modules/system/upstart/upstart.nix @@ -54,17 +54,20 @@ let ''; in { - inherit (job) description requires wants before environment path; + inherit (job) description requires wants before partOf environment path; after = (if job.startOn == "stopped udevtrigger" then [ "systemd-udev-settle.service" ] else if job.startOn == "started udev" then [ "systemd-udev.service" ] else - if job.startOn == "" || job.startOn == "startup" then [ ] else + if job.startOn == "ip-up" then [] else + if job.startOn == "" || job.startOn == "startup" then [] else builtins.trace "Warning: job ‘${job.name}’ has unknown startOn value ‘${job.startOn}’." [] ) ++ job.after; wantedBy = - (if job.startOn == "" then [ ] else [ "multi-user.target" ]) ++ job.wantedBy; + (if job.startOn == "" then [] else + if job.startOn == "ip-up" then [ "ip-up.target" ] else + [ "multi-user.target" ]) ++ job.wantedBy; serviceConfig = ''