Defining custom option in nix file

Hi

I am currently trying to create a shared config between my desktop and my laptop. In doing so I wanted to create a custom option with mkOption in my home.nix file to check which config files to fetch.

I have tried to create the custom option in my home.nix file as follows:

  options.dotfiles = {
   isLaptop = mkEnableOption "Use laptop dotfiles";
  };

However I can’t seem to find a way to set the value of this option in another file. Trying to set it with config.dotfiles.isLaptop = true gives me an error message saying:

Module `/etc/nixos/configuration.nix' has an unsupported attribute `boot'. This is caused by introducing a top-level `config' or `options' attribute.

When I change the config to

config = {
  dotfiles.isLaptop = true;
}

it tells me the option dotfiles does not exist.

Is what I am trying to do possible using nix or should I approach it differently?

When you introduce a config or options attribute, you need to move everything that sets a value under config.

So this:

{
  options.foo = …;

  boot = …;
  programs = …;
}

has to become this:

{
  options.foo = …;

  config = {
    boot = …;
    programs = …;
  };
}

This seems to compile however my home.nix file doesn’t seem to follow it. I am trying to use different dotfiles as follows:

config = mkMerge [
    (mkIf config.dotfiles.isLaptop {
      home.file = {
        ".p10k.zsh" = {
          source = "${laptopDotfiles}/p10k/.p10k.zsh"; 
        };
      etc...
      };
    })
    (mkIf (!config.dotfiles.isLaptop) {
      home.file = {
        ".p10k.zsh" = {
          source = "${dotfiles}/p10k/.p10k.zsh"; 
        };
      etc...
      };
    })
    {
    other config options
    }
];

Am I doing this correctly or do variables/options not work this way in nix? I import the file setting the option at the top of my configuration.nix file, home manager imports my home.nix where the option is declared later in configuration.nix.