a) For creating folders, there is systemd.tmpfiles. Despite the implications of its name, you can use it to automatically ensure folders exist, without setting up any clean up. Looks something like this in my config:
systemd.tmpfiles.rules = [
"d /mnt/media/Movies 0770 media media - -"
];
b) I don’t use SMB, but for normal Unix passwords, I just set them imperatively after installation.
More generally, you can do imperative things when activating a new NixOS configuration using system.activationScripts. Of course, the script you run should be idempotent and such changes would not be able to be rolled-back by standard NixOS mechanisms - imperative is imperative.
The other issue with this approach is that it is not really secure to include the password in your NixOS config, as the Nix store (to which the activation scripts get written) is world-readable (see this longstanding issue).
Yeah, I think tmpfiles is good for setting up empty Samba shares and permissions.
Basically everything in NixOS is done with activation scripts, so it is certainly possible to write them in a way that works with rolling back.
It ought to be possible to reproducibly and declaratively make the Samba state, but I haven’t seen any work on that (and I’ve looked a bit). If anyone knows about anyone working on that, I’d be very interested.
One issue is Samba uses a different hash type than /etc/passwd so I don’t see an easy way to directly keep the Linux & SMB passwords in sync. One hacky option would be to use the users.users.<name>.passwordFile option and then use an activationScript to populate the smbpasswd database.
Alternatively you could use the users.users.<name>.hashedPassword value directly as the SMB password but it might be annoying (you’d have to compute the hash on each client each time you mount the share).
If you have a lot of users or want the most professional option then LDAP is your best bet but it takes some effort to configure. The best option likely depends on your specific use case. IMO you may want to consider using NFS, SFTP, and SSHFS.
How can I configure my home directory in NixOS to be accessible over the network only by valid users? I’m having trouble setting it up correctly. Additionally, is there a way to create users, groups, and add users to the database during the initial setup in configuration.nix?
Any guidance or examples would be greatly appreciated. Thank you!
no i mean i use the unix ‘network file system’ NFS.
Which is greatly superior to cifs, what sweaty blamer & locked gates wrote.
Network File System (NFS) is a distributed file system protocol developed by Sun Microsystems in 1984.02 It allows a user on a client computer to access files over a computer network, similar to how local storage is accessed. NFS is an open IETF standard defined in a Request for Comments (RFC), allowing anyone to implement the protocol.2 It defines the way files are stored and retrieved from storage devices across networks