{"id":13631165,"url":"https://github.com/RGBCube/HTMNIX","last_synced_at":"2025-04-17T18:32:04.898Z","repository":{"id":224903870,"uuid":"764534437","full_name":"RGBCube/HTMNIX","owner":"RGBCube","description":"HTML for Nix to rule them all.","archived":false,"fork":false,"pushed_at":"2024-03-06T10:22:38.000Z","size":62,"stargazers_count":63,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-01T22:47:57.143Z","etag":null,"topics":["html","nix"],"latest_commit_sha":null,"homepage":"https://rgbcu.be/blog/htmnix","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RGBCube.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-28T08:55:36.000Z","updated_at":"2024-07-02T05:14:52.000Z","dependencies_parsed_at":"2024-03-06T11:37:33.554Z","dependency_job_id":null,"html_url":"https://github.com/RGBCube/HTMNIX","commit_stats":null,"previous_names":["rgbcube/htmnix"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGBCube%2FHTMNIX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGBCube%2FHTMNIX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGBCube%2FHTMNIX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RGBCube%2FHTMNIX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RGBCube","download_url":"https://codeload.github.com/RGBCube/HTMNIX/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223762878,"owners_count":17198384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["html","nix"],"created_at":"2024-08-01T22:02:13.406Z","updated_at":"2024-11-08T22:31:10.248Z","avatar_url":"https://github.com/RGBCube.png","language":"Nix","funding_links":[],"categories":["Nix"],"sub_categories":[],"readme":"# HTMNIX\n\nWrite composeable HTML with Nix!\n\nHere is an example snippet:\n\n```nix\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003e\"Hello, Internet!\"\u003c.title\u003e\n  \u003c.head\u003e\n  \u003cbody\u003e\n      \u003cp\u003e\"Yep, this is 100% Nix!\"\u003c.p\u003e\n\n      \u003cimg.\u003e{src=\"/foo.png\"; alt=\"Attributes also work!\";}\n  \u003c.body\u003e\n\u003c.html\u003e\n```\n\n[Here is an example site created using HTMNIX and the `build.sh` in\nthe current directory that you are supposed to vendor](https://github.com/RGBCube/NixSite)\n\nYou might be wondering, _How?_\n\nIf you are, go read my [blog post](https://rgbcu.be/blog/htmnix)!\n\nBut before that you may want to try it for yourself!\nYou can! Just enter the REPL by running this command:\n\n```sh\nnix repl github:RGBCube/HTMNIX\n```\n\n## Provided Functions\n\nThese are the functions and variables provided by HTMNIX\nwhich will be available in every HTMNIX file and the HTMNIX REPL\n(You can enter it by running `nix repl github:RGBCube/HTMNIX`!).\n\n- `lib`: Just the nixpkgs lib. Pretty useful to have.\n\n- `raw`: Used for a string to be included in the HTML without escaping.\n  Just pass the string into this and it will not be escaped.\n\n- `call`: Calls another HTMNIX file and brings this list of provided\n  variables into its scope before evaulation. Basically the same as `import`\n  if you disregard the bringing-into-scope it does.\n\n- `DOCTYPE`: Equivalent to a `\u003c!DOCTYPE html\u003e` tag, this exists because you can't\n  express it in Nix syntax and have to resort to calling `__findFile` with the\n  string you want instead.\n\n- `__findFile`: Where the magic happens. This overrides the default `__findFile`\n  allowing for us to return magic functor sets for `\u003cwhatever.here\u003e` expressions.\n  The `\u003cnixpkgs\u003e` expression however is propagated into the builtin one so it does\n  not interfere with your workflow.\n\n## More Examples\n\n\u003e All of the examples here can be rendered with the following\n\u003e command (assuming `html.nix` has the example content):\n\u003e\n\u003e ```sh\n\u003e TARGET_FILE=$(realpath html.nix) nix eval github:RGBCube/HTMNIX#result --raw --impure\n\u003e ```\n\n\u003e Also keep in mind that everything is passed as an argument to the\n\u003e first HTML tag's functor. So you will need to surrond some things with\n\u003e parens for it to evaulate properly.\n\u003e\n\u003e Some notable things that require parens include:\n\u003e - Function calls.\n\u003e - `let in`'s.\n\u003e - Expressions that have spaces in them.\n\n\u003e Adding onto the previous note, if you want to see how your\n\u003e HTMNIX file is **actually** evaluated, you can run the following command:\n\u003e\n\u003e ```sh\n\u003e nix-instantiate --parse html.nix\n\u003e ```\n\u003e\n\u003e This will insert a ton of parens everywhere, thus un-ambiguating the parsing.\n\u003e Here is an example:\n\u003e\n\u003e ```nix\n\u003e nix-instantiate --parse - \u003c\u003c :end\n\u003e \u003cul\u003e\n\u003e   \u003cli\u003e\"That's all!\"\u003c.li\u003e\n\u003e \u003c.ul\u003e\n\u003e :end\n\u003e ```\n\u003e\n\u003e This produces the following output:\n\u003e\n\u003e ```nix\n\u003e (__findFile __nixPath \"ul\" (__findFile __nixPath \"li\") \"That's all!\" (__findFile __nixPath \".li\") (__findFile __nixPath \".ul\"))\n\u003e ```\n\nCreate a directory listing:\n\n```nix\n\u003cul\u003e\n  (lib.mapAttrsToList\n    (name: type: \u003cli\u003e\"${name} (${type})\"\u003c.li\u003e)\n    (builtins.readDir ./.))\n\u003c.ul\u003e\n```\n\nList metadata about a derivation:\n\n```nix\nlet\n  pkg = (import \u003cnixpkgs\u003e {}).youtube-dl;\nin\n\n\u003cdiv\u003e{class=\"package\";}\n  \u003cp\u003e\"Name: ${pkg.pname}\"\u003c.p\u003e\n  \u003cdetails\u003e\n    \u003csummary\u003e\"See metadata\"\u003c.summary\u003e\n    \u003cul\u003e\n      \u003cli\u003e\"Full name: ${pkg.name}\"\n      \u003cli\u003e\"Version: ${pkg.version}\"\n      \u003cli\u003e(let\n        license = if lib.isList pkg.meta.license then\n          lib.elemAt pkg.meta.license 0\n        else\n          pkg.meta.license;\n      in \"License: ${license.fullName}\")\n    \u003c.ul\u003e\n  \u003c.details\u003e\n\u003c.div\u003e\n```\n\nInsert a raw unescaped string into your HTML:\n\n```nix\n\u003chead\u003e\n  \u003ctitle\u003e\"Look ma! So unsafe!\"\u003c.title\u003e\n\u003c.head\u003e\n\u003cbody\u003e(raw ''\n  \u003cblink\u003ePlease don't do this at home...\u003c/blink\u003e\n'')\u003c.body\u003e\n```\n\nCall another Nix file as a HTMNIX file, with all the magic:\n\n```nix\n# -- inside comment.nix --\n{ name, comment }:\n\n\u003cdiv\u003e{class=\"review\";}\n  \u003cfigcaption\u003e\n    \u003cimg.\u003e{src=\"/assets/${lib.replaceStrings [ \" \" ] [ \"-\" ] name}-headshot.webp\";}\n    \u003ch2\u003ename\u003c.h2\u003e\n  \u003c.figcaption\u003e\n\n  \u003cp\u003ecomment\u003c.p\u003e\n\u003c.div\u003e\n\n# -- inside html.nix --\nlet\n  comments = [\n    { name = \"John Doe\"; comment = \"Very nice service, reversed my hair loss!\"; }\n    { name = \"Joe\"; comment = \"Didn't work for me. 0/10.\"; }\n    { name = \"Skid\"; comment = \"\u003cscript\u003ealert('Got you!')\u003c/script\u003e\"; } # Does not work as all strings are escaped by default.\n  ];\nin\n\n\u003cul\u003e\n  (map\n    (comment: \u003cli\u003e(call ./comment.nix comment)\u003c.li\u003e)\n    comments)\n\u003c.ul\u003e\n```\n\n## License\n\n```\nMIT License\n\nCopyright (c) 2024-present RGBCube\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRGBCube%2FHTMNIX","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FRGBCube%2FHTMNIX","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FRGBCube%2FHTMNIX/lists"}