Hi, I just started with Nixos a week ago, I have a problem configuring the system. I apologize for this long post. I want to configure configuration.nix for sudo to run commands without passwd. I am confused about the path of the packages. I tried entering path returned by $ which cryptsetup like

security.sudo = {
       enable = true;
       configFile = ''
         %sudo ALL = (root) NOPASSWD: /run/current-system/sw/bin/cryptsetup
         %sudo ALL = (root) NOPASSWD: /run/current-system/sw/bin/lvs
       '';
  };

and as shown in nixos wiki like the following

security.sudo = {
  enable = true;
  extraRules = [{
    commands = [
      {
        command = "${pkgs.systemd}/bin/cryptsetup";
        options = [ "NOPASSWD" ];
      }
    ];
    groups = [ "wheel" ];
  }];
};

I don’t get any errors on nixos-rebuild test/switch but I can’t get it to work. I’ll appreciate if you can help me understand this. Thanks in advance

  • MustardCornbread@programming.devOP
    link
    fedilink
    English
    arrow-up
    5
    ·
    1 year ago

    I got this working with security.sudo.extraConfig

    {config, pkgs, ... }:
    { ...
       security.sudo.extraConfig = ''
          # Allow wheel group to run specific commands without a password
         %wheel ALL=(ALL) NOPASSWD: /run/current-system/sw/bin/cryptsetup
         %wheel ALL=(ALL) NOPASSWD: /run/wrappers/bin/mount
        '';
    ...
    }