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,29 +1,15 @@
|
||||
{
|
||||
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
|
||||
# 'clanLib' attribute set
|
||||
# Wrapped with fix, so we can depend on other clanLib functions without passing the whole flake
|
||||
lib.fix (
|
||||
clanLib:
|
||||
let
|
||||
buildClanLib = (
|
||||
clanLib.callLib ./modules {
|
||||
clan-core = self;
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
|
||||
inherit (buildClanLib)
|
||||
buildClan
|
||||
clan
|
||||
;
|
||||
f = clanLib: {
|
||||
__unfix__ = f;
|
||||
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
|
||||
@@ -50,5 +36,7 @@ lib.fix (
|
||||
|
||||
# TODO: Flatten our lib functions like this:
|
||||
resolveModule = clanLib.callLib ./resolve-module { };
|
||||
}
|
||||
};
|
||||
in
|
||||
f
|
||||
)
|
||||
|
||||
@@ -17,9 +17,47 @@ rec {
|
||||
./jsonschema/flake-module.nix
|
||||
./types/flake-module.nix
|
||||
];
|
||||
flake.clanLib = import ./default.nix {
|
||||
flake.clanLib =
|
||||
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
|
||||
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