Sudo is not working on nixos

I am using flake to manage my nixos(23.05), recently i installed home-manager. It is working fine but now sudo is not working.
It is throwing this error :
sudo: /run/current-system/sw/bin//sudo must be owned by uid 0 and have the setuid bit set

The part i added for home-manager :

in input

home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";

in module

home-manager.nixosModules.home-manager
  {
    home-manager.useGlobalPkgs = true;
    home-manager.useUserPackages = true;
    home-manager.users.vipul = import ./home.nix;
  }

/run/wrappers/bin/sudo is working fine.

That’s interesting. If all you changed was the home-manager stuff, you should be fine. So it might be something strange in your ./home.nix? Though even that’s kinda hard to believe.

this is my home.nix → home.nix
I am using same home-manager in macos, it is working fine

    bash = {
      enable = true;
      initExtra = ''
        # Make Nix and home-manager installed things available in PATH.
        export PATH=/run/current-system/sw/bin/:/nix/var/nix/profiles/default/bin:$HOME/.nix-profile/bin:/etc/profiles/per-user/$USER/bin:$PATH
      '';
    };

Well there it is. You’re putting /run/current-system/sw/bin before everything in PATH. But NixOS puts that behind /run/wrappers/bin.

4 Likes