Initial commit

This commit is contained in:
kirbara 2025-12-01 13:23:24 +07:00
commit cfcc57a8bd
Signed by: exp
GPG key ID: D7E63AD0019E75D9
353 changed files with 18756 additions and 0 deletions

View file

@ -0,0 +1,55 @@
# __findFile implementation to resolve deep aspects.
# inspired by https://fzakaria.com/2025/08/10/angle-brackets-in-a-nix-flake-world
{
lib,
config,
...
}:
_nixPath: name:
let
findAspect =
path:
let
head = lib.head path;
tail = lib.tail path;
notFound = "Aspect not found: ${lib.concatStringsSep "." path}";
headIsDen = head == "den";
readFromDen = lib.getAttrFromPath ([ "den" ] ++ tail) config;
headIsAspect = builtins.hasAttr head config.den.aspects;
aspectsPath = [
"den"
"aspects"
] ++ path;
readFromAspects = lib.getAttrFromPath aspectsPath config;
headIsDenful = lib.hasAttrByPath [ "ful" head ] config.den;
denfulTail = if lib.head tail == "provides" then lib.tail tail else tail;
denfulPath = [
"den"
"ful"
head
] ++ denfulTail;
readFromDenful = lib.getAttrFromPath denfulPath config;
found =
if headIsDen then
readFromDen
else if headIsAspect then
readFromAspects
else if headIsDenful then
readFromDenful
else
throw notFound;
in
found;
in
lib.pipe name [
(lib.strings.replaceStrings [ "/" ] [ ".provides." ])
(lib.strings.splitString ".")
(findAspect)
]

View file

@ -0,0 +1,4 @@
{ inputs, ... }:
{
imports = [ (inputs.import-tree ../modules) ];
}

View file

@ -0,0 +1,24 @@
lib:
let
check =
params: func:
let
givenArgs = builtins.isAttrs params;
fargs = lib.functionArgs func;
provided = builtins.attrNames params;
args = lib.mapAttrsToList (name: optional: { inherit name optional; }) fargs;
required = map (x: x.name) (lib.filter (x: !x.optional) args);
intersection = lib.intersectLists required provided;
satisfied = givenArgs && lib.length required == lib.length intersection;
noExtras = lib.length required == lib.length provided;
exactly = satisfied && noExtras;
in
{
inherit satisfied exactly;
};
in
{
__functor = self: self.atLeast;
atLeast = params: func: (check params func).satisfied;
exactly = params: func: (check params func).exactly;
}

101
flake/den/nix/lib.nix Normal file
View file

@ -0,0 +1,101 @@
{
inputs,
lib,
config,
...
}:
let
# "Just Give 'Em One of These" - Moe Szyslak
# A __functor that applies context to parametric includes (functions)
funk =
apply: aspect:
aspect
// {
__functor = self: ctx: {
includes = builtins.filter (x: x != { }) (map (apply ctx) (builtins.filter isFn self.includes));
};
};
isFn = f: (builtins.isFunction f) || (f ? __functor);
canTake = import ./fn-can-take.nix lib;
# creates an aspect that inherits class from fromAspect.
owned =
aspect:
aspect
// {
includes = [ ];
__functor =
self:
# deadnix: skip
{ class, aspect-chain }:
self;
};
# only static includes from an aspect.
statics =
aspect:
aspect
// {
__functor =
self:
# deadnix: skip
{ class, aspect-chain }@ctx:
funk applyStatics self ctx;
};
applyStatics =
ctx: f:
if isStatic f then
f ctx
else if !isFn f then
f
else
{ };
isStatic = canTake {
class = "";
aspect-chain = [ ];
};
take.unused = _unused: used: used;
take.exactly = take canTake.exactly;
take.atLeast = take canTake.atLeast;
take.__functor =
_: takes: fn: ctx:
if takes ctx fn then fn ctx else { };
parametric.atLeast = funk (lib.flip take.atLeast);
parametric.exactly = funk (lib.flip take.exactly);
parametric.fixedTo = lib.flip parametric.atLeast;
parametric.expands = attrs: funk (ctx: (lib.flip take.atLeast) (ctx // attrs));
parametric.__functor =
self: ctx:
if ctx == true then
self.atLeast
else if ctx == false then
self.exactly
else if isFn ctx then
funk ctx
else
self.fixedTo ctx;
aspects = inputs.flake-aspects.lib lib;
__findFile = import ./den-brackets.nix { inherit lib config; };
den-lib = {
inherit
parametric
aspects
__findFile
statics
owned
isFn
canTake
take
;
};
in
den-lib

View file

@ -0,0 +1,29 @@
name: input:
{ config, lib, ... }:
let
isLocal = !builtins.isAttrs input;
isOutput = isLocal && input == true;
aliasModule = lib.mkAliasOptionModule [ name ] [ "den" "ful" name ];
type = lib.types.attrsOf config.den.lib.aspects.types.providerType;
source = if isLocal then { } else input.denful.${name};
output =
if isOutput then
{
config.flake.denful.${name} = config.den.ful.${name};
options.flake.denful.${name} = lib.mkOption { inherit type; };
}
else
{ };
in
{
imports = [
aliasModule
output
];
config._module.args.${name} = config.den.ful.${name};
config.den.ful.${name} = source;
options.den.ful.${name} = lib.mkOption { inherit type; };
}

View file

@ -0,0 +1,13 @@
let
rev = "9100a0f";
narHash = "sha256:09m84vsz1py50giyfpx0fpc7a4i0r1xsb54dh0dpdg308lp4p188";
compat = fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz";
sha256 = narHash;
};
flake = import compat { src = ../templates/default; };
pkgs = flake.outputs.packages;
in
{
x86_64-linux.default = pkgs.x86_64-linux.vm;
}