Error when using lib.mkIf and lib.mkMerge to set configuration based on hostname

248 views Asked by At

I am trying to set configuration based on hostname

config = lib.mkMerge [
  ( lib.mkIf config.networking.hostName == "nuc" {
    config.installconfig.hardware.intel = true;
  } )

  ( lib.mkIf config.networking.hostName == "xps" {
    config.installconfig = {
      hardware.intel = true;
      workstation-components.enable = true;
      users.allow-rad = true;
    };
  } )
];

I get the following error at "nuc"

error: attempt to call something which is not a function but a string.

I understand the error, but I am not sure how to structure the lib.mkIf condition block.

Could someone help me fix this please?

1

There are 1 answers

1
l0b0 On BEST ANSWER

You need to group together the parts of the conditionals:

let
  config = pkgs.lib.mkMerge [
    (pkgs.lib.mkIf (config.networking.hostName == "nuc") {
        config.installconfig.hardware.intel = true;
      })

    (pkgs.lib.mkIf (config.networking.hostName == "xps") {
        config.installconfig = {
          hardware.intel = true;
          workstation-components.enable = true;
          users.allow-rad = true;
        };
      })
  ];
in
  config.contents