!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

149 Members
30 Servers

You have reached the beginning of time (for this room).


SenderMessageTime
9 Jul 2025
@atagen:ch.atagen.coatagen joined the room.07:41:54
14 Jul 2025
@mightyiam:matrix.org@mightyiam:matrix.org joined the room.10:05:13
@n4ch723hr3r:nope.chat@n4ch723hr3r:nope.chat joined the room.14:00:31
18 Jul 2025
@sandro:supersandro.deSandro 🐧 joined the room.12:28:34
20 Jul 2025
@x10an14:matrix.orgx10an14 joined the room.14:14:08
@x10an14:matrix.orgx10an14

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:nope.chat@n4ch723hr3r:nope.chati think you have to overwrite the type if that is possible14:17:24
@x10an14:matrix.orgx10an14
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:nope.chat@n4ch723hr3r:nope.chatfrom 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 type14:19:38
@x10an14:matrix.orgx10an14
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:matrix.orgx10an14
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:nope.chat@n4ch723hr3r:nope.chati was thinking about a general sense. like if you wanted to extend users.users for example.14:23:14

Show newer messages


Back to Room ListRoom Version: 10