A little lost on flakes and overlays and how to incorporate them

EDIT: Solved! Of course, as these things always go, I can spend days trying to figure something out, and once I ask for help, I manage to figure it out. The solution, in case someone stumbles upon it, was:

  1. Within the modules = ; section of my flake.nix, add (import ./overlays), as so:
modules = [
...
(import ./overlays)
...
];

Create the overlays/default.nix, containing:

{ config, pkgs, lib, inputs, ... }:
{
  nixpkgs.overlays = [
    inputs.hyprpanel.overlay.x86_64-linux
  ];
}

And then in my home/programs/common.nix:

...
home.packages = [
  pkgs.hyprpanel
];

Original post:

Hi everyone. New NixOS user here and I’m really excited to figure this whole system out as it will, eventually, enable me to accomplish things I’ve wanted for years.

To start, I used this template as my starting point for NixOS. So far I’ve been able to adapt it to my needs and get myself going with a bunch of packages with no issues.

My current config is here if someone wouldn’t mind taking a look to see if they can guide me in the right direction.

Where I run into difficulties is trying to install packages from outside of nixpkgs, for example: hyprpanel. This package has a flake.nix file, and a default.nix. I’m not really sure what to do with those, but I expect the answer is probably nothing. I’ve included the repo in my flake.nix file:

{
...
  inputs = {
    # Hyprpanel
    hyprpanel = {
      url = "github:Jas-SinghFSU/HyprPanel";
    };
...

and included that in my outputs:

...
  outputs = inputs @ {
    self,
    nixpkgs,
    home-manager,
    hyprland,
    hyprpanel,
    spicetify-nix,
    stylix,
    ...
  }: {
...

The repository says to call the input in the overlay = section of my config.

# flake.nix

{
  inputs.hyprpanel.url = "github:Jas-SinghFSU/HyprPanel";
  # ...

  outputs = { self, nixpkgs, ... }@inputs: 
  let
    # ...
	system = "x86_64-linux"; # change to whatever your system should be.
    pkgs = import nixpkgs {
	  inherit system;
	  # ...
	  overlays = [
        inputs.hyprpanel.overlay.${system}
	  ];
	};
  in {
    # ...
  }
}

However, I don’t have an overlay section in my config. I’ve tried writing that in in a number of places but at this point I’m just throwing things at a wall and hoping I get lucky, which is nearly impossible.

Could anyone point me in the right direction? I’ve read so many things that I feel like I’m even more confused now than I was before.

2 Likes

Never use import in the module system. Just provide the path in imports (or modules, which is the same thing, just used as an arg to lib.evalModules).

1 Like

Thanks, fixed! Would you mind explaining why to never use it like that?

1 Like

@fzakaria made a great blogpost about this Import but don’t import your NixOS modules | Farid Zakaria’s Blog

2 Likes

A quick explanation here:

But the simplest answer is: because you don’t need to use import (the nix builtin keyword) when you have the far more expressive imports (attribute used by the module system). They do different things, but with all the functionality provided by nixpkgs, I’ve not needed to use import in my config at all…

2 Likes