feat: use nixpkgs-lib, moar seperations
This commit is contained in:
parent
c73ac62ffb
commit
52ec8e0921
7
example.nix
Normal file
7
example.nix
Normal file
@ -0,0 +1,7 @@
|
||||
tags: with tags;
|
||||
html [
|
||||
(body [
|
||||
(p "Hello,")
|
||||
(p "world!")
|
||||
])
|
||||
]
|
26
flake.lock
Normal file
26
flake.lock
Normal 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
|
||||
}
|
22
flake.nix
22
flake.nix
@ -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;
|
||||
};
|
||||
}
|
||||
|
8
lib.nix
8
lib.nix
@ -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
|
@ -1,4 +1,4 @@
|
||||
{ lib ? import ./lib.nix, pkgs }:
|
||||
{ lib, pkgs }:
|
||||
let pkgBin = name: "${pkgs.${name}}/bin/${name}"; in
|
||||
{
|
||||
mkServePathScript = path: pkgs.writeScriptBin "serve" { } ''
|
||||
|
8
tags.nix
8
tags.nix
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user