Turn on numlock at boot

Hello all,

I need help please. I want to turn on numlock at boot please.
I tried the following:

systemd.services.numlock = {
  description = "Enable NumLock at startup";
  wantedBy = [ "multi-user.target" ];  # Ensure it starts with the system
  serviceConfig = {
    Type = "oneshot";
    RemainAfterExit = "yes";
    ExecStart = "${pkgs.kbd}/bin/setleds +num";  # Command to turn on NumLock
  };
};

But rebuilding NixOS fails with the following error:

setleds: Unable to read keyboard flags: Inappropriate ioctl for device

When runnging setleds on a terminal, I get the same error.

Please help :slight_smile:

Never used setleds, numlockx was working fine afair.

If you’re using home-manager:

xsession.numlock.enable

Otherwise, declaring it as user unit via systemd.user.services might help.

Yes, I am aware of numlockx. But:

  1. It will not work when we all move to wayland since its only for X.
  2. I want it enabled before X (or wayland for that matter) starts.

Yes, I am aware of the home-manager option. I wanna do it without home-manager.

Oh I missed this part from your original message:

Looks like another issue.
Could you try redirecting it to a TTY? Here is an example I found on github.

I tried it. Here is the result:

λ sudo setleds +num < /dev/tty1
zsh: permission denied: /dev/tty1

Same without sudo.

sudo cannot apply after the < part. You can run after switching to root though.

But what I suggested was to declare the systemd unit with setting like TTYPath = "/dev/tty8"; to force-run it on a TTY :slight_smile:

I did what you asked, and the result is the same. Here is how I did it:

systemd.services.numlock = {
  description = "Enable NumLock at startup";
  wantedBy = [ "multi-user.target" ];  # Ensure it starts with the system
  serviceConfig = {
    TTYPath = "/dev/tty8";
    Type = "oneshot";
    RemainAfterExit = "yes";
    ExecStart = "${pkgs.kbd}/bin/setleds +num";  # Command to turn on NumLock
  };
};

As a last resort, could you also add:

      StandardInput = "tty";
      StandardOutput = "tty";

If this also does not work, I will have to give up :slight_smile:

Nope. It did not help. But, there is no more error after rebuilding NixOS, but rebooting does not turn on the numlock.
Also, trying sudo systemctl enable numlock and/or sudo systemctl start numlock does not spews an error but also does not turn on the numlock.