{ lib, config, ... }: let cfg = config.runit; in { options = { runit.services = lib.mkOption { type = lib.types.attrsOf ( lib.types.submodule { run = lib.mkOption { type = lib.types.string; description = "The command to run. Equivalent to ExecStart in systemd"; }; check = lib.mkOption { type = lib.types.optional lib.types.string; description = "The command to run to check if the service is running."; }; finish = lib.mkOption { type = lib.types.optional lib.types.string; description = "The command to run when the service is stopped."; }; conf = lib.mkOption { type = lib.types.optional lib.types.string; description = "The command to run to configure the service."; }; } ); default = { }; }; }; config = { environment.etc = lib.mkMerge lib.mapAttrsToList ( name: value: { "service/${name}/run".source = value.run; } // lib.optionalAttrs (value.check != null) { "service/${name}/check".source = value.check; } // lib.optionalAttrs (value.finish != null) { "service/${name}/finish".source = value.finish; } // lib.optionalAttrs (value.conf != null) { "service/${name}/conf".source = value.conf; } ) cfg.services; }; }