Skip to content

Instantly share code, notes, and snippets.

@LnL7
Last active July 10, 2024 03:34
Show Gist options
  • Save LnL7/e645b9075933417e7fd8f93207787581 to your computer and use it in GitHub Desktop.
Save LnL7/e645b9075933417e7fd8f93207787581 to your computer and use it in GitHub Desktop.
NixOS configuration overlays
{ config, pkgs, ... }:
let
# Import unstable channel.
# sudo nix-channel --add http://nixos.org/channels/nixpkgs-unstable nixpkgs-unstable
# sudo nix-channel --update nixpkgs-unstable
unstable = import <nixpkgs-unstable> {};
in
{
environment.systemPackages =
[ pkgs.hello # regular channel
unstable.spotify # newer version from nixpkgs-unstable
];
virtualisation.libvirtd.enable = true;
nixpkgs.overlays =
[ (self: super:
{
# override with newer version from nixpkgs-unstable
qemu = unstable.qemu;
# custom package that depends on hello from nixpkgs-unstable
foo = super.callPackage ./pkgs/foo { inherit (unstable) hello; };
})
];
}
@nuxeh
Copy link

nuxeh commented May 2, 2020

Excellent example, thanks! :) I was really trying to find a way to overlay modules as well as packages, and couldn't find a solution until finding this!

@LnL7
Copy link
Author

LnL7 commented May 2, 2020

You can't really overlay modules, but there's a way to replace a module. This means it only works for modules limited to a single file, but it mostly works in those cases.

https://gist.github.com/LnL7/bd05394218033cff17ec20eb93a44a4a

@pushqrdx
Copy link

pushqrdx commented Jan 6, 2021

Just adding that you can also use a local copy of either nixpkgs or nixpkgs-unstable (or both at the same time) by passing in -I nipkgs=/path/to/stable/fork -I nixpkgs-unstable=/path/to/unstable/fork to any of the tools. nixos-rebuild for instance.

@ony
Copy link

ony commented Mar 30, 2021

It might be possible to bring in unstable.qemu with dependencies satisfied from pkgs using override attribute of package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment