8 changed files with 293 additions and 6 deletions
@ -0,0 +1,91 @@
@@ -0,0 +1,91 @@
|
||||
{ |
||||
"nodes": { |
||||
"flake-utils": { |
||||
"locked": { |
||||
"lastModified": 1648297722, |
||||
"narHash": "sha256-W+qlPsiZd8F3XkzXOzAoR+mpFqzm3ekQkJNa+PIh1BQ=", |
||||
"owner": "numtide", |
||||
"repo": "flake-utils", |
||||
"rev": "0f8662f1319ad6abf89b3380dd2722369fc51ade", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "numtide", |
||||
"repo": "flake-utils", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"mozillapkgs": { |
||||
"flake": false, |
||||
"locked": { |
||||
"lastModified": 1645464064, |
||||
"narHash": "sha256-YeN4bpPvHkVOpQzb8APTAfE7/R+MFMwJUMkqmfvytSk=", |
||||
"owner": "mozilla", |
||||
"repo": "nixpkgs-mozilla", |
||||
"rev": "15b7a05f20aab51c4ffbefddb1b448e862dccb7d", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "mozilla", |
||||
"repo": "nixpkgs-mozilla", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"naersk": { |
||||
"inputs": { |
||||
"nixpkgs": "nixpkgs" |
||||
}, |
||||
"locked": { |
||||
"lastModified": 1648544490, |
||||
"narHash": "sha256-EoBDcccV70tfz2LAs5lK0BjC7en5mzUVlgLsd5E6DW4=", |
||||
"owner": "nix-community", |
||||
"repo": "naersk", |
||||
"rev": "e30ef9a5ce9b3de8bb438f15829c50f9525ca730", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"owner": "nix-community", |
||||
"repo": "naersk", |
||||
"type": "github" |
||||
} |
||||
}, |
||||
"nixpkgs": { |
||||
"locked": { |
||||
"lastModified": 1648219316, |
||||
"narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", |
||||
"owner": "NixOS", |
||||
"repo": "nixpkgs", |
||||
"rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"id": "nixpkgs", |
||||
"type": "indirect" |
||||
} |
||||
}, |
||||
"nixpkgs_2": { |
||||
"locked": { |
||||
"lastModified": 1648219316, |
||||
"narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", |
||||
"owner": "NixOS", |
||||
"repo": "nixpkgs", |
||||
"rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", |
||||
"type": "github" |
||||
}, |
||||
"original": { |
||||
"id": "nixpkgs", |
||||
"type": "indirect" |
||||
} |
||||
}, |
||||
"root": { |
||||
"inputs": { |
||||
"flake-utils": "flake-utils", |
||||
"mozillapkgs": "mozillapkgs", |
||||
"naersk": "naersk", |
||||
"nixpkgs": "nixpkgs_2" |
||||
} |
||||
} |
||||
}, |
||||
"root": "root", |
||||
"version": 7 |
||||
} |
@ -0,0 +1,128 @@
@@ -0,0 +1,128 @@
|
||||
{ |
||||
inputs = { |
||||
flake-utils.url = "github:numtide/flake-utils"; |
||||
naersk.url = "github:nix-community/naersk"; |
||||
mozillapkgs = { |
||||
url = "github:mozilla/nixpkgs-mozilla"; |
||||
flake = false; |
||||
}; |
||||
}; |
||||
|
||||
outputs = { self, nixpkgs, flake-utils, naersk, mozillapkgs }: |
||||
flake-utils.lib.eachDefaultSystem ( |
||||
system: let |
||||
pkgs = nixpkgs.legacyPackages."${system}"; |
||||
mozilla = pkgs.callPackage (mozillapkgs + "/package-set.nix") {}; |
||||
rust = (mozilla.rustChannelOf { |
||||
date = "2022-03-31"; |
||||
channel = "nightly"; |
||||
sha256 = "k6wD6/2qNQ7rmIvGi1ddtKSTUXjXFbIr0Sg2mqF2nYg="; |
||||
}).rust; |
||||
|
||||
naersk-lib = naersk.lib."${system}".override { |
||||
cargo = rust; |
||||
rustc = rust; |
||||
}; |
||||
in |
||||
rec { |
||||
# `nix build` |
||||
packages.carasite = naersk-lib.buildPackage { |
||||
pname = "carasite"; |
||||
root = ./.; |
||||
remapPathPrefix = true; |
||||
buildInputs = with pkgs; [ |
||||
git |
||||
]; |
||||
overrideMain = attrs: { |
||||
preBuild = '' |
||||
ls -alR src |
||||
cp -r templates /build/dummy-src/ |
||||
cp -r statics /build/dummy-src/ |
||||
''; |
||||
|
||||
postInstall = '' |
||||
mv $out/bin/site $out/bin/carasite |
||||
|
||||
cp -rf $src/blog $out/blog |
||||
cp -rf $src/statics $out/css |
||||
cp -rf $src/projects $out/projects |
||||
''; |
||||
|
||||
}; |
||||
}; |
||||
defaultPackage = packages.carasite; |
||||
|
||||
# `nix run` |
||||
apps.carasite = flake-utils.lib.mkApp { |
||||
drv = packages.carasite; |
||||
}; |
||||
defaultApp = apps.carasite; |
||||
|
||||
nixosModules.site = { config, lib, ... }: { |
||||
options = { |
||||
cara.services.carasite.enable = lib.mkEnableOption "enable cara's site"; |
||||
cara.services.carasite.domain = lib.mkOption { |
||||
type = lib.types.str; |
||||
default = "devcara.com"; |
||||
description = "The domain to use"; |
||||
}; |
||||
|
||||
cara.services.carasite.port = lib.mkOption { |
||||
type = lib.types.port; |
||||
default = 3000; |
||||
description = "The port to bind to"; |
||||
}; |
||||
}; |
||||
|
||||
config = lib.mkIf config.cara.services.carasite.enable { |
||||
users.users.cara-site = { |
||||
createHome = true; |
||||
isSystemUser = true; |
||||
home = "/var/lib/cara-site"; |
||||
group = "cara-site"; |
||||
}; |
||||
|
||||
systemd.services.cara-site = { |
||||
wantedBy = [ "multi-user.target" ]; |
||||
environment = { |
||||
PORT = "${config.cara.services.carasite.port}"; |
||||
}; |
||||
serviceConfig = { |
||||
User = "cara-site"; |
||||
Group = "cara-site"; |
||||
Restart = "always"; |
||||
WorkingDirectory = "/var/lib/cara-site"; |
||||
script = let site = defaultPackage; |
||||
in '' |
||||
export PORT=${config.cara.services.carasite.port} |
||||
cd ${site} |
||||
exec ${site/bin/xesite} |
||||
''; |
||||
}; |
||||
}; |
||||
|
||||
services.nginx = { |
||||
enable = true; |
||||
recommendedProxySettings = true; |
||||
recommendedTlsSettings = true; |
||||
virtualHosts."${config.cara.services.carasite.domain}" = { |
||||
addSSL = true; |
||||
forceSSL = true; |
||||
enableACME = true; |
||||
|
||||
locations."/" = { |
||||
proxyPass = "http://127.0.0.1:${config.cara.services.carasite.port}"; |
||||
}; |
||||
}; |
||||
}; |
||||
}; |
||||
}; |
||||
|
||||
|
||||
# `nix develop` |
||||
devShell = pkgs.mkShell { |
||||
nativeBuildInputs = with pkgs; [ rustc cargo ]; |
||||
}; |
||||
} |
||||
); |
||||
} |
@ -0,0 +1,19 @@
@@ -0,0 +1,19 @@
|
||||
--- |
||||
title: Website |
||||
date: 2022-03-29 |
||||
--- |
||||
|
||||
# Overview |
||||
|
||||
This site used to be written using [Hugo][hugo], and written in Markdown. It's now |
||||
written in Rust, with content remaining in Markdown. I mostly chose to do this |
||||
so I could explore more of frontend development and especially the Rust web |
||||
ecosystem. |
||||
|
||||
[hugo]: https://gohugo.io |
||||
|
||||
# Architecture |
||||
|
||||
The Rust backend is hosted at |
||||
[muirrum/site](https://git.devcara.com/muirrum/site). It loads the markdown into |
||||
HTML and stores it in global state that's then passed to each handler. |
@ -0,0 +1,38 @@
@@ -0,0 +1,38 @@
|
||||
use crate::blog::post; |
||||
pub mod handlers { |
||||
|
||||
use color_eyre::eyre::eyre; |
||||
use std::sync::Arc; |
||||
|
||||
use crate::templates::{self, Html, RenderRucte}; |
||||
use warp::http::Response; |
||||
use warp::{Rejection, Reply}; |
||||
|
||||
use crate::internal::SiteState; |
||||
|
||||
use crate::blog::post::Post; |
||||
|
||||
pub async fn list(state: Arc<SiteState>) -> Result<impl Reply, Rejection> { |
||||
let state = state.clone(); |
||||
Response::builder().html(|o| templates::bloglist_html(o, state.projects.clone(), "Projects".into())) |
||||
} |
||||
|
||||
pub async fn project(name: String, state: Arc<SiteState>) -> Result<impl Reply, Rejection> { |
||||
let mut want: Option<Post> = None; |
||||
|
||||
for post in &state.projects { |
||||
if post.link == format!("projects/{}", name) { |
||||
want = Some(post.clone()); |
||||
break; |
||||
} |
||||
} |
||||
|
||||
match want { |
||||
Some(post) => { |
||||
let body = Html(post.body_html.clone()); |
||||
Response::builder().html(|o| templates::post_html(o, post, body)) |
||||
} |
||||
None => panic!("No post found"), |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue