Why does /etc/shells exist?

This is a generic *nix related question. Is there some reason chsh queries /etc/shells before deciding whether it should change the shell entry in /etc/passwd? In nixos, setting programs.<shell>.enable sets up some startup files in /etc as well, but I don’t think that’s the reason /etc/shells exists.

Also, is there a reason nixos places startup files in /etc? Zsh allows the global rc file paths to be configurable (https://github.com/zsh-users/zsh/blob/8037462895b4de98528a6b56c2f35d606150d3f3/INSTALL#L436).

man 5 shells says, it’s a whitelist of allowed shells on the system.

Not sure though about the decisions behind your other question.

As @NobbZ said, this is used as a whitelist of what shells are allowed. I think in NixOS, this file is only relevant with users.mutableUsers = true .

It’s usually easiest to just use /etc as the configuration directory. Otherwise, changing anything in --enable-etcdir= ends up requiring a rebuild of Zsh. Having a package depend directly on its configuration is usually considered bad practice in Nixpkgs. We let NixOS manage /etc for us, and this tends to work pretty good.

That is not entirely true. The file lists valid login shells. Some software uses the file to check if a user is a normal user since those will have valid login shell set in /etc/passwd. When improperly set up, it can cause issues like Normal users not appearing in login manager lists - #2 by aloysius