diff --git a/example.nix b/example.nix new file mode 100644 index 0000000..868a1e9 --- /dev/null +++ b/example.nix @@ -0,0 +1,7 @@ +tags: with tags; +html [ + (body [ + (p "Hello,") + (p "world!") + ]) +] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c525463 --- /dev/null +++ b/flake.lock @@ -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 +} diff --git a/flake.nix b/flake.nix index 484e488..a3aaea0 100644 --- a/flake.nix +++ b/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; }; } diff --git a/lib.nix b/lib.nix deleted file mode 100644 index 8a90d37..0000000 --- a/lib.nix +++ /dev/null @@ -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 diff --git a/pkgs-lib.nix b/pkgs-lib.nix index e526707..d5b9249 100644 --- a/pkgs-lib.nix +++ b/pkgs-lib.nix @@ -1,4 +1,4 @@ -{ lib ? import ./lib.nix, pkgs }: +{ lib, pkgs }: let pkgBin = name: "${pkgs.${name}}/bin/${name}"; in { mkServePathScript = path: pkgs.writeScriptBin "serve" { } '' diff --git a/tags.nix b/tags.nix index 56dd736..d14b38d 100644 --- a/tags.nix +++ b/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}") 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;