2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-08-16 22:48:46 +01:00
|
|
|
|
2014-04-14 15:26:48 +01:00
|
|
|
with lib;
|
2009-08-16 22:48:46 +01:00
|
|
|
|
2010-05-14 21:28:04 +01:00
|
|
|
let
|
2011-08-21 21:38:45 +01:00
|
|
|
|
|
|
|
cfg = config.security.polkit;
|
|
|
|
|
2010-05-14 21:28:04 +01:00
|
|
|
in
|
|
|
|
|
2009-08-16 22:48:46 +01:00
|
|
|
{
|
|
|
|
|
2011-08-21 21:38:45 +01:00
|
|
|
options = {
|
2009-08-16 22:48:46 +01:00
|
|
|
|
2011-08-21 21:38:45 +01:00
|
|
|
security.polkit.enable = mkOption {
|
2013-10-30 16:37:45 +00:00
|
|
|
type = types.bool;
|
2011-08-21 21:38:45 +01:00
|
|
|
default = true;
|
|
|
|
description = "Whether to enable PolKit.";
|
2010-05-14 21:28:04 +01:00
|
|
|
};
|
2009-08-16 22:48:46 +01: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 21:38:45 +01:00
|
|
|
default = "";
|
|
|
|
example =
|
|
|
|
''
|
2013-11-18 17:01:07 +00:00
|
|
|
/* Log authorization checks. */
|
|
|
|
polkit.addRule(function(action, subject) {
|
|
|
|
polkit.log("user " + subject.user + " is attempting action " + action.id + " from PID " + subject.pid);
|
|
|
|
});
|
|
|
|
|
|
|
|
/* Allow any local user to do anything (dangerous!). */
|
|
|
|
polkit.addRule(function(action, subject) {
|
|
|
|
if (subject.local) return "yes";
|
|
|
|
});
|
2011-08-21 21:38:45 +01: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 21:38:45 +01:00
|
|
|
'';
|
2010-05-14 21:28:04 +01:00
|
|
|
};
|
2009-08-16 22:48:46 +01:00
|
|
|
|
2011-08-21 21:38:45 +01:00
|
|
|
security.polkit.adminIdentities = mkOption {
|
2013-11-18 16:45:31 +00:00
|
|
|
type = types.listOf types.str;
|
2019-12-09 06:38:33 +00:00
|
|
|
default = [ "unix-group:wheel" ];
|
2013-11-18 16:45:31 +00:00
|
|
|
example = [ "unix-user:alice" "unix-group:admin" ];
|
2011-08-21 21:38:45 +01:00
|
|
|
description =
|
|
|
|
''
|
|
|
|
Specifies which users are considered “administrators”, for those
|
|
|
|
actions that require the user to authenticate as an
|
2013-08-10 22:07:13 +01:00
|
|
|
administrator (i.e. have an <literal>auth_admin</literal>
|
2019-12-09 06:38:33 +00:00
|
|
|
value). By default, this is all users in the <literal>wheel</literal> group.
|
2011-08-21 21:38:45 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2016-01-28 10:24:18 +00:00
|
|
|
environment.systemPackages = [ pkgs.polkit.bin pkgs.polkit.out ];
|
2011-08-21 21:38:45 +01:00
|
|
|
|
2015-11-26 17:14:22 +00:00
|
|
|
systemd.packages = [ pkgs.polkit.out ];
|
2013-11-09 15:29:18 +00:00
|
|
|
|
2014-04-19 13:29:02 +01:00
|
|
|
systemd.services.polkit.restartTriggers = [ config.system.path ];
|
2017-04-04 13:18:49 +01:00
|
|
|
systemd.services.polkit.stopIfChanged = false;
|
2014-04-19 13:29:02 +01:00
|
|
|
|
2013-11-09 15:29:18 +00:00
|
|
|
# The polkit daemon reads action/rule files
|
|
|
|
environment.pathsToLink = [ "/share/polkit-1" ];
|
|
|
|
|
2013-11-18 16:33:20 +00:00
|
|
|
# PolKit rules for NixOS.
|
|
|
|
environment.etc."polkit-1/rules.d/10-nixos.rules".text =
|
|
|
|
''
|
|
|
|
polkit.addAdminRule(function(action, subject) {
|
2013-11-18 16:45:31 +00:00
|
|
|
return [${concatStringsSep ", " (map (i: "\"${i}\"") cfg.adminIdentities)}];
|
2013-11-18 16:33:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
''; #TODO: validation on compilation (at least against typos)
|
2011-08-21 21:38:45 +01:00
|
|
|
|
2015-10-16 17:28:55 +01:00
|
|
|
services.dbus.packages = [ pkgs.polkit.out ];
|
2011-08-21 21:38:45 +01:00
|
|
|
|
2013-10-15 13:47:51 +01:00
|
|
|
security.pam.services.polkit-1 = {};
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2017-01-29 11:33:56 +00:00
|
|
|
security.wrappers = {
|
2017-02-22 22:01:39 +00:00
|
|
|
pkexec.source = "${pkgs.polkit.bin}/bin/pkexec";
|
2019-08-13 22:52:01 +01:00
|
|
|
polkit-agent-helper-1.source = "${pkgs.polkit.out}/lib/polkit-1/polkit-agent-helper-1";
|
2017-01-29 11:33:56 +00:00
|
|
|
};
|
2011-08-21 21:38:45 +01:00
|
|
|
|
2018-09-29 20:28:54 +01:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
# Probably no more needed, clean up
|
|
|
|
"R /var/lib/polkit-1"
|
|
|
|
"R /var/lib/PolicyKit"
|
|
|
|
];
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2018-06-30 00:58:35 +01:00
|
|
|
users.users.polkituser = {
|
2013-11-09 15:29:18 +00:00
|
|
|
description = "PolKit daemon";
|
|
|
|
uid = config.ids.uids.polkituser;
|
|
|
|
};
|
|
|
|
|
2009-08-16 22:48:46 +01:00
|
|
|
};
|
|
|
|
|
2009-08-17 02:16:38 +01:00
|
|
|
}
|
2013-11-09 15:29:18 +00:00
|
|
|
|