Flakes and packages

I am trying to get my head around how nix flakes pulls inn packages, lets say I want Picom, and I have a picom.nix:

{pkgs, lib, config, ...}:
with lib;
with builtins;
let
  xorg = (elem "xorg" config.sys.graphics.desktopProtocols);
  desktopMode = xorg;
in {
  config = mkIf desktopMode {
    environment.systemPackages = with pkgs; [
      picom
    ];

    services.picom = {
      enable = true;
      fade = true;
      fadeDelta = 5;
      shadow = true;
      backend = "glx";
    };
  };
}

Then in my nixos flake.nix

How can I then add picom in my flake.nix as a module and when I build and switch my flake it installs picom based on this picom.nix

Maybe I am bad in explaining what I want, but please be free to comment if the question is not clear.

Is picom.nix part of the repo that also contain your flake.nix? If yes, does it not work if you add the file-path to the list of modules in line 44 of your flake.nix?

You can add it to your nixosModules set which you then import all values from. Something like this:

nixosModules.picom = import picom.nix;
nixosConfigurations.mXlaptop = lib.nixosSystem {
  inherit system;
  modules = [ 
    ./system/configuration.nix 
    { nixpkgs.overlays = overlays; }
  ] ++ builtins.attrValues self.nixosModules;
};

I follow pretty much the same pattern for my Home and Nixos modules and configurations in my personal setup.

So all I have to do is add the path on line 44, in my flake.nix and It will install picom based on the settings in picom.nix?

Yeah, that’s also possible, though scales badly if you have more than one system.

But ok, then I can make sense of other people’s setup and see how that I can scale it, I was just wondering on how i was to add it. Thank you guys for helping out

I have then another question if that is fine, right now I am installing ST from my configuration.nix, then use overlay to get my build of st from github. How would I go and just add my github and install st as a module, same as picom?

My flake.nix in ST: Github

If your st was having a module in its outputs, you could just add it to the modules list.

Something like st.nixosModules.default if you added it under the name default.

Not sure I am able to get my mind on how that would look, if you have time, could you explain a bit more? or give an example?

Your st flake needs to have a nixosModule.default in its outputs, that does what you want the module to do.

Your system flake then just consumes that module like I said in my previous post.

When I try to build after adding modules, as seen here in my dotfiles

I am getting an error:

$ sudo nixos-rebuild switch --flake .#mXlaptop
path '/home/merrinx/.flakes/modules' does not contain a 'flake.nix', searching up
building the system configuration...
path '/home/merrinx/.flakes/modules' does not contain a 'flake.nix', searching up
error: infinite recursion encountered

       at /nix/store/56h5pqxpsml9mw7zzd7s59iqvf85bhyb-source/lib/modules.nix:898:14:

          897|     { _type = "if";
          898|       inherit condition content;
             |              ^
          899|     };
(use '--show-trace' to show detailed location information)

Cannot figure out what the problem is, please advice if there is something I can do.

Your picom module is defined in a way that it will always lead to infinite recursion.

It sets the key it enables itself on.

Usually a module should never set any child of its cfg.

How would I fix this?

As I am not quite sure about the goals and purpose of that module, I am not quite sure.

I always think that a module without any options is kind of weird. They have their purpose, but it’s still weird in my opinion.

The purpose is to install picom and run the service with the listed parameters, What more options would there be… sorry for asking dumb questions