Asking as a non nix expert, but a fairly decent software engineer. Are there any guidelines for how to design software that optimally integrate with Nix packaging? Basically I’m wanting to write some software specifically for nixos and I want to make it super easy to integrate with the nix store etc. For example:
Where should static and dynamic data live?
Should all runtime options be settable using environment variables so that it can be configured as options in the nix module?
Should everything be run-able from within a “nix-shell --pure shell.nix” etc?
Keep all static data in a directory that can be configured at build time. Preferably expect the data to follow FHS-style paths inside this directory. ($dir/bin, $dir/share, etc)
Dynamic data must not be put in this directory (as it will be in the nix store which is read-only). Put it in the home directory or /var or the like, depending on what makes sense.
Runtime options aren’t usually too difficult to configure no matter how you set them. On the whole, using a configuration file is preferable to env vars for a program used during a user login session, though, since env vars don’t update without a relog.
Depends on the type of software somewhat, but worrying about nix-shell is probably not necessary.
Make sure your build system can work without network access! This is the single thing that induces the most headaches when packaging software with nix.
Don’t download (dynamic) binaries and run them and expect that to work.
Not thinking of anything else off the top of my head.
It should really be rather easy, as long as you follow good practices for general Linux applications/services. The issue is that many don’t, or simply don’t know about them.
In general, when developing for Linux, you should ideally know either the XDG specs (for applications) or be competent with systemd (for services).
With the notable exception of secrets. The best practice for secrets on UNIXey systems in general is to read them from files. Those files should not contain any other values, and their location should be configurable.
Here, too, respecting the systemd spec makes things easy for you, downstream packagers, and users.
That’s for services, of course, applications should use the secret service instead.
These things apply to Linux development in general, their lack just becomes more noticeable on NixOS.