2014-04-14 14:26:48 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
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
|
|
|
|
2024-08-27 18:42:52 +00:00
|
|
|
security.polkit.enable = lib.mkEnableOption "polkit";
|
2009-08-16 21:48:46 +00:00
|
|
|
|
2024-08-27 18:42:52 +00:00
|
|
|
security.polkit.package = lib.mkPackageOption pkgs "polkit" { };
|
2024-06-24 14:50:31 +00:00
|
|
|
|
2024-08-27 18:42:52 +00:00
|
|
|
security.polkit.debug = lib.mkEnableOption "debug logs from polkit. This is required in order to see log messages from rule definitions";
|
2022-10-02 07:46:28 +00:00
|
|
|
|
2024-08-27 18:42:52 +00:00
|
|
|
security.polkit.extraConfig = lib.mkOption {
|
|
|
|
type = lib.types.lines;
|
2011-08-21 20:38:45 +00:00
|
|
|
default = "";
|
|
|
|
example =
|
|
|
|
''
|
2013-11-18 17:01:07 +00:00
|
|
|
/* Log authorization checks. */
|
|
|
|
polkit.addRule(function(action, subject) {
|
2022-10-02 07:46:28 +00:00
|
|
|
// Make sure to set { security.polkit.debug = true; } in configuration.nix
|
2013-11-18 17:01:07 +00:00
|
|
|
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 20:38:45 +00:00
|
|
|
'';
|
2022-07-20 10:32:04 +00:00
|
|
|
description =
|
2011-08-21 20:38:45 +00:00
|
|
|
''
|
2013-11-09 15:29:18 +00:00
|
|
|
Any polkit rules to be added to config (in JavaScript ;-). See:
|
2023-10-30 20:41:44 +00:00
|
|
|
<https://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
|
|
|
|
2024-08-27 18:42:52 +00:00
|
|
|
security.polkit.adminIdentities = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.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" ];
|
2022-07-20 10:32:04 +00:00
|
|
|
description =
|
2011-08-21 20:38:45 +00:00
|
|
|
''
|
|
|
|
Specifies which users are considered “administrators”, for those
|
|
|
|
actions that require the user to authenticate as an
|
2022-07-20 10:32:04 +00:00
|
|
|
administrator (i.e. have an `auth_admin`
|
|
|
|
value). By default, this is all users in the `wheel` group.
|
2011-08-21 20:38:45 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-08-27 18:42:52 +00:00
|
|
|
config = lib.mkIf cfg.enable {
|
2011-08-21 20:38:45 +00:00
|
|
|
|
2024-06-24 14:50:31 +00:00
|
|
|
environment.systemPackages = [ cfg.package.bin cfg.package.out ];
|
2011-08-21 20:38:45 +00:00
|
|
|
|
2024-06-24 14:50:31 +00:00
|
|
|
systemd.packages = [ cfg.package.out ];
|
2013-11-09 15:29:18 +00:00
|
|
|
|
2022-10-02 07:46:28 +00:00
|
|
|
systemd.services.polkit.serviceConfig.ExecStart = [
|
|
|
|
""
|
2024-08-27 18:42:52 +00:00
|
|
|
"${cfg.package.out}/lib/polkit-1/polkitd ${lib.optionalString (!cfg.debug) "--no-debug"}"
|
2022-10-02 07:46:28 +00:00
|
|
|
];
|
|
|
|
|
2014-04-19 12:29:02 +00:00
|
|
|
systemd.services.polkit.restartTriggers = [ config.system.path ];
|
2017-04-04 12:18:49 +00:00
|
|
|
systemd.services.polkit.stopIfChanged = false;
|
2014-04-19 12:29:02 +00: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) {
|
2024-08-27 18:42:52 +00:00
|
|
|
return [${lib.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 20:38:45 +00:00
|
|
|
|
2024-06-24 14:50:31 +00:00
|
|
|
services.dbus.packages = [ cfg.package.out ];
|
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
|
|
|
|
2017-01-29 11:33:56 +00:00
|
|
|
security.wrappers = {
|
2021-09-12 16:53:48 +00:00
|
|
|
pkexec =
|
|
|
|
{ setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
2024-06-24 14:50:31 +00:00
|
|
|
source = "${cfg.package.bin}/bin/pkexec";
|
2021-09-12 16:53:48 +00:00
|
|
|
};
|
|
|
|
polkit-agent-helper-1 =
|
|
|
|
{ setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
2024-06-24 14:50:31 +00:00
|
|
|
source = "${cfg.package.out}/lib/polkit-1/polkit-agent-helper-1";
|
2021-09-12 16:53:48 +00:00
|
|
|
};
|
2017-01-29 11:33:56 +00:00
|
|
|
};
|
2011-08-21 20:38:45 +00:00
|
|
|
|
2018-09-29 19:28:54 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
# Probably no more needed, clean up
|
|
|
|
"R /var/lib/polkit-1"
|
|
|
|
"R /var/lib/PolicyKit"
|
|
|
|
];
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users.polkituser = {
|
2013-11-09 15:29:18 +00:00
|
|
|
description = "PolKit daemon";
|
|
|
|
uid = config.ids.uids.polkituser;
|
2021-04-15 18:53:28 +00:00
|
|
|
group = "polkituser";
|
2013-11-09 15:29:18 +00:00
|
|
|
};
|
|
|
|
|
2023-02-26 03:26:28 +00:00
|
|
|
users.groups.polkituser = {};
|
2009-08-16 21:48:46 +00:00
|
|
|
};
|
|
|
|
|
2009-08-17 01:16:38 +00:00
|
|
|
}
|