nixos-configuration/modules/autologin.nix
2021-11-17 16:08:19 +00:00

31 lines
969 B
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.myConfig;
in
{
options.myConfig = {
autologin = {
enable = pkgs.lib.mkEnableOption "Enable tty1 autologin";
username = pkgs.lib.mkOption {
type = lib.types.str;
description = "Username of user to be automatically logged in at tty1";
};
};
};
config = lib.mkIf cfg.autologin.enable {
systemd.services."autovt@tty1" = {
description = "Autologin at the TTY1";
after = [ "systemd-logind.service" ]; # without it user session not started and xorg can't be run from this tty
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = [
"" # override upstream default with an empty ExecStart
"@${pkgs.utillinux}/sbin/agetty agetty --login-program ${pkgs.shadow}/bin/login --autologin '${cfg.autologin.username}' --noclear %I $TERM"
];
Restart = "always";
Type = "idle";
};
};
};
}