<commit_before>{ config, lib, ... }:

with lib;

{
  options = {
    Label = mkOption {
      type = types.str;
      description = "This required key uniquely identifies the job to launchd.";
    };

    Disabled = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This optional key is used as a hint to <literal>launchctl(1)</literal> that it should not submit this job to launchd when
        loading a job or jobs. The value of this key does NOT reflect the current state of the job on the run-ning running
        ning system. If you wish to know whether a job is loaded in launchd, reading this key from a configura-tion configuration
        tion file yourself is not a sufficient test. You should query launchd for the presence of the job using
        the <literal>launchctl(1)</literal> list subcommand or use the ServiceManagement framework's
        <literal>SMJobCopyDictionary()</literal> method.

        Note that as of Mac OS X v10.6, this key's value in a configuration file conveys a default value, which
        is changed with the [-w] option of the <literal>launchctl(1)</literal> load and unload subcommands. These subcommands no
        longer modify the configuration file, so the value displayed in the configuration file is not necessar-ily necessarily
        ily the value that <literal>launchctl(1)</literal> will apply. See <literal>launchctl(1)</literal> for more information.

        Please also be mindful that you should only use this key if the provided on-demand and KeepAlive crite-ria criteria
        ria are insufficient to describe the conditions under which your job needs to run. The cost to have a
        job loaded in launchd is negligible, so there is no harm in loading a job which only runs once or very
        rarely.
      '';
    };

    UserName = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        This optional key specifies the user to run the job as. This key is only applicable when launchd is
        running as root.
      '';
    };

    GroupName = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        This optional key specifies the group to run the job as. This key is only applicable when launchd is
        running as root. If UserName is set and GroupName is not, the the group will be set to the default
        group of the user.
      '';
    };

    inetdCompatibility = mkOption {
      default = null;
      example = { Wait = true; };
      description = ''
        The presence of this key specifies that the daemon expects to be run as if it were launched from inetd.
      '';
      type = types.nullOr (types.submodule {
        options = {
          Wait = mkOption {
            type = types.nullOr (types.either types.bool types.str);
            default = null;
            description = ''
              This flag corresponds to the "wait" or "nowait" option of inetd. If true, then the listening
              socket is passed via the standard in/out/error file descriptors. If false, then <literal>accept(2)</literal> is
              called on behalf of the job, and the result is passed via the standard in/out/error descriptors.
            '';
          };
        };
      });
    };

    LimitLoadToHosts = mkOption {
      type = types.nullOr (types.listOf types.str);
      default = null;
      description = ''
        This configuration file only applies to the hosts listed with this key. Note: One should set kern.host-name kern.hostname
        name in <literal>sysctl.conf(5)</literal> for this feature to work reliably.
      '';
    };

    LimitLoadFromHosts = mkOption {
      type = types.nullOr (types.listOf types.str);
      default = null;
      description = ''
        This configuration file only applies to hosts NOT listed with this key. Note: One should set kern.host-name kern.hostname
        name in <literal>sysctl.conf(5)</literal> for this feature to work reliably.
      '';
    };

    LimitLoadToSessionType = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        This configuration file only applies to sessions of the type specified. This key is used in concert
        with the -S flag to <command>launchctl</command>.
      '';
    };

    Program = mkOption {
      type = types.nullOr types.path;
      default = null;
      description = ''
        This key maps to the first argument of <literal>execvp(3)</literal>.  If this key is missing, then the first element of
        the array of strings provided to the ProgramArguments will be used instead.  This key is required in
        the absence of the ProgramArguments key.
      '';
    };

    ProgramArguments = mkOption {
      type = types.nullOr (types.listOf types.str);
      default = null;
      description = ''
        This key maps to the second argument of <literal>execvp(3)</literal>.  This key is required in the absence of the Program
        key. Please note: many people are confused by this key. Please read <literal>execvp(3)</literal> very carefully!
      '';
    };

    EnableGlobbing = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This flag causes launchd to use the <literal>glob(3)</literal> mechanism to update the program arguments before invoca-tion. invocation.
        tion.
      '';
    };

    EnableTransactions = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This flag instructs launchd that the job promises to use <literal>vproc_transaction_begin(3)</literal> and
        <literal>vproc_transaction_end(3)</literal> to track outstanding transactions that need to be reconciled before the
        process can safely terminate. If no outstanding transactions are in progress, then launchd is free to
        send the SIGKILL signal.
      '';
    };

    OnDemand = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This key was used in Mac OS X 10.4 to control whether a job was kept alive or not. The default was
        true.  This key has been deprecated and replaced in Mac OS X 10.5 and later with the more powerful
        KeepAlive option.
      '';
    };

    KeepAlive = mkOption {
      type = types.nullOr (types.either types.bool (types.submodule {
        options = {

          SuccessfulExit = mkOption {
            type = types.nullOr types.bool;
            default = null;
            description = ''
              If true, the job will be restarted as long as the program exits and with an exit status of zero.
              If false, the job will be restarted in the inverse condition.  This key implies that "RunAtLoad"
              is set to true, since the job needs to run at least once before we can get an exit status.
            '';
          };

          NetworkState = mkOption {
            type = types.nullOr types.bool;
            default = null;
            description = ''
              If true, the job will be kept alive as long as the network is up, where up is defined as at least
              one non-loopback interface being up and having IPv4 or IPv6 addresses assigned to them.  If
              false, the job will be kept alive in the inverse condition.
            '';
          };

          PathState = mkOption {
            type = types.nullOr (types.attrsOf types.bool);
            default = null;
            description = ''
              Each key in this dictionary is a file-system path. If the value of the key is true, then the job
              will be kept alive as long as the path exists.  If false, the job will be kept alive in the
              inverse condition. The intent of this feature is that two or more jobs may create semaphores in
              the file-system namespace.
            '';
          };

          OtherJobEnabled = mkOption {
            type = types.nullOr (types.attrsOf types.bool);
            default = null;
            description = ''
              Each key in this dictionary is the label of another job. If the value of the key is true, then
              this job is kept alive as long as that other job is enabled. Otherwise, if the value is false,
              then this job is kept alive as long as the other job is disabled.  This feature should not be
              considered a substitute for the use of IPC.
            '';
          };

        };
      }));
      default = null;
      description = ''
        This optional key is used to control whether your job is to be kept continuously running or to let
        demand and conditions control the invocation. The default is false and therefore only demand will start
        the job. The value may be set to true to unconditionally keep the job alive. Alternatively, a dictio-nary dictionary
        nary of conditions may be specified to selectively control whether launchd keeps a job alive or not. If
        multiple keys are provided, launchd ORs them, thus providing maximum flexibility to the job to refine
        the logic and stall if necessary. If launchd finds no reason to restart the job, it falls back on
        demand based invocation.  Jobs that exit quickly and frequently when configured to be kept alive will
        be throttled to converve system resources.
      '';
    };

    RunAtLoad = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This optional key is used to control whether your job is launched once at the time the job is loaded.
        The default is false.
      '';
    };

    RootDirectory = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''<commit_msg>launchd: add extra KeepAlive options<commit_after>{ config, lib, ... }:

with lib;

{
  options = {
    Label = mkOption {
      type = types.str;
      description = "This required key uniquely identifies the job to launchd.";
    };

    Disabled = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This optional key is used as a hint to <literal>launchctl(1)</literal> that it should not submit this job to launchd when
        loading a job or jobs. The value of this key does NOT reflect the current state of the job on the run-ning running
        ning system. If you wish to know whether a job is loaded in launchd, reading this key from a configura-tion configuration
        tion file yourself is not a sufficient test. You should query launchd for the presence of the job using
        the <literal>launchctl(1)</literal> list subcommand or use the ServiceManagement framework's
        <literal>SMJobCopyDictionary()</literal> method.

        Note that as of Mac OS X v10.6, this key's value in a configuration file conveys a default value, which
        is changed with the [-w] option of the <literal>launchctl(1)</literal> load and unload subcommands. These subcommands no
        longer modify the configuration file, so the value displayed in the configuration file is not necessar-ily necessarily
        ily the value that <literal>launchctl(1)</literal> will apply. See <literal>launchctl(1)</literal> for more information.

        Please also be mindful that you should only use this key if the provided on-demand and KeepAlive crite-ria criteria
        ria are insufficient to describe the conditions under which your job needs to run. The cost to have a
        job loaded in launchd is negligible, so there is no harm in loading a job which only runs once or very
        rarely.
      '';
    };

    UserName = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        This optional key specifies the user to run the job as. This key is only applicable when launchd is
        running as root.
      '';
    };

    GroupName = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        This optional key specifies the group to run the job as. This key is only applicable when launchd is
        running as root. If UserName is set and GroupName is not, the the group will be set to the default
        group of the user.
      '';
    };

    inetdCompatibility = mkOption {
      default = null;
      example = { Wait = true; };
      description = ''
        The presence of this key specifies that the daemon expects to be run as if it were launched from inetd.
      '';
      type = types.nullOr (types.submodule {
        options = {
          Wait = mkOption {
            type = types.nullOr (types.either types.bool types.str);
            default = null;
            description = ''
              This flag corresponds to the "wait" or "nowait" option of inetd. If true, then the listening
              socket is passed via the standard in/out/error file descriptors. If false, then <literal>accept(2)</literal> is
              called on behalf of the job, and the result is passed via the standard in/out/error descriptors.
            '';
          };
        };
      });
    };

    LimitLoadToHosts = mkOption {
      type = types.nullOr (types.listOf types.str);
      default = null;
      description = ''
        This configuration file only applies to the hosts listed with this key. Note: One should set kern.host-name kern.hostname
        name in <literal>sysctl.conf(5)</literal> for this feature to work reliably.
      '';
    };

    LimitLoadFromHosts = mkOption {
      type = types.nullOr (types.listOf types.str);
      default = null;
      description = ''
        This configuration file only applies to hosts NOT listed with this key. Note: One should set kern.host-name kern.hostname
        name in <literal>sysctl.conf(5)</literal> for this feature to work reliably.
      '';
    };

    LimitLoadToSessionType = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
        This configuration file only applies to sessions of the type specified. This key is used in concert
        with the -S flag to <command>launchctl</command>.
      '';
    };

    Program = mkOption {
      type = types.nullOr types.path;
      default = null;
      description = ''
        This key maps to the first argument of <literal>execvp(3)</literal>.  If this key is missing, then the first element of
        the array of strings provided to the ProgramArguments will be used instead.  This key is required in
        the absence of the ProgramArguments key.
      '';
    };

    ProgramArguments = mkOption {
      type = types.nullOr (types.listOf types.str);
      default = null;
      description = ''
        This key maps to the second argument of <literal>execvp(3)</literal>.  This key is required in the absence of the Program
        key. Please note: many people are confused by this key. Please read <literal>execvp(3)</literal> very carefully!
      '';
    };

    EnableGlobbing = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This flag causes launchd to use the <literal>glob(3)</literal> mechanism to update the program arguments before invoca-tion. invocation.
        tion.
      '';
    };

    EnableTransactions = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This flag instructs launchd that the job promises to use <literal>vproc_transaction_begin(3)</literal> and
        <literal>vproc_transaction_end(3)</literal> to track outstanding transactions that need to be reconciled before the
        process can safely terminate. If no outstanding transactions are in progress, then launchd is free to
        send the SIGKILL signal.
      '';
    };

    OnDemand = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This key was used in Mac OS X 10.4 to control whether a job was kept alive or not. The default was
        true.  This key has been deprecated and replaced in Mac OS X 10.5 and later with the more powerful
        KeepAlive option.
      '';
    };

    KeepAlive = mkOption {
      type = types.nullOr (types.either types.bool (types.submodule {
        options = {

          SuccessfulExit = mkOption {
            type = types.nullOr types.bool;
            default = null;
            description = ''
              If true, the job will be restarted as long as the program exits and with an exit status of zero.
              If false, the job will be restarted in the inverse condition.  This key implies that "RunAtLoad"
              is set to true, since the job needs to run at least once before we can get an exit status.
            '';
          };

          NetworkState = mkOption {
            type = types.nullOr types.bool;
            default = null;
            description = ''
              If true, the job will be kept alive as long as the network is up, where up is defined as at least
              one non-loopback interface being up and having IPv4 or IPv6 addresses assigned to them.  If
              false, the job will be kept alive in the inverse condition.
            '';
          };

          PathState = mkOption {
            type = types.nullOr (types.attrsOf types.bool);
            default = null;
            description = ''
              Each key in this dictionary is a file-system path. If the value of the key is true, then the job
              will be kept alive as long as the path exists.  If false, the job will be kept alive in the
              inverse condition. The intent of this feature is that two or more jobs may create semaphores in
              the file-system namespace.
            '';
          };

          OtherJobEnabled = mkOption {
            type = types.nullOr (types.attrsOf types.bool);
            default = null;
            description = ''
              Each key in this dictionary is the label of another job. If the value of the key is true, then
              this job is kept alive as long as that other job is enabled. Otherwise, if the value is false,
              then this job is kept alive as long as the other job is disabled.  This feature should not be
              considered a substitute for the use of IPC.
            '';
          };

          Crashed = mkOption {
            type = types.nullOr types.bool;
            default = null;
            description = ''
              If true, the the job will be restarted as long as it exited due to a signal which is typically
              associated with a crash (SIGILL, SIGSEGV, etc.). If false, the job will be restarted in the
              inverse condition.
            '';
          };

          AfterInitialDemand = mkOption {
            type = types.nullOr types.bool;
            default = null;
          };

        };
      }));
      default = null;
      description = ''
        This optional key is used to control whether your job is to be kept continuously running or to let
        demand and conditions control the invocation. The default is false and therefore only demand will start
        the job. The value may be set to true to unconditionally keep the job alive. Alternatively, a dictio-nary dictionary
        nary of conditions may be specified to selectively control whether launchd keeps a job alive or not. If
        multiple keys are provided, launchd ORs them, thus providing maximum flexibility to the job to refine
        the logic and stall if necessary. If launchd finds no reason to restart the job, it falls back on
        demand based invocation.  Jobs that exit quickly and frequently when configured to be kept alive will
        be throttled to converve system resources.
      '';
    };

    RunAtLoad = mkOption {
      type = types.nullOr types.bool;
      default = null;
      description = ''
        This optional key is used to control whether your job is launched once at the time the job is loaded.
        The default is false.
      '';
    };

    RootDirectory = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = ''
{'fraction_non_alphanumeric': 0.06334171969809087, 'fraction_numerical': 0.0024665778698633517, 'mean_word_length': 2.1744440964610083, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 67, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3367271', 'n_tokens_mistral': 5052, 'n_tokens_neox': 4934, 'n_words': 2427}