Polkit: Difference between revisions

From NixOS Wiki
imported>Chewie
(Mention use of systemd user service to launch a polkit authentication agent)
imported>Robbins
mNo edit summary
Line 17: Line 17:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
systemd = {
systemd = {
    user.services.polkit-gnome-authentication-agent-1 = {
  user.services.polkit-gnome-authentication-agent-1 = {
     description = "polkit-gnome-authentication-agent-1";
     Unit = {
    wants = [ "graphical-session.target" ];
      Description = "polkit-gnome-authentication-agent-1";
    wantedBy = [ "graphical-session.target" ];
      Wants = [ "graphical-session.target" ];
    after = [ "graphical-session.target" ];
      WantedBy = [ "graphical-session.target" ];
     serviceConfig = {
      After = [ "graphical-session.target" ];
     };
    Service = {
       Type = "simple";
       Type = "simple";
      ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
        ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
      Restart = "on-failure";
        Restart = "on-failure";
      RestartSec = 1;
        RestartSec = 1;
      TimeoutStopSec = 10;
        TimeoutStopSec = 10;
    };
      };
   };
   };
};
};
</syntaxhighlight>
</syntaxhighlight>

Revision as of 04:49, 21 December 2022

Polkit is used for controlling system-wide privileges. It provides an organized way for non-privileged processes to communicate with privileged ones. In contrast to sudo, it does not grant root permission to an entire process, but rather allows a finer level of control of centralized system policy.

Enable polkit

Polkit is disabled by default. If you wish to enable it, you can set security.polkit.enable to true.

Authentication agents

If Polkit seems not to work properly, you could check that you have an authentication agent installed and running (especially if you use a more niche desktop environment like e.g. i3wm).

For example, polkit_gnome is a GNOME-based authentication agent, but it will usually only autostart when used with GNOME, KDE, or Unity (examine its autostart file in etc/xdg/autostart/polkit-gnome-authentication-agent-1.desktop for details); otherwise you will need to start it yourself, e.g. by copying that autostart file to ~/.config/autostart/ and removing the parts that restrict it to GNOME/KDE/Unity.

Alternatively, you can start it on login by creating a systemd user service:

systemd = {
  user.services.polkit-gnome-authentication-agent-1 = {
    Unit = {
      Description = "polkit-gnome-authentication-agent-1";
      Wants = [ "graphical-session.target" ];
      WantedBy = [ "graphical-session.target" ];
      After = [ "graphical-session.target" ];
    };
    Service = {
      Type = "simple";
        ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
        Restart = "on-failure";
        RestartSec = 1;
        TimeoutStopSec = 10;
      };
  };
};