feat: use nixpkgs-lib, moar seperations

This commit is contained in:
dusk 2021-05-15 02:51:50 +03:00
parent c73ac62ffb
commit 52ec8e0921
Signed by: dusk
GPG Key ID: 1D8F8FAF2294D6EA
6 changed files with 49 additions and 24 deletions

7
example.nix Normal file
View File

@ -0,0 +1,7 @@
tags: with tags;
html [
(body [
(p "Hello,")
(p "world!")
])
]

26
flake.lock Normal file
View File

@ -0,0 +1,26 @@
{
"nodes": {
"nixpkgsLib": {
"locked": {
"lastModified": 1620519687,
"narHash": "sha256-+6Dd72b2CASuXm2W7KRxZIE7AOy/dj4mU28vaF+zxcs=",
"owner": "divnix",
"repo": "nixpkgs.lib",
"rev": "c7b6169809c5f74dd0c34f3d69e9d12ba4d448de",
"type": "github"
},
"original": {
"owner": "divnix",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgsLib": "nixpkgsLib"
}
}
},
"root": "root",
"version": 7
}

View File

@ -1,26 +1,24 @@
{
inputs = { };
inputs = {
nixpkgsLib.url = "github:divnix/nixpkgs.lib";
};
outputs = { self }:
outputs = { self, nixpkgsLib }:
let
tagsPath = ./tags.nix;
libPath = ./lib.nix;
pkgsLibPath = ./pkgs-lib.nix;
lib = import libPath;
lib = nixpkgsLib.lib;
tags = import ./tags.nix { format = true; inherit lib; };
in
{
lib = {
inherit tagsPath libPath pkgsLibPath;
tags = import tagsPath { format = true; inherit lib; };
core = lib;
inherit tags;
};
overlays = {
pkgsLib = (final: prev: {
htmlNix = import pkgsLibPath { inherit lib; pkgs = prev; };
htmlNix = import ./pkgs-lib.nix { inherit lib; pkgs = prev; };
});
};
example = import ./example.nix tags;
};
}

View File

@ -1,8 +0,0 @@
let
inherit (builtins) isAttrs isList map;
in
{
mapAttrsToList = f: attrs: map (name: f name attrs.${name}) (builtins.attrNames attrs);
concatStrings = builtins.concatStringsSep "";
genAttrs = f: names: builtins.listToAttrs (map (n: { name = n; value = (f n); }) names);
} // builtins

View File

@ -1,4 +1,4 @@
{ lib ? import ./lib.nix, pkgs }:
{ lib, pkgs }:
let pkgBin = name: "${pkgs.${name}}/bin/${name}"; in
{
mkServePathScript = path: pkgs.writeScriptBin "serve" { } ''

View File

@ -1,5 +1,7 @@
{ format ? false, lib ? import ./lib.nix }:
with lib; let
{ format ? false, lib }:
let
inherit (lib) concatStrings mapAttrsToList genAttrs isAttrs isList;
fmt = if format then "\n " else "";
evalAttrs = attrs: concatStrings (mapAttrsToList (name: value: " ${name}=\"${value}\"") attrs);
@ -9,7 +11,7 @@ with lib; let
then (children: "<${name}${evalAttrs maybeAttrs}>${fmt}${evalChildren children}${fmt}</${name}>")
else tag name { } maybeAttrs;
tags = (genAttrs tag [ "html" "head" "body" "div" "p" "a" ]);
tags = (genAttrs [ "html" "head" "body" "div" "p" "a" ] tag);
in
tags // {
inherit tag;