Tree! It's the square hole for imports. That's right. It goes in the

square hole.
This commit is contained in:
kat witch 2021-11-20 23:36:45 +00:00
parent e716081479
commit d0363ab8e9
No known key found for this signature in database
GPG key ID: 1B477797DCA5EC72
22 changed files with 178 additions and 123 deletions

View file

@ -1,5 +0,0 @@
{ ... }: {
excludes = [
"to-do"
];
}

View file

@ -1,12 +0,0 @@
{ sources, ... }: {
functor = {
enable = true;
external = [
(import (sources.arcexprs + "/modules")).home-manager
(import (sources.katexprs + "/modules")).home
(import (sources.impermanence + "/home-manager.nix"))
(import sources.anicca).modules.home
(sources.tf-nix + "/modules/home/secrets.nix")
];
};
}

View file

@ -1,5 +0,0 @@
{ sources, ... }: {
functor = {
enable = true;
};
}

View file

@ -1,13 +0,0 @@
{ sources, ... }: {
functor = {
enable = true;
external = [
(import (sources.arcexprs + "/modules")).nixos
(import (sources.katexprs + "/modules")).nixos
(import (sources.impermanence + "/nixos.nix"))
(import sources.anicca).modules.nixos
(sources.tf-nix + "/modules/nixos/secrets.nix")
(sources.tf-nix + "/modules/nixos/secrets-users.nix")
];
};
}

View file

@ -1,5 +1,5 @@
{ lib, tree, ... }: with lib; let { lib, tree, ... }: with lib; let
profiles = tree.dirs // tree.files; profiles = tree.prev;
appendedProfiles = with profiles; { appendedProfiles = with profiles; {
aarch64 = { aarch64 = {
deploy.profile.cross = { deploy.profile.cross = {

View file

@ -1,4 +0,0 @@
{ ... }: {
defaultOnly = true;
includeFolders.default.enable = true;
}

View file

@ -1,11 +0,0 @@
{ lib, tree, ... }@args: with lib;
let
wrappedBase = base: mapAttrs
(name: paths: {
imports = if isAttrs paths then attrValues paths else singleton paths;
})
(base);
in
(wrappedBase (filterAttrs (n: v: ! v ? "default") tree.dirs))
// (mapAttrs (n: v: removeAttrs v [ "default" ]) (filterAttrs (n: v: v ? "default") tree.dirs))
// (removeAttrs tree.files [ "default" ])

View file

@ -1,8 +1,5 @@
{ lib, tree, ... }: with lib; let { lib, tree, ... }: with lib; let
profiles = (filterAttrs (n: v: v ? "default") tree.dirs) profiles = tree.prev;
// tree.defaultDirs
// (mapAttrs (n: v: removeAttrs v [ "default" ]) (filterAttrs (n: v: v ? "default") tree.dirs))
// tree.files;
appendedProfiles = with profiles; { appendedProfiles = with profiles; {
ms-7b86 = { ms-7b86 = {
imports = [ imports = [

View file

@ -1,7 +0,0 @@
{ ... }: {
defaultOnly = true;
includeFolders = {
enable = true;
default.enable = true;
};
}

View file

@ -1,5 +1,5 @@
{ lib, sources, tree, ... }: with lib; let { lib, sources, tree, ... }: with lib; let
profiles = tree.dirs // tree.files; profiles = tree.prev;
appendedProfiles = with profiles; { appendedProfiles = with profiles; {
ubuntu = { config, ... }: { ubuntu = { config, ... }: {
deploy.profile.hardware.oracle = { deploy.profile.hardware.oracle = {

View file

@ -1,4 +0,0 @@
{ ... }: {
defaultOnly = true;
includeFolders.default.enable = true;
}

View file

@ -1,5 +0,0 @@
{ ... }: {
defaultOnly = true;
includeFolders.enable = true;
includeFolders.default.enable = true;
}

View file

@ -1,5 +0,0 @@
{ ... }: {
defaultOnly = true;
recursiveInclude = true;
includeFolders.default.enable = true;
}

View file

@ -1,6 +0,0 @@
{ ... }: {
includeFolders = {
enable = true;
default.enable = true;
};
}

View file

@ -1,7 +0,0 @@
{ ... }: {
defaultOnly = true;
includeFolders = {
enable = true;
default.enable = true;
};
}

View file

@ -1,7 +0,0 @@
{ ... }: {
defaultOnly = true;
includeFolders = {
enable = true;
default.enable = true;
};
}

View file

@ -1,6 +0,0 @@
{ ... }: {
imports = [
./vim.nix
./nvim.nix
];
}

View file

@ -1,19 +1,19 @@
{ lib, tree, ... }: with lib; let { lib, tree, ... }: with lib; let
wrapImports = imports: mapAttrs wrapImports = imports: mapAttrs
(name: paths: { config, ... }: { (_: paths: { config, ... }: {
config.home-manager.users.kat = { config.home-manager.users.kat = {
imports = if isAttrs paths then attrValues paths else singleton paths; imports = singleton paths;
}; };
}) })
imports; imports;
dirImports = wrapImports tree.dirs; dirImports = wrapImports tree.prev;
serviceImports = wrapImports tree.dirs.services; serviceImports = wrapImports tree.prev.services;
in in
(removeAttrs dirImports (singleton "base")) // { dirImports // {
base = { base = {
imports = [ imports = [
dirImports.base dirImports.base
tree.files.nixos tree.prev.nixos
]; ];
}; };
server = { }; server = { };

View file

@ -1,4 +0,0 @@
{ ... }: {
excludes = [
];
}

View file

@ -1,7 +0,0 @@
{ ... }: {
defaultOnly = true;
recursiveInclude = true;
includeFolders = {
default.enable = true;
};
}

View file

@ -23,11 +23,55 @@ let
allStr = toString all; allStr = toString all;
}; };
tree = import ./tree.nix { inherit lib; } {
inherit sources;
folder = ./config;
config = {
"modules/nixos" = {
functor = {
enable = true;
external = [
(import (sources.arcexprs + "/modules")).nixos
(import (sources.katexprs + "/modules")).nixos
(import (sources.impermanence + "/nixos.nix"))
(import sources.anicca).modules.nixos
(sources.tf-nix + "/modules/nixos/secrets.nix")
(sources.tf-nix + "/modules/nixos/secrets-users.nix")
];
};
};
"modules/home" = {
functor = {
enable = true;
external = [
(import (sources.arcexprs + "/modules")).home-manager
(import (sources.katexprs + "/modules")).home
(import (sources.impermanence + "/home-manager.nix"))
(import sources.anicca).modules.home
(sources.tf-nix + "/modules/home/secrets.nix")
];
};
};
"modules/meta".functor.enable = true;
"profiles/*".functor.enable = true;
"profiles/hardware".evaluateDefault = true;
"profiles/cross".evaluateDefault = true;
"profiles/hardware/*".evaluateDefault = true;
"services/*".aliasDefault = true;
"trusted/secrets".evaluateDefault = true;
"trusted".excludes = [ "tf" ];
"users/*".evaluateDefault = true;
"users/kat/*".functor.enable = true;
"users/kat/services/mpd".functor.enable = true;
};
};
root = ./.; root = ./.;
xarg = lib.recursiveMod { folder = ./config; inherit sources lib; };
metaBase = import ./meta.nix { inherit config lib pkgs root; }; metaBase = import ./meta.nix { inherit config lib pkgs root; };
xarg = tree.impure;
eval = lib.evalModules { eval = lib.evalModules {
modules = lib.singleton metaBase modules = lib.singleton metaBase
++ lib.singleton xarg.modules.meta ++ lib.singleton xarg.modules.meta
@ -44,13 +88,14 @@ let
(lib.attrNames xarg.hosts)); (lib.attrNames xarg.hosts));
specialArgs = { specialArgs = {
inherit sources root; inherit sources root tree;
meta = self; meta = self;
} // xarg; } // xarg;
}; };
inherit (eval) config; inherit (eval) config;
self = config // { inherit pkgs lib sourceCache sources; } // xarg;
self = config // { inherit pkgs lib sourceCache sources tree; } // xarg;
in in
self self

121
tree.nix Normal file
View file

@ -0,0 +1,121 @@
{ lib }: { config, folder, sources, ... }@args: with lib; let
pureTreeGrab = { base, path }: let
realPath = toString path;
dirContents = builtins.readDir path;
isDirectory = entry: dirContents."${entry}" == "directory";
isHidden = entry: hasPrefix "." entry;
isDir = entry: _: (isDirectory entry) && !(isHidden entry);
directories = filterAttrs isDir dirContents;
isNixFile = entry: _: let
result = builtins.match "(.*)\\.nix" entry;
in result != null && builtins.length result > 0;
nixFiles = filterAttrs isNixFile dirContents;
getPath = entry: "${realPath}/${entry}";
getPaths = entries: mapAttrs' (n: v:
nameValuePair (removeSuffix ".nix" n) (getPath n)
) entries;
nixFilePaths = getPaths nixFiles;
dirPaths = getPaths directories;
recursedPaths = mapAttrs (_: fullPath: pureTreeGrab {
inherit base;
path = fullPath;
}) dirPaths;
contents = recursedPaths // nixFilePaths;
in contents;
configTreeStruct = { config, ... }: {
options.treeConfig = mkOption {
type = with types; attrsOf (submodule ({ name, options, config, ... }: {
options = {
evaluateDefault = mkOption {
type = types.bool;
description = "Replace the contents of this branch or leaf with those provided by the evaluation of default.nix.";
default = false;
};
aliasDefault = mkOption {
type = types.bool;
description = "Replace the contents of this branch or leaf with the default.nix.";
default = false;
};
excludes = mkOption {
type = types.listOf types.str;
description = "Exclude files or folders from the recurser.";
default = [];
};
functor = {
enable = mkOption {
type = types.bool;
description = "Provide a functor for the path provided";
default = false;
};
external = mkOption {
type = types.listOf types.unspecified;
description = "Add external imports into the functor.";
default = [];
};
excludes = mkOption {
type = types.listOf types.str;
description = "Exclude files or folders from the functor.";
default = [];
};
};
};
}));
};
config.treeConfig = {
"*" = {};
};
};
configTree.treeConfig = config;
configTreeModule = (evalModules {
modules = [
configTreeStruct
configTree
];
}).config.treeConfig;
mapAttrsRecursive = f: set: let
recurse = path: set: let
g = name: value: if isAttrs value
then f (path ++ [name]) (recurse (path ++ [name]) value)
else f (path ++ [name]) value;
in mapAttrs g set;
in recurse [] set;
getPathString = path: concatStringsSep "/" path;
getConfig = path: default: configTreeModule.${getPathString path} or default;
revtail = path: sublist 0 (length path - 1) path;
getConfigRecursive = path: let
parentPath = revtail path;
in getConfig (path ++ singleton "*") (getConfigRecursive parentPath);
processLeaves = tree: config: mapAttrsRecursive (path: value: let
pathString = getPathString path;
leafConfig = getConfig path (getConfigRecursive (revtail path));
processConfig = path: value: let
processFunctor = prev: prev // {
__functor = self: { ... }: {
imports = attrValues (removeAttrs prev leafConfig.functor.excludes) ++ leafConfig.functor.external;
};
};
processAliasDefault = prev: prev.default;
processDefault = prev: import prev.default (args // {
inherit lib;
tree = {
prev = removeAttrs prev (singleton "default");
pure = pureTree;
impure = impureTree;
};
});
processExcludes = prev: removeAttrs prev leafConfig.excludes;
processes = optionals (isAttrs value) (
optional (leafConfig.excludes != []) processExcludes
++ optional leafConfig.evaluateDefault processDefault
++ optional leafConfig.aliasDefault processAliasDefault
++ optional leafConfig.functor.enable processFunctor
);
in pipe value processes;
in processConfig path value) tree;
pureTree = pureTreeGrab { base = folder; path = folder; };
impureTree = processLeaves pureTree configTreeModule;
in {
config = configTreeModule;
pure = pureTree;
impure = impureTree;
}