Actually, the above won't work due to the general nature of Posix and Linux. 
This may be better:
    
    
    import macros
    import distros
    
    macro findOS*(): Distribution =
      var body = newNimNode(nnkStmtList)
      
      
      for distro in Distribution:
        if distro in {Linux, Posix}:
          continue
        let distLit = ident($distro)
        body.add(
          quote do:
            if detectOS(`distLit`):
              return Distribution.`distLit`
        )
      
      # We want to check these last because they are more general
      body.add(
        quote do:
          if detectOS(Linux):
            return Distribution.Linux
          if detectOS(Posix):
            return Distribution.Posix
      )
      
      result = quote do:
        (proc (): Distribution = `body`)()
    
    echo findOS()
    
    
    Run

But it's actually a tricky problem that might not be able to be solved with an 
iteration of Distribution, which is probably why it's not in the stdlib.

Reply via email to