From eda854d50f6515e4a5e61a846a18a1f0efaa7886 Mon Sep 17 00:00:00 2001
From: "William A. Kennington III" <william@wkennington.com>
Date: Wed, 9 Apr 2014 23:55:17 -0500
Subject: [PATCH] systemd: Add an assertion to guarantee oneshot units do not
 have restart set

This prevents insidious errors once systemd begins handling the unit. If
the unit is loaded at boot, any errors of this nature are logged to the
console before the journal service is running. This makes it very hard
to diagnose the issue. Therefore, this assertion helps guarantee the
mistake is not made.
---
 nixos/modules/system/boot/systemd.nix | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/nixos/modules/system/boot/systemd.nix b/nixos/modules/system/boot/systemd.nix
index 7d5283489184..4705ceb8086a 100644
--- a/nixos/modules/system/boot/systemd.nix
+++ b/nixos/modules/system/boot/systemd.nix
@@ -630,6 +630,12 @@ in
 
   config = {
 
+    assertions = mapAttrsToList (name: service: {
+      assertion = !hasAttr "Type" service.serviceConfig || service.serviceConfig.Type != "oneshot"
+        || !hasAttr "Restart" service.serviceConfig || service.serviceConfig.Restart == "no";
+      message = "${name}: Type=oneshot services must have Restart=no";
+    }) cfg.services;
+
     system.build.units = units;
 
     environment.systemPackages = [ systemd ];