Skip to content

Commit

Permalink
nixos,darwin: add sharedModules and extraSpecialArgs options (nix-com…
Browse files Browse the repository at this point in the history
…munity#1793)

This allows users of the nixos and nix-darwin module to set shared modules
for all users and extra specialArgs to be available to home-manager modules.

The latter is named extraSpecialArgs just like the argument to
modules/default.nix.
This could be confusing since the the two are independent in code,
but they do mean the same thing so I think the name fits.

Darwin can now refer to the global system configuration if used as a module
through the special `darwinConfig` argument.

Co-authored-by: Nicolas Berbiche <[email protected]>
  • Loading branch information
2 people authored and cab404 committed Apr 23, 2021
1 parent ff0ebc0 commit 137b166
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
25 changes: 23 additions & 2 deletions nix-darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ let
extendedLib = import ../modules/lib/stdlib-extended.nix pkgs.lib;

hmModule = types.submoduleWith {
specialArgs = { lib = extendedLib; };
specialArgs = {
lib = extendedLib;
darwinConfig = config;
} // cfg.extraSpecialArgs;
modules = [
({ name, ... }: {
imports = import ../modules/modules.nix {
Expand All @@ -26,7 +29,7 @@ let
home.homeDirectory = config.users.users.${name}.home;
};
})
];
] ++ cfg.sharedModules;
};

in
Expand Down Expand Up @@ -55,6 +58,24 @@ in
'';
};

extraSpecialArgs = mkOption {
type = types.attrs;
default = { };
example = literalExample "{ modulesPath = ../modules; }";
description = ''
Extra <literal>specialArgs</literal> passed to Home Manager.
'';
};

sharedModules = mkOption {
type = with types; listOf (oneOf [ attrs (functionTo attrs) path ]);
default = [ ];
example = literalExample "[ { home.packages = [ nixpkgs-fmt ]; } ]";
description = ''
Extra modules added to all users.
'';
};

verbose = mkEnableOption "verbose output on activation";

users = mkOption {
Expand Down
22 changes: 20 additions & 2 deletions nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let
specialArgs = {
lib = extendedLib;
nixosConfig = config;
};
} // cfg.extraSpecialArgs;
modules = [
({ name, ... }: {
imports = import ../modules/modules.nix {
Expand All @@ -34,7 +34,7 @@ let
home.homeDirectory = config.users.users.${name}.home;
};
})
];
] ++ cfg.sharedModules;
};

serviceEnvironment = optionalAttrs (cfg.backupFileExtension != null) {
Expand Down Expand Up @@ -65,6 +65,24 @@ in {
'';
};

extraSpecialArgs = mkOption {
type = types.attrs;
default = { };
example = literalExample "{ modulesPath = ../modules; }";
description = ''
Extra <literal>specialArgs</literal> passed to Home Manager.
'';
};

sharedModules = mkOption {
type = with types; listOf (oneOf [ attrs (functionTo attrs) path ]);
default = [ ];
example = literalExample "[ { home.packages = [ nixpkgs-fmt ]; } ]";
description = ''
Extra modules added to all users.
'';
};

verbose = mkEnableOption "verbose output on activation";

users = mkOption {
Expand Down

0 comments on commit 137b166

Please sign in to comment.