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.2k stars 119 forks source link

How to add overlays such as emacs-overlay to primary nixpkgs #55

Open ParetoOptimalDev opened 7 months ago

ParetoOptimalDev commented 7 months ago

This is partially covered in #48, however that's for if you want to add to the unstable-packages overlay.

I've instead:

I added it to my inputs:

      emacs-overlay.url  = "github:nix-community/emacs-overlay";

This makes available pkgs.inputs.emacs-overlay.emacs-pgtk for example, which partially works.

However for some reason, it doesn't seem to also include pkgs.inputs.emacs-overlay.emacsWithPackagesFromUsePackage for some reason.

Maybe this is some sort of merging error?

Also, if I wanted to include the override so that I could just use pkgs.emacs-pgtk throughout my configuration, how would I do that in this config?

Thanks!

schwanberger commented 7 months ago

I also had some issues with using the emacs overlay properly.

In the hopes of helping someone in the future, I have achieved the following

Assuming the standard template, I made these changes: (overlays/default.nix)

  unstable-packages-emacs-overlay = final: _prev: {
    unstable-emacs-overlay = import inputs.nixpkgs-unstable {
      system = final.system;
      config.allowUnfree = true;
      overlays = [ (import inputs.emacs-overlay) ];
    };
  };

(flake.nix)

...
  nixConfig = {
    extra-substituters = [
      # Nix community's cache server
      "https://nix-community.cachix.org"
      # Devenv cachix - doing some testing
      "https://devenv.cachix.org"
    ];
    extra-trusted-public-keys = [
      "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
      "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
    ];
  };
...
inputs = {
...
    emacs-overlay = {
      url = "github:nix-community/emacs-overlay";
      inputs.nixpkgs.follows = "nixpkgs-unstable";
    };
...
}

In NixOS module (nixos/configuration.nix)

{ inputs, outputs, lib, config, pkgs, ... }:
let
  emacs-pgtk-unstable = with pkgs.unstable-emacs-overlay;
    [
      ((emacsPackagesFor emacs-unstable-pgtk).emacsWithPackages
        (epkgs: with epkgs; [ vterm sqlite ]))
    ];
in {
...
  nixpkgs = {
    # You can add overlays here
    overlays = [
      # Add overlays your own flake exports (from overlays and pkgs dir):
      outputs.overlays.additions
      outputs.overlays.modifications
      outputs.overlays.unstable-packages
      outputs.overlays.unstable-packages-emacs-overlay
...
  nix = {
    settings = {
      # Enable flakes and new 'nix' command
      experimental-features = "nix-command flakes";
      # Deduplicate and optimize nix store
      auto-optimise-store = true;
      substituters =
        [ "https://nix-community.cachix.org" "https://devenv.cachix.org" ];
      trusted-public-keys = [
        "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
        "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
      ];
      trusted-users = [ "root" "@wheel" ];
    };
  };
...

I can then get the emacs version I want from the overlay (controlled via flake.lock) like so:

  environment.systemPackages = with pkgs.unstable; [ ... ] ++ emacs-pgtk-unstable;

In case you're interested, I made my nix config publicly available here: https://github.com/schwanberger/nix