I wouldn’t put them in separate flakes. That’s completely pointless and will just be a headache to maintain. You get absolutely zero benefit from this, and the increase in build time, update time/effort, metadata file lines, LoC, etc. will all be felt.
Splitting out separate projects makes sense, if you have disjoint sets of contributors and/or users, but the types of scripts that people would put in their $PATH are normally married to their system configuration, and don’t really make sense to split out.
This does not mean you cannot write derivations for your scripts, with or without flakes. Place in your configuration.nix something like:
# configuration.nix
{ pkgs, lib, ... }: let
scripts = lib.packagesFromDirectoryRecursive {
inherit (pkgs) callPackage;
directory = ./packages;
};
in {
_module.args = {
inherit scripts;
};
}
… then you can create packages in ./packages just like the packages defined in nixpkgs, and they’ll be accessible as scripts.<filename>. So, to e.g. add a little hello-world script to systemPackages from a module you import from configuration.nix:
# packages/hello-world.nix
{
writers,
hello,
...
}:
writers.writeBashBin "hello-world" {
makeWrapperArgs = [
"--prefix" "PATH" ":" "${lib.makeBinPath [ hello ]}"
];
} ''
hello
''
Or alternatively if you want to separate out the script file
# packages/hello-world/package.nix
{
writers,
hello,
...
}:
writers.writeBashBin "hello-world" {
makeWrapperArgs = [
"--prefix" "PATH" ":" "${lib.makeBinPath [ hello ]}"
];
} ./hello-world.bash
#!/usr/bin/env bash
# packages/hello-world/hello-world.bash
# The shebang won't actually be used, but
# I like including one anyway.
hello
# config/some-module.nix
{ scripts, ... }: {
environment.systemPackages = [
scripts.hello-world
];
}
With flakes, you can absolutely put this same attrset in the packages output of your system flake, if you so desire. This will limit you to zero nesting, though.
I currently do this, but realistically, you won’t have any consumers, so adding it to your flake metadata is pointless (as is, frankly, using flakes for NixOS configuration). I intend to move away from exposing my local packages with the packages output, and I would not recommend anyone does so with a flake whose purpose is NixOS deployments.