!wfudwzqQUiJYJnqfSY:nixos.org

NixOS Module System

172 Members
37 Servers

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


SenderMessageTime
21 Jul 2025
@x10an14:matrix.orgx10an14

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:mozilla.orgnbp

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:mozilla.orgnbp 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:matrix.orgx10an14

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
@nbp:mozilla.orgnbp x10an14: This is the right channel. Thanks for the link, I was not aware of the pipe operator. 12:03:29
@x10an14:matrix.orgx10an14 Aight, and yw =) 12:07:17

Show newer messages


Back to Room ListRoom Version: 10