Flakes have per-system attributes (typically package related) which are usually depend upon something platform specific (e.g. something could be x86_64-linux only and cannot be built/used on darwin’s) and system-independent outputs (modules). See output schema in wiki for more details.
In your flake you are declaring the nixosModules output as a per system attribute by defining it inside the call to flake-utils.lib.eachDefaultSystem. One way to make it system-independent with flake-utils is to merge it to the result of eachDefaultSystem call:
One important thing to keep in mind is that modules take pkgs as an argument, so when you use pkgs.myCustomPackage in your module – myCustomPackage needs to be a part of the pkgs.
With flakes one pattern is to make the myCustomModule take the flake itself as the outer parameter, like so:
# flake.nix
outputs = { self, /* the rest of the params */ }:
# ...
{
nixosModules.default = import ./myCustomModule.nix { inherit self; };
}
# myCustomModule.nix
self:
{ pkgs, lib, config, ... }:
let
thisFlakePackages' = self.packages.${pkgs.system};
in
{
options.services.myService.package = thisFlakePackages'.default;
}
IMO when it comes to patterns like this one, flake.parts offer a more concise way to write this with flakes.
OK, I see that per-system attributes might be needed for some packages.
And I will have a look at “flake.parts”.
Thanks for the pointer. I will give that a try.
But I don’t think the problem I am describing (providing a service configuration)
is related to the general pattern, is it?
I am trying to expose the service but obviously I am still not exposing it the right way
Your nixcfg repo does not really pass the module from release-go flake to the machine’s configuration.
To fix this:
Make the nixosModules.default system-independent (merge the result or use flake.parts). Glancing at the repo, I think you’ve done this already.
Fix the way you are passing flake’s package to its module (e.g. through the outer argument in my previous post). Without this step pkgs.relase-go will not exist and this line will produce an error.
Import the release-go flake’s module in your nixcfg. (this is actually the reason for “no such option” error)
Since you’re passing inputs to the utm.nix, you could try this:
As an example for something very similar – there’s xremap flake. It has a perSystem package which gets pulled into a nixosModule. Might not be the best example because of repo-specific machinery but it’s the one I have at hand .
Alternatively there’s rust-web-server template with a bit more boilerplate directly in the flake file