2009-08-16 23:48:46 +02:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
2010-05-14 22:28:04 +02:00
|
|
|
let
|
2011-08-21 22:38:45 +02:00
|
|
|
|
|
|
|
cfg = config.security.polkit;
|
|
|
|
|
2010-05-14 22:28:04 +02:00
|
|
|
in
|
|
|
|
|
2009-08-16 23:48:46 +02:00
|
|
|
{
|
|
|
|
|
2011-08-21 22:38:45 +02:00
|
|
|
options = {
|
2009-08-16 23:48:46 +02:00
|
|
|
|
2011-08-21 22:38:45 +02:00
|
|
|
security.polkit.enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
description = "Whether to enable PolKit.";
|
2010-05-14 22:28:04 +02:00
|
|
|
};
|
2009-08-16 23:48:46 +02:00
|
|
|
|
2011-08-21 22:38:45 +02:00
|
|
|
security.polkit.permissions = mkOption {
|
|
|
|
default = "";
|
|
|
|
example =
|
|
|
|
''
|
|
|
|
[Disallow Users To Suspend]
|
|
|
|
Identity=unix-group:users
|
|
|
|
Action=org.freedesktop.upower.*
|
|
|
|
ResultAny=no
|
|
|
|
ResultInactive=no
|
|
|
|
ResultActive=no
|
2009-08-16 23:48:46 +02:00
|
|
|
|
2011-08-21 22:38:45 +02:00
|
|
|
[Allow Anybody To Eject Disks]
|
|
|
|
Identity=unix-user:*
|
|
|
|
Action=org.freedesktop.udisks.drive-eject
|
|
|
|
ResultAny=yes
|
|
|
|
ResultInactive=yes
|
|
|
|
ResultActive=yes
|
|
|
|
|
|
|
|
[Allow Alice To Mount Filesystems After Admin Authentication]
|
|
|
|
Identity=unix-user:alice
|
|
|
|
Action=org.freedesktop.udisks.filesystem-mount
|
|
|
|
ResultAny=auth_admin
|
|
|
|
ResultInactive=auth_admin
|
|
|
|
ResultActive=auth_admin
|
|
|
|
'';
|
|
|
|
description =
|
|
|
|
''
|
2013-08-10 23:07:13 +02:00
|
|
|
Allows the default permissions of privileged actions to be overridden.
|
2011-08-21 22:38:45 +02:00
|
|
|
'';
|
2010-05-14 22:28:04 +02:00
|
|
|
};
|
2009-08-16 23:48:46 +02:00
|
|
|
|
2011-08-21 22:38:45 +02:00
|
|
|
security.polkit.adminIdentities = mkOption {
|
|
|
|
default = "unix-user:0;unix-group:wheel";
|
|
|
|
example = "";
|
|
|
|
description =
|
|
|
|
''
|
|
|
|
Specifies which users are considered “administrators”, for those
|
|
|
|
actions that require the user to authenticate as an
|
2013-08-10 23:07:13 +02:00
|
|
|
administrator (i.e. have an <literal>auth_admin</literal>
|
2011-08-21 22:38:45 +02:00
|
|
|
value). By default, this is the <literal>root</literal>
|
|
|
|
user and all users in the <literal>wheel</literal> group.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2011-08-22 13:46:32 +02:00
|
|
|
environment.systemPackages = [ pkgs.polkit ];
|
2011-08-21 22:38:45 +02:00
|
|
|
|
2011-09-14 20:20:50 +02:00
|
|
|
# The polkit daemon reads action files
|
2011-08-21 22:38:45 +02:00
|
|
|
environment.pathsToLink = [ "/share/polkit-1/actions" ];
|
|
|
|
|
|
|
|
environment.etc =
|
|
|
|
[ # No idea what the "null backend" is, but it seems to need this.
|
|
|
|
{ source = "${pkgs.polkit}/etc/polkit-1/nullbackend.conf.d";
|
|
|
|
target = "polkit-1/nullbackend.conf.d";
|
|
|
|
}
|
|
|
|
|
|
|
|
# This file determines what users are considered
|
|
|
|
# "administrators".
|
|
|
|
{ source = pkgs.writeText "10-nixos.conf"
|
|
|
|
''
|
|
|
|
[Configuration]
|
|
|
|
AdminIdentities=${cfg.adminIdentities}
|
|
|
|
'';
|
|
|
|
target = "polkit-1/localauthority.conf.d/10-nixos.conf";
|
|
|
|
}
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-08-21 22:38:45 +02:00
|
|
|
{ source = pkgs.writeText "org.nixos.pkla" cfg.permissions;
|
|
|
|
target = "polkit-1/localauthority/10-vendor.d/org.nixos.pkla";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2011-08-22 13:46:32 +02:00
|
|
|
services.dbus.packages = [ pkgs.polkit ];
|
2011-08-21 22:38:45 +02:00
|
|
|
|
2013-10-15 14:47:51 +02:00
|
|
|
security.pam.services.polkit-1 = {};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2011-08-21 22:38:45 +02:00
|
|
|
security.setuidPrograms = [ "pkexec" ];
|
|
|
|
|
|
|
|
security.setuidOwners = singleton
|
|
|
|
{ program = "polkit-agent-helper-1";
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
setuid = true;
|
2011-08-22 13:46:32 +02:00
|
|
|
source = "${pkgs.polkit}/libexec/polkit-1/polkit-agent-helper-1";
|
2011-08-21 22:38:45 +02:00
|
|
|
};
|
|
|
|
|
2010-09-13 17:41:38 +02:00
|
|
|
system.activationScripts.polkit =
|
2009-08-16 23:48:46 +02:00
|
|
|
''
|
2010-05-18 18:46:32 +02:00
|
|
|
mkdir -p /var/lib/polkit-1/localauthority
|
|
|
|
chmod 700 /var/lib/polkit-1{/localauthority,}
|
2011-07-26 16:13:07 +02:00
|
|
|
|
|
|
|
# Force polkitd to be restarted so that it reloads its
|
|
|
|
# configuration.
|
2011-07-26 16:19:06 +02:00
|
|
|
${pkgs.procps}/bin/pkill -INT -u root -x polkitd
|
2009-08-16 23:48:46 +02:00
|
|
|
'';
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-08-16 23:48:46 +02:00
|
|
|
};
|
|
|
|
|
2009-08-17 03:16:38 +02:00
|
|
|
}
|