"error: value is a function while a set was expected" because of "inherit" statement

Solution: options.nix returned a function because it started with { config }:, so I just had to remove that.

I’ve been troubleshooting by myself, but I haven’t been able to find a solution, so:

I use a flake for my NixOS and Home Manager config. (here)

I use a structure rather similar to, but not the exact same as, this flake, and I just switched to having a dedicated file for “options.” However, now when I check the flake or rebuild, I get this error: error: value is a function while a set was expected. I worked around with this:

#inherit (import ./options.nix) username hostname;
username = (import ./options.nix) username;
hostname = "nixos-pc";

and then got it again:

       … while checking the NixOS configuration 'nixosConfigurations.nixos-pc'

         at /nix/store/rckyay7rjhsf89cq6xks3kcnc71krva5-source/flake.nix:27:5:

           26|
           27|     nixosConfigurations.${hostname} = nixpkgs.lib.nixosSystem {
             |     ^
           28|       specialArgs = {

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: value is a function while a set was expected

This let me narrow it down to the inherit statement.

{ inputs, config, pkgs, ... }:

let
  inherit (import ./options.nix)
    displayName username hostname
    KBLayout KBModel KBOptions;
in {

But to me, my flake.nix and system.nix seem to have no difference in the inherit statements to my reference flake.nix and system.nix which passes nix flake check.

So why does mine fail?
Thanks

The issue here is that in the reference flake, options.nix just returns an attrset. But in yours, it returns a function, because you have { config }: at the top. So that’s why the error is “value is a function while a set is expected”. If you want your options.nix to depend on some config parameter as it does, then you need to pass that along when you import it: inherit (import ./options.nix { config = ... }) ...;

Thank you

As a maybe follow-up, in options.nix, I set KBLayout depending on what deviceType is, so how can reference deviceType?
Even if I did this:

    inherit (import ./options.nix { config = ... }) username hostname;

I don’t know what to set config to to have it be options.nix?
Is there some sort of self I can use?

To be honest, I think something like this is the wrong approach to begin with. This is the kind of thing that is better done by defining a NixOS option and then using the config that the module system givese you to set other options based on it.