added a nix flake for building
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
|||||||
/target
|
/target
|
||||||
/themes
|
/themes
|
||||||
|
/result
|
||||||
|
|||||||
38
build.rs
38
build.rs
@@ -1,15 +1,33 @@
|
|||||||
use std::fs::{File, create_dir};
|
use std::fs::File;
|
||||||
use std::path::Path;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
// This file is kind of ugly, I tried to make nix build work
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let dest_path = Path::new("themes/Catppuccin-Macchiato.tmTheme");
|
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
|
let local_theme_path = PathBuf::from(&manifest_dir).join("themes/Catppuccin-Macchiato.tmTheme");
|
||||||
|
|
||||||
if !dest_path.exists() {
|
let final_path = if let Ok(nix_theme_path) = std::env::var("THEME_PATH") {
|
||||||
let mut response = reqwest::blocking::get("https://raw.githubusercontent.com/catppuccin/bat/refs/heads/main/themes/Catppuccin%20Macchiato.tmTheme")
|
// In case of nix build
|
||||||
.expect("Failed to download theme");
|
println!("cargo:rerun-if-env-changed=THEME_PATH");
|
||||||
|
nix_theme_path
|
||||||
|
} else {
|
||||||
|
// In case of cargo
|
||||||
|
if !local_theme_path.exists() {
|
||||||
|
println!("cargo:warning=Theme not found, downloading...");
|
||||||
|
|
||||||
create_dir("themes").expect("Could not create themes dir");
|
std::fs::create_dir_all(local_theme_path.parent().unwrap())
|
||||||
let mut file = File::create(dest_path).expect("Failed to create theme file");
|
.expect("Could not create themes directory");
|
||||||
std::io::copy(&mut response, &mut file).expect("Failed to save theme");
|
|
||||||
}
|
let mut response = reqwest::blocking::get("https://raw.githubusercontent.com/catppuccin/bat/refs/heads/main/themes/Catppuccin%20Macchiato.tmTheme")
|
||||||
|
.expect("Failed to download theme");
|
||||||
|
|
||||||
|
let mut file = File::create(&local_theme_path).expect("Failed to create theme file");
|
||||||
|
std::io::copy(&mut response, &mut file).expect("Failed to save theme");
|
||||||
|
}
|
||||||
|
|
||||||
|
local_theme_path.to_str().unwrap().to_string()
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("cargo:rustc-env=THEME_FILE_PATH={}", final_path);
|
||||||
}
|
}
|
||||||
|
|||||||
109
flake.lock
generated
Normal file
109
flake.lock
generated
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"code-theme": {
|
||||||
|
"flake": false,
|
||||||
|
"locked": {
|
||||||
|
"narHash": "sha256-28LGXKITHbrmt6qrcG/W+qTlaWthre7x7izp/TPjQgA=",
|
||||||
|
"type": "file",
|
||||||
|
"url": "https://raw.githubusercontent.com/catppuccin/bat/refs/heads/main/themes/Catppuccin%20Macchiato.tmTheme"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"type": "file",
|
||||||
|
"url": "https://raw.githubusercontent.com/catppuccin/bat/refs/heads/main/themes/Catppuccin%20Macchiato.tmTheme"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1731533236,
|
||||||
|
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1767767207,
|
||||||
|
"narHash": "sha256-Mj3d3PfwltLmukFal5i3fFt27L6NiKXdBezC1EBuZs4=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "5912c1772a44e31bf1c63c0390b90501e5026886",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1744536153,
|
||||||
|
"narHash": "sha256-awS2zRgF4uTwrOKwwiJcByDzDOdo3Q1rPZbiHQg/N38=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "18dd725c29603f582cf1900e0d25f9f1063dbf11",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "NixOS",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"code-theme": "code-theme",
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs",
|
||||||
|
"rust-overlay": "rust-overlay"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"rust-overlay": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs_2"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1767754000,
|
||||||
|
"narHash": "sha256-znoNJs2QZFl+wCFLd6FbUJ00c74kvzOjyQYXc45uFvo=",
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"rev": "0b3a5ad260479f2c9bdadf3ba5b2a4be359cfcdd",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "oxalica",
|
||||||
|
"repo": "rust-overlay",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
64
flake.nix
Normal file
64
flake.nix
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
{
|
||||||
|
description = "Blog website";
|
||||||
|
|
||||||
|
inputs = {
|
||||||
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||||
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
||||||
|
|
||||||
|
code-theme = {
|
||||||
|
url = "https://raw.githubusercontent.com/catppuccin/bat/refs/heads/main/themes/Catppuccin%20Macchiato.tmTheme";
|
||||||
|
flake = false;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
outputs = { nixpkgs, flake-utils, rust-overlay, code-theme, ... }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
overlays = [ rust-overlay.overlays.default ];
|
||||||
|
pkgs = import nixpkgs {
|
||||||
|
inherit system overlays;
|
||||||
|
};
|
||||||
|
rust = pkgs.rust-bin.stable.latest.default;
|
||||||
|
openssl = pkgs.openssl;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
packages.default = pkgs.rustPlatform.buildRustPackage {
|
||||||
|
pname = "blog";
|
||||||
|
version = "0.1.0";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
THEME_PATH = "${code-theme}";
|
||||||
|
|
||||||
|
cargoLock = {
|
||||||
|
lockFile = ./Cargo.lock;
|
||||||
|
};
|
||||||
|
|
||||||
|
nativeBuildInputs = [
|
||||||
|
rust
|
||||||
|
pkgs.pkg-config
|
||||||
|
];
|
||||||
|
|
||||||
|
buildInputs = [
|
||||||
|
openssl
|
||||||
|
];
|
||||||
|
|
||||||
|
OPENSSL_LIB_DIR = "${openssl.out}/lib";
|
||||||
|
OPENSSL_INCLUDE_DIR = "${openssl.dev}/include";
|
||||||
|
PKG_CONFIG_PATH = "${openssl.dev}/lib/pkgconfig";
|
||||||
|
};
|
||||||
|
|
||||||
|
devShells.default = pkgs.mkShell {
|
||||||
|
packages = [
|
||||||
|
rust
|
||||||
|
pkgs.cargo
|
||||||
|
pkgs.rust-analyzer
|
||||||
|
pkgs.pkg-config
|
||||||
|
openssl
|
||||||
|
];
|
||||||
|
OPENSSL_DIR = openssl.dev;
|
||||||
|
PKG_CONFIG_PATH = "${openssl.dev}/lib/pkgconfig";
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -34,7 +34,8 @@ lazy_static! {
|
|||||||
pub static ref THEME_SET: ThemeSet = {
|
pub static ref THEME_SET: ThemeSet = {
|
||||||
let mut set = ThemeSet::load_defaults();
|
let mut set = ThemeSet::load_defaults();
|
||||||
|
|
||||||
let theme_bytes = include_bytes!("../themes/Catppuccin-Macchiato.tmTheme");
|
// let theme_bytes = include_bytes!("../themes/Catppuccin-Macchiato.tmTheme");
|
||||||
|
let theme_bytes = include_bytes!(env!("THEME_FILE_PATH"));
|
||||||
|
|
||||||
let mut cursor = Cursor::new(theme_bytes);
|
let mut cursor = Cursor::new(theme_bytes);
|
||||||
match syntect::highlighting::ThemeSet::load_from_reader(&mut cursor) {
|
match syntect::highlighting::ThemeSet::load_from_reader(&mut cursor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user