NixOS shutdown during cold boot

Hello!

I recently installed NixOS 24.11 on my machine, a Slimbook PRO X with an AMD 7 4800H. I’m facing a weird problem. When trying to boot while on battery (no AC plugged in), NixOS will shutdown immediately, sometimes shortly after starting Stage 2, sometimes even before it leaves Stage 1.

I had previously installed NixOS 24.05 and had the same issue, but thought it was a problem with the machine. However, I installed Fedora and had been working without a problem. When the last NixOS release was announced, I wanted to try it again, but the problem persists. I’ve already searched the internet and this forum, but only found people with boot processes hang, not abruptly shuting down.

Any help would be much appreciated.

configuration.nix

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{
  config,
  pkgs,
  ...
}: {
  imports = [
    # Include the results of the hardware scan.
    ./hardware-configuration.nix
  ];

  nix.settings.experimental-features = ["nix-command" "flakes"];

  # Bootloader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;
  boot.kernelParams = [
    "clocksource=tsc"
    "tsc=reliable"
    "mitigations=off"
  ];
  boot.kernelPackages = pkgs.linuxPackages_latest;

  boot.initrd.luks.devices."luks-e5db336d-1ea7-403b-a339-5fbc18062dd9".device = "/dev/disk/by-uuid/e5db336d-1ea7-403b-a339-5fbc18062dd9";
  networking.hostName = "host"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Enable networking
  networking.networkmanager.enable = true;

  # Set your time zone.
  time.timeZone = "Europe/Madrid";

  # Select internationalisation properties.
  i18n.defaultLocale = "es_ES.UTF-8";

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "es_ES.UTF-8";
    LC_IDENTIFICATION = "es_ES.UTF-8";
    LC_MEASUREMENT = "es_ES.UTF-8";
    LC_MONETARY = "es_ES.UTF-8";
    LC_NAME = "es_ES.UTF-8";
    LC_NUMERIC = "es_ES.UTF-8";
    LC_PAPER = "es_ES.UTF-8";
    LC_TELEPHONE = "es_ES.UTF-8";
    LC_TIME = "es_ES.UTF-8";
  };

  # Enable the X11 windowing system.
  services.xserver.enable = true;

  # Enable the Pantheon Desktop Environment.
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;

  # Configure keymap in X11
  services.xserver.xkb = {
    layout = "es";
    variant = "";
  };

  # Configure console keymap
  console.keyMap = "es";

  # Enable CUPS to print documents.
  services.printing.enable = true;

  # Enable sound with pipewire.
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.user = {
    isNormalUser = true;
    description = "User";
    extraGroups = ["networkmanager" "wheel"];
    shell = pkgs.zsh;
    packages = with pkgs; [
      #  thunderbird
      pciutils
      usbutils
      python3
      libreoffice
    ];
  };

  # Enable automatic login for the user.
  services.displayManager.autoLogin.enable = true;
  services.displayManager.autoLogin.user = "pablo";

  hardware.keyboard.qmk.enable = true;
  services.udev.packages = with pkgs; [
    qmk-udev-rules
    via
  ];

  virtualisation.libvirtd = {
    enable = true;
    #qemu = {
    #  package = pkgs.qemu_full;
    #  runAsRoot = true;
    #  swtpm.enable = true;
    #  ovmf = {
    #    enable = true;
    #    packages = [
    #      (pkgs.OVMF.override {
    #        secureBoot = true;
    #        tpmSupport = true;
    #      })
    #      .fd
    #    ];
    #  };
    #};
  };

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  programs = {
    gnupg.agent = {
      enable = true;
      enableSSHSupport = true;
    };
    virt-manager.enable = true;
    zsh.enable = true;
    firefox = {
      enable = true;

      package = pkgs.librewolf;

      nativeMessagingHosts.packages = with pkgs; [
        browserpass
        tridactyl-native
      ];

      policies = {
        DisableTelemetry = true;
        DisableFirefoxStudies = true;
        DontCheckDefaultBrowser = true;
        DisablePocket = true;
        SearchBar = "unified";

        Preferences = let
          lock-false = {
            Value = false;
            Status = "locked";
          };
          # lock-true = {
          #   Value = true;
          #   Status = "locked";
          # };
          # lock-empty-string = {
          #   Value = "";
          #   Status = "locked";
          # };
        in {
          "extensions.pocket.enabled" = lock-false;
        };

        ExtensionSettings = {
          "uBlock0@raymondhill.net" = {
            install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi";
            installation_mode = "force_installed";
          };
        };
      };
    };
  };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  services.openssh.enable = true;

  # Open ports in the firewall.
  networking.firewall = rec {
    allowedTCPPorts = [22];
    allowedTCPPortRanges = [
      {
        from = 1714;
        to = 1764;
      }
    ];
    allowedUDPPortRanges = allowedTCPPortRanges;
  };

  # Install firefox.
  #programs.firefox.enable = true;

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    #  vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
    firefox
  ];

  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "24.11"; # Did you read the comment?
}

hardware-configuration.nix

# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usb_storage" "sd_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/dcb6bab4-2ea0-44ce-81c5-ec3347f1cee3";
      fsType = "ext4";
    };

  boot.initrd.luks.devices."luks-b60a35ae-4994-4dbd-8537-7536164b117f".device = "/dev/disk/by-uuid/b60a35ae-4994-4dbd-8537-7536164b117f";

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/85EA-6684";
      fsType = "vfat";
      options = [ "fmask=0077" "dmask=0077" ];
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/cf5dc8cd-d1b3-4ef1-aba7-316e6acd2232"; }
    ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.eno1.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp1s0.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}
1 Like

Hi, sorry to bump, but I reinstalled and am having the same problem. I am willing to live with it, anoying as it may be, but if someone could point me in the right direction I would be so grateful. journald doesn’t give me a single clue of what is going on, or why the laptop boots when plugged in to power and doesn’t when on battery. Once booted, it works perfectly. I recently added some power settings (powertop, acpi-cpufreq and such), and while the power consumption went down, it didn’t change this boot problem.

The system has FDE, and waits for the password. Once it is correctly introduced, it continues the boot process, and it is then that it suddenly shuts down when on battery.

Also, even if the title says during cold boot, it happens on reboot too.

Hello.
First of all do other Operating Systems or other Distros work?
Second can you post the dmesg log?
Also can you post your powersettings and hardware and software infos of your system?

Hello,

  1. Yes, when I bought the computer it came with windows 11 and it booted fine. I then installed NixOS 24.05 and had this issue. After trying to fix it, I installed Fedora (can’t remember the exact version). I used several versions, maybe 40 and 41, without an issue. I briefly installed elementaryOS and, again, it booted without a problem.
  2. Here is the log for the last boot that failed using this command journalctl -o short-precise -k -b -1: link to privatebin
  1. Here are my config files:
configuration.nix
# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{
 #config,
 pkgs,
 ...
}: {
 imports = [
   # Include the results of the hardware scan.
   ./hardware-configuration.nix
 ];

 nix.settings.experimental-features = ["nix-command" "flakes"];

 # Hardware optimizations
 powerManagement = {
   enable = true;
   powertop.enable = true;
   cpuFreqGovernor = "powersave";
 };
 services.power-profiles-daemon.enable = false;
 services.auto-cpufreq = {
   enable = true;
   settings = {
     battery = {
       governor = "powersave";
       turbo = "never";
     };
     charger = {
       governor = "powersave";
       turbo = "auto";
     };
   };
 };
 services.thermald.enable = true;
 services.system76-scheduler = {
   enable = true;
   useStockConfig = true;
 };

 # Bootloader.
 boot.loader.systemd-boot.enable = true;
 boot.loader.efi.canTouchEfiVariables = true;
 boot.kernelParams = [
   "clocksource=tsc"
   "tsc=reliable"
   "mitigations=off"
 ];
 boot.kernelPackages = pkgs.linuxPackages_latest;

 boot.initrd.luks.devices."luks-".device = "/dev/disk/by-uuid/4a98d9c1-0c75-4d59-b9cb-eca6fdbd2530";
 networking.hostName = "REDACTED"; # Define your hostname.
 # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

 # Configure network proxy if necessary
 # networking.proxy.default = "http://user:password@proxy:port/";
 # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

 # Enable networking
 networking.networkmanager.enable = true;

 # Set your time zone.
 time.timeZone = "Europe/Madrid";

 # Select internationalisation properties.
 i18n.defaultLocale = "es_ES.UTF-8";

 i18n.extraLocaleSettings = {
   LC_ADDRESS = "es_ES.UTF-8";
   LC_IDENTIFICATION = "es_ES.UTF-8";
   LC_MEASUREMENT = "es_ES.UTF-8";
   LC_MONETARY = "es_ES.UTF-8";
   LC_NAME = "es_ES.UTF-8";
   LC_NUMERIC = "es_ES.UTF-8";
   LC_PAPER = "es_ES.UTF-8";
   LC_TELEPHONE = "es_ES.UTF-8";
   LC_TIME = "es_ES.UTF-8";
 };

 # Enable the X11 windowing system.
 services.xserver.enable = true;

 # Enable the Pantheon Desktop Environment.
 services.xserver.displayManager.gdm.enable = true;
 services.xserver.desktopManager.gnome.enable = true;

 # Configure keymap in X11
 services.xserver.xkb = {
   layout = "es";
   variant = "";
 };

 # Configure console keymap
 console.keyMap = "es";

 # Enable CUPS to print documents.
 services.printing.enable = true;

 # Enable sound with pipewire.
 hardware.pulseaudio.enable = false;
 security.rtkit.enable = true;
 services.pipewire = {
   enable = true;
   alsa.enable = true;
   alsa.support32Bit = true;
   pulse.enable = true;
   # If you want to use JACK applications, uncomment this
   #jack.enable = true;

   # use the example session manager (no others are packaged yet so this is enabled by default,
   # no need to redefine it in your config for now)
   #media-session.enable = true;
 };

 # Enable touchpad support (enabled default in most desktopManager).
 # services.xserver.libinput.enable = true;

 # Define a user account. Don't forget to set a password with ‘passwd’.
 users.users.REDACTED = {
   isNormalUser = true;
   description = "REDACTED";
   extraGroups = ["networkmanager" "wheel"];
   shell = pkgs.zsh;
   packages = with pkgs; [
     #  thunderbird
     pciutils
     usbutils
   ];
 };

 # Enable automatic login for the user.
 services.displayManager.autoLogin.enable = false;
 services.displayManager.autoLogin.user = "REDACTED";

 hardware.keyboard.qmk.enable = true;
 services.udev.packages = with pkgs; [
   qmk-udev-rules
   via
 ];

 virtualisation.libvirtd = {
   enable = true;
   qemu = {
     package = pkgs.qemu_full;
     runAsRoot = true;
     swtpm.enable = true;
     ovmf = {
       enable = true;
       packages = [
         (pkgs.OVMF.override {
           secureBoot = true;
           tpmSupport = true;
         })
         .fd
       ];
     };
   };
 };

 # Some programs need SUID wrappers, can be configured further or are
 # started in user sessions.
 # programs.mtr.enable = true;
 programs = {
   gnupg.agent = {
     enable = true;
     enableSSHSupport = true;
   };
   virt-manager.enable = true;
   zsh.enable = true;
   firefox = {
     enable = false;

     package = pkgs.librewolf;

     nativeMessagingHosts.packages = with pkgs; [
       browserpass
       tridactyl-native
     ];

     policies = {
       DisableTelemetry = true;
       DisableFirefoxStudies = true;
       DontCheckDefaultBrowser = true;
       DisablePocket = true;
       SearchBar = "unified";

       Preferences = let
         lock-false = {
           Value = false;
           Status = "locked";
         };
         # lock-true = {
         #   Value = true;
         #   Status = "locked";
         # };
         # lock-empty-string = {
         #   Value = "";
         #   Status = "locked";
         # };
       in {
         "extensions.pocket.enabled" = lock-false;
       };

       ExtensionSettings = {
         "uBlock0@raymondhill.net" = {
           install_url = "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi";
           installation_mode = "force_installed";
         };
       };
     };
   };
 };

 # List services that you want to enable:

 # Enable the OpenSSH daemon.
 services.openssh.enable = true;

 # Open ports in the firewall.
 networking.firewall = rec {
   allowedTCPPorts = [22];
   allowedTCPPortRanges = [
     {
       from = 1714;
       to = 1764;
     }
   ];
   allowedUDPPortRanges = allowedTCPPortRanges;
 };

 # Install firefox.
 #programs.firefox.enable = true;

 # List packages installed in system profile. To search, run:
 # $ nix search wget
 environment.systemPackages = with pkgs; [
   vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
   firefox
   libreoffice
   powertop
 ];

 # Some programs need SUID wrappers, can be configured further or are
 # started in user sessions.
 # programs.mtr.enable = true;
 # programs.gnupg.agent = {
 #   enable = true;
 #   enableSSHSupport = true;
 # };

 # List services that you want to enable:

 # Enable the OpenSSH daemon.
 # services.openssh.enable = true;

 # Open ports in the firewall.
 # networking.firewall.allowedTCPPorts = [ ... ];
 # networking.firewall.allowedUDPPorts = [ ... ];
 # Or disable the firewall altogether.
 # networking.firewall.enable = false;

 # This value determines the NixOS release from which the default
 # settings for stateful data, like file locations and database versions
 # on your system were taken. It‘s perfectly fine and recommended to leave
 # this value at the release version of the first install of this system.
 # Before changing this value read the documentation for this option
 # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
 system.stateVersion = "24.11"; # Did you read the comment?
}

hardware-configuration.nix
# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-amd" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/8cbd7c61-0186-481b-b4ee-770b0a1a3e55";
      fsType = "ext4";
    };

  boot.initrd.luks.devices."luks-c1619c04-4fdb-4310-80e5-46d1f313dd5b".device = "/dev/disk/by-uuid/c1619c04-4fdb-4310-80e5-46d1f313dd5b";

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/3E30-7C02";
      fsType = "vfat";
      options = [ "fmask=0077" "dmask=0077" ];
    };

  swapDevices =
    [ { device = "/dev/disk/by-uuid/ba05909d-14d1-4b34-be89-3ef5e4a87976"; }
    ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.eno1.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp1s0.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

Sorry for the long wait.
The only thing I could find was that the battery life is not great any more. Can you confirm this?
Also did it happened right after you installed nixos or just some time later.
Also have you done a bios update?

Thank you for reading the log and taking the time to reply! I couldn’t get to it until now.

I noticed a bit of a dent on the battery life with the default install, but with the acpi, powertop and system76 configurations, it lasts more or less as long as with Fedora (last installed OS).

This cold boot problem happens right away. I can boot the live system without a problem, even on battery, but once installed, I cannot. I haven’t tried it without LUKS+FDE, but I don’t know if that could be it.

I installed the last manufacturer provided BIOS last summer, when I got the laptop. It didn’t affect any other linux-based system I installed, and didn’t try windows with it.

Hmm.
One or two things I have seen in your config that my be causing problems are these:

  1. The encription with luks once in your hardware config and once in you normal one:

that seems a bit odd. Maybe try it without encription.
2. What are these kernel Params for

Sometimes these two kernel params can cause issues. Try it without them.

Hi,

Those kernel params force the tsc clock on the kernel. I need them in order to emulate a specific OS with qemu. I tried in the past to remove them and still didn’t work, but I’ll try again.

As for the LUKS part, it may be due to an inherited configuration.nix. I’ll try commenting it out, and if removing tsc from the boot params doesn’t work, I guess I’ll reinstall without LUKS encryption. Altough I think it makes no sense that LUKS messes with the boot process in that regard, because it works with the AC plugged in.

Thanks, I’ll post again when I try these out.

Yeah but better safe than sorry. I did some more digging and found that maybe acpi=off may help.
Just put this in your kernel params.
Also just to make sure can you still access your Bios when on battery?
What does the battery life say?
Also what happens when you run a stress test on battery?

Hi,

I have access to the BIOS, but there’s no info on the battery. I tried the “acpi=off” kernel param, and it does boot, but the system becomes very unstable, screen brightness is full… I then tried to remove the tsc related kernel params and it does boot, so I guess I’ll have to chose between using that emulator and having a normally functioning system.

Thank you very much for your help!

1 Like

Hello again, it seems it wasn’t it. I don’t know what could have been, but booting the same generation does nothing. Any direction I should be looking?

Ok that is strange.
How many times did the boot from the battery work?
What have you changed before it didn’t work again?

It is strange indeed. Yesterday in the morning, after the whole night shut down, and after a successful boot on battery in the evening, it didn’t boot, with the same kernel params off (tsc related). I didn’t change anything else. This morning, it did boot, with the last geration, but also with a previous one, that did include those params. The battery was full, but it wasn’t yesterday. It may be related to that. I’ll try again when the battery is below 60%, which it was yesterday, and then again with a full battery. That didn’t happen on fedora, though, it booted as long as there was any battery left, and FDE with LUKS was setup in the same way.

In an unrelated note, I think that booting with acpi=off damaged my mouse and keyboard. Is it possible?

No should not be a problem. ACPI - Wikipedia
Why does your mouse and keyboard won’t work anymore even after deleting this option?
Also could you try running a stress test on battery?

I don’t know how to do that, but I can research and try.

It is not that they don’t work, it’s that they started misbehaving. The mouse becomes unresponsive after stopping its movement and the keyboard was registering repeated keystrokes.

just try mprime. It is prime95 but for linux.

With acpi=off?

I’ll look into it, I hope to be able to do it asap.

EDIT: I just did a quick internet search and found mprime is just a program that looks for prime numbers. How should I perform a stress test on the battery? I never did one, and have been performing several, quick queries on the internet with no luck. Every stress test I found is directed towards the processor or RAM. Besides, I have had no battery issues with any OS, not even NixOS, apart from this cold boot problem.

Either with that flag or (after booting with it two times) without it. I haven’t had much time to use my computer last couple days, so I am not sure if it is still happening. Will update when I can.

Again, thank you for your help!

OK
can you please try this step by step:

  1. Replace "clocksource=tsc" and "tsc=reliable" with "clocksource=hpet"
  2. Since full-disk encryption (FDE) with LUKS involves additional early-boot steps (unlocking the encrypted partitions via the initrd), it’s conceivable that on battery the extra I/O (or an ACPI event) could trigger a subtle problem that isn’t visible when running on AC power. Try it without encryption
  3. use upower to verify battery health
  4. Try different Kernel like Zen pkgs.linuxPackages_zen
  5. stress test battery with mprime or something like this.

Yeah mprime stresses your cpu. That will draw maximum power and therefor stresses your battery also.
6. Try other acpi options acpi_osi="!Windows 2012" or acpi=strict