I am working on a over arching module which encapsulates my home-manager configuration. The goal is to provide a common configuration for machines with just enough options to meet specific needs.
As an example, I want full documentation on my main machines but want to turn documentation off on the firewall. I also want a set of shell aliases on all machines. Here is what I came up with so far.
~/.config/nixpkgs/home.nix:
{ config, pkgs, ... }:
{
programs.home-manager.enable = true;
...
imports = [ ./mkg ];
mkg.enable = true;
mkg.docs.enable = false;
}
~/.config/nixpkgs/mkg/default.nix:
{ config, lib, pkgs, ... }:
let
inherit (lib) types mkOption mkIf mkMerge;
cfg = config.mkg;
in {
options.mkg = {
enable = mkOption {
type = types.bool;
default = true;
description = "Enable profile for mkg.";
};
docs.enable = mkOption {
type = types.bool;
default = false;
description = "Whether to install all documentation.";
};
};
config = mkIf cfg.enable (mkMerge [
(mkIf true { # AWKWARD
nixpkgs.config.time.timeZone = "US/Eastern";
nixpkgs.config.environment = {
shellAliases = {
...
};
};
})
(mkIf cfg.docs.enable {
nixpkgs.config.documentation = {
enable = cfg.docs.enable;
nixos.enable = cfg.docs.enable;
man.enable = cfg.docs.enable;
...
};
})
]);
}
One thing that troubles me is the mkIf true
I used to make the shell aliases available everywhere. This seems like a code smell to me. How could I do it better?
Does anyone have an example of using a single unified module in this manner to encapsulate their configuration?