about summary refs log tree commit diff
diff options
context:
space:
mode:
authornicoo <nicoo@mur.at>2023-10-25 22:24:04 +0000
committergithub-actions[bot] <github-actions[bot]@users.noreply.github.com>2023-11-26 18:58:01 +0000
commita01493271f2fa7e6f0c8219ee195393848860c7b (patch)
treeef4325df6cd9f4cca68570f167121e3c38009ae1
parent39608712fb05d607f36ce0f19997b3c3e4ebc319 (diff)
nixos/sudo-rs: refactor processing of `cfg.extraRules`
(cherry picked from commit 03db94319af0d0c9bab329f9db33e62d916127c8)
-rw-r--r--nixos/modules/security/sudo-rs.nix21
1 files changed, 10 insertions, 11 deletions
diff --git a/nixos/modules/security/sudo-rs.nix b/nixos/modules/security/sudo-rs.nix
index 1351734c1f933..1c1cc32fa79ed 100644
--- a/nixos/modules/security/sudo-rs.nix
+++ b/nixos/modules/security/sudo-rs.nix
@@ -7,7 +7,6 @@ let
   cfg = config.security.sudo-rs;
 
   inherit (config.security.pam) enableSSHAgentAuth;
-  inherit (pkgs) sudo-rs;
 
   toUserString = user: if (isInt user) then "#${toString user}" else "${user}";
   toGroupString = group: if (isInt group) then "%#${toString group}" else "%${group}";
@@ -236,16 +235,16 @@ in
         # Keep SSH_AUTH_SOCK so that pam_ssh_agent_auth.so can do its magic.
         Defaults env_keep+=SSH_AUTH_SOCK
       '')
-      (concatStringsSep "\n" (
-        lists.flatten (
-          map (
-            rule: optionals (length rule.commands != 0) [
-              (map (user: "${toUserString user}	${rule.host}=(${rule.runAs})	${toCommandsString rule.commands}") rule.users)
-              (map (group: "${toGroupString group}	${rule.host}=(${rule.runAs})	${toCommandsString rule.commands}") rule.groups)
-            ]
-          ) cfg.extraRules
-        )
-      ) + "\n")
+      (pipe cfg.extraRules [
+        (filter (rule: length rule.commands != 0))
+        (map (rule: [
+          (map (user: "${toUserString user}     ${rule.host}=(${rule.runAs})    ${toCommandsString rule.commands}") rule.users)
+          (map (group: "${toGroupString group}  ${rule.host}=(${rule.runAs})    ${toCommandsString rule.commands}") rule.groups)
+        ]))
+        flatten
+        (concatStringsSep "\n")
+      ])
+      "\n"
       (optionalString (cfg.extraConfig != "") ''
         # extraConfig
         ${cfg.extraConfig}