summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/flake/configs.nix214
-rw-r--r--modules/flake/configurations.nix216
2 files changed, 216 insertions, 214 deletions
diff --git a/modules/flake/configs.nix b/modules/flake/configs.nix
deleted file mode 100644
index 290255f..0000000
--- a/modules/flake/configs.nix
+++ /dev/null
@@ -1,214 +0,0 @@
-{
- config,
- lib,
- inputs,
- withSystem,
- ...
-}:
-let
- cfg = config.configurations;
-
- applySpecialArgs = lib.recursiveUpdate { inherit inputs; };
- applyModules = lib.concat (
- lib.toList (
- { pkgs, ... }:
- {
- _module.args.inputs' = withSystem pkgs.stdenv.hostPlatform.system ({ inputs', ... }: inputs');
- }
- )
- );
-
- nixosSystem =
- {
- nixpkgs,
- modules,
- specialArgs,
- ...
- }@args:
- nixpkgs.lib.nixosSystem (
- lib.removeAttrs args [ "nixpkgs" ]
- // {
- modules = applyModules modules;
- specialArgs = applySpecialArgs specialArgs;
- }
- );
-
- darwinSystem =
- {
- nix-darwin,
- modules,
- specialArgs,
- ...
- }@args:
- nix-darwin.lib.darwinSystem (
- lib.removeAttrs args [ "nix-darwin" ]
- // {
- modules = applyModules modules;
- specialArgs = applySpecialArgs specialArgs;
- }
- );
-
- homeManagerConfiguration =
- {
- home-manager,
- modules,
- extraSpecialArgs,
- ...
- }@args:
- home-manager.lib.homeManagerConfiguration (
- lib.removeAttrs args [ "home-manager" ]
- // {
- modules = applyModules modules;
- extraSpecialArgs = applySpecialArgs extraSpecialArgs;
- }
- );
-
- modulesType = lib.types.listOf lib.types.deferredModule;
-
- specialArgsOption = lib.mkOption {
- type = lib.types.lazyAttrsOf lib.types.raw;
- default = { };
- description = "Extra arguments to pass to all modules, that are available in `imports` but can not be extended or overridden by the `modules`.";
- example = lib.literalExpression ''
- { foo = "bar"; }
- '';
- };
-
- legacyPackagesType = lib.types.lazyAttrsOf lib.types.raw;
- flakeType = legacyPackagesType;
-
- freeformType = lib.types.attrsOf lib.types.any;
-
- nixosConfigurationSubmodule = {
- inherit freeformType;
-
- options = {
- nixpkgs = lib.mkOption {
- type = flakeType;
- default = inputs.nixpkgs or (throw "`nixpkgs` must be defined");
- defaultText = "inputs.nixpkgs";
- description = "A nixpkgs input.";
- example = lib.literalExpression "inputs.nixpkgs-stable";
- };
-
- modules = lib.mkOption {
- type = modulesType;
- default = [ ];
- description = "The NixOS modules to include in the system configuration.";
- example = lib.literalExpression ''
- [ ./configuration.nix ]
- '';
- };
-
- specialArgs = specialArgsOption;
- modulesLocation = lib.mkOption {
- type = lib.types.nullOr lib.types.path;
- default = null;
- description = "A default location for modules that aren't passed by path, used for error messages.";
- };
- };
- };
-
- darwinConfigurationSubmodule = {
- inherit freeformType;
-
- options = {
- nix-darwin = lib.mkOption {
- type = flakeType;
- default = inputs.nix-darwin or inputs.darwin or (throw "`nix-darwin` must be defined");
- defaultText = "inputs.nix-darwin or inputs.darwin";
- description = "A nix-darwin input.";
- example = lib.literalExpression "inputs.nix-darwin";
- };
-
- modules = lib.mkOption {
- type = modulesType;
- default = [ ];
- description = "The Darwin modules to include in the system configuration.";
- example = lib.literalExpression ''
- [ ./configuration.nix ]
- '';
- };
-
- specialArgs = specialArgsOption;
- };
- };
-
- homeConfigurationSubmodule = {
- inherit freeformType;
-
- options = {
- home-manager = lib.mkOption {
- type = flakeType;
- default = inputs.home-manager or (throw "`home-manager` must be defined");
- defaultText = "inputs.home-manager";
- description = "A home-manager input.";
- example = lib.literalExpression "inputs.hm";
- };
-
- pkgs = lib.mkOption {
- type = legacyPackagesType;
- description = "An instance of Nixpkgs to use in the configuration.";
- example = lib.literalExpression ''
- withSystem "x86_64-linux" ({ pkgs, ... }: pkgs)
- '';
- };
-
- modules = lib.mkOption {
- type = modulesType;
- default = [ ];
- description = "The home-manager modules to include in the configuration.";
- example = lib.literalExpression ''
- [ ./home.nix ]
- '';
- };
-
- extraSpecialArgs = specialArgsOption;
- };
- };
-in
-{
- options.configurations = {
- nixos = lib.mkOption {
- type = lib.types.attrsOf (lib.types.submodule nixosConfigurationSubmodule);
- default = { };
- apply = lib.mapAttrs (lib.const nixosSystem);
- description = "A map of configuration names and options for `nixosSystem`.";
- example = lib.literalExpression ''
- {
- my-machine = { modules = [ ./configuration.nix ]; }
- }
- '';
- };
-
- darwin = lib.mkOption {
- type = lib.types.attrsOf (lib.types.submodule darwinConfigurationSubmodule);
- default = { };
- apply = lib.mapAttrs (lib.const darwinSystem);
- description = "A map of configuration names and options for `darwinSystem`.";
- example = lib.literalExpression ''
- {
- my-mac = { modules = [ ./darwin-configuration.nix ]; }
- }
- '';
- };
-
- home = lib.mkOption {
- type = lib.types.attrsOf (lib.types.submodule homeConfigurationSubmodule);
- default = { };
- apply = lib.mapAttrs (lib.const homeManagerConfiguration);
- description = "A map of configuration names and options for `homeManagerConfiguration`.";
- example = lib.literalExpression ''
- {
- my-home = { modules = [ ./home.nix ]; }
- }
- '';
- };
- };
-
- config.flake = {
- nixosConfigurations = cfg.nixos;
- darwinConfigurations = cfg.darwin;
- homeConfigurations = cfg.home;
- };
-}
diff --git a/modules/flake/configurations.nix b/modules/flake/configurations.nix
new file mode 100644
index 0000000..9aa149b
--- /dev/null
+++ b/modules/flake/configurations.nix
@@ -0,0 +1,216 @@
+{
+ config,
+ lib,
+ inputs,
+ withSystem,
+ ...
+}:
+
+let
+ namespace = "configurations";
+ cfg = config.${namespace};
+
+ /**
+ Submodule representing common options between builder functions
+ like `nixosSystem`, `darwinSystem`, and `homeManagerConfiguration`
+ */
+ configurationBuilderSubmodule =
+ { options, ... }:
+
+ {
+ freeformType = lib.types.attrsOf lib.types.any;
+
+ options = {
+ builder = lib.mkOption {
+ type = lib.types.functionTo options.configuration.type;
+ };
+
+ modules = lib.mkOption {
+ type = lib.types.listOf lib.types.deferredModule;
+ default = [ ];
+ apply = lib.concat [
+ (
+ { pkgs, ... }:
+
+ {
+ _module.args.inputs' = withSystem pkgs.stdenv.hostPlatform.system ({ inputs', ... }: inputs');
+ }
+ )
+ ];
+ description = "The modules to include in the configuration.";
+ example = lib.literalExpression ''
+ [ ./configuration.nix ]
+ '';
+ };
+
+ specialArgs = lib.mkOption {
+ type = lib.types.lazyAttrsOf lib.types.raw;
+ default = { };
+ apply = lib.recursiveUpdate { inherit inputs; };
+ description = "Extra arguments to pass to all modules, that are available in `imports` but can not be extended or overridden by the `modules`.";
+ example = lib.literalExpression ''
+ { foo = "bar"; }
+ '';
+ };
+
+ configuration = lib.mkOption {
+ type = lib.types.lazyAttrsOf lib.types.raw;
+ internal = true;
+ readOnly = true;
+ };
+ };
+ };
+
+ /**
+ Submodule representing a nixosConfiguration builder definition and it's accompanying options
+ */
+ nixosConfigurationSubmodule = lib.types.submodule (
+ { config, ... }:
+
+ {
+ imports = [ configurationBuilderSubmodule ];
+
+ options = {
+ builder = lib.mkOption {
+ default = inputs.nixpkgs.lib.nixosSystem or null;
+ defaultText = "inputs.nixpkgs.lib.nixosSystem or null";
+ description = "Builder for a NixOS configuration.";
+ example = lib.literalExpression "inputs.nixpkgs-stable.lib.nixosSystem";
+ };
+
+ modulesLocation = lib.mkOption {
+ type = lib.types.nullOr lib.types.path;
+ default = null;
+ description = "A default location for modules that aren't passed by path, used for error messages.";
+ };
+ };
+
+ config = {
+ configuration = config.builder (
+ lib.removeAttrs config [
+ "_module"
+ "builder"
+ "configuration"
+ ]
+ );
+ };
+ }
+ );
+
+ /**
+ Submodule representing a darwinConfiguration builder definition and it's accompanying options
+ */
+ darwinConfigurationSubmodule = lib.types.submodule (
+ { config, ... }:
+
+ {
+ imports = [ configurationBuilderSubmodule ];
+
+ options = {
+ builder = lib.mkOption {
+ default = (inputs.nix-darwin or inputs.darwin or { }).lib.darwinSystem or null;
+ defaultText = "(inputs.nix-darwin or input.darwin or { }).lib.darwinSystem or null";
+ description = "Builder for a nix-darwin configuration.";
+ example = lib.literalExpression "inputs.nix-darwin.lib.nixosSystem";
+ };
+ };
+
+ config = {
+ configuration = config.builder (
+ lib.removeAttrs config [
+ "_module"
+ "builder"
+ "configuration"
+ ]
+ );
+ };
+ }
+ );
+
+ /**
+ Submodule representing a homeConfiguration builder definition and it's accompanying options
+ */
+ homeConfigurationSubmodule = lib.types.submodule (
+ { config, ... }:
+
+ {
+ imports = [ configurationBuilderSubmodule ];
+
+ options = {
+ builder = lib.mkOption {
+ default = inputs.home-manager.lib.homeManagerConfiguration or null;
+ defaultText = "inputs.home-manager.lib.homeManagerConfiguration or null";
+ description = "Builder for a home-manager configuration.";
+ example = lib.literalExpression "inputs.hm.lib.homeManagerConfiguration";
+ };
+
+ pkgs = lib.mkOption {
+ type = lib.types.pkgs;
+ description = "An instance of Nixpkgs to use in the configuration.";
+ example = lib.literalExpression ''
+ withSystem "x86_64-linux" ({ pkgs, ... }: pkgs)
+ '';
+ };
+ };
+
+ config = {
+ configuration = config.builder (
+ lib.removeAttrs config [
+ "_module"
+ "builder"
+ "configuration"
+ "specialArgs"
+ ]
+ // {
+ extraSpecialArgs = config.specialArgs;
+ }
+ );
+ };
+ }
+ );
+
+ configurationOption = lib.mkOption {
+ default = { };
+ };
+
+ configurations = lib.mapAttrs (lib.const (lib.mapAttrs (lib.const (cfg': cfg'.configuration)))) cfg;
+in
+{
+ options.${namespace} = {
+ nixos = configurationOption // {
+ type = lib.types.attrsOf nixosConfigurationSubmodule;
+ description = "A map of NixOS configuration names and options.";
+ example = lib.literalExpression ''
+ {
+ my-machine = { modules = [ ./configuration.nix ]; }
+ }
+ '';
+ };
+
+ darwin = configurationOption // {
+ type = lib.types.attrsOf darwinConfigurationSubmodule;
+ description = "A map of nix-darwin configuration names and options.";
+ example = lib.literalExpression ''
+ {
+ my-mac = { modules = [ ./darwin-configuration.nix ]; }
+ }
+ '';
+ };
+
+ home = configurationOption // {
+ type = lib.types.attrsOf homeConfigurationSubmodule;
+ description = "A map of home-manager configuration names and options.";
+ example = lib.literalExpression ''
+ {
+ my-home = { modules = [ ./home.nix ]; }
+ }
+ '';
+ };
+ };
+
+ config.flake = {
+ nixosConfigurations = configurations.nixos;
+ darwinConfigurations = configurations.darwin;
+ homeConfigurations = configurations.home;
+ };
+}