This seems to come up in various bugtrackers from time to time: Debian #46049, Debian #711001, RH #133683. But none of these seem to be implemented.
To recap: the Name Service Switch reads
/etc/nsswitch.conf where to look for e.g.
$ strace -f -e open,stat getent services > /dev/null
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
open("/etc/nsswitch.conf", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/libnss_db.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/lib/x86_64-linux-gnu/libnss_files.so.2", O_RDONLY|O_CLOEXEC) = 3
open("/usr/lib/x86_64-linux-gnu/libdb-5.3.so", O_RDONLY|O_CLOEXEC) = 3
open("/var/lib/misc/DB_CONFIG", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/var/lib/misc/services.db", 0x7ffd79d77060) = -1 ENOENT (No such file or directory)
open("/etc/services", O_RDONLY|O_CLOEXEC) = 3
+++ exited with 0 +++
libnss_db.so.2 could only be found because I installed libnss-db earlier.
So, if one manages to create a Berkeley DB database in
/var/lib/misc/services.db with additional service names, this could work.
libnss-db (Debian/unstable here), this is indeed possible:
$ grep ^[A-Z] /etc/default/libnss-db
ETC = /etc/local
DBS = services
VAR_DB = /var/lib/misc
AWK = awk
MAKEDB = makedb --quiet
$ cat /etc/local/services
# Local services
foobar 1234/tcp # Foo
$ getent services | wc -l
$ getent services foobar barbaz
/etc/local is not a registered configuration directory, it should not be touched by any upgrade process
Otherwise, these pathnames seem to be hardcoded and can only be changed/extended in a recompile, hence the wishlist tickets mentioned above.
$ strings /lib/x86_64-linux-gnu/libnss_files.so.2 | grep services
Note: there's also an libnss-extrausers package, which seems to provide additional files for NSS, but only for