| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | { config, lib, pkgs, ... }: | 
					
						
							| 
									
										
										
										
											2009-08-16 21:48:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-14 16:26:48 +02:00
										 |  |  | with lib; | 
					
						
							| 
									
										
										
										
											2009-08-16 21:48:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 17:37:45 +01: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 16:29:18 +01:00
										 |  |  |     security.polkit.extraConfig = mkOption { | 
					
						
							| 
									
										
										
										
											2013-10-30 17:37:45 +01:00
										 |  |  |       type = types.lines; | 
					
						
							| 
									
										
										
										
											2011-08-21 20:38:45 +00:00
										 |  |  |       default = ""; | 
					
						
							|  |  |  |       example = | 
					
						
							|  |  |  |         ''
 | 
					
						
							| 
									
										
										
										
											2013-11-18 18:01:07 +01: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 20:38:45 +00:00
										 |  |  |         '';
 | 
					
						
							|  |  |  |       description = | 
					
						
							|  |  |  |         ''
 | 
					
						
							| 
									
										
										
										
											2013-11-09 16:29:18 +01: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-11-18 17:45:31 +01:00
										 |  |  |       type = types.listOf types.str; | 
					
						
							|  |  |  |       default = [ "unix-user:0" "unix-group:wheel" ]; | 
					
						
							|  |  |  |       example = [ "unix-user:alice" "unix-group:admin" ]; | 
					
						
							| 
									
										
										
										
											2011-08-21 20:38:45 +00:00
										 |  |  |       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 { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-28 11:24:18 +01:00
										 |  |  |     environment.systemPackages = [ pkgs.polkit.bin pkgs.polkit.out ]; | 
					
						
							| 
									
										
										
										
											2011-08-21 20:38:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-26 18:14:22 +01:00
										 |  |  |     systemd.packages = [ pkgs.polkit.out ]; | 
					
						
							| 
									
										
										
										
											2013-11-09 16:29:18 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-19 14:29:02 +02:00
										 |  |  |     systemd.services.polkit.restartTriggers = [ config.system.path ]; | 
					
						
							|  |  |  |     systemd.services.polkit.unitConfig.X-StopIfChanged = false; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-09 16:29:18 +01:00
										 |  |  |     # The polkit daemon reads action/rule files | 
					
						
							|  |  |  |     environment.pathsToLink = [ "/share/polkit-1" ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-18 17:33:20 +01:00
										 |  |  |     # PolKit rules for NixOS. | 
					
						
							|  |  |  |     environment.etc."polkit-1/rules.d/10-nixos.rules".text = | 
					
						
							|  |  |  |       ''
 | 
					
						
							|  |  |  |         polkit.addAdminRule(function(action, subject) { | 
					
						
							| 
									
										
										
										
											2013-11-18 17:45:31 +01:00
										 |  |  |           return [${concatStringsSep ", " (map (i: "\"${i}\"") cfg.adminIdentities)}]; | 
					
						
							| 
									
										
										
										
											2013-11-18 17:33:20 +01:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ${cfg.extraConfig} | 
					
						
							|  |  |  |       ''; #TODO: validation on compilation (at least against typos)
 | 
					
						
							| 
									
										
										
										
											2011-08-21 20:38:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-16 19:28:55 +03:00
										 |  |  |     services.dbus.packages = [ pkgs.polkit.out ]; | 
					
						
							| 
									
										
										
										
											2011-08-21 20:38:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-15 14:47:51 +02: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 16:29:18 +01:00
										 |  |  |     security.setuidOwners = [ | 
					
						
							| 
									
										
										
										
											2011-08-21 20:38:45 +00:00
										 |  |  |       { program = "polkit-agent-helper-1"; | 
					
						
							|  |  |  |         owner = "root"; | 
					
						
							|  |  |  |         group = "root"; | 
					
						
							|  |  |  |         setuid = true; | 
					
						
							| 
									
										
										
										
											2015-10-14 06:03:25 +02:00
										 |  |  |         source = "${pkgs.polkit.out}/lib/polkit-1/polkit-agent-helper-1"; | 
					
						
							| 
									
										
										
										
											2013-11-09 16:29:18 +01:00
										 |  |  |       } | 
					
						
							|  |  |  |     ]; | 
					
						
							| 
									
										
										
										
											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 16:29:18 +01:00
										 |  |  |         # Probably no more needed, clean up | 
					
						
							|  |  |  |         rm -rf /var/lib/{polkit-1,PolicyKit} | 
					
						
							| 
									
										
										
										
											2009-08-16 21:48:46 +00:00
										 |  |  |       '';
 | 
					
						
							| 
									
										
										
										
											2011-09-14 18:20:50 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-11-09 16:29:18 +01: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 16:29:18 +01:00
										 |  |  | 
 |