I am using flakes to build my NixOS system. I have an overlay or a custom package derivation buried somewhere in one of the modules that I use to build my system. The flake.nix looks something like this:
{ pkgs, ... }:
let my-overlay = self: super: # bla bla bla
in {
nixpkgs.overlays = [ my-overlay ];
# more gui stuff
}
Now I would like to move my-overlay from gui.nix to outputs.overlays in flake.nix but still “use” it in gui.nix. So the line nixpkgs.overlays = [ my-overlay ]; should essentially stay in the file so that I can just remove the gui.nix from my modules list if I want to and effectively not be using the overlay any longer.
So how can I access outputs.overlays inside a file that is listed in the modules list of my nixpkgs.lib.nixosSystem call?
(The question could be equally stated for outputs.packages.)
background
This is not critical in any way (my config builds and works just fine). But I am trying to modularize my flake a little so that parts of it could be used from outside. For example I moved some custom package to outputs.packages in order to nix build it and trying out stuff. Now I am done and I would like to just use outputs.packages in gui.nix instead of copying the code around again.
You can access the flake output through self. E.g. self.nixosConfigurations.my-computer will contain your nixos configuration. To have it be available in gui.nix you will have to add self or self.defaultOverlay (or something else) to the extraArgs of the nixosSystem call. You can then use { pkgs, self, ... }: in your nixos configuration files.
Using the deprecated extraArgs was the reason why I was unable to build a flake configuration with config.specialisation set. Now I replaced it with an inline module like you showed and it works, thank you!