Preventing reboot and poweroff for all users from CLI and GUI, Only allow root

Hi, I have tried several suggestions on setting polkit to prevent reboot and poweroff from CLI and GUI as regular user on my nixos 25.11 but havent managed it to work.. I would also like to prevent shutdown from KDE Plasma 6.

Any help would be deeply appreciated!

Here is from my configuration.nix

[code]

security.polkit.enable = true;
security.polkit.extraConfig = ‘’
polkit.addRule(function(action, subject) {
if (action.id.startsWith(“org.freedesktop.login1.”) &&
(action.id.includes(“shutdown”) ||
action.id.includes(“reboot”) ||
action.id.includes(“halt”) ||
action.id.includes(“power-off”))) {
if (subject.user != “root”) {
return polkit.Result.REJECT;
}
}
});
‘’;

[/code]

Hi! Please use a code block to format your code snippet.

Code should be formatted via triple-backticks, as per Posting code or preformatted text - Using Discourse - Discourse Meta.

Also note that 25.11 is deprecated and migration to 26.05 should be done ASAP.

As for your question, I’ve never seen REJECT as a possible result (did you use an LLM for this?), I assume you probably meant polkit.Result.NO - see polkit(8) — Arch manual pages.

Thank you got it to work with CLI, I have updated to 26.05 but it doesnt seem to be a solution for preventing users to switch user from sddm and shutdown or reboot machine, or are there?

Shouldn’t it be polkit.Result.NO?

whoops, already mentioned. Thanks @waffle8946 :slight_smile:

Asked and answered.​​