anchor.diff:          description = "Extra lines to append to SeatDefaults section.";
         };
   
  +      autoLogin = mkOption {
  +        default = {};
  +        description = ''
  +          Configuration for automatic login.
  +        '';
  +
  +        type = types.submodule {
  +          options = {
  +            enable = mkOption {
  +              type = types.bool;
  +              default = false;
  +              description = ''
  +                Automatically log in as the specified <option>autoLogin.user</option>.
  +              '';
  +            };
  +
  +            user = mkOption {
  +              type = types.nullOr types.str;
  +              default = null;
  +              description = ''
  +                User to be used for the automatic login.
  +              '';
  +            };
  +
  +            timeout = mkOption {
  +              type = types.int;
  +              default = 0;
  +              description = ''
  +                Show the greeter for this many seconds before automatic login occurs.
  +              '';
  +            };
  +          };
  +        };
  +      };
  +
       };
     };
   
     config = mkIf cfg.enable {
  +
  +    assertions = [
  +      { assertion = cfg.autoLogin.enable -> cfg.autoLogin.user != null;
  +        message = ''
  +          LightDM auto-login requires services.xserver.displayManager.lightdm.autoLogin.user to be set
  +        '';
  +      }
  +      { assertion = cfg.autoLogin.enable -> elem defaultSessionName dmcfg.session.names;
  +        message = ''
  +          LightDM auto-login requires that services.xserver.desktopManager.default and
  +          services.xserver.windowMananger.default are set to valid values. The current
  +          default session: ${defaultSessionName} is not valid.
  +        '';
  +      }
  +      { assertion = !cfg.greeter.enable -> (cfg.autoLogin.enable && cfg.autoLogin.timeout == 0);
  +        message = ''
  +          LightDM can only run without greeter if automatic login is enabled and the timeout for it
  +          is set to zero.
  +        '';
  +      }
  +    ];
  +
       services.xserver.displayManager.slim.enable = false;
   
       services.xserver.displayManager.job = {
  
positive.code:         session  optional ${pkgs.systemd}/lib/security/pam_systemd.so
        '';
      };
  
      users.extraUsers.lightdm = {
        createHome = true;
  
negative.code:   lightdmConf = writeText "lightdm.conf"
      ''
        [LightDM]
        ${optionalString cfg.greeter.enable ''
          greeter-user = ${config.users.extraUsers.lightdm.name}
          greeters-directory = ${cfg.greeter.package}
        ''}
        sessions-directory = ${dmcfg.session.desktops}
  
        [Seat:*]
        xserver-command = ${xserverWrapper}
        session-wrapper = ${dmcfg.session.script}
        ${optionalString cfg.greeter.enable ''
          greeter-session = ${cfg.greeter.name}
        ''}
        ${optionalString cfg.autoLogin.enable ''
          autologin-user = ${cfg.autoLogin.user}
          autologin-user-timeout = ${toString cfg.autoLogin.timeout}
          autologin-session = ${defaultSessionName}
        ''}
        ${cfg.extraSeatDefaults}
      '';
  
    defaultSessionName =
      let
        dm = xcfg.desktopManager.default;
        wm = xcfg.windowManager.default;
      in dm + optionalString (wm != "none") (" + " + wm);
  in
  {
    # Note: the order in which lightdm greeter modules are imported
  