3

I'm running NixOS with systemd and Niri (a Wayland compositor). Right now, I have to log in on the text console and run niri-session (source) to get a graphical session.

Of course, I could install LightDM and configure autologin. But what is the point for a display manager when I'm the only user of the machine and don't run any other session? The machine is sufficiently protected by the disk encryption password.

What would be the cleanest way to automatically boot into Niri without a display manager?

1 Answers1

1

There seem to be multiple options:

This is how I configured it in NixOS:

add a autologin.nix file:

{ config, lib, pkgs, ... }:
let
  # autologin on tty7y. Otherwise autologin and getty alternate in grabbing tty1 on nixos-rebuild switch
  autologin_on_7 = pkgs.autologin.overrideAttrs (_: {
    postPatch = ''
      substituteInPlace "main.c" \
        --replace-fail "setup_vt(1);" "setup_vt(7);" \
        --replace-fail "XDG_VTNR=1" "XDG_VTNR=7"
    '';
  }
  );
in
{
  # see https://git.sr.ht/~kennylevinsen/autologin
  # TODO https://superuser.com/questions/1904422/how-to-auto-login-without-display-manager-for-nixos-wayland-niri/1904473#1904473
  environment.systemPackages = [ autologin_on_7 ];

systemd.services.autologin = { enable = true; restartIfChanged = lib.mkForce false; description = "Autologin"; after = [ "systemd-user-sessions.service" "plymouth-quit-wait.service" ];

serviceConfig = {
  ExecStart = "${autologin_on_7}/bin/autologin thk ${pkgs.niri}/bin/niri-session";
  Type = "simple";
  IgnoreSIGPIPE = "no";
  SendSIGHUP = "yes";
  TimeoutStopSec = "30s";
  KeyringMode = "shared";
  Restart = "always";
  RestartSec = "10";
};
startLimitBurst = 5;
startLimitIntervalSec = 30;
aliases = [ "display-manager.service" ];
wantedBy = [ "multi-user.target" ];

};

security.pam.services.autologin = { enable = true; name = "autologin"; startSession = true; setLoginUid = true; updateWtmp = true; }; }

and import this file from your configuration.nix:

{ config, lib, pkgs, ... }:
{
  imports =
    [
      ./hardware-configuration.nix
      ./autologin.nix
      # and probably more imports ...
    ];

Update: I patched autologin so that it uses tty7. Otherwise systemd would kill autoload.service and getty1.service alternatively on nixos-rebuild switch due to the conflict defined previously. Also it is nicer to keep tty1 for the kernel output.

Giacomo1968
  • 58,727