initial commit
This commit is contained in:
commit
74670edee1
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
result
|
24
flake.lock
Normal file
24
flake.lock
Normal file
|
@ -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
|
||||
}
|
35
flake.nix
Normal file
35
flake.nix
Normal file
|
@ -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;
|
||||
};
|
||||
};
|
||||
}
|
9
nixite/default.nix
Normal file
9
nixite/default.nix
Normal file
|
@ -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;
|
||||
}
|
13
nixite/elems.nix
Normal file
13
nixite/elems.nix
Normal file
|
@ -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)
|
||||
];
|
||||
}
|
18
nixite/html.nix
Normal file
18
nixite/html.nix
Normal file
|
@ -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}</${elem.tag}>'';
|
||||
|
||||
writeAttrs = attrs:
|
||||
toString builtins.attrValues (
|
||||
builtins.mapAttrs (key: value: ''${key}="${value}"'') attrs
|
||||
);
|
||||
|
||||
tag = tag: child: {
|
||||
inherit tag child;
|
||||
__toString = toHTML;
|
||||
};
|
||||
}
|
26
nixite/md.nix
Normal file
26
nixite/md.nix
Normal file
|
@ -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: ''
|
||||
<h1>
|
||||
${toString content}
|
||||
</h1>
|
||||
'';
|
||||
|
||||
p = content: ''
|
||||
<p>
|
||||
${toString content}
|
||||
</p>
|
||||
'';
|
||||
}
|
12
nixite/site.nix
Normal file
12
nixite/site.nix
Normal file
|
@ -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
|
||||
'';
|
||||
}
|
3
src/index.md
Normal file
3
src/index.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Hello World
|
||||
|
||||
Making a website in Nix? That sounds dumb.
|
Loading…
Reference in a new issue