Commit 460eb13f authored by Felix Buehler's avatar Felix Buehler
Browse files

nixos/services.gammu-smsd: remove `with lib;`

parent 36eaab47
Loading
Loading
Loading
Loading
+61 −63
Original line number Diff line number Diff line
{ pkgs, lib, config, ... }:

with lib;
let
  cfg = config.services.gammu-smsd;

@@ -10,7 +8,7 @@ let
    Connection = ${cfg.device.connection}
    SynchronizeTime = ${if cfg.device.synchronizeTime then "yes" else "no"}
    LogFormat = ${cfg.log.format}
    ${optionalString (cfg.device.pin != null) "PIN = ${cfg.device.pin}"}
    ${lib.optionalString (cfg.device.pin != null) "PIN = ${cfg.device.pin}"}
    ${cfg.extraConfig.gammu}


@@ -18,25 +16,25 @@ let
    LogFile = ${cfg.log.file}
    Service = ${cfg.backend.service}

    ${optionalString (cfg.backend.service == "files") ''
    ${lib.optionalString (cfg.backend.service == "files") ''
      InboxPath = ${cfg.backend.files.inboxPath}
      OutboxPath = ${cfg.backend.files.outboxPath}
      SentSMSPath = ${cfg.backend.files.sentSMSPath}
      ErrorSMSPath = ${cfg.backend.files.errorSMSPath}
    ''}

    ${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "sqlite") ''
    ${lib.optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "sqlite") ''
      Driver = ${cfg.backend.sql.driver}
      DBDir = ${cfg.backend.sql.database}
    ''}

    ${optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "native_pgsql") (
    ${lib.optionalString (cfg.backend.service == "sql" && cfg.backend.sql.driver == "native_pgsql") (
      with cfg.backend; ''
        Driver = ${sql.driver}
        ${optionalString (sql.database!= null) "Database = ${sql.database}"}
        ${optionalString (sql.host != null) "Host = ${sql.host}"}
        ${optionalString (sql.user != null) "User = ${sql.user}"}
        ${optionalString (sql.password != null) "Password = ${sql.password}"}
        ${lib.optionalString (sql.database!= null) "Database = ${sql.database}"}
        ${lib.optionalString (sql.host != null) "Host = ${sql.host}"}
        ${lib.optionalString (sql.user != null) "User = ${sql.user}"}
        ${lib.optionalString (sql.password != null) "Password = ${sql.password}"}
      '')}

    ${cfg.extraConfig.smsd}
@@ -53,42 +51,42 @@ in {
  options = {
    services.gammu-smsd = {

      enable = mkEnableOption "gammu-smsd daemon";
      enable = lib.mkEnableOption "gammu-smsd daemon";

      user = mkOption {
        type = types.str;
      user = lib.mkOption {
        type = lib.types.str;
        default = "smsd";
        description = "User that has access to the device";
      };

      device = {
        path = mkOption {
          type = types.path;
        path = lib.mkOption {
          type = lib.types.path;
          description = "Device node or address of the phone";
          example = "/dev/ttyUSB2";
        };

        group = mkOption {
          type = types.str;
        group = lib.mkOption {
          type = lib.types.str;
          default = "root";
          description = "Owner group of the device";
          example = "dialout";
        };

        connection = mkOption {
          type = types.str;
        connection = lib.mkOption {
          type = lib.types.str;
          default = "at";
          description = "Protocol which will be used to talk to the phone";
        };

        synchronizeTime = mkOption {
          type = types.bool;
        synchronizeTime = lib.mkOption {
          type = lib.types.bool;
          default = true;
          description = "Whether to set time from computer to the phone during starting connection";
        };

        pin = mkOption {
          type = types.nullOr types.str;
        pin = lib.mkOption {
          type = lib.types.nullOr lib.types.str;
          default = null;
          description = "PIN code for the simcard";
        };
@@ -96,14 +94,14 @@ in {


      log = {
        file = mkOption {
          type = types.str;
        file = lib.mkOption {
          type = lib.types.str;
          default = "syslog";
          description = "Path to file where information about communication will be stored";
        };

        format = mkOption {
          type = types.enum [ "nothing" "text" "textall" "textalldate" "errors" "errorsdate" "binary" ];
        format = lib.mkOption {
          type = lib.types.enum [ "nothing" "text" "textall" "textalldate" "errors" "errorsdate" "binary" ];
          default = "errors";
          description = "Determines what will be logged to the LogFile";
        };
@@ -111,15 +109,15 @@ in {


      extraConfig = {
        gammu = mkOption {
          type = types.lines;
        gammu = lib.mkOption {
          type = lib.types.lines;
          default = "";
          description = "Extra config lines to be added into [gammu] section";
        };


        smsd = mkOption {
          type = types.lines;
        smsd = lib.mkOption {
          type = lib.types.lines;
          default = "";
          description = "Extra config lines to be added into [smsd] section";
        };
@@ -127,70 +125,70 @@ in {


      backend = {
        service = mkOption {
          type = types.enum [ "null" "files" "sql" ];
        service = lib.mkOption {
          type = lib.types.enum [ "null" "files" "sql" ];
          default = "null";
          description = "Service to use to store sms data.";
        };

        files = {
          inboxPath = mkOption {
            type = types.path;
          inboxPath = lib.mkOption {
            type = lib.types.path;
            default = "/var/spool/sms/inbox/";
            description = "Where the received SMSes are stored";
          };

          outboxPath = mkOption {
            type = types.path;
          outboxPath = lib.mkOption {
            type = lib.types.path;
            default = "/var/spool/sms/outbox/";
            description = "Where SMSes to be sent should be placed";
          };

          sentSMSPath = mkOption {
            type = types.path;
          sentSMSPath = lib.mkOption {
            type = lib.types.path;
            default = "/var/spool/sms/sent/";
            description = "Where the transmitted SMSes are placed";
          };

          errorSMSPath = mkOption {
            type = types.path;
          errorSMSPath = lib.mkOption {
            type = lib.types.path;
            default = "/var/spool/sms/error/";
            description = "Where SMSes with error in transmission is placed";
          };
        };

        sql = {
          driver = mkOption {
            type = types.enum [ "native_mysql" "native_pgsql" "odbc" "dbi" ];
          driver = lib.mkOption {
            type = lib.types.enum [ "native_mysql" "native_pgsql" "odbc" "dbi" ];
            description = "DB driver to use";
          };

          sqlDialect = mkOption {
            type = types.nullOr types.str;
          sqlDialect = lib.mkOption {
            type = lib.types.nullOr lib.types.str;
            default = null;
            description = "SQL dialect to use (odbc driver only)";
          };

          database = mkOption {
            type = types.nullOr types.str;
          database = lib.mkOption {
            type = lib.types.nullOr lib.types.str;
            default = null;
            description = "Database name to store sms data";
          };

          host = mkOption {
            type = types.str;
          host = lib.mkOption {
            type = lib.types.str;
            default = "localhost";
            description = "Database server address";
          };

          user = mkOption {
            type = types.nullOr types.str;
          user = lib.mkOption {
            type = lib.types.nullOr lib.types.str;
            default = null;
            description = "User name used for connection to the database";
          };

          password = mkOption {
            type = types.nullOr types.str;
          password = lib.mkOption {
            type = lib.types.nullOr lib.types.str;
            default = null;
            description = "User password used for connection to the database";
          };
@@ -199,7 +197,7 @@ in {
    };
  };

  config = mkIf cfg.enable {
  config = lib.mkIf cfg.enable {
    users.users.${cfg.user} = {
      description = "gammu-smsd user";
      isSystemUser = true;
@@ -207,7 +205,7 @@ in {
    };

    environment.systemPackages = with cfg.backend; [ gammuPackage ]
    ++ optionals (service == "sql" && sql.driver == "sqlite")  [ pkgs.sqlite ];
    ++ lib.optionals (service == "sql" && sql.driver == "sqlite")  [ pkgs.sqlite ];

    systemd.services.gammu-smsd = {
      description = "gammu-smsd daemon";
@@ -215,29 +213,29 @@ in {
      wantedBy = [ "multi-user.target" ];

      wants = with cfg.backend; [ ]
      ++ optionals (service == "sql" && sql.driver == "native_pgsql") [ "postgresql.service" ];
      ++ lib.optionals (service == "sql" && sql.driver == "native_pgsql") [ "postgresql.service" ];

      preStart = with cfg.backend;

        optionalString (service == "files") (with files; ''
        lib.optionalString (service == "files") (with files; ''
          mkdir -m 755 -p ${inboxPath} ${outboxPath} ${sentSMSPath} ${errorSMSPath}
          chown ${cfg.user} -R ${inboxPath}
          chown ${cfg.user} -R ${outboxPath}
          chown ${cfg.user} -R ${sentSMSPath}
          chown ${cfg.user} -R ${errorSMSPath}
        '')
      + optionalString (service == "sql" && sql.driver == "sqlite") ''
      + lib.optionalString (service == "sql" && sql.driver == "sqlite") ''
         cat "${gammuPackage}/${initDBDir}/sqlite.sql" \
         | ${pkgs.sqlite.bin}/bin/sqlite3 ${sql.database}
        ''
      + (let execPsql = extraArgs: concatStringsSep " " [
          (optionalString (sql.password != null) "PGPASSWORD=${sql.password}")
      + (let execPsql = extraArgs: lib.concatStringsSep " " [
          (lib.optionalString (sql.password != null) "PGPASSWORD=${sql.password}")
          "${config.services.postgresql.package}/bin/psql"
          (optionalString (sql.host != null) "-h ${sql.host}")
          (optionalString (sql.user != null) "-U ${sql.user}")
          (lib.optionalString (sql.host != null) "-h ${sql.host}")
          (lib.optionalString (sql.user != null) "-U ${sql.user}")
          "$extraArgs"
          "${sql.database}"
        ]; in optionalString (service == "sql" && sql.driver == "native_pgsql") ''
        ]; in lib.optionalString (service == "sql" && sql.driver == "native_pgsql") ''
         echo '\i '"${gammuPackage}/${initDBDir}/pgsql.sql" | ${execPsql ""}
       '');