commit 74670edee108b45e217425ac2c941c102da75c0f Author: tristan Date: Sat Dec 30 18:27:23 2023 +0000 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..1623a6b --- /dev/null +++ b/flake.lock @@ -0,0 +1,24 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1703013332, + "narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=", + "path": "/nix/store/50bgi74d890mpkp90w1jwc5g0dw4dccr-source", + "rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a1edc88 --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + description = "A site in nix?"; + + outputs = { + self, + nixpkgs, + }: let + system = "x86_64-linux"; + pkgs = import nixpkgs { + inherit system; + }; + nixite = import ./nixite/. {inherit pkgs;}; + in { + packages.${system} = with nixite; { + # default = nixite.mkSite (nixite.layout (nixite.md.readMd ./src/index.md)); + default = nixite.mkSite { + index = + html.toHTML + ( + elems.doc + [ + (elems.title "Nixite") + ] + [ + (elems.h 1 "Nixite") + (elems.main + (elems.p "hello")) + ] + ); + }; + + serve = nixite.serve self.packages.${system}.default; + }; + }; +} diff --git a/nixite/default.nix b/nixite/default.nix new file mode 100644 index 0000000..e4d3fec --- /dev/null +++ b/nixite/default.nix @@ -0,0 +1,9 @@ +{pkgs, ...}: { + mkSite = import ./site.nix {inherit pkgs;}; + serve = site: (pkgs.writeShellScriptBin "serve" '' + ${pkgs.caddy}/bin/caddy file-server --root ${site} + ''); + md = import ./md.nix; + html = import ./html.nix; + elems = import ./elems.nix; +} diff --git a/nixite/elems.nix b/nixite/elems.nix new file mode 100644 index 0000000..9d01a0f --- /dev/null +++ b/nixite/elems.nix @@ -0,0 +1,13 @@ +let + html = import ./html.nix; +in { + p = child: html.tag "p" child; + main = child: html.tag "main" child; + h = v: child: html.tag "h${toString v}" child; + title = child: html.tag "title" child; + doc = head: body: + html.tag "html" [ + (html.tag "head" head) + (html.tag "body" body) + ]; +} diff --git a/nixite/html.nix b/nixite/html.nix new file mode 100644 index 0000000..42452d9 --- /dev/null +++ b/nixite/html.nix @@ -0,0 +1,18 @@ +rec { + toHTML = elem: + if builtins.typeOf elem == "string" + then elem + else if builtins.typeOf elem == "list" + then builtins.toString (map toHTML elem) + else ''<${elem.tag}>${toHTML elem.child}''; + + writeAttrs = attrs: + toString builtins.attrValues ( + builtins.mapAttrs (key: value: ''${key}="${value}"'') attrs + ); + + tag = tag: child: { + inherit tag child; + __toString = toHTML; + }; +} diff --git a/nixite/md.nix b/nixite/md.nix new file mode 100644 index 0000000..04eb345 --- /dev/null +++ b/nixite/md.nix @@ -0,0 +1,26 @@ +rec { + readMd = path: processMd (builtins.readFile path); + processMd = md: { + title = "idk"; + content = toString (map (c: + if builtins.typeOf c == "string" + then processMdBlock c + else null) (builtins.split "\n\n" md)); + }; + + processMdBlock = block: p block; + + isHeading = block: builtins.match "#+ .*" block; + + h = content: '' +

+ ${toString content} +

+ ''; + + p = content: '' +

+ ${toString content} +

+ ''; +} diff --git a/nixite/site.nix b/nixite/site.nix new file mode 100644 index 0000000..570737b --- /dev/null +++ b/nixite/site.nix @@ -0,0 +1,12 @@ +{pkgs, ...}: site: +pkgs.stdenv.mkDerivation { + name = "site"; + src = ./.; + buildPhase = '' + mkdir dist + echo "${toString site.index}" > dist/index.html + ''; + installPhase = '' + cp -r dist $out + ''; +} diff --git a/src/index.md b/src/index.md new file mode 100644 index 0000000..795bbef --- /dev/null +++ b/src/index.md @@ -0,0 +1,3 @@ +# Hello World + +Making a website in Nix? That sounds dumb.