Skip to content

Commit eb7de2d

Browse files
committed
chore: nix flake support
1 parent 5fc3b0d commit eb7de2d

File tree

8 files changed

+353
-33
lines changed

8 files changed

+353
-33
lines changed

.gitignore

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1+
# Output website
12
/dist/
2-
/target/
3+
4+
# Rust build directory
5+
/target
6+
7+
# Tailwindcss output
38
/style/output.css
9+
10+
# Nodejs
411
node_modules
5-
pnpm-lock.yaml
12+
pnpm-lock.yaml
13+
14+
# Nix
15+
/result

.vscode/settings.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
[package]
2-
name = "trunk-template"
2+
name = "rust-website"
33
version = "0.1.0"
44
edition = "2021"
5-
description = "Template for starting a Yew project using Trunk"
6-
readme = "README.md"
7-
repository = "https://github.com/yewstack/yew-trunk-minimal-template"
5+
description = "Website of Rust Uzbekistan"
6+
readme = "readme.md"
7+
repository = "https://github.com/rust-lang-uz/website"
88
license = "MIT OR Apache-2.0"
99
keywords = ["yew", "trunk"]
1010
categories = ["gui", "wasm", "web-programming"]
11+
homepage = "https://rust-lang.uz"
1112

1213
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1314
[dependencies]
@@ -16,13 +17,13 @@ js-sys = "0.3.65"
1617
uuid = { version = "1.5.0", features = ["v4"] }
1718
wasm-bindgen = "0.2.88"
1819
web-sys = { version = "0.3.65", features = [
19-
"Crypto",
20-
"Window",
21-
"DomRect",
22-
"Element",
23-
"EventTarget",
24-
"AddEventListenerOptions",
25-
"ScrollIntoViewOptions",
26-
"ScrollBehavior"
20+
"Crypto",
21+
"Window",
22+
"DomRect",
23+
"Element",
24+
"EventTarget",
25+
"AddEventListenerOptions",
26+
"ScrollIntoViewOptions",
27+
"ScrollBehavior",
2728
] }
28-
yew = { version="0.20", features=["csr"] }
29+
yew = { version = "0.20", features = ["csr"] }

default.nix

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{ pkgs ? import <nixpkgs> { }
2+
, fenix,
3+
}:
4+
let
5+
lib = pkgs.lib;
6+
getLibFolder = pkg: "${pkg}/lib";
7+
8+
toolchain = with fenix.packages.${pkgs.system};
9+
combine [
10+
stable.toolchain
11+
targets.wasm32-unknown-unknown.stable.rust-std
12+
];
13+
14+
15+
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
16+
in
17+
pkgs.rustPlatform.buildRustPackage {
18+
pname = "rust-website";
19+
version = manifest.version;
20+
cargoLock.lockFile = ./Cargo.lock;
21+
src = pkgs.lib.cleanSource ./.;
22+
23+
nativeBuildInputs = with pkgs; [
24+
# LLVM & GCC
25+
gcc
26+
cmake
27+
gnumake
28+
pkg-config
29+
llvmPackages.llvm
30+
llvmPackages.clang
31+
llvmPackages.bintools
32+
33+
# Tailwindcss
34+
tailwindcss
35+
36+
# Rust
37+
rustc
38+
cargo
39+
trunk
40+
clippy
41+
libiconv
42+
toolchain
43+
wasm-pack
44+
pkg-config
45+
rust-analyzer
46+
wasm-bindgen-cli
47+
];
48+
49+
buildInputs = with pkgs; [
50+
openssl
51+
libressl
52+
];
53+
54+
buildPhase = ''
55+
# Build the css
56+
tailwindcss -i ./style/input.css -o ./style/output.css
57+
58+
# Wasm-bindgen nigga can't build without storing cache at HOME
59+
export HOME="$(pwd)/home"
60+
mkdir -p $HOME
61+
62+
# Create the dist folder
63+
cargo build --release
64+
65+
# Build wasm webiste
66+
trunk build --release
67+
'';
68+
69+
installPhase = ''
70+
# Create out directory
71+
mkdir -p $out/www
72+
73+
# Move all finished content
74+
mv ./dist/* $out/www
75+
'';
76+
77+
# If you wanna get thorny
78+
# RUST_BACKTRACE = 1;
79+
NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)}";
80+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
81+
pkgs.gcc
82+
pkgs.libiconv
83+
pkgs.llvmPackages.llvm
84+
];
85+
CARGO_TARGET_WASM32_UNKNOWN_UNKNOWN_LINKER = "lld";
86+
87+
meta = with lib; {
88+
homepage = manifest.package.homepage;
89+
description = "Website of Rust Uzbekistan community";
90+
license = with lib.licenses; [ gpl3Only ];
91+
92+
platforms = with platforms; linux ++ darwin;
93+
94+
maintainers = [
95+
{
96+
name = "Sokhibjon Orzikulov";
97+
email = "sakhib@orzklv.uz";
98+
handle = "orzklv";
99+
github = "orzklv";
100+
githubId = 54666588;
101+
keys = [
102+
{
103+
fingerprint = "00D2 7BC6 8707 0683 FBB9 137C 3C35 D3AF 0DA1 D6A8";
104+
}
105+
];
106+
}
107+
];
108+
};
109+
}

flake.lock

Lines changed: 100 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
description = "Website for Rust Uzbekistan community";
3+
4+
inputs = {
5+
# Too old to work with most libraries
6+
# nixpkgs.url = "github:nixos/nixpkgs/nixos-24.05";
7+
8+
# Perfect!
9+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
10+
11+
# The flake-utils library
12+
flake-utils.url = "github:numtide/flake-utils";
13+
14+
# Additional helper Rust toolchain management
15+
fenix = {
16+
url = "github:nix-community/fenix";
17+
inputs.nixpkgs.follows = "nixpkgs";
18+
};
19+
};
20+
21+
outputs = {
22+
nixpkgs,
23+
fenix,
24+
flake-utils,
25+
...
26+
}:
27+
flake-utils.lib.eachDefaultSystem
28+
(
29+
system: let
30+
pkgs = nixpkgs.legacyPackages.${system};
31+
in {
32+
# Nix script formatter
33+
formatter = pkgs.alejandra;
34+
35+
# Development environment
36+
devShells.default = import ./shell.nix {inherit pkgs fenix;};
37+
38+
# Output package
39+
packages.default = pkgs.callPackage ./. {inherit pkgs fenix;};
40+
}
41+
)
42+
// {
43+
# Overlay module
44+
# nixosModules.xinux.bot = import ./module.nix self;
45+
};
46+
}

0 commit comments

Comments
 (0)