How to configure Nixos for Kiosk or Fullscreen applications?

We’re building an embedded systems application with Nixos as the base OS.

Our goal is to have the system boot directly into our custom (graphical) application where it occupies the entire screen; some refer to this mode as either kisok or full screen.

At present our configuration.nix is set up as follows, where we fire up a window and desktop managers, and automatically login and then fire up our app. Given what we’ve read, this seems like overkill.

What is the proper way to configure a minimal graphical nixos installation to support our needs?

  # Enable X11
  services.xserver.enable = true;

 #  We need nvidia drivers.
  services.xserver.videoDrivers = [ "nvidia" ];
  hardware.nvidia.package = config.boot.kernelPackages.nvidiaPackages.stable; 

 # GDM or something more else?
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;

 # Auto loging
  services.xserver.displayManager.autoLogin.user = "user-name";
  services.xserver.displayManager.autoLogin.enable = true;

 # Sleep required otherwise system crash. 
  services.xserver.displayManager.job.preStart = "sleep 10";

Recommendations?

Thanks!

with wayland I used:

{
  services.cage = {
    enable = true;
    program = "${app}/bin/my_app";
    user = "some_user";
  };

  # wait for network and DNS
  systemd.services."cage-tty1".after = [
    "network-online.target"
    "systemd-resolved.service"
  ];
}

with x11 I used:

{ pkgs, app, user, ... }:

let
  autostart = ''
    #!${pkgs.bash}/bin/bash
    # End all lines with '&' to not halt startup script execution

    firefox --kiosk https://stigok.com/ &
  '';

  inherit (pkgs) writeScript;
in
{
  services.xserver = {
    enable = true;
    layout = "us"; # keyboard layout
    libinput.enable = true;

    # Let lightdm handle autologin
    displayManager.lightdm = {
      enable = true;
      # autoLogin = {
      #   timeout = 0;
      # };
    };

    # Start openbox after autologin
    windowManager.openbox.enable = true;
    displayManager = {
      defaultSession = "none+openbox";
      autoLogin = {
        inherit user;
        enable = true;
      };
    };
  };

  systemd.services."display-manager".after = [
    "network-online.target"
    "systemd-resolved.service"
  ];

  # Overlay to set custom autostart script for openbox
  nixpkgs.overlays = with pkgs; [
    (_self: super: {
      openbox = super.openbox.overrideAttrs (_oldAttrs: rec {
        postFixup = ''
          ln -sf /etc/openbox/autostart $out/etc/xdg/openbox/autostart
        '';
      });
    })
  ];

  # By defining the script source outside of the overlay, we don't have to
  # rebuild the package every time we change the startup script.
  environment.etc."openbox/autostart".source = writeScript "autostart" autostart;
}

For x11, I stole that config from https://blog.stigok.com/2020/06/19/nixos-xserver-openbox-auto-start-browser-application.html

I regret nothing.

1 Like

@bbigras Thanks for the tips. I’ve got a couple of follow up questions…

  1. Are these your configuration.nix settings? I noticed in the link you shared, they author described placing similar settings in /etc/nixos/xorg.conf

  2. Have you had any issues with auto login causing a crash? See https://github.com/NixOS/nixpkgs/issues/103746