clan: Add autoloaded clanModules from flake inputs. Rename 'directory' to 'self' in buildClan
This commit is contained in:
23
lib/build-clan/auto-imports.nix
Normal file
23
lib/build-clan/auto-imports.nix
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
lib,
|
||||
self,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
# Returns an attrset with inputs that have the attribute `clanModules`
|
||||
inputsWithClanModules = lib.filterAttrs (
|
||||
_name: value: builtins.hasAttr "clanModules" value
|
||||
) self.inputs;
|
||||
|
||||
flattenedClanModules = lib.foldl' (
|
||||
acc: input:
|
||||
lib.mkMerge [
|
||||
acc
|
||||
input.clanModules
|
||||
]
|
||||
) { } (lib.attrValues inputsWithClanModules);
|
||||
in
|
||||
{
|
||||
inventory.modules = flattenedClanModules;
|
||||
}
|
||||
@@ -8,7 +8,8 @@
|
||||
}:
|
||||
{
|
||||
## Inputs
|
||||
directory, # The directory containing the machines subdirectory # allows to include machine-specific modules i.e. machines.${name} = { ... }
|
||||
directory ? null, # The directory containing the machines subdirectory # allows to include machine-specific modules i.e. machines.${name} = { ... }
|
||||
self ? null,
|
||||
# A map from arch to pkgs, if specified this nixpkgs will be only imported once for each system.
|
||||
# This improves performance, but all nipxkgs.* options will be ignored.
|
||||
# deadnix: skip
|
||||
@@ -19,15 +20,27 @@
|
||||
...
|
||||
}@attrs:
|
||||
let
|
||||
eval = import ./eval.nix {
|
||||
evalUnchecked = import ./eval.nix {
|
||||
inherit
|
||||
lib
|
||||
nixpkgs
|
||||
specialArgs
|
||||
clan-core
|
||||
;
|
||||
self = directory;
|
||||
inherit specialArgs;
|
||||
self = if self != null then self else directory;
|
||||
};
|
||||
|
||||
# Doing `self ? lib.trace "please use self" directory`, doesn't work
|
||||
# as when both (directory and self) are set we get an infinite recursion error
|
||||
eval =
|
||||
if directory == null && self == null then
|
||||
throw "The buildClan function requires argument 'self' to be set"
|
||||
else if directory != null && self != null then
|
||||
throw "Both 'self' and 'directory' are set, please remove 'directory' in favor of the 'self' argument"
|
||||
else if directory != null then
|
||||
lib.warn "The 'directory' argument in buildClan has been deprecated in favor of the 'self' argument" evalUnchecked
|
||||
else
|
||||
evalUnchecked;
|
||||
rest = builtins.removeAttrs attrs [ "specialArgs" ];
|
||||
in
|
||||
eval {
|
||||
@@ -35,5 +48,6 @@ eval {
|
||||
rest
|
||||
# implementation
|
||||
./module.nix
|
||||
./auto-imports.nix
|
||||
];
|
||||
}
|
||||
|
||||
@@ -8,8 +8,7 @@ let
|
||||
in
|
||||
{
|
||||
options = {
|
||||
# Required options
|
||||
directory = lib.mkOption {
|
||||
self = lib.mkOption {
|
||||
type = types.path;
|
||||
default = self;
|
||||
defaultText = "Root directory of the flake";
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
}:
|
||||
let
|
||||
inherit (config)
|
||||
directory
|
||||
self
|
||||
machines
|
||||
pkgsForSystem
|
||||
specialArgs
|
||||
@@ -44,7 +44,7 @@ let
|
||||
serviceConfigs = (
|
||||
buildInventory {
|
||||
inherit inventory;
|
||||
inherit directory;
|
||||
inherit self;
|
||||
}
|
||||
);
|
||||
|
||||
@@ -59,14 +59,14 @@ let
|
||||
nixpkgs.lib.nixosSystem {
|
||||
modules =
|
||||
let
|
||||
hwConfig = "${directory}/machines/${name}/hardware-configuration.nix";
|
||||
diskoConfig = "${directory}/machines/${name}/disko.nix";
|
||||
hwConfig = "${self}/machines/${name}/hardware-configuration.nix";
|
||||
diskoConfig = "${self}/machines/${name}/disko.nix";
|
||||
in
|
||||
[
|
||||
{
|
||||
# Autoinclude configuration.nix and hardware-configuration.nix
|
||||
imports = builtins.filter builtins.pathExists [
|
||||
"${directory}/machines/${name}/configuration.nix"
|
||||
"${self}/machines/${name}/configuration.nix"
|
||||
hwConfig
|
||||
diskoConfig
|
||||
];
|
||||
@@ -81,7 +81,7 @@ let
|
||||
{
|
||||
# Settings
|
||||
clan.core.settings = {
|
||||
inherit directory;
|
||||
directory = self;
|
||||
inherit (config.inventory.meta) name icon;
|
||||
|
||||
machine = {
|
||||
@@ -160,7 +160,7 @@ let
|
||||
) supportedSystems
|
||||
);
|
||||
|
||||
inventoryFile = "${directory}/inventory.json";
|
||||
inventoryFile = "${self}/inventory.json";
|
||||
|
||||
inventoryLoaded =
|
||||
if builtins.pathExists inventoryFile then
|
||||
@@ -171,6 +171,7 @@ let
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
(lib.mkRenamedOptionModule [ "directory" ] [ "self" ])
|
||||
# Merge the inventory file
|
||||
{
|
||||
inventory = _: {
|
||||
@@ -180,9 +181,9 @@ in
|
||||
}
|
||||
# TODO: Figure out why this causes infinite recursion
|
||||
{
|
||||
inventory.machines = lib.optionalAttrs (builtins.pathExists "${directory}/machines") (
|
||||
inventory.machines = lib.optionalAttrs (builtins.pathExists "${self}/machines") (
|
||||
builtins.mapAttrs (_n: _v: { }) (
|
||||
(lib.filterAttrs (_: t: t == "directory") (builtins.readDir "${directory}/machines"))
|
||||
(lib.filterAttrs (_: t: t == "directory") (builtins.readDir "${self}/machines"))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ in
|
||||
test_all_simple =
|
||||
let
|
||||
config = evalClan {
|
||||
directory = ./.;
|
||||
self = ./.;
|
||||
machines = { };
|
||||
inventory = {
|
||||
meta.name = "test";
|
||||
|
||||
Reference in New Issue
Block a user