Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)

physlock: add allowAnyUser option

+41 -19
+41 -19
nixos/modules/services/security/physlock.nix
··· 30 30 ''; 31 31 }; 32 32 33 + allowAnyUser = mkOption { 34 + type = types.bool; 35 + default = false; 36 + description = '' 37 + Whether to allow any user to lock the screen. This will install a 38 + setuid wrapper to allow any user to start physlock as root, which 39 + is a minor security risk. Call the physlock binary to use this instead 40 + of using the systemd service. 41 + 42 + Note that you might need to relog to have the correct binary in your 43 + PATH upon changing this option. 44 + ''; 45 + }; 46 + 33 47 disableSysRq = mkOption { 34 48 type = types.bool; 35 49 default = true; ··· 79 93 80 94 ###### implementation 81 95 82 - config = mkIf cfg.enable { 96 + config = mkIf cfg.enable (mkMerge [ 97 + { 83 98 84 - # for physlock -l and physlock -L 85 - environment.systemPackages = [ pkgs.physlock ]; 99 + # for physlock -l and physlock -L 100 + environment.systemPackages = [ pkgs.physlock ]; 86 101 87 - systemd.services."physlock" = { 88 - enable = true; 89 - description = "Physlock"; 90 - wantedBy = optional cfg.lockOn.suspend "suspend.target" 91 - ++ optional cfg.lockOn.hibernate "hibernate.target" 92 - ++ cfg.lockOn.extraTargets; 93 - before = optional cfg.lockOn.suspend "systemd-suspend.service" 94 - ++ optional cfg.lockOn.hibernate "systemd-hibernate.service" 95 - ++ cfg.lockOn.extraTargets; 96 - serviceConfig.Type = "forking"; 97 - script = '' 98 - ${pkgs.physlock}/bin/physlock -d${optionalString cfg.disableSysRq "s"} 99 - ''; 100 - }; 102 + systemd.services."physlock" = { 103 + enable = true; 104 + description = "Physlock"; 105 + wantedBy = optional cfg.lockOn.suspend "suspend.target" 106 + ++ optional cfg.lockOn.hibernate "hibernate.target" 107 + ++ cfg.lockOn.extraTargets; 108 + before = optional cfg.lockOn.suspend "systemd-suspend.service" 109 + ++ optional cfg.lockOn.hibernate "systemd-hibernate.service" 110 + ++ cfg.lockOn.extraTargets; 111 + serviceConfig = { 112 + Type = "forking"; 113 + ExecStart = "${pkgs.physlock}/bin/physlock -d${optionalString cfg.disableSysRq "s"}"; 114 + }; 115 + }; 101 116 102 - security.pam.services.physlock = {}; 117 + security.pam.services.physlock = {}; 118 + 119 + } 120 + 121 + (mkIf cfg.allowAnyUser { 122 + 123 + security.wrappers.physlock = { source = "${pkgs.physlock}/bin/physlock"; user = "root"; }; 103 124 104 - }; 125 + }) 126 + ]); 105 127 106 128 }