Autologin Hyprland

services.greetd = {
  enable = true;
  settings = rec {
    initial_session = {
      command = "Hyprland";
      user = "myuser";
    };
    default_session = initial_session;
  };
};

Is there a way to log only at startup, so after quitting Hyprland it will stay in TTY?

Checkout this thread https://discourse.nixos.org/t/how-to-enable-login-screen-and-start-hyperland-after-login OP uses greetd and example therein; but if I understand you correctly you don’t want to autologin after you quit hyprland initially? Seems so now that i’m re-reading it. I’ll dig around but haven’t done this myself

Yes exactly. After second hyprland exit it crash. Can’t close TTY. On other Linux distro I was using:

sudo mkdir /etc/systemd/system/getty@tty1.service.d/

/etc/systemd/system/getty@tty1.service.d/autologin.conf:

[Service]
ExecStart=
ExecStart=-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin <username> %I $TERM
Type=idle
Environment=XDG_SESSION_TYPE=wayland
sudo systemctl enable getty@tty1

in that case have a look at nix - How to create a systemd service template in NixOS? - Stack Overflow
also more on the (unofficial) wiki Systemd Hardening - NixOS Wiki - probably official docs someplace but I can’t find them ATM

Tnx. I tried to glue something from it:

systemd.services.getty@tty1 = {
    serviceConfig = {
      ExecStart ="";
      ExecStart = "-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin <username> %I $TERM";
      Type = "idle";
    };
};

On rebuild configuration it complained about @.

try this systemd.services."getty@tty1"

That helped. On rebuild it complained about already defined ExecStart, so I removed 1st one. It works but I need to figure out also how to start Hyprland. It looks now like this:

systemd.services."getty@tty1" = {
    serviceConfig = {
      ExecStart = "-/sbin/agetty -o '-p -f -- \\u' --noclear --autologin <username> %I $TERM";
      Type = "idle";
    };
    Environment="XDG_SESSION_TYPE=Hyprland";
};

That line with Env is wrong. That option should be probably here, but I don’t know which one.

I forget that in configuration.nix there is already autologin:
services.getty.autologinUser = "mee";
I disabled it and my systemd service getty@tty1 doesn’t work.
Maybe I can somehow add option from here to start Hyprland.

I hate to point you to the source but perhaps you can find what you’re looking for there? https://github.com/NixOS/nixpkgs/blob/b22abecec7b09ac3a36a727afdcca72f74d51e04/nixos/modules/system/boot/systemd.nix#L295 Not sure

I’m trying to find out the simplest solution from all of them. In this video it seems reasonable. I had in the past similar line like that. Or if you can look on my prev post if I can do it with services.getty.

hmmm, check the config in this post https://www.reddit.com/r/NixOS/comments/u0cdpi/tuigreet_with_xmonad_how/ - I think using services.greetd (if you can) is the best bet but I don’t really know tbh - wish I could be of more help

1 Like

I appreciate all the help. For now I will try to not quit Hyprland 2 times in a row.

I use the below config using greetd. It’ll autologin and start Hyprland when you first boot. After you logout, it’ll start tuigreet, a TUI greeter, where you’ll need to type in your password to login. You could also read the docs for more info. Be sure to change the username variable to your username.

{ pkgs, ... }:

let
  tuigreet = "${pkgs.greetd.tuigreet}/bin/tuigreet";
  session = "${pkgs.hyprland}/bin/Hyprland";
  username = "user";
in

{
  services.greetd = {
    enable = true;
    settings = {
      initial_session = {
        command = "${session}";
        user = "${username}";
      };
      default_session = {
        command = "${tuigreet} --greeting 'Welcome to NixOS!' --asterisks --remember --remember-user-session --time -cmd ${session}";
        user = "greeter";
      };
    };
  };
}

3 Likes

Now I can logout from Hyprland as many times as I want without any crashing. It works exactly like you described. This is great. Tnx!

2 Likes