# My first overlay, for emacs

**URL:** https://discourse.nixos.org/t/my-first-overlay-for-emacs/7570
**Category:** Uncategorized
**Created:** [June 8, 2020, 3:55pm UTC](https://discourse.nixos.org/t/my-first-overlay-for-emacs/7570 "2020-06-08T15:55:08Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![JeffreyBenjaminBrown](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jeffreybenjaminbrown/32/1676_2.png) [@JeffreyBenjaminBrown](https://discourse.nixos.org/u/JeffreyBenjaminBrown)
#### Post date: [June 8, 2020, 3:55pm UTC](https://discourse.nixos.org/t/my-first-overlay-for-emacs/7570/1 "2020-06-08T15:55:08Z")

</div>

In the course of [trying to install org-roam for Emacs](([emacsPackages.org-roam: init at 0.1.2 by rasendubi · Pull Request #80280 · NixOS/nixpkgs · GitHub](https://github.com/NixOS/nixpkgs/pull/80280)), I’ve realized that I have to understand overlays.

# Questions about the [NixOS wiki page on overlays](https://nixos.wiki/wiki/Overlays)

The first section, “Applying overlays manually”, includes just the code snippet `import <nixpkgs> { overlays = [overlay1 overlay2]; }`. Where would one use that? In the `configuration.nix` file? From the nix repl?

The next section, “Applying overlays automatically”, includes “user level” and “system level” subsections. I’m the only user of my system, and the only way I ever build is via sudo, so I’m interested in the system level, right?

If so, in the “system level” subsection it says, “If you want your overlays to be accessible by nix tools and also in the system-wide configuration, add nixpkgs-overlays to your NIX\_PATH:”

```auto
NIX_PATH="$NIX_PATH:nixpkgs-overlays=/etc/nixos/overlays"

```

That looks like a bash command. Is there some bash file that gets loaded every time I start the OS, to which I should add that line? I don’t see `.bashrc` or `.bash_profile` in my home directory.

Then there’s a third subsection called “Using nixpkgs.overlays from configuration.nix as in your NIX\_PATH”. Is that an alternative to the “system level” section earlier? It’s the only one that mentions the `configuration.nix` file.

My `.nix` files do not mention `nix.nixPath`, so it seems like I should add this:

```auto
  nix.nixPath =
    # Prepend default nixPath values.
    options.nix.nixPath.default ++
    # Append our nixpkgs-overlays.
    ["nixpkgs-overlays=/etc/nixos/overlays-compat/"]
  ;

```

and then put this code into `/etc/nixos/overlays-compat/overlays.nix`:

```auto
self: super:
with super.lib;
let
  # Load the system config and get the `nixpkgs.overlays` option
  overlays = (import <nixpkgs/nixos> { }).config.nixpkgs.overlays;
in
  # Apply all overlays to the input of the current "main" overlay
  foldl' (flip extends) (_: super) overlays self

```

# Questions about using `emacs-overlay`

The [emacs-overlay](https://github.com/nix-community/emacs-overlay#latest-master-each-rebuild) README says that “probably the most convenient way to pull in this overlay is by just fetching the tarball of latest master on rebuild”, and provides the following code for doing so:

```auto
{
  nixpkgs.overlays = [
    (import (builtins.fetchTarball {
      url = https://github.com/nix-community/emacs-overlay/archive/master.tar.gz;
    }))
  ];
}

```

Where does that code go? Should I create an `emacs-overlay.nix` file in `/etc/nixos/overlays-compat/`, containing that code and nothing else? Will the `foldl' (flip ...` line in `overlays.nix` find and incorporate it?

---

_[View the full topic](https://discourse.nixos.org/t/my-first-overlay-for-emacs/7570)._
