From 82d6ba7003fcf51e9a5b71ab1923e18d5c00fd6f Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 20 Feb 2021 22:02:25 -0800 Subject: [PATCH] nixos,darwin: add sharedModules and extraSpecialArgs options (#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 --- nix-darwin/default.nix | 25 +++++++++++++++++++++++-- nixos/default.nix | 22 ++++++++++++++++++++-- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/nix-darwin/default.nix b/nix-darwin/default.nix index 956695926..c529ca4a1 100644 --- a/nix-darwin/default.nix +++ b/nix-darwin/default.nix @@ -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 { @@ -26,7 +29,7 @@ let home.homeDirectory = config.users.users.${name}.home; }; }) - ]; + ] ++ cfg.sharedModules; }; in @@ -55,6 +58,24 @@ in ''; }; + extraSpecialArgs = mkOption { + type = types.attrs; + default = { }; + example = literalExample "{ modulesPath = ../modules; }"; + description = '' + Extra specialArgs 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 { diff --git a/nixos/default.nix b/nixos/default.nix index 6645b9068..4b58d154c 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -12,7 +12,7 @@ let specialArgs = { lib = extendedLib; nixosConfig = config; - }; + } // cfg.extraSpecialArgs; modules = [ ({ name, ... }: { imports = import ../modules/modules.nix { @@ -34,7 +34,7 @@ let home.homeDirectory = config.users.users.${name}.home; }; }) - ]; + ] ++ cfg.sharedModules; }; serviceEnvironment = optionalAttrs (cfg.backupFileExtension != null) { @@ -65,6 +65,24 @@ in { ''; }; + extraSpecialArgs = mkOption { + type = types.attrs; + default = { }; + example = literalExample "{ modulesPath = ../modules; }"; + description = '' + Extra specialArgs 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 {