My NixOS configuration currently is disorganized. For example, I have installed sway, but all sway-related config goes into several different places, and I want to move it all into a single place.
In particular, I have in my configuration.nix
{ config, pkgs, ... }:
let
my-python-packages = python-packages: with python-packages; [
numpy
...
i3ipc
...
];
python-with-packages = pkgs.python310.withPackages my-python-packages;
in
{
environment.systemPackages = with pkgs; [
...
python-with-packages
mako # I know I can put that in programs.sway.extraPackages - I put it here mostly for demonstration purposes
...
];
...
programs.sway = {
enable = true;
...
}
...
}
I also use home-manager and have a home.nix with additional sway-related options:
So I’d like to make a separate file that contains all sway configuration in a single separate file (probably would be a module, but I’m open to other solutions) which:
Sets the system and home-manager options - I know how to do that, what’s causing me problems are the next two points.
Adds i3ipc to my python installation (it has other packages like numpy specified elsewhere)
Adds mako to my system packages without using programs.sway.extraPackages. I will use that option in my final config, but I’d like to figure out how to add a system package from a custom module or a separate file
And then put all your sway configuration in sway.nix, just as if it was in configuration.nix it would already work. This also works for lists like environment.systemPackages, the module system will simply append all the lists together.
If there is a conflict, nix will tell you and ask you to use lib.mkOverride to decide which option should take priority. But this is unlikely, since you probably won’t put sway configuration in multiple places.
The tricky bit is the additional python package. For this you could indeed create a pythonPackages option, make the module system do its merging on that list, and then set your python with that list.
I always wonder why such an option doesn’t exist in NixOS yet. A programs.python with programs.python.extraPackages and programs.python.package would make the whole python env setup thing so much less confusing for new users, and also solve this particular problem.
Maybe I should create a PR? Anyone here know why it’s not the case yet?
You could probably use config.programs.python.package, assuming there is a packageBase to override the base python, and the full package gets resolved into package. config refers to the fully resolved attributes, in case you didn’t realize
So, I don’t actually have a list to auto-merge, but rather a function that returns a list. I’m not sure how to do that. Maybe I should make the option be list of strings, but then
how to get the actual packages to pass to pkgs.python310.withPackages?