Skip to content

Commit 8a1af4a

Browse files
committed
init: starting new repo for a proc macro
1 parent 00c695f commit 8a1af4a

File tree

10 files changed

+380
-0
lines changed

10 files changed

+380
-0
lines changed

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.github/workflows/test.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Test CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
test-flake:
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Check out the repository
11+
uses: actions/checkout@v4
12+
13+
- name: Install Nix
14+
uses: DeterminateSystems/nix-installer-action@main
15+
16+
- name: Cache Nix store
17+
uses: DeterminateSystems/magic-nix-cache-action@main
18+
19+
- name: Check up flake configuration
20+
run: nix flake check --all-systems --show-trace
21+
22+
test-image:
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Check out the repository
27+
uses: actions/checkout@v4
28+
29+
- name: Install Nix
30+
uses: DeterminateSystems/nix-installer-action@main
31+
32+
- name: Cache Nix store
33+
uses: DeterminateSystems/magic-nix-cache-action@main
34+
35+
- name: Test project
36+
run: nix build
37+
38+
- name: Test project
39+
run: nix develop --command -- cargo test

Cargo.lock

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

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "template"
3+
version = "0.1.0"
4+
edition = "2021"
5+
homepage = "https://github.com/xinux-org/templates"
6+
repository = "https://github.com/xinux-org/templates"
7+
description = "Just a Rust template via nix flakes"
8+
9+
# Dependencies that will included with final binary
10+
[dependencies]
11+
12+
# Development dependencies which aren't used in release binary
13+
[dev-dependencies]
14+
15+
# Optimize release binary as much as possible
16+
[profile.release]
17+
strip = true
18+
opt-level = "z"
19+
lto = true
20+
codegen-units = 1

default.nix

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
{
2+
pkgs ? import <nixpkgs> {},
3+
fenix ? import <fenix> {},
4+
}: let
5+
# Helpful nix function
6+
lib = pkgs.lib;
7+
getLibFolder = pkg: "${pkg}/lib";
8+
9+
# Manifest via Cargo.toml
10+
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
11+
12+
# Rust Toolchain via fenix
13+
toolchain = fenix.packages.${pkgs.system}.fromToolchainFile {
14+
file = ./rust-toolchain.toml;
15+
16+
# Don't worry, if you need sha256 of your toolchain,
17+
# just run `nix build` and copy paste correct sha256.
18+
sha256 = "sha256-vMlz0zHduoXtrlu0Kj1jEp71tYFXyymACW8L4jzrzNA=";
19+
};
20+
in
21+
pkgs.rustPlatform.buildRustPackage {
22+
# Package related things automatically
23+
# obtained from Cargo.toml, so you don't
24+
# have to do everything manually
25+
pname = manifest.name;
26+
version = manifest.version;
27+
28+
# Your govnocodes
29+
src = pkgs.lib.cleanSource ./.;
30+
31+
cargoLock = {
32+
lockFile = ./Cargo.lock;
33+
# Use this if you have dependencies from git instead
34+
# of crates.io in your Cargo.toml
35+
# outputHashes = {
36+
# # Sha256 of the git repository, doesn't matter if it's monorepo
37+
# "example-0.1.0" = "sha256-80EwvwMPY+rYyti8DMG4hGEpz/8Pya5TGjsbOBF0P0c=";
38+
# };
39+
};
40+
41+
# Compile time dependencies
42+
nativeBuildInputs = with pkgs; [
43+
# GCC toolchain
44+
gcc
45+
gnumake
46+
pkg-config
47+
48+
# LLVM toolchain
49+
cmake
50+
llvmPackages.llvm
51+
llvmPackages.clang
52+
53+
# Rust
54+
toolchain
55+
56+
# Other compile time dependencies
57+
# here
58+
];
59+
60+
# Runtime dependencies which will be shipped
61+
# with nix package
62+
buildInputs = with pkgs; [
63+
# openssl
64+
# libressl
65+
];
66+
67+
# Set Environment Variables
68+
RUST_BACKTRACE = 1;
69+
70+
# Compiler LD variables
71+
NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)}";
72+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
73+
pkgs.gcc
74+
pkgs.libiconv
75+
pkgs.llvmPackages.llvm
76+
];
77+
78+
meta = with lib; {
79+
homepage = manifest.homepage;
80+
description = manifest.description;
81+
license = with lib.licenses; [asl20 mit];
82+
platforms = with platforms; linux ++ darwin;
83+
84+
maintainers = [
85+
{
86+
name = "Example";
87+
email = "[email protected]";
88+
handle = "example";
89+
github = "example";
90+
githubId = 00000000;
91+
keys = [
92+
{
93+
fingerprint = "0000 0000 0000 0000 0000 0000 0000 0000 0000 0000";
94+
}
95+
];
96+
}
97+
];
98+
};
99+
}

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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
description = "A Rust project bootstrapped with github:xinux-org/templates";
3+
4+
inputs = {
5+
# Stable for keeping thins clean
6+
# nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
7+
8+
# Fresh and new for testing
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+
# Rust toolchain shit
15+
fenix = {
16+
url = "github:nix-community/fenix";
17+
inputs.nixpkgs.follows = "nixpkgs";
18+
};
19+
};
20+
21+
outputs = {
22+
self,
23+
nixpkgs,
24+
flake-utils,
25+
fenix,
26+
...
27+
} @ inputs:
28+
flake-utils.lib.eachDefaultSystem (system: let
29+
pkgs = nixpkgs.legacyPackages.${system};
30+
in {
31+
# Nix script formatter
32+
formatter = pkgs.alejandra;
33+
34+
# Development environment
35+
devShells.default = import ./shell.nix {inherit pkgs fenix;};
36+
37+
# Output package
38+
packages.default = pkgs.callPackage ./. {inherit pkgs fenix;};
39+
});
40+
}

rust-toolchain.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "stable"
3+
components = ["rust-src", "rustfmt", "rust-analyzer", "rust-std", "clippy"]

shell.nix

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
pkgs ? import <nixpkgs> {},
3+
fenix ? import <fenix> {},
4+
}: let
5+
# Helpful nix function
6+
getLibFolder = pkg: "${pkg}/lib";
7+
8+
# Rust Toolchain via fenix
9+
toolchain = fenix.packages.${pkgs.system}.fromToolchainFile {
10+
file = ./rust-toolchain.toml;
11+
12+
# Don't worry, if you need sha256 of your toolchain,
13+
# just run `nix build` and copy paste correct sha256.
14+
sha256 = "sha256-vMlz0zHduoXtrlu0Kj1jEp71tYFXyymACW8L4jzrzNA=";
15+
};
16+
in
17+
pkgs.stdenv.mkDerivation {
18+
name = "template-dev";
19+
20+
# Compile time dependencies
21+
nativeBuildInputs = with pkgs; [
22+
# GCC toolchain
23+
gcc
24+
gnumake
25+
pkg-config
26+
27+
# LLVM toolchain
28+
cmake
29+
llvmPackages.llvm
30+
llvmPackages.clang
31+
32+
# Hail the Nix
33+
nixd
34+
statix
35+
deadnix
36+
alejandra
37+
38+
# Rust
39+
toolchain
40+
cargo-watch
41+
42+
# Other compile time dependencies
43+
# here
44+
];
45+
46+
# Runtime dependencies which will be shipped
47+
# with nix package
48+
buildInputs = with pkgs; [
49+
# openssl
50+
# libressl
51+
];
52+
53+
# Set Environment Variables
54+
RUST_BACKTRACE = "full";
55+
56+
# Compiler LD variables
57+
# > Make sure packages have /lib or /include path'es
58+
NIX_LDFLAGS = "-L${(getLibFolder pkgs.libiconv)}";
59+
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath [
60+
pkgs.gcc
61+
pkgs.libiconv
62+
pkgs.llvmPackages.llvm
63+
];
64+
65+
shellHook = ''
66+
# Extra steps
67+
'';
68+
}

src/main.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
println!("Hello, world!");
3+
}

0 commit comments

Comments
 (0)