build(tree): move to upstream

This commit is contained in:
Kat Inskip 2024-01-27 13:44:01 -08:00
parent 4540b14963
commit da267214b7
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
4 changed files with 106 additions and 193 deletions

44
flake.lock generated
View file

@ -87,7 +87,7 @@
"flakelib": { "flakelib": {
"inputs": { "inputs": {
"fl-config": "fl-config", "fl-config": "fl-config",
"std": "std" "std": "std_2"
}, },
"locked": { "locked": {
"lastModified": 1683326042, "lastModified": 1683326042,
@ -175,7 +175,9 @@
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs",
"nur": "nur", "nur": "nur",
"sops-nix": "sops-nix", "sops-nix": "sops-nix",
"systemd2mqtt": "systemd2mqtt" "std": "std",
"systemd2mqtt": "systemd2mqtt",
"tree": "tree"
} }
}, },
"rust": { "rust": {
@ -221,6 +223,21 @@
} }
}, },
"std": { "std": {
"locked": {
"lastModified": 1701658249,
"narHash": "sha256-KIt1TUuBvldhaVRta010MI5FeQlB8WadjqljybjesN0=",
"owner": "chessai",
"repo": "nix-std",
"rev": "715db541ffff4194620e48d210b76f73a74b5b5d",
"type": "github"
},
"original": {
"owner": "chessai",
"repo": "nix-std",
"type": "github"
}
},
"std_2": {
"inputs": { "inputs": {
"nix-std": "nix-std" "nix-std": "nix-std"
}, },
@ -274,6 +291,29 @@
"repo": "default", "repo": "default",
"type": "github" "type": "github"
} }
},
"tree": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"std": [
"std"
]
},
"locked": {
"lastModified": 1676505934,
"narHash": "sha256-jeqZtNLOKXRSDmD1v+b9+v+hwVyH6kcKzZ9f0gcJpdk=",
"owner": "kittywitch",
"repo": "tree",
"rev": "a831f6fd209e3d00c5026303994de28d0031ab3b",
"type": "github"
},
"original": {
"owner": "kittywitch",
"repo": "tree",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -6,6 +6,9 @@
url = "github:arcnmx/nixexprs/master"; url = "github:arcnmx/nixexprs/master";
flake = false; flake = false;
}; };
std = {
url = "github:chessai/nix-std";
};
ci = { ci = {
url = "github:arcnmx/ci/v0.6"; url = "github:arcnmx/ci/v0.6";
flake = false; flake = false;
@ -20,6 +23,11 @@
url = "github:Mic92/sops-nix"; url = "github:Mic92/sops-nix";
inputs.nixpkgs.follows = "nixpkgs"; inputs.nixpkgs.follows = "nixpkgs";
}; };
tree = {
url = "github:kittywitch/tree";
inputs.std.follows = "std";
inputs.nixpkgs.follows = "nixpkgs";
};
systemd2mqtt = { systemd2mqtt = {
url = "github:arcnmx/systemd2mqtt"; url = "github:arcnmx/systemd2mqtt";
inputs = { inputs = {

View file

@ -1,130 +0,0 @@
{ lib }: { config, folder, inputs, ... }@args: let
inherit (lib.attrsets) filterAttrs mapAttrs' mapAttrs isAttrs nameValuePair attrValues;
inherit (lib.strings) hasPrefix removeSuffix;
inherit (lib.lists) imap1 singleton optionals optional sublist;
inherit (lib.trivial) pipe;
inherit (lib.options) mkOption;
inherit (lib.modules) evalModules;
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 = lib.types.attrsOf (lib.types.submodule ({ name, options, config, ... }: {
options = {
evaluateDefault = mkOption {
type = lib.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 = lib.types.bool;
description = "Replace the contents of this branch or leaf with the default.nix.";
default = false;
};
excludes = mkOption {
type = lib.types.listOf lib.types.str;
description = "Exclude files or folders from the recurser.";
default = [];
};
functor = {
enable = mkOption {
type = lib.types.bool;
description = "Provide a functor for the path provided";
default = false;
};
external = mkOption {
type = lib.types.listOf lib.types.unspecified;
description = "Add external imports into the functor.";
default = [];
};
excludes = mkOption {
type = lib.types.listOf lib.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 f [] (recurse [] set);
getPathString = path: builtins.concatStringsSep "/" path;
getConfig = path: default: configTreeModule.${getPathString path} or default;
revtail = path: sublist 0 (builtins.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 = if path == [] then
configTreeModule."/"
else 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;
}

117
tree.nix
View file

@ -2,68 +2,63 @@
inputs, inputs,
lib, lib,
... ...
}: let }: (inputs.tree.tree {
mkTree = import ./mkTree.nix {inherit lib;}; inherit inputs;
tree = mkTree { folder = ./.;
inherit inputs; config = {
folder = ./.; "/" = {
config = { excludes = [
"/" = { "tf"
excludes = [ "inputs"
"tf" "default"
"inputs" "patchedInputs"
"default" "mkTree"
"patchedInputs" "outputs"
"mkTree" "tree"
"outputs" "flake"
"tree" "meta"
"flake" "inputs"
"meta" ];
"inputs" };
"modules/nixos" = {
functor = {
external = with (import (inputs.arcexprs + "/modules")).nixos; [
nix
systemd
dht22-exporter
glauth
modprobe
kernel
crypttab
mutable-state
common-root
pulseaudio
wireplumber
alsa
bindings
matrix-appservices
matrix-synapse-appservices
display
filebin
mosh
doc-warnings
inputs.systemd2mqtt.nixosModules.default
]; ];
}; };
"modules/nixos" = {
functor = {
external =
with (import (inputs.arcexprs + "/modules")).nixos; [
nix
systemd
dht22-exporter
glauth
modprobe
kernel
crypttab
mutable-state
common-root
pulseaudio
wireplumber
alsa
bindings
matrix-appservices
matrix-synapse-appservices
display
filebin
mosh
doc-warnings
inputs.systemd2mqtt.nixosModules.default
];
};
};
"modules/nixos".functor.enable = true;
"modules/meta".functor.enable = true;
"modules/system".functor.enable = true;
"modules/home".functor.enable = true;
"modules/type".functor.enable = true;
"nixos/*".functor = {
enable = true;
};
"system".functor.enable = true;
"hardware".evaluateDefault = true;
"nixos/cross".evaluateDefault = true;
"hardware/*".evaluateDefault = true;
"home".evaluateDefault = true;
"home/*".functor.enable = true;
}; };
"modules/nixos".functor.enable = true;
"modules/meta".functor.enable = true;
"modules/system".functor.enable = true;
"modules/home".functor.enable = true;
"modules/type".functor.enable = true;
"nixos/*".functor = {
enable = true;
};
"system".functor.enable = true;
"hardware".evaluateDefault = true;
"nixos/cross".evaluateDefault = true;
"hardware/*".evaluateDefault = true;
"home".evaluateDefault = true;
"home/*".functor.enable = true;
}; };
in })
tree