Create custom module for system configuration

Each of your “.nix” file is a nix module. Based on my understanding of your question, what you can do as a first step is:

  1. Add options to child1.nix controlling whether it is enabled and whether it is added to wheel etc
  2. Still import child1.nix in your configuration.nix.
  3. In configuration.nix, you can specify/override the mynamespace.user.child1.enable and mynamespace.user.child1.isWheel.

To achieve that, child1.nix should look like

{ config, lib, pkgs, ... }:

let cfg = config.mynamespace.user.child1;

in {
  options.mynamespace.user.child1 = with lib; {
    enable = lib.mkEnableOption "Enable the userchild1";
    isWheel = lib.mkOption {
      type = lib.types.bool;
      default = true;
      description = ''
        whether add to the group wheel                  
      '';
    };    
  };

  config = lib.mkIf cfg.enable {
    users = {
      extraUsers = {
        "child1" = {
          uid = xxxx;
          extraGroups = [
            ... # other groups
          ] ++ lib.lists.optionals cfg.isWheel [ "wheel" ];;
        };
      };
    };
  };
}

Please note the usage of lib.mkIf and lib.lists.optionals.

1 Like