Created
August 26, 2024 15:30
-
-
Save pjones/4e87e10b4ad752efcfacf9df327f9996 to your computer and use it in GitHub Desktop.
How to use an overlay in a flake to mix stable and unstable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
description = "Packages from stable and unstable"; | |
inputs = { | |
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05"; | |
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; | |
}; | |
outputs = inputs@{ self, nixpkgs, ... }: | |
let | |
supportedSystems = [ | |
"x86_64-linux" | |
"aarch64-linux" | |
]; | |
# Function to generate a set based on supported systems: | |
forAllSystems = f: | |
nixpkgs.lib.genAttrs supportedSystems (system: f system); | |
# Load the stable version of nixpkgs and apply the overlay which | |
# is defined below: | |
nixpkgsFor = forAllSystems (system: | |
import nixpkgs { | |
inherit system; | |
overlays = builtins.attrValues self.overlays; | |
}); | |
# Load nixpkgs-unstable: | |
unstableFor = forAllSystems (system: | |
import inputs.nixpkgs-unstable { | |
inherit system; | |
}); | |
in | |
{ | |
# Define an overlay called `default`. | |
# | |
# An overlay is a function that takes two arguments. The second | |
# argument is the package set that we are going to modify. The | |
# first argument is the future set that we are returning. | |
overlays = { | |
default = final: prev: { | |
qcal = unstableFor.${prev.system}.qcal; | |
}; | |
}; | |
# An incomplete NixOS configure that will use qcal from | |
# unstable. | |
nixosConfigurations = { | |
myhost = nixpkgs.lib.nixosSystem rec { | |
system = "x86_64-linux"; | |
modules = [ | |
{ nixpkgs.pkgs = nixpkgsFor.${system}; } | |
]; | |
}; | |
}; | |
# A shell environment that will use qcal from unstable: | |
devShells = forAllSystems (system: | |
let pkgs = nixpkgsFor.${system}; | |
in { | |
default = pkgs.mkShell { | |
buildInputs = [ | |
pkgs.qcal # This is from unstable! | |
]; | |
}; | |
}); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment