Documentation how to use overlays
Thank you for these useful templates!
I'd like to use a nixpkgs overlay with this (use a different version of nix). Do you have an example how to use overlays with these templates? In my case I use mkARMMacosSystem.
I'd like to apply the following overlay to nixpkgs:
final: prev: {
nix = final.nixVersions.nix_2_16;
}
Happy to accept a docs PR for this, but this is what it looks like:
https://github.com/srid/nixos-config/blob/17a7452602a9e0c9b8b35e8df91795003b1a051a/flake.nix#L88-L93
That said, if all you want is to use a different version of Nix, you probably want to set nix.package.
Hi, @srid
Nix beginner here. Can you elaborate, how you would do wiring home manager configuration in this case? It doesn't pick up overlays for me.
I've simplified test case to following steps:
- Use
nixos-unified-templateto generate empty configuration - Add sample overlay (below)
- Used package from overlay in home configuration (below)
- Launched nix repl and loaded flake with
:lf . - Verified that home configuraiton is loaded correctly by acessing
outputs.legacyPackages.aarch64-darwin.homeConfigurations.runner.config.home.packages- I can seehellopackage in list of derivations - Tried to instantiate darwin config by acessing
darwinConfigurations.example.config.home-manager.users.runner.home.packages - Got exception (below)
I understand that I am missing a step of providing overlay to darwin (or nixos) config, but I don't see how to provide it. Did read documentation and code of flake-parts but could not figure out how to perform this task. Also went through your nix config repo but still did not understand how it works for you, probably there's a line I am missing somewhere.
I've managed to use custom package by using callPackage; but that works for simple case of adding a package. What I'd like to do is to extend jdk package to install self-signed certificates to it and automatically provide it to all packages that rely on jdk which looks like a perfect task for overlay.
Example code:
overlays/default.nix
{ flake, ... }:
let
inherit (flake) inputs;
inherit (inputs) self;
in
self: super:
{
hello-world = self.pkgs.hello; # Just a rename to see if overlay is picked up
}
flake.nix:
...
# Wired using https://nixos-unified.org/autowiring.html
outputs = inputs@{ self, ... }:
let
root = ./.;
systems = [ "aarch64-darwin" ];
in
inputs.flake-parts.lib.mkFlake # had to use flake-parts as nixos-unified.iib.mkFlake does not accept overlay args
{
inherit inputs;
}
{
inherit systems;
_module.args = { inherit root; };
imports = with builtins;
if pathExists "${root}/nix/modules/flake-parts" then
map
(fn: "${root}/nix/modules/flake-parts/${fn}")
(attrNames (readDir (root + /nix/modules/flake-parts)))
else if pathExists "${root}/modules/flake-parts" then
map
(fn: "${root}/modules/flake-parts/${fn}")
(attrNames (readDir (root + /modules/flake-parts)))
else
throw "Neither modules/flake-parts nor nix/modules/flake-parts exist";
perSystem = { self', system, pkgs, lib, config, inputs', ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
overlays = [
self.overlays.default # <---
];
};
};
};
last change from template - adding hello-world package to modules/home/packages.nix.
Exception:
nix-repl> darwinConfigurations.example.config.home-manager.users.runner.home.packages
error:
… while evaluating the attribute 'value'
at /nix/store/riqkpszjqk02bi1wppfg8ip5xvh102qd-source/lib/modules.nix:816:9:
815| in warnDeprecation opt //
816| { value = addErrorContext "while evaluating the option `${showOption loc}':" value;
| ^
817| inherit (res.defsFinal') highestPrio;
… while evaluating the option `home-manager.users.runner.home.packages':
… while evaluating the attribute 'mergedValue'
at /nix/store/riqkpszjqk02bi1wppfg8ip5xvh102qd-source/lib/modules.nix:851:5:
850| # Type-check the remaining definitions, and merge them. Or throw if no definitions.
851| mergedValue =
| ^
852| if isDefined then
… while evaluating definitions from `/nix/store/hh7ki9vch449vak9p768m9vlmzccv28s-source/modules/home/packages.nix':
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: undefined variable 'hello-world'
at /nix/store/hh7ki9vch449vak9p768m9vlmzccv28s-source/modules/home/packages.nix:26:5:
25| less
26| hello-world
| ^
27| ];
nix-repl>
@ytaras Sorry I missed you comment. Autowiring just makes the overlay available in flake output (i.e., self.overlays); you still want to manually use that overlay in the corresponding nixos/ nix-darwin setting (nixpkgs.overlays option). You can see how I do that here:
https://github.com/srid/nixos-config/blob/66388f030711732e39a7168cc4ec7b5e24a9ae71/modules/nixos/shared/nix.nix#L14
But we should still document this clearly.
Yes, that's the part I've been missing. Thank you!
I still can not make it working. Trying to implement this project; https://github.com/Jas-SinghFSU/HyprPanel with self.overlays which @srid method mentioned in https://github.com/srid/nixos-unified/issues/24#issuecomment-2463536368
{ flake, ... }:
let
inherit (flake) inputs;
inherit (inputs) self;
in
self: super: {
hyprpanel = inputs.hyprpanel.overlay;
}