nixos-facter-modules icon indicating copy to clipboard operation
nixos-facter-modules copied to clipboard

Modules Structure: separate (nixos) config from options

Open hsjobeki opened this issue 1 year ago • 3 comments
trafficstars

When playing around with nixos-facter-modules i noticed that the files could be a bit optimized.

  • somebody may want to import only the interface (options) but also would need to import all the nixos modules, because it sets config options in the same files.
# broadcom.nix
{ lib, config, ... }:
let
  inherit (config.facter) report;
  cfg = config.facter.networking.broadcom;
in
{
  options.facter.networking.broadcom = with lib; {
   # ...
  };

  config = {
    hardware.enableRedistributableFirmware = lib.mkIf cfg.full_mac.enable (lib.mkDefault true);

    boot = lib.mkIf cfg.sta.enable {
      kernelModules = [ "wl" ];
      extraModulePackages = [ config.boot.kernelPackages.broadcom_sta ];
    };
  };

}

hsjobeki avatar Sep 16 '24 10:09 hsjobeki

@hsjobeki is it generally better practice to define options separately from config?

brianmcgee avatar Sep 25 '24 10:09 brianmcgee

@hsjobeki is it generally better practice to define options separately from config?

Yes. I'd say so. But i havent seen any general recommendation ruleset. But that should be on it.

hsjobeki avatar Sep 25 '24 10:09 hsjobeki

@brianmcgee

I use a nix file that generates a markdown doc based on all options.nix files in my repo. This is only possible because all of my options are defined separately from the configs. Could be one use-case of separation.

timonteutelink avatar Apr 11 '25 18:04 timonteutelink