anchor.diff:      })
   
       (mkIf cfg.carbon.enableAggregator {
  -      systemd.services.carbonAggregator = {
  +      systemd.services.carbonAggregator = let name = "carbon-aggregator"; in {
           enable = cfg.carbon.enableAggregator;
           description = "Carbon Data Aggregator";
           wantedBy = [ "multi-user.target" ];
           after = [ "network-interfaces.target" ];
           environment = carbonEnv;
           serviceConfig = {
  -          ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-aggregator"}";
  -          User = "graphite";
  -          Group = "graphite";
  -        };
  +          ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts name}";
  +          User = "graphite";
  +          Group = "graphite";
  +          PIDFile="/run/${name}/${name}.pid";
  +        };
  +        preStart = mkPidFileDir name;
         };
       })
   
       (mkIf cfg.carbon.enableRelay {
  -      systemd.services.carbonRelay = {
  +      systemd.services.carbonRelay = let name = "carbon-relay"; in {
           description = "Carbon Data Relay";
           wantedBy = [ "multi-user.target" ];
           after = [ "network-interfaces.target" ];
           environment = carbonEnv;
           serviceConfig = {
  -          ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-relay"}";
  -          User = "graphite";
  -          Group = "graphite";
  -        };
  +          ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts name}";
  +          User = "graphite";
  +          Group = "graphite";
  +          PIDFile="/run/${name}/${name}.pid";
  +        };
  +        preStart = mkPidFileDir name;
         };
       })
   
  
positive.code: 
    config = mkMerge [
      (mkIf cfg.carbon.enableCache {
        systemd.services.carbonCache = {
          description = "Graphite Data Storage Backend";
          wantedBy = [ "multi-user.target" ];
          after = [ "network-interfaces.target" ];
          environment = carbonEnv;
          serviceConfig = {
            ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-cache"}";
            User = "graphite";
            Group = "graphite";
            PermissionsStartOnly = true;
          };
          preStart = ''
            mkdir -p ${cfg.dataDir}/whisper
            chmod 0700 ${cfg.dataDir}/whisper
            chown -R graphite:graphite ${cfg.dataDir}
  
negative.code:   };
  
    carbonOpts = name: with config.ids; ''
      --nodaemon --syslog --prefix=${name} --pidfile /run/${name}/${name}.pid ${name}
    '';
  
    mkPidFileDir = name: ''
      mkdir -p /run/${name}
      chmod 0700 /run/${name}
      chown -R graphite:graphite /run/${name}
    '';
  
    carbonEnv = {
      PYTHONPATH = "${pkgs.python27Packages.carbon}/lib/python2.7/site-packages";
      GRAPHITE_ROOT = dataDir;
  