Skip to content

Commit

Permalink
feat: add nix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
justinrubek committed Feb 10, 2023
1 parent cded0bb commit 13b132c
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 3 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
result
result*
.direnv
.pre-commit-config.yaml
target
7 changes: 7 additions & 0 deletions Cargo.lock

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

7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[workspace]
members = ["crates/*"]
resolver = "2"

[profile.release]
# opt-level = 2 # fast and small wasm

11 changes: 11 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "cli"
version = "0.1.0"
edition = "2021"

[dependencies]
# clap = { version = "4.0.19", features = ["derive"] }
# reqwest = { version = "0.11.12", features = ["rustls-tls"] }
# serde = { version = "1", features = ["derive"] }
# serde_json = "1.0.87"
# tokio = { version = "1", features = ["full"] }
3 changes: 3 additions & 0 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}
123 changes: 123 additions & 0 deletions flake-parts/cargo.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
{
inputs,
self,
...
} @ part-inputs: {
imports = [];

perSystem = {
pkgs,
lib,
system,
inputs',
...
}: let
devTools = with pkgs; [
# rust tooling
fenix-toolchain
bacon
rustfmt
# misc
];

extraBuildInputs = [
pkgs.pkg-config
];
extraNativeBuildInputs = [
];

allBuildInputs = base: base ++ extraBuildInputs;
allNativeBuildInputs = base: base ++ extraNativeBuildInputs;

fenix-channel = inputs'.fenix.packages.latest;
fenix-toolchain = fenix-channel.withComponents [
"rustc"
"cargo"
"clippy"
"rust-analysis"
"rust-src"
"rustfmt"
"llvm-tools-preview"
];

craneLib = inputs.crane.lib.${system}.overrideToolchain fenix-toolchain;

common-build-args = rec {
src = inputs.nix-filter.lib {
root = ../.;
include = [
"crates"
"Cargo.toml"
"Cargo.lock"
];
};

pname = "thoenix";

buildInputs = allBuildInputs [];
nativeBuildInputs = allNativeBuildInputs [];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
};
deps-only = craneLib.buildDepsOnly ({} // common-build-args);

clippy-check = craneLib.cargoClippy ({
cargoArtifacts = deps-only;
cargoClippyExtraArgs = "--all-features -- --deny warnings";
}
// common-build-args);

rust-fmt-check = craneLib.cargoFmt ({
inherit (common-build-args) src;
}
// common-build-args);

tests-check = craneLib.cargoNextest ({
cargoArtifacts = deps-only;
partitions = 1;
partitionType = "count";
}
// common-build-args);

pre-commit-hooks = inputs.pre-commit-hooks.lib.${system}.run {
inherit (common-build-args) src;
hooks = {
alejandra.enable = true;
};
};

cli-package = craneLib.buildPackage ({
pname = "cli";
cargoArtifacts = deps-only;
cargoExtraArgs = "--bin cli";
}
// common-build-args);
in rec {
devShells.default = pkgs.mkShell rec {
buildInputs = allBuildInputs [fenix-toolchain] ++ devTools;
nativeBuildInputs = allNativeBuildInputs [];
LD_LIBRARY_PATH = pkgs.lib.makeLibraryPath buildInputs;
inherit (self.checks.${system}.pre-commit-hooks) shellHook;
};

packages = {
inherit fenix-toolchain;
default = packages.cli;
cli = cli-package;
};

apps = {
cli = {
type = "app";
program = "${self.packages.${system}.cli}/bin/cli";
};
default = apps.cli;
};

checks = {
inherit pre-commit-hooks;
clippy = clippy-check;
tests = tests-check;
rust-fmt = rust-fmt-check;
};
};
}
Loading

0 comments on commit 13b132c

Please sign in to comment.