Misterio77 / nix-starter-configs

Simple and documented config templates to help you get started with NixOS + home-manager + flakes. All the boilerplate you need!
Creative Commons Zero v1.0 Universal
2.66k stars 133 forks source link

How to add an overlay? #4

Closed Guekka closed 2 years ago

Guekka commented 2 years ago

First, thanks for this template. I've almost been able to convert my configuration to flakes. The only thing I'm missing is overlays. I thought just adding them in the overlay folder would be enough, but it looks like it doesn't work?

Misterio77 commented 2 years ago

Hey!

Just adding them to overlay/default.nix (if you're using the standard template) should work.

Guekka commented 2 years ago

I'm sorry, but you could please give a small example? I'm not sure if I have to modify the composeManyExtensions line For instance, I'm trying to add openAsar to Discord, which is just a boolean to turn on.

tshipenchko commented 2 years ago

For example please show how to use pkgs from unstable with primary stable nixpkgs

Guekka commented 2 years ago

So, it appears just pasting my overlay without the self: super line inside modifications appears to work However, I'd like to find a way to put it in a separate file

Misterio77 commented 2 years ago

Sorry for the delay. The idea is that you can add as many overlays as yout want, e.g. import them from a file or declare them directly. Then you just add it to composeManyExtensions and you should be good to go. Here's a couple exaples:


Just add them to the existing overlay/default.nix:

{ inputs, ... }:
let
  additions = final: _prev: import ../pkgs { pkgs = final; };
  modifications = final: prev: {
    some-package = prev.some-package.overrideAttrs (oldAttrs: {
      something-something = "foo bar";
    });
  };
in
inputs.nixpkgs.lib.composeManyExtensions [ additions modifications ]

Or to a separate file:

overlays/cool-overlay.nix:

final: prev: {
  some-package = prev.some-package.overrideAttrs (oldAttrs: {
    something-something = "foo bar";
  });
}

overlays/default.nix:

{ inputs, ... }:
let
  additions = final: _prev: import ../pkgs { pkgs = final; };
  modifications = final: prev: { };
  cool-overlay = import ./cool-overlay.nix;
in
inputs.nixpkgs.lib.composeManyExtensions [ additions modifications cool-overlay ]
Misterio77 commented 2 years ago

As for a dual nixpkgs (stable+unstable) setup:

In this example I'll add a hello-unstable and neovim-unstable that come from nixos-unstable.

flake.nix

{
# ...
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
  };
  # Define your systems using stable nixpkgs...
  # ...
}

overlays/default.nix:

{ inputs, ... }:
let
  additions = final: _prev: import ../pkgs { pkgs = final; };
  modifications = final: prev: { };
  unstable-overrides = final: prev: 
  let pkgs-unstable = inputs.nixpkgs-unstable.legacyPackages.${final.system};
  in {
    hello-unstable = pkgs-unstable.hello;
    neovim-unstable = pkgs-unstable.neovim;
  };
in
inputs.nixpkgs.lib.composeManyExtensions [ additions modifications unstable-overrides ]

You should be able to nix build .#hello-unstable now.

Misterio77 commented 2 years ago

Hope these examples help you folks out!

Guekka commented 2 years ago

They did! I was able to get Copilot working with clion. Thanks!

Guekka commented 2 years ago

I'd suggest adding these info to the readme