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), I’ve realized that I have to understand overlays.
Questions about the NixOS wiki page on 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:”
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:
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
:
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 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:
{
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?