It looks as if Nick Matzke’s hypothesis is correct, and the base of a bacterial flagellum was re-purposed from a structure used in the immune system. In fact, scientists are ready to recognize that the flagellum base plate is a variation of the type III secretion system. Nick wrote
Finally, if I were doing a revision, I would update the terminology along the lines suggested in Desvaux et al. 2006 (“Type III secretion: what’s in a name?” Trends in Microbiology 14(4), 157-160, April 2006 – DOI). As they point out, the terminological distinction between “flagellum” and “type 3 secretion system” is dubious and artificial, and it is more true to acknowledge that flagella have a type III secretion system. Therefore, there are two known groups of type III secretion systems, flagellar and nonflagellar, abbreviated F-T3SS and NF-T3SS.
There is much more to be said about recent research and its implications for flagellum evolution. For the near future I intend to post my thoughts on this in the new flagellum evolution section [UPDATE: fixed the link] of the Panda’s Thumb blog.