2009-08-16 21:48:46 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
|
|
|
|
with pkgs.lib;
|
|
|
|
|
2010-05-14 20:28:04 +00:00
|
|
|
let
|
2011-08-21 20:38:45 +00:00
|
|
|
|
|
|
|
cfg = config.security.polkit;
|
|
|
|
|
2010-05-14 20:28:04 +00:00
|
|
|
in
|
|
|
|
|
2009-08-16 21:48:46 +00:00
|
|
|
{
|
|
|
|
|
2011-08-21 20:38:45 +00:00
|
|
|
options = {
|
2009-08-16 21:48:46 +00:00
|
|
|
|
2011-08-21 20:38:45 +00:00
|
|
|
security.polkit.enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2011-08-21 20:38:45 +00:00
|
|
|
default = true;
|
|
|
|
description = "Whether to enable PolKit.";
|
2010-05-14 20:28:04 +00:00
|
|
|
};
|
2009-08-16 21:48:46 +00:00
|
|
|
|
2013-11-09 15:29:18 +00:00
|
|
|
security.polkit.extraConfig = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.lines;
|
2011-08-21 20:38:45 +00:00
|
|
|
default = "";
|
|
|
|
example =
|
|
|
|
''
|
2013-11-09 15:29:18 +00:00
|
|
|
TODO
|
2011-08-21 20:38:45 +00:00
|
|
|
'';
|
|
|
|
description =
|
|
|
|
''
|
2013-11-09 15:29:18 +00:00
|
|
|
Any polkit rules to be added to config (in JavaScript ;-). See:
|
|
|
|
http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html#polkit-rules
|
2011-08-21 20:38:45 +00:00
|
|
|
'';
|
2010-05-14 20:28:04 +00:00
|
|
|
};
|
2009-08-16 21:48:46 +00:00
|
|
|
|
2011-08-21 20:38:45 +00:00
|
|
|
security.polkit.adminIdentities = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.str;
|
2011-08-21 20:38:45 +00:00
|
|
|
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 21:07:13 +00:00
|
|
|
administrator (i.e. have an <literal>auth_admin</literal>
|
2011-08-21 20:38:45 +00: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 11:46:32 +00:00
|
|
|
environment.systemPackages = [ pkgs.polkit ];
|
2011-08-21 20:38:45 +00:00
|
|
|
|
2013-11-09 15:29:18 +00:00
|
|
|
systemd.packages = [ pkgs.polkit ];
|
|
|
|
|
|
|
|
# The polkit daemon reads action/rule files
|
|
|
|
environment.pathsToLink = [ "/share/polkit-1" ];
|
|
|
|
|
|
|
|
# PolKit rules for NixOS
|
|
|
|
environment.etc = [ {
|
|
|
|
source = pkgs.writeText "10-nixos.conf"
|
|
|
|
''
|
|
|
|
polkit.addAdminRule(function(action, subject) {
|
|
|
|
return ["${cfg.adminIdentities}"];
|
|
|
|
});
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
''; #TODO: validation on compilation (at least against typos)
|
|
|
|
target = "polkit-1/rules.d/10-nixos.conf";
|
|
|
|
} ];
|
2011-08-21 20:38:45 +00:00
|
|
|
|
2011-08-22 11:46:32 +00:00
|
|
|
services.dbus.packages = [ pkgs.polkit ];
|
2011-08-21 20:38:45 +00:00
|
|
|
|
2013-10-15 12:47:51 +00:00
|
|
|
security.pam.services.polkit-1 = {};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2011-08-21 20:38:45 +00:00
|
|
|
security.setuidPrograms = [ "pkexec" ];
|
|
|
|
|
2013-11-09 15:29:18 +00:00
|
|
|
security.setuidOwners = [
|
2011-08-21 20:38:45 +00:00
|
|
|
{ program = "polkit-agent-helper-1";
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
setuid = true;
|
2013-11-09 15:29:18 +00:00
|
|
|
source = "${pkgs.polkit}/lib/polkit-1/polkit-agent-helper-1";
|
|
|
|
}
|
|
|
|
];
|
2011-08-21 20:38:45 +00:00
|
|
|
|
2010-09-13 15:41:38 +00:00
|
|
|
system.activationScripts.polkit =
|
2009-08-16 21:48:46 +00:00
|
|
|
''
|
2013-11-09 15:29:18 +00:00
|
|
|
# Probably no more needed, clean up
|
|
|
|
rm -rf /var/lib/{polkit-1,PolicyKit}
|
2011-07-26 14:13:07 +00:00
|
|
|
|
|
|
|
# Force polkitd to be restarted so that it reloads its
|
|
|
|
# configuration.
|
2011-07-26 14:19:06 +00:00
|
|
|
${pkgs.procps}/bin/pkill -INT -u root -x polkitd
|
2009-08-16 21:48:46 +00:00
|
|
|
'';
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2013-11-09 15:29:18 +00:00
|
|
|
users.extraUsers.polkituser = {
|
|
|
|
description = "PolKit daemon";
|
|
|
|
uid = config.ids.uids.polkituser;
|
|
|
|
};
|
|
|
|
|
2009-08-16 21:48:46 +00:00
|
|
|
};
|
|
|
|
|
2009-08-17 01:16:38 +00:00
|
|
|
}
|
2013-11-09 15:29:18 +00:00
|
|
|
|