A nonabelian duality for (higher) gauge theories