| 20 Jul 2025 |
n4ch723hr3r | https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/networking/ssh/sshd.nix#L666 | 14:30:20 |
x10an14 | n4ch723hr3r: I think this is the closest I could easily find in that huge file that might answer my question (how to access option values declared elsewhere in another file/option): https://github.com/NixOS/nixpkgs/blob/nixos-unstable/nixos/modules/services/networking/ssh/sshd.nix#L149 | 14:46:03 |
n4ch723hr3r | accessing the values can be done over config but i thought you want to extend a module with a new option | 14:48:01 |
x10an14 | Ahhh, no, because they don't use those values inside the submodule, I saw wrong | 14:48:22 |
x10an14 | I want/need both, and it's the 1st of those two that I got stuck on/struggled with | 14:48:51 |
n4ch723hr3r | so in the second file you do:
options.flake.modules.foo = lib.mkOption {
type =
with lib.types;
attrsOf (
submodule (
{ name, ... }:
{
options = {
home-manager = lib.mkOption {
......
| 14:50:09 |
n4ch723hr3r | thats at least how i understood this attrsOf extending | 14:50:58 |
x10an14 | the inherits in the let ... in block in the 2nd file error out for me, no such value/attrs present:
2025-07-20 15:50:27+02:00 ~/Doc/sr./nix-parts-conf w/❄️nix-shell-envtook 17s
x10an14@home-desktop ❯ : nix eval --json .#modules.x10.home-manager | from json
warning: Git tree '/home/x10an14/Documents/sr.ht/nix-parts-conf' is dirty
error:
… while evaluating the attribute 'root.result'
at «flakes-internal»/call-flake.nix:98:7:
97| {
98| result =
| ^
99| if node.flake or true then
… in the left operand of the update (//) operator
at «flakes-internal»/call-flake.nix:85:9:
84| # This is shadowed in the next //
85| // sourceInfo
| ^
86| // {
… while evaluating the option `flake':
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: The option `flake.modules.x10.device-configs' in module `/nix/store/6rgggbp9175wyswk9d2pl66v22vn4c3b-source/device-configs/default.nix' would be a parent of the following options, but its type `attribute set of (submodule)' does not support nested options.
- option(s) with prefix `flake.modules.x10.device-configs.home-manager' in module `/nix/store/6rgggbp9175wyswk9d2pl66v22vn4c3b-source/device-configs/home-manager.nix'
| 14:51:34 |
n4ch723hr3r | the snowfall scared me xD | 14:52:02 |
x10an14 | Ahh, right, gotten blind to my own code. Thanks, let me try. | 14:52:10 |
x10an14 | Does the same w/me... | 14:52:18 |
n4ch723hr3r | { name, config, ... }: i dont think config exists in that scope, right? | 14:52:46 |
n4ch723hr3r | you probably need to do fooConfs.${name}... | 14:53:26 |
n4ch723hr3r | and afaik fooConfs is often named cfg in nix modules | 14:53:52 |
x10an14 | Nah, sorry, there's something I'm messing up/not getting 😅 See this paste: https://paste.sr.ht/~x10an14/653ed23dd63ba7166d4da89b315c9cce3c4f92c8 And see the comment. Here's the error when I try to nix eval .#modules.x10.device-configs:
x10an14@home-desktop ❯ : nix eval .#modules.x10.device-configs
warning: Git tree '/home/x10an14/Documents/sr.ht/nix-parts-conf' is dirty
{ "x10an14@home-desktop" = { homeManager = { entryPoint = «error: attribute 'username' missing»; homeDirectory = «error: attribute 'system' missing»; toplevelBuild = «error: The option `flake.modules.x10.device-configs."x10an14@home-desktop".homeManager.toplevelBuild' was accessed but has no value defined. Try setting the option.»; }; hostname = "home-desktop"; system = "x86_64-linux"; username = "x10an14"; }; "x10an14@nav-x10an14-t14" = { homeManager = { entryPoint = «error: attribute 'username' missing»; homeDirectory = «error: attribute 'system' missing»; toplevelBuild = «error: The option `flake.modules.x10.device-configs."x10an14@nav-x10an14-t14".homeManager.toplevelBuild' was accessed but has no value defined. Try setting the option.»; }; hostname = "nav-x10an14-t14"; system = "x86_64-linux"; username = "x10an14"; }; }
See the errors reporting missing attributes?
| 15:03:15 |
n4ch723hr3r | you can also do nix repl then enter :lf . | 15:04:06 |
x10an14 | I know that, but again, I'm asking here because I don't know what I should be exploring. There's something missing in my mental model, and I'm here asking for a nudge in the right direction^^
Answering your suggestion on using the nix repl directly, how can I in the repl explore what the config attribute w/the comments look like? I only know how to explore evaluated configs/outputs in the repl
| 15:06:31 |
n4ch723hr3r | {
name,
username, # <- I want access to these, that live under `config.flake.modules.x10.device-configs.<a device>,`
hostname, # <- I want access to these, that live under `config.flake.modules.x10.device-configs.<a device>,`
system, # <- I want access to these, that live under `config.flake.modules.x10.device-configs.<a device>,`
...
}:
let
ihnerit (config.flake.modules.x10.device-config.${name}) username;
in
{
options.homeManager = {
| 15:06:44 |
n4ch723hr3r | * {
name,
...
}:
let
ihnerit (config.flake.modules.x10.device-config.${name}) username;
in
{
options.homeManager = {
| 15:06:54 |
n4ch723hr3r | how about that? | 15:07:01 |
n4ch723hr3r | * {
name,
...
}:
let
inherit (config.flake.modules.x10.device-config.${name}) username;
in
{
options.homeManager = {
| 15:07:07 |
x10an14 | Gotcha. Just managed to put 2+2 together with your previous mention of fooConf.${name}. I got infinite recursion error | 15:09:37 |
n4ch723hr3r | yeah i hope that makes sense why you got infinite recursion error | 15:10:34 |
n4ch723hr3r | * yeah i hope that it makes sense why you got infinite recursion error | 15:10:45 |
x10an14 | I got it to work with lots of help from @mightyiam:matrix.org (thanks)! =) | 17:11:02 |
n4ch723hr3r | nice what did you do? | 22:12:49 |
| 21 Jul 2025 |
x10an14 | Something I'd already tried earlier but discarded due to an unrelated error (that I thought told me I could not do things this way):
{
type =
with lib.types;
attrsOf (
submodule (
nixosConfig:
let
cfg = nixosConfig.config.nixos;
inherit (nixosConfig.config) hostname username system;
in
{
options.nixos = builtins.break {
entryPoint = lib.mkOption {
type = lib.types.path;
default = "${repoRoot}/nixos/${username}_at_${hostname}";
};
toplevelBuild = lib.mkOption {
type = lib.types.raw;
readOnly = true;
};
};
config.nixos.toplevelBuild = lib.mkIf (builtins.pathExists cfg.entryPoint) (
inputs.nixpkgs.lib.nixosSystem {
modules = [
{
nixpkgs.hostPlatform = { inherit system; };
}
(import cfg.entryPoint (inputs // { inherit repoRoot; }))
"${repoRoot}/x10/options/unfree-packages.nix"
inputs.nur.modules.nixos.default
];
specialArgs = {
inherit inputs hostname repoRoot;
};
}
);
}
)
);
}
So yeah, the inner config variable of the extending submodule contains the submodule's "sibling" option values.
| 07:14:28 |
nbp | x10an14: taking the discussion from the beginning …
If you want to declare options specific to one instance, you can do it as follow:
{ lib, ... }@toplevel:
{
config.flake.modules.foo.<fooInstance> = {config, ...}@submoduleInstance: {
options.home-manager = lib.mkOption { ... };
config.home-manager = ...;
}
}
If you want to make the home-manager option available to all instances, then your initial example is almost there, you have to redefine the foo option with the submodule that you want to add. Submodule option declarations are merged, see fileSystems option as an example, which is declared in multiple modules.
| 09:36:22 |
nbp | If you want your option to define home-manager.<user> from foo.<user>, unfortunately there is no simple shortcut that exists today, you will have to fallback to the nix language / Nixpkgs library to map the attributes of one into the other. | 09:39:25 |
x10an14 | nbp: Thanks! =D
I got it to work, as described in the previous 2x messages of mine =) This is how I did it: https://git.sr.ht/~x10an14/nix-parts-conf/tree/main/item/device-configs/home-manager.nix
Any feedback/suggestions welcome! PS: I urge those who've got feedback/suggestions to consider whether it's too niche for this channel/is maybe better suited for a DM =)
| 10:29:35 |