Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Nix flake #142

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
output.log
.direnv
96 changes: 96 additions & 0 deletions flake.lock

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

78 changes: 78 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
crane.url = "github:ipetkov/crane";
crane.inputs.nixpkgs.follows = "nixpkgs";
advisory-db.url = "github:rustsec/advisory-db";
advisory-db.flake = false;
};

outputs = inputs @ {
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux"];

perSystem = {
config,
pkgs,
system,
inputs',
self',
...
}: let
pkgs = nixpkgs.legacyPackages.${system};
advisory-db = inputs.advisory-db;
craneLib = inputs.crane.mkLib pkgs;

runtimeInputs = with pkgs; [glib vips];
nativeBuildInputs = with pkgs; [openssl pkg-config];
src = craneLib.cleanCargoSource ./.;

ore-cli = craneLib.buildPackage {
inherit src nativeBuildInputs;
doCheck = false;
buildInputs = runtimeInputs;
};

cargoArtifacts = craneLib.buildDepsOnly {inherit src nativeBuildInputs;};

in {
checks = {
inherit ore-cli;

# Clippy
ore-cli-clippy = craneLib.cargoClippy {
inherit cargoArtifacts src;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};

# Check formatting
ore-cli-fmt = craneLib.cargoFmt {inherit src;};

# Audit dependencies
ore-cli-audit = craneLib.cargoAudit {inherit src advisory-db;};

# Run tests with cargo-nextest
ore-cli-nextest = craneLib.cargoNextest {
inherit cargoArtifacts src;
buildInputs = runtimeInputs; # needed for tests
partitions = 1;
partitionType = "count";
};
};

packages = {
default = ore-cli;
};

devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self'.checks;
packages = runtimeInputs ++ nativeBuildInputs;
};
};
};
}