Skip to content

Commit

Permalink
chore: nix flake support
Browse files Browse the repository at this point in the history
  • Loading branch information
orzklv committed Dec 22, 2024
1 parent 5fc3b0d commit eb7de2d
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 33 deletions.
14 changes: 12 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Output website
/dist/
/target/

# Rust build directory
/target

# Tailwindcss output
/style/output.css

# Nodejs
node_modules
pnpm-lock.yaml
pnpm-lock.yaml

# Nix
/result
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

26 changes: 13 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[package]
name = "trunk-template"
name = "rust-website"
version = "0.1.0"
edition = "2021"
description = "Template for starting a Yew project using Trunk"
readme = "README.md"
repository = "https://github.com/yewstack/yew-trunk-minimal-template"
description = "Website of Rust Uzbekistan"
readme = "readme.md"
repository = "https://github.com/rust-lang-uz/website"
license = "MIT OR Apache-2.0"
keywords = ["yew", "trunk"]
categories = ["gui", "wasm", "web-programming"]
homepage = "https://rust-lang.uz"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Expand All @@ -16,13 +17,13 @@ js-sys = "0.3.65"
uuid = { version = "1.5.0", features = ["v4"] }
wasm-bindgen = "0.2.88"
web-sys = { version = "0.3.65", features = [
"Crypto",
"Window",
"DomRect",
"Element",
"EventTarget",
"AddEventListenerOptions",
"ScrollIntoViewOptions",
"ScrollBehavior"
"Crypto",
"Window",
"DomRect",
"Element",
"EventTarget",
"AddEventListenerOptions",
"ScrollIntoViewOptions",
"ScrollBehavior",
] }
yew = { version="0.20", features=["csr"] }
yew = { version = "0.20", features = ["csr"] }
109 changes: 109 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{ pkgs ? import <nixpkgs> { }
, fenix,
}:
let
lib = pkgs.lib;
getLibFolder = pkg: "${pkg}/lib";

toolchain = with fenix.packages.${pkgs.system};
combine [
stable.toolchain
targets.wasm32-unknown-unknown.stable.rust-std
];


manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
in
pkgs.rustPlatform.buildRustPackage {
pname = "rust-website";
version = manifest.version;
cargoLock.lockFile = ./Cargo.lock;
src = pkgs.lib.cleanSource ./.;

nativeBuildInputs = with pkgs; [
# LLVM & GCC
gcc
cmake
gnumake
pkg-config
llvmPackages.llvm
llvmPackages.clang
llvmPackages.bintools

# Tailwindcss
tailwindcss

# Rust
rustc
cargo
trunk
clippy
libiconv
toolchain
wasm-pack
pkg-config
rust-analyzer
wasm-bindgen-cli
];

buildInputs = with pkgs; [
openssl
libressl
];

buildPhase = ''
# Build the css
tailwindcss -i ./style/input.css -o ./style/output.css
# Wasm-bindgen nigga can't build without storing cache at HOME
export HOME="$(pwd)/home"
mkdir -p $HOME
# Create the dist folder
cargo build --release
# Build wasm webiste
trunk build --release
'';

installPhase = ''
# Create out directory
mkdir -p $out/www
# Move all finished content
mv ./dist/* $out/www
'';

# If you wanna get thorny
# RUST_BACKTRACE = 1;
NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)}";
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
pkgs.gcc
pkgs.libiconv
pkgs.llvmPackages.llvm
];
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld";

meta = with lib; {
homepage = manifest.package.homepage;
description = "Website of Rust Uzbekistan community";
license = with lib.licenses; [ gpl3Only ];

platforms = with platforms; linux ++ darwin;

maintainers = [
{
name = "Sokhibjon Orzikulov";
email = "sakhib@orzklv.uz";
handle = "orzklv";
github = "orzklv";
githubId = 54666588;
keys = [
{
fingerprint = "00D2 7BC6 8707 0683 FBB9 137C 3C35 D3AF 0DA1 D6A8";
}
];
}
];
};
}
100 changes: 100 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 46 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
description = "Website for Rust Uzbekistan community";

inputs = {
# Too old to work with most libraries
# nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";

# Perfect!
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

# The flake-utils library
flake-utils.url = "github:numtide/flake-utils";

# Additional helper Rust toolchain management
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
nixpkgs,
fenix,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem
(
system: let
pkgs = nixpkgs.legacyPackages.${system};
in {
# Nix script formatter
formatter = pkgs.alejandra;

# Development environment
devShells.default = import ./shell.nix {inherit pkgs fenix;};

# Output package
packages.default = pkgs.callPackage ./. {inherit pkgs fenix;};
}
)
// {
# Overlay module
# nixosModules.xinux.bot = import ./module.nix self;
};
}
Loading

0 comments on commit eb7de2d

Please sign in to comment.