Modularizing my nix-based dotfiles to be used on multiple machines

I recently spent some time reorganizing my dotfiles so they can be more easily reused across environments. I specifically wanted to avoid having to rebase the main branch into my work branch on a regular basis, and I also wanted to ability to pull these into a private repository for work stuff so I could include private config more easily, without exposing it to the outside world. AND… I also recently started tinking with a homelab server, and it’s running NixOS, so most of the work ended up going into making sure these things work for standalone home-manager, as well as NixOS.

Desire

I wanted to be able to have a simple flake import where I could just drop the flake’s home config into another nix config, like:

{
  description = "Nix config for my homelab server";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

    flyinggrizzly = {
      url = "github:flyinggrizzly/nixfiles/homelab-prep";
      inputs.nixpkgs.follows = "nixpkgs";
    };

    home-manager.follows = "flyinggrizzly/home-manager";
  };

  outputs = { self, nixpkgs, home-manager, flyinggrizzly, ... }@inputs: {
    nixosConfigurations = {

      beelink-mini-s-homelab = nixpkgs.lib.nixosSystem {
        modules = [
          ./beelink-mini-s-homelab/configuration.nix

          # This is the magic!
          (flyinggrizzly.lib.nixosHome {
            platform = "x86_64-linux";
            username = "seandmr";
            stateVersion = "24.11";
            desktop.enable = false;
            darwin.enable = false;
            neovim = {
              enableLlmTools = false;
            };
          })
        ];
      };

    };
  };
}

All I have to di is call the lib.nixosHome function with some params, and the rest is set up.

Of course, on a headless machine, desktop.enable is off, as is darwin.enable.

And then I can toggle off any neovim config that relies on LLM tools in any env I want–useful for the homelab server where I just want a consistent vim setup, but don’t want to deal with any config or access issues.

Then, if I want to add further customizations, especially for vim, I can include custom lua config, or even custom lua files. This is useful for work, where I have separate LLM access config.

Next steps

I’m going to port my mac config into the nix-machines config, and migrate it to nix-darwin, or at least nixbrew. Right now I’m handrolling some Homebrew syncing, because unfortunately there are still some packages only available in Homebrew instead of Nix.

Also, maybe check out nixvim?