I tried ChatGPT:
boot.loader.grub = {
enable = true;
device = "${vars.bootDevice}";
useOSProber = true;
extraEntries = ''
menuentry "NixOS (text only)" {
linux $kernel systemConfig=$systemConfig init=$initrd systemd.unit=multi-user.target
initrd $initrd
}
'';
};
and DeepSeek:
boot.loader.grub = {
enable = true;
device = "${vars.bootDevice}";
useOSProber = true;
extraEntries = ''
menuentry "Text Only" {
linux $kernel $kernelParams systemd.unit=multi-user.target
initrd $initrd
}
'';
};
Both have failed miserably.
Any ideas?
I think it can be achieved by defining a specialisation.
https://wiki.nixos.org/wiki/Specialisation
I tried:
specialisation = {
tty = {
inheritParentConfig = true;
configuration = {
# Override to disable X server and desktop managers
services.xserver.enable = lib.mkOverride 101 false;
services.xserver.desktopManager.plasma5.enable = lib.mkOverride 101 false;
services.xserver.desktopManager.gnome.enable = lib.mkOverride 101 false;
services.xserver.desktopManager.lxqt.enable = lib.mkOverride 101 false;
# Override display manager sub-options (do not override 'enable' as it is not defined)
services.xserver.displayManager.lightdm.enable = lib.mkOverride 101 false;
services.xserver.displayManager.gdm.enable = lib.mkOverride 101 false;
};
};
};
But unfortunately didn’t work.
I think setting services.xserver.enable
to false
would effectively disable your display manager and drop you into tty, unless you’re using a display manager that is not under services.xserver
, e.g. sddm. So what is exactly the display manager you use? You can only use one of them, and it doesn’t make sense to disable some of them randomly.
BTW, why do you want to boot into text only mode? If you only want to use a text only tty, then you can try Ctrl + Alt + (one of F1~F7) to switch among tty1~tty7. Usually most of them are not running graphic interface.
Hello my friend! Thank you very much for your attention.
Let me give you a little more context:
This code is part of a repository I have that tries to keep things somewhat “generic.” You can find it here: https://github.com/noksys/genoc.
In the UI directory: https://github.com/noksys/genoc/tree/main/ui,
you can find specific configurations for different graphical biotypes. One of them is “terminal.nix.” If you include Gnome, for example, it does:
gnome.enable = lib.mkForce true;
and disables all others to prevent conflicts. For this reason, I had to use lib.mkOverride 101 false;
to take even higher priority than the regular lib.mkForce
.
That’s not the issue, though. The problem is that I tried running:
sudo nixos-rebuild switch --specialisation tty
and it simply ignored everything I did. It also didn’t create a new entry in Grub, as expected.
Why do I want the option to boot into text mode only? Several reasons, but the most obvious one is to avoid loading countless unnecessary things used only in graphical mode. Switching the terminal doesn’t seem like a good option. Additionally, my KDE has been having some issues that make my laptop freeze even if I’m operating from a different terminal. I want a way to completely disable it.
Adding this entry to Grub should be simple, but apparently, I’m making a syntax error somewhere.
Tried adding the following expression to my NixOS config
{
specialisation = {
text.configuration = {
systemd.services.display-manager.enable = false;
};
};
}
and then sudo nixos-rebuild boot
, a systemd-boot entry not starting the display manager appeared as expected.
I don’t like the idea of abusing mkForce
. In many cases, conflicts should be handled by users themselves, and raising an error of the conflict is more helpful than silently overriding the conflicting value defined elsewhere.
I don’t think having the graphic session terminated while switching is an expected behavior. You may reboot to the specialisation instead.
Haven’t tried with grub yet, but I guess it might be in a subentry or something. Also check if you have properly imported the file defining the specialisation.
1 Like
You are correct in all your statements. I feel like a fool now. I think there was just one missing: sudo nixos-rebuild boot
and the way you suggested really simplifies things a lot. I didn’t need to resort to priority manipulation.