Hello fellow Nix users,
I’m trying to modularize my Home Manager configuration to avoid redundancy when using multiple package channels (e.g., nixpkgs-unstable
). My current setup might lead to repetitive use of let other-channel = import <other-channel> {};
blocks, which I’d like to replace with custom arguments passed to child modules. Here’s what I’ve tried:
Current Setup (home.nix
)
{ config, pkgs, ... }:
let
unstable = import <nixpkgs-unstable> { };
in {
imports = [ ./devbox.nix ];
home.packages = (with pkgs;[ddcutil])++(with unstable; [typst]);
}
Child Module (devbox.nix
)
{ pkgs, lib, config, unstable, ... }: {
options.devbox.enable = lib.mkEnableOption "Enable devbox";
config = lib.mkIf config.devbox.enable {
home.packages = with unstable; [ devbox ];
};
}
This fails with error: the option 'unstable' does not exist
when imported.
Attempted Solutions
- Passing arguments via imports (unsuccessful):
imports = [ ./devbox.nix { unstable = import <nixpkgs-unstable> {}; } ];
- Default argument in module (also unsuccessful):
{ unstable ? import <nixpkgs-unstable> {}, ... }: { ... }
So basically, can I pass custom arguments like unstable
to child modules without repeating let
blocks ?
NB
- I’m using Home Manager without Flakes.
- The
nixpkgs-unstable
channel is already added vianix-channel
.
Any guidance would be appreciated!