refactor: remove _loaded, add a new loadedConfig arg to src/default.nix

This commit is contained in:
Yusuf Bera Ertan 2022-10-20 16:14:35 +03:00
parent 7be6110eaf
commit dea20d928a
No known key found for this signature in database
GPG Key ID: 1D8F8FAF2294D6EA
7 changed files with 26 additions and 38 deletions

View File

@ -163,9 +163,7 @@
import ./src rec {
externalDir = externalDirFor."${system}";
inherit externalPaths externalSources inputs lib pkgs;
config = {
inherit overridesDirs;
};
config = {inherit overridesDirs;};
});
docsCli = forAllSystems (

View File

@ -6,17 +6,16 @@
pkgs ? import <nixpkgs> {},
lib ? pkgs.lib,
nix ? pkgs.nix,
# default to empty dream2nix config
# already validated config.
# this is mainly used by src/lib.nix since it loads the config beforehand.
loadedConfig ? null,
# default to empty dream2nix config. This is assumed to be not loaded.
config ?
import ./modules/config.nix {
configRaw =
if builtins ? getEnv && builtins.getEnv "dream2nixConfig" != ""
# if called via CLI, load config via env
then builtins.toPath (builtins.getEnv "dream2nixConfig")
# load from default directory
else {};
inherit lib;
},
if builtins ? getEnv && builtins.getEnv "dream2nixConfig" != ""
# if called via CLI, load config via env
then builtins.toPath (builtins.getEnv "dream2nixConfig")
# load from default directory
else {},
/*
Inputs that are not required for building, and therefore not need to be
copied alongside a dream2nix installation.
@ -48,16 +47,18 @@
# load from default directory
else ./external,
} @ args: let
argsConfig = config;
in let
b = builtins;
l = lib // builtins;
config = import ./modules/config.nix {
configRaw = argsConfig;
inherit lib;
};
config =
if loadedConfig != null
then loadedConfig
else
import ./modules/config.nix {
inherit lib;
rawConfig = args.config;
};
configFile = pkgs.writeText "dream2nix-config.json" (b.toJSON config);

View File

@ -13,11 +13,14 @@
initDream2nix = config: pkgs:
import ./default.nix
{inherit config inputs pkgs externalPaths externalSources;};
{
loadedConfig = config;
inherit inputs pkgs externalPaths externalSources;
};
loadConfig = config'': let
config' = import ./modules/config.nix {
configRaw = config'';
rawConfig = config'';
inherit lib;
};

View File

@ -1,5 +1,5 @@
{
configRaw,
rawConfig,
lib,
}: let
b = builtins;
@ -19,14 +19,11 @@
then input
else throw "input for loadAttrs must be json file or string or attrs";
config = loadAttrs configRaw;
config = loadAttrs rawConfig;
evaled = lib.evalModules {
modules = [./config {inherit config;}];
specialArgs = {inherit lib;};
};
in
# If the config was already loaded, then we skip validating it again
if configRaw._loaded or null == true
then configRaw
else evaled.config
evaled.config

View File

@ -1,6 +1,5 @@
{
imports = [
./interface.nix
./implementation.nix
];
}

View File

@ -1,5 +0,0 @@
{
config = {
_loaded = true;
};
}

View File

@ -3,11 +3,6 @@
t = l.types;
in {
options = {
_loaded = l.mkOption {
type = t.bool;
readOnly = true;
internal = true;
};
overridesDirs = l.mkOption {
type = t.listOf t.path;
default = [];