14 Jul 2025 |
| n4ch723hr3r joined the room. | 14:00:31 |
18 Jul 2025 |
| Sandro 🐧 joined the room. | 12:28:34 |
20 Jul 2025 |
| x10an14 joined the room. | 14:14:08 |
x10an14 | I already asked in https://matrix.to/#/!6oudZq5zJjAyrxL2uY:0upti.me/$7AxNR83n3qUrjad6j0KXIDLtaUKnZIxy-sP_liLL04A, but this might be a better place:
I have written 1x module, and I want to make use of it (read: extend it) in another .nix file.
The module I have written looks like this:
{ lib, ... }:
{
options.flake.modules.foo = lib.mkOption {
type =
with lib.types;
attrsOf (
submodule (
{ name, ... }:
{
options = {
username = lib.mkOption {
type = str;
default = lib.splitString "@" name |> lib.flip builtins.elemAt 0;
};
hostname = lib.mkOption {
type = str;
default = lib.splitString "@" name |> lib.flip builtins.elemAt 1;
};
system = lib.mkOption {
type = enum [
"x86_64-linux"
];
};
};
}
)
);
};
config.flake.modules.foo."username@hostname".system = "x86_64-linux";
}
Now I want to extend foo like this:
{
lib,
repoRoot,
...
}@toplevel:
let
fooConfs = toplevel.config.flake.modules.foo;
in
{
options.flake.modules.foo.<fooInstance>.home-manager = lib.mkOption {
type =
with lib.types;
attrsOf (
submodule (
{
name,
config,
...
}:
let
username = config.username;
hostname = config.hostname;
system = config.system;
in
{
entryPoint = lib.mkOption {
type = lib.types.path;
default = "${repoRoot}/home-manager/${username}@${hostname}";
};
homeDirectory = lib.mkOption {
type = lib.types.path;
default =
if lib.strings.hasSuffix "-darwin" system then "/Users/${username}" else "/home/${username}";
};
toplevelBuild = lib.mkOption {
type = lib.types.raw;
readOnly = true;
};
}
)
);
};
config.flake.modules.foo.<fooInstance>.home-manager = fooConfs;
}
I have obviously grossly misunderstood something, so anyone here got any suggestions on how to proceed?
BTW: I'm not even sure I want homeManager to be nested under flake.modules.foo , I'd be happier if it was alongside like so flake.modules.homeManager.<instance of home-manager generated from instance of foo>
| 14:15:34 |
n4ch723hr3r | i think you have to overwrite the type if that is possible | 14:17:24 |
x10an14 | In reply to @n4ch723hr3r:nope.chat i think you have to overwrite the type if that is possible Is your answer independent of the BTW? | 14:18:31 |
n4ch723hr3r | from what i understand about the module system everything inside attrsOf is a subtype so you have to find a way to put something new into that type | 14:19:38 |
x10an14 | In reply to @n4ch723hr3r:nope.chat from what i understand about the module system everything inside attrsOf is a subtype so you have to find a way to put something new into that type So if my BTW wish is taken into account, the point you're making loses relevance, right? | 14:21:04 |
x10an14 | In reply to @n4ch723hr3r:nope.chat from what i understand about the module system everything inside attrsOf is a subtype so you have to find a way to put something new into that type I think you're correct about this though | 14:21:33 |
n4ch723hr3r | i was thinking about a general sense. like if you wanted to extend users.users for example. | 14:23:14 |
n4ch723hr3r | im not sure about if this is even possible since youd have to overwrite or wrap the binOp functor in .type.functor | 14:23:57 |
n4ch723hr3r | you can also explore via nix repl ;) | 14:24:13 |
n4ch723hr3r | apparently you can 🤔 | 14:27:06 |
n4ch723hr3r | users.users = lib.mkOption {
type = with lib.types; attrsOf (submodule userOptions);
};
found this in the openssh module
| 14:27:27 |
n4ch723hr3r | thats why if you search for "users.users" on search.nixos.org there are sometimes openssh and sometimes users-groups.nix given as a source | 14:28:46 |
n4ch723hr3r | x10an14 so maybe try extending it like openssh does for users.users and see what happens xD | 14:29:58 |
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 |