2020-04-24 23:36:52 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.security.polkit;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2022-09-09 14:08:57 +00:00
|
|
|
security.polkit.enable = mkEnableOption (lib.mdDoc "polkit");
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
security.polkit.debug = mkEnableOption (lib.mdDoc "debug logs from polkit. This is required in order to see log messages from rule definitions.");
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
security.polkit.extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example =
|
|
|
|
''
|
|
|
|
/* Log authorization checks. */
|
|
|
|
polkit.addRule(function(action, subject) {
|
2022-10-30 15:09:59 +00:00
|
|
|
// Make sure to set { security.polkit.debug = true; } in configuration.nix
|
2020-04-24 23:36:52 +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";
|
|
|
|
});
|
|
|
|
'';
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc
|
2020-04-24 23:36:52 +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
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
security.polkit.adminIdentities = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ "unix-group:wheel" ];
|
|
|
|
example = [ "unix-user:alice" "unix-group:admin" ];
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc
|
2020-04-24 23:36:52 +00:00
|
|
|
''
|
|
|
|
Specifies which users are considered “administrators”, for those
|
|
|
|
actions that require the user to authenticate as an
|
2022-08-12 12:06:08 +00:00
|
|
|
administrator (i.e. have an `auth_admin`
|
|
|
|
value). By default, this is all users in the `wheel` group.
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.polkit.bin pkgs.polkit.out ];
|
|
|
|
|
|
|
|
systemd.packages = [ pkgs.polkit.out ];
|
|
|
|
|
2022-10-30 15:09:59 +00:00
|
|
|
systemd.services.polkit.serviceConfig.ExecStart = [
|
|
|
|
""
|
|
|
|
"${pkgs.polkit.out}/lib/polkit-1/polkitd ${optionalString (!cfg.debug) "--no-debug"}"
|
|
|
|
];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.polkit.restartTriggers = [ config.system.path ];
|
|
|
|
systemd.services.polkit.stopIfChanged = false;
|
|
|
|
|
|
|
|
# The polkit daemon reads action/rule files
|
|
|
|
environment.pathsToLink = [ "/share/polkit-1" ];
|
|
|
|
|
|
|
|
# PolKit rules for NixOS.
|
|
|
|
environment.etc."polkit-1/rules.d/10-nixos.rules".text =
|
|
|
|
''
|
|
|
|
polkit.addAdminRule(function(action, subject) {
|
|
|
|
return [${concatStringsSep ", " (map (i: "\"${i}\"") cfg.adminIdentities)}];
|
|
|
|
});
|
|
|
|
|
|
|
|
${cfg.extraConfig}
|
|
|
|
''; #TODO: validation on compilation (at least against typos)
|
|
|
|
|
|
|
|
services.dbus.packages = [ pkgs.polkit.out ];
|
|
|
|
|
|
|
|
security.pam.services.polkit-1 = {};
|
|
|
|
|
|
|
|
security.wrappers = {
|
2021-09-22 15:38:15 +00:00
|
|
|
pkexec =
|
|
|
|
{ setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${pkgs.polkit.bin}/bin/pkexec";
|
|
|
|
};
|
|
|
|
polkit-agent-helper-1 =
|
|
|
|
{ setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${pkgs.polkit.out}/lib/polkit-1/polkit-agent-helper-1";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
# Probably no more needed, clean up
|
|
|
|
"R /var/lib/polkit-1"
|
|
|
|
"R /var/lib/PolicyKit"
|
|
|
|
];
|
|
|
|
|
|
|
|
users.users.polkituser = {
|
|
|
|
description = "PolKit daemon";
|
|
|
|
uid = config.ids.uids.polkituser;
|
2021-08-08 23:34:03 +00:00
|
|
|
group = "polkituser";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2021-08-08 23:34:03 +00:00
|
|
|
users.groups.polkituser = {};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|