mirror of
https://github.com/nix-community/flakelight.git
synced 2025-06-21 10:07:51 +02:00
Allow functions for NixOS or home-manager configurations
This allows a configuration to be set as a function that will be passed autoloadArgs. This is useful when each configuration is in its own file when autoloading.
This commit is contained in:
parent
e401f68030
commit
6d00e0f544
18
api_guide.md
18
api_guide.md
@ -617,6 +617,10 @@ outputs for NixOS systems and home-manager users.
|
|||||||
|
|
||||||
They should be set to an attribute set of respective configurations.
|
They should be set to an attribute set of respective configurations.
|
||||||
|
|
||||||
|
Alternatively, the configurations can be functions, in which case those
|
||||||
|
functions will be passed `autoloadArgs` and must return a standard
|
||||||
|
configuration (this is useful when using autoloads with the `nixDir` feature).
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
```nix
|
```nix
|
||||||
@ -646,6 +650,20 @@ For example:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Optionally, defining as a function:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
inputs.flakelight.url = "github:accelbread/flakelight";
|
||||||
|
outputs = { flakelight, ... }:
|
||||||
|
flakelight ./. {
|
||||||
|
nixosConfigurations.system = { lib, ... }: lib.nixosSystem {
|
||||||
|
# nixosSystem arguments
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### nixosModules, homeModules, and flakelightModules
|
### nixosModules, homeModules, and flakelightModules
|
||||||
|
|
||||||
The `nixosModules`, `homeModules`, and `flakelightModules` options allow you to
|
The `nixosModules`, `homeModules`, and `flakelightModules` options allow you to
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, lib, ... }:
|
{ config, lib, flakelight, autoloadArgs, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) isAttrs;
|
inherit (builtins) isAttrs mapAttrs;
|
||||||
inherit (lib) foldl mapAttrsToList mergeOneOption mkOption mkOptionType mkIf
|
inherit (lib) foldl mapAttrsToList mergeOneOption mkOption mkOptionType mkIf
|
||||||
recursiveUpdate;
|
recursiveUpdate;
|
||||||
inherit (lib.types) lazyAttrsOf;
|
inherit (lib.types) lazyAttrsOf;
|
||||||
|
inherit (flakelight.types) optFunctionTo;
|
||||||
|
|
||||||
homeConfiguration = mkOptionType {
|
homeConfiguration = mkOptionType {
|
||||||
name = "homeConfiguration";
|
name = "homeConfiguration";
|
||||||
@ -19,16 +20,17 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.homeConfigurations = mkOption {
|
options.homeConfigurations = mkOption {
|
||||||
type = lazyAttrsOf homeConfiguration;
|
type = lazyAttrsOf (optFunctionTo homeConfiguration);
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
config.outputs = mkIf (config.homeConfigurations != { }) {
|
config.outputs = mkIf (config.homeConfigurations != { }) {
|
||||||
inherit (config) homeConfigurations;
|
homeConfigurations = mapAttrs (_: f: f autoloadArgs)
|
||||||
|
config.homeConfigurations;
|
||||||
checks = foldl recursiveUpdate { } (mapAttrsToList
|
checks = foldl recursiveUpdate { } (mapAttrsToList
|
||||||
(n: v: {
|
(n: v: {
|
||||||
${v.config.nixpkgs.system}."home-${n}" = v.activationPackage;
|
${v.config.nixpkgs.system}."home-${n}" = v.activationPackage;
|
||||||
})
|
})
|
||||||
config.homeConfigurations);
|
(mapAttrs (_: f: f autoloadArgs) config.homeConfigurations));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,13 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, lib, ... }:
|
{ config, lib, flakelight, autoloadArgs, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) isAttrs;
|
inherit (builtins) isAttrs mapAttrs;
|
||||||
inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType
|
inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType
|
||||||
recursiveUpdate;
|
recursiveUpdate;
|
||||||
inherit (lib.types) lazyAttrsOf;
|
inherit (lib.types) lazyAttrsOf;
|
||||||
|
inherit (flakelight.types) optFunctionTo;
|
||||||
|
|
||||||
nixosConfiguration = mkOptionType {
|
nixosConfiguration = mkOptionType {
|
||||||
name = "nixosConfiguration";
|
name = "nixosConfiguration";
|
||||||
@ -21,17 +22,18 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.nixosConfigurations = mkOption {
|
options.nixosConfigurations = mkOption {
|
||||||
type = lazyAttrsOf nixosConfiguration;
|
type = lazyAttrsOf (optFunctionTo nixosConfiguration);
|
||||||
default = { };
|
default = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
config.outputs = mkIf (config.nixosConfigurations != { }) {
|
config.outputs = mkIf (config.nixosConfigurations != { }) {
|
||||||
inherit (config) nixosConfigurations;
|
nixosConfigurations = mapAttrs (_: f: f autoloadArgs)
|
||||||
|
config.nixosConfigurations;
|
||||||
checks = foldl recursiveUpdate { } (mapAttrsToList
|
checks = foldl recursiveUpdate { } (mapAttrsToList
|
||||||
(n: v: {
|
(n: v: {
|
||||||
${v.config.nixpkgs.system}."nixos-${n}" =
|
${v.config.nixpkgs.system}."nixos-${n}" =
|
||||||
v.config.system.build.toplevel;
|
v.config.system.build.toplevel;
|
||||||
})
|
})
|
||||||
config.nixosConfigurations);
|
(mapAttrs (_: f: f autoloadArgs) config.nixosConfigurations));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user