Handling options that don't exist on some platforms

I’ve been using nixos with flakes for a while. I’m switching jobs which has required me to switch to MacOS. I’d like to continue using nix to manage as much of my system as I can. I would like to continue using my same flake as much of the configuration makes sense on Mac as well. There are obviously things that will not work and I’m trying to find a way to handle them. The first one that I came across was this:

error: The option `fonts.fontconfig' does not exist. Definition values:
       - In `/nix/store/k38shkyrk5kbwa8igvky6imwic6dzqxm-source/profiles/core':
             defaultFonts = {
               monospace = [
                 "DejaVu Sans Mono for Powerline"

I can just remove that for darwin hosts but, how exactly can I go about doing that? My first thought was to use mkIf to only build on build for Linux i.e.

{ pkgs, lib, config, ... }:
with lib; mkIf pkgs.stdenv.isLinux {
    fontconfig.enable = true;
    fontconfig.defaultFonts = {

      monospace = [ "DejaVu Sans Mono for Powerline" ];

      sansSerif = [ "DejaVu Sans" ];


This does not work, it still gives the same error. The thing that I found that works is to put the nixos specific things in a different profile and only include that in nixos hosts. While I found that this works, it is clunky to work with.

I’m looking for something along the lines of my first idea, where the configuration lives together and certain parts of it are inactive based on the platform of the machine. How can I go about making that happen?

I generally move most of my logic into home-manager, which is much more friendly cross platform.

Most of my configuration does live in home-manager. There are a few things that I keep at the system level. This is for those. I guess with the small number of them, I could live with the solution that I found, I would just like it to be less clunky.

Most NixOS modules are linux specific. You may want to GitHub - LnL7/nix-darwin: nix modules for darwin instead