I’ve recently started writing my own modules for nixos configuration to share them between different machines. So I wanted to have nice auto completion for my own options via nixd.
But I’m struggling to understand where do I get options definitions from. The guide provided by nixd seems to be using nix-parts (based on the attributes in used flakes, e. g. (builtins.getFlake \"/home/lyc/flakes\").nixosConfigurations.adrastea.options
). The only non-flake based way they suggest is (import <home-manager/modules> { configuration = ~/.config/home-manager/home.nix; pkgs = import <nixpkgs> {}; }).options
, but it is specific for home-manager.
I’ve also tried to evaluate modules myself, with pkgs.lib.evalModules
. But I haven’t figured it out how to actually use it on my modules.
test.nix
{lib, ...}:{
options.testOption = lib.mkEnableOption "test";
}
more-complex.nix
{ config, pkgs, lib, ... }:
{
options = ...;
}
nix repl
nix-repl> (pkgs.lib.evalModules {modules = [ (import /path/to/file/test.nix) ];})
{
_module = { ... };
_type = "configuration";
class = null;
config = { ... };
extendModules = «lambda extendModules @ /nix/store/ag2xcw8qdzji8plkd9fishqd2b95wzrd-nixos-24.11/nixos/lib/modules.nix:338:9»;
options = { ... };
type = { ... };
}
nix-repl> (pkgs.lib.evalModules {modules = [ (import /path/to/file/more-complex.nix) ];})
{
_module = «error: attribute 'pkgs' missing»;
_type = "configuration";
class = null;
config = «error: attribute 'pkgs' missing»;
extendModules = «lambda extendModules @ /nix/store/ag2xcw8qdzji8plkd9fishqd2b95wzrd-nixos-24.11/nixos/lib/modules.nix:338:9»;
options = «error: attribute 'pkgs' missing»;
type = { ... };
}
It breaks if pkgs
is passed to it. I don’t know how to pass pkgs
to this module and there hardly any documentation on this function.
So, can someone explain how do you get these config definitions from nested modules?