mirror of
https://github.com/nix-community/flakelight.git
synced 2024-11-22 07:23:11 +01: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.
|
||||
|
||||
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:
|
||||
|
||||
```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
|
||||
|
||||
The `nixosModules`, `homeModules`, and `flakelightModules` options allow you to
|
||||
|
@ -2,12 +2,13 @@
|
||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
{ config, lib, ... }:
|
||||
{ config, lib, flakelight, autoloadArgs, ... }:
|
||||
let
|
||||
inherit (builtins) isAttrs;
|
||||
inherit (builtins) isAttrs mapAttrs;
|
||||
inherit (lib) foldl mapAttrsToList mergeOneOption mkOption mkOptionType mkIf
|
||||
recursiveUpdate;
|
||||
inherit (lib.types) lazyAttrsOf;
|
||||
inherit (flakelight.types) optFunctionTo;
|
||||
|
||||
homeConfiguration = mkOptionType {
|
||||
name = "homeConfiguration";
|
||||
@ -19,16 +20,17 @@ let
|
||||
in
|
||||
{
|
||||
options.homeConfigurations = mkOption {
|
||||
type = lazyAttrsOf homeConfiguration;
|
||||
type = lazyAttrsOf (optFunctionTo homeConfiguration);
|
||||
default = { };
|
||||
};
|
||||
|
||||
config.outputs = mkIf (config.homeConfigurations != { }) {
|
||||
inherit (config) homeConfigurations;
|
||||
homeConfigurations = mapAttrs (_: f: f autoloadArgs)
|
||||
config.homeConfigurations;
|
||||
checks = foldl recursiveUpdate { } (mapAttrsToList
|
||||
(n: v: {
|
||||
${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>
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
{ config, lib, ... }:
|
||||
{ config, lib, flakelight, autoloadArgs, ... }:
|
||||
let
|
||||
inherit (builtins) isAttrs;
|
||||
inherit (builtins) isAttrs mapAttrs;
|
||||
inherit (lib) foldl mapAttrsToList mergeOneOption mkIf mkOption mkOptionType
|
||||
recursiveUpdate;
|
||||
inherit (lib.types) lazyAttrsOf;
|
||||
inherit (flakelight.types) optFunctionTo;
|
||||
|
||||
nixosConfiguration = mkOptionType {
|
||||
name = "nixosConfiguration";
|
||||
@ -21,17 +22,18 @@ let
|
||||
in
|
||||
{
|
||||
options.nixosConfigurations = mkOption {
|
||||
type = lazyAttrsOf nixosConfiguration;
|
||||
type = lazyAttrsOf (optFunctionTo nixosConfiguration);
|
||||
default = { };
|
||||
};
|
||||
|
||||
config.outputs = mkIf (config.nixosConfigurations != { }) {
|
||||
inherit (config) nixosConfigurations;
|
||||
nixosConfigurations = mapAttrs (_: f: f autoloadArgs)
|
||||
config.nixosConfigurations;
|
||||
checks = foldl recursiveUpdate { } (mapAttrsToList
|
||||
(n: v: {
|
||||
${v.config.nixpkgs.system}."nixos-${n}" =
|
||||
v.config.system.build.toplevel;
|
||||
})
|
||||
config.nixosConfigurations);
|
||||
(mapAttrs (_: f: f autoloadArgs) config.nixosConfigurations));
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user