lib: move clan out of lib into flake
This allows clanLib to stay agnostic and be more testable
This commit is contained in:
52
lib/clan/default.nix
Normal file
52
lib/clan/default.nix
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
## WARNING: Do not add core logic here.
|
||||||
|
## This is only a wrapper such that 'clan' can be called as a function.
|
||||||
|
{
|
||||||
|
lib,
|
||||||
|
clan-core,
|
||||||
|
}:
|
||||||
|
/**
|
||||||
|
Function that takes clan options as function arguments.
|
||||||
|
|
||||||
|
It behaves equivalent to:
|
||||||
|
|
||||||
|
```nix
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
clan-core.modules.clan.default
|
||||||
|
args
|
||||||
|
];
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
- self: Reference to the current flake. This is required be passed.
|
||||||
|
- ...: All other arguments - Which are options as of the 'clan.*' module
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The clan configuration.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
self ? lib.warn "Argument: 'self' must be set" null, # Reference to the current flake
|
||||||
|
...
|
||||||
|
}@m:
|
||||||
|
let
|
||||||
|
nixpkgs = self.inputs.nixpkgs or clan-core.inputs.nixpkgs;
|
||||||
|
nix-darwin = self.inputs.nix-darwin or clan-core.inputs.nix-darwin;
|
||||||
|
in
|
||||||
|
lib.evalModules {
|
||||||
|
class = "clan";
|
||||||
|
specialArgs = {
|
||||||
|
inherit
|
||||||
|
self
|
||||||
|
;
|
||||||
|
inherit
|
||||||
|
nixpkgs
|
||||||
|
nix-darwin
|
||||||
|
;
|
||||||
|
};
|
||||||
|
modules = [
|
||||||
|
clan-core.modules.clan.default
|
||||||
|
m
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -1,54 +1,42 @@
|
|||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
# TODO: Get rid of self here.
|
|
||||||
# DONT add any new functions that depend on self here.
|
|
||||||
# If a lib function depends on a piece in clan-core add that piece to the function arguments
|
|
||||||
self ? throw "'self' should not be used in lib/default.nix, dont depend on it. It will be removed in short notice.",
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
# Produces the
|
# Produces the
|
||||||
# 'clanLib' attribute set
|
# 'clanLib' attribute set
|
||||||
# Wrapped with fix, so we can depend on other clanLib functions without passing the whole flake
|
# Wrapped with fix, so we can depend on other clanLib functions without passing the whole flake
|
||||||
lib.fix (
|
lib.fix (
|
||||||
clanLib:
|
|
||||||
let
|
let
|
||||||
buildClanLib = (
|
f = clanLib: {
|
||||||
clanLib.callLib ./modules {
|
__unfix__ = f;
|
||||||
clan-core = self;
|
clan = throw "lib.clan is not yet initialized. Use lib.clan exported by the clan-core flake.";
|
||||||
}
|
/**
|
||||||
);
|
Like callPackage, but doesn't try to automatically detect arguments
|
||||||
|
'lib' and 'clanLib' are always passed, plus the additional arguments
|
||||||
|
*/
|
||||||
|
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
||||||
|
|
||||||
|
evalService = clanLib.callLib ./modules/inventory/distributed-service/evalService.nix { };
|
||||||
|
# ------------------------------------
|
||||||
|
# ClanLib functions
|
||||||
|
inventory = clanLib.callLib ./modules/inventory { };
|
||||||
|
test = clanLib.callLib ./test { };
|
||||||
|
flake-inputs = clanLib.callLib ./flake-inputs.nix { };
|
||||||
|
# Custom types
|
||||||
|
types = clanLib.callLib ./types { };
|
||||||
|
|
||||||
|
# Plain imports.
|
||||||
|
introspection = import ./introspection { inherit lib; };
|
||||||
|
jsonschema = import ./jsonschema { inherit lib; };
|
||||||
|
facts = import ./facts.nix { inherit lib; };
|
||||||
|
docs = import ./docs.nix { inherit lib; };
|
||||||
|
|
||||||
|
# flakes
|
||||||
|
flakes = clanLib.callLib ./flakes.nix { };
|
||||||
|
|
||||||
|
# TODO: Flatten our lib functions like this:
|
||||||
|
resolveModule = clanLib.callLib ./resolve-module { };
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
f
|
||||||
|
|
||||||
inherit (buildClanLib)
|
|
||||||
buildClan
|
|
||||||
clan
|
|
||||||
;
|
|
||||||
/**
|
|
||||||
Like callPackage, but doesn't try to automatically detect arguments
|
|
||||||
'lib' and 'clanLib' are always passed, plus the additional arguments
|
|
||||||
*/
|
|
||||||
callLib = file: args: import file ({ inherit lib clanLib; } // args);
|
|
||||||
|
|
||||||
evalService = clanLib.callLib ./modules/inventory/distributed-service/evalService.nix { };
|
|
||||||
# ------------------------------------
|
|
||||||
# ClanLib functions
|
|
||||||
inventory = clanLib.callLib ./modules/inventory { };
|
|
||||||
test = clanLib.callLib ./test { };
|
|
||||||
flake-inputs = clanLib.callLib ./flake-inputs.nix { };
|
|
||||||
# Custom types
|
|
||||||
types = clanLib.callLib ./types { };
|
|
||||||
|
|
||||||
# Plain imports.
|
|
||||||
introspection = import ./introspection { inherit lib; };
|
|
||||||
jsonschema = import ./jsonschema { inherit lib; };
|
|
||||||
facts = import ./facts.nix { inherit lib; };
|
|
||||||
docs = import ./docs.nix { inherit lib; };
|
|
||||||
|
|
||||||
# flakes
|
|
||||||
flakes = clanLib.callLib ./flakes.nix { };
|
|
||||||
|
|
||||||
# TODO: Flatten our lib functions like this:
|
|
||||||
resolveModule = clanLib.callLib ./resolve-module { };
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,9 +17,47 @@ rec {
|
|||||||
./jsonschema/flake-module.nix
|
./jsonschema/flake-module.nix
|
||||||
./types/flake-module.nix
|
./types/flake-module.nix
|
||||||
];
|
];
|
||||||
flake.clanLib = import ./default.nix {
|
flake.clanLib =
|
||||||
inherit lib inputs self;
|
let
|
||||||
};
|
clanLib = import ./default.nix {
|
||||||
|
inherit lib inputs self;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
# Extend clanLib here by lib.clan
|
||||||
|
# This allows clanLib to stay agnostic from flakes or clan-core
|
||||||
|
lib.fix (
|
||||||
|
lib.extends (final: _: {
|
||||||
|
buildClan =
|
||||||
|
module:
|
||||||
|
lib.warn ''
|
||||||
|
==================== DEPRECATION NOTICE ====================
|
||||||
|
Please migrate
|
||||||
|
from: 'clan = inputs.<clan-core>.lib.buildClan'
|
||||||
|
to : 'clan = inputs.<clan-core>.lib.clan'
|
||||||
|
in your flake.nix.
|
||||||
|
|
||||||
|
Please also migrate
|
||||||
|
from: 'inherit (clan) nixosConfigurations clanInternals; '
|
||||||
|
to : "
|
||||||
|
inherit (clan.config) nixosConfigurations clanInternals;
|
||||||
|
clan = clan.config;
|
||||||
|
"
|
||||||
|
in your flake.nix.
|
||||||
|
|
||||||
|
Reason:
|
||||||
|
- Improves consistency between flake-parts and non-flake-parts users.
|
||||||
|
|
||||||
|
- It also allows us to use the top level attribute 'clan' to expose
|
||||||
|
attributes that can be used for cross-clan functionality.
|
||||||
|
============================================================
|
||||||
|
'' (final.clan module).config;
|
||||||
|
clan = import ./clan {
|
||||||
|
inherit lib;
|
||||||
|
clan-core = self;
|
||||||
|
};
|
||||||
|
}) clanLib.__unfix__
|
||||||
|
);
|
||||||
|
|
||||||
# TODO: remove this legacy alias
|
# TODO: remove this legacy alias
|
||||||
flake.lib = flake.clanLib;
|
flake.lib = flake.clanLib;
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
## WARNING: Do not add core logic here.
|
|
||||||
## This is only a wrapper such that 'clan' can be called as a function.
|
|
||||||
{
|
|
||||||
lib,
|
|
||||||
clan-core,
|
|
||||||
...
|
|
||||||
}:
|
|
||||||
rec {
|
|
||||||
buildClan =
|
|
||||||
module:
|
|
||||||
lib.warn ''
|
|
||||||
==================== DEPRECATION NOTICE ====================
|
|
||||||
Please migrate
|
|
||||||
from: 'clan = inputs.<clan-core>.lib.buildClan'
|
|
||||||
to : 'clan = inputs.<clan-core>.lib.clan'
|
|
||||||
in your flake.nix.
|
|
||||||
|
|
||||||
Please also migrate
|
|
||||||
from: 'inherit (clan) nixosConfigurations clanInternals; '
|
|
||||||
to : "
|
|
||||||
inherit (clan.config) nixosConfigurations clanInternals;
|
|
||||||
clan = clan.config;
|
|
||||||
"
|
|
||||||
in your flake.nix.
|
|
||||||
|
|
||||||
Reason:
|
|
||||||
- Improves consistency between flake-parts and non-flake-parts users.
|
|
||||||
|
|
||||||
- It also allows us to use the top level attribute 'clan' to expose
|
|
||||||
attributes that can be used for cross-clan functionality.
|
|
||||||
============================================================
|
|
||||||
'' (clan module).config;
|
|
||||||
|
|
||||||
clan =
|
|
||||||
{
|
|
||||||
self ? lib.warn "Argument: 'self' must be set" null, # Reference to the current flake
|
|
||||||
...
|
|
||||||
}@m:
|
|
||||||
let
|
|
||||||
nixpkgs = self.inputs.nixpkgs or clan-core.inputs.nixpkgs;
|
|
||||||
nix-darwin = self.inputs.nix-darwin or clan-core.inputs.nix-darwin;
|
|
||||||
in
|
|
||||||
lib.evalModules {
|
|
||||||
class = "clan";
|
|
||||||
specialArgs = {
|
|
||||||
inherit
|
|
||||||
self
|
|
||||||
;
|
|
||||||
inherit
|
|
||||||
nixpkgs
|
|
||||||
nix-darwin
|
|
||||||
;
|
|
||||||
};
|
|
||||||
modules = [
|
|
||||||
m
|
|
||||||
clan-core.modules.clan.default
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user