Skip to content

Commit

Permalink
Merge pull request #87 from dotboris/flake-revamp
Browse files Browse the repository at this point in the history
Improve the flake
  • Loading branch information
dotboris authored Feb 3, 2024
2 parents 7093c35 + 52b7451 commit 05ae1cf
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 109 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo clippy --version
- run: cargo clippy --all-targets --all-features -- -D warnings

nix-flake-check:
name: nix flake check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v25
with:
# Helps avoid rate limiting
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- run: nix flake check -L --all-systems --keep-going
41 changes: 0 additions & 41 deletions .github/workflows/nix.yml

This file was deleted.

48 changes: 22 additions & 26 deletions flake.lock

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

88 changes: 46 additions & 42 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,55 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay/stable";
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};

# Flake outputs
outputs = { self, nixpkgs, rust-overlay, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
# Overlays enable you to customize the Nixpkgs attribute set
overlays = [
# Makes a `rust-bin` attribute available in Nixpkgs
(import rust-overlay)
# Provides a `rustToolchain` attribute for Nixpkgs that we can use to
# create a Rust environment
(self: super: {
rustToolchain = super.rust-bin.stable.latest.default;
})
];
pkgs = import nixpkgs { inherit system overlays; };
in
{
packages = {
default = pkgs.rustPlatform.buildRustPackage {
name = "cdo";
src = ./.;
cargoLock = { lockFile = ./Cargo.lock; };
};
};
outputs = {
self,
nixpkgs,
crane,
flake-utils,
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
craneLib = crane.mkLib pkgs;

# Development environment output
devShells = {
default = pkgs.mkShell {
# The Nix packages provided in the environment
packages = (with pkgs; [
# The usual suite for rust tools including cargo, Clippy,
# cargo-fmt rustdoc, rustfmt, and other tools.
rustToolchain
# To format this file (how meta)
nixpkgs-fmt
]) ++ pkgs.lib.optionals pkgs.stdenv.isDarwin
(with pkgs; [ libiconv ]);
};
};
});
src = craneLib.cleanCargoSource (craneLib.path ./.);
commonArgs = {
inherit src;
strictDeps = true;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
cdo = craneLib.buildPackage (commonArgs
// {
inherit cargoArtifacts;
});
in {
formatter = pkgs.alejandra;

packages.default = cdo;

checks = {
inherit cdo;
clippy = craneLib.cargoClippy (commonArgs // {inherit cargoArtifacts;});
test = craneLib.cargoTest (commonArgs // {inherit cargoArtifacts;});
rustfmt = craneLib.cargoFmt {inherit src;};
alejandra =
pkgs.runCommand "alejandra" {
buildInputs = [pkgs.alejandra];
} ''
alejandra -c ${./.}
mkdir $out
'';
};

devShells.default = craneLib.devShell {
checks = self.checks.${system};
# Ensure `rust-analyzer` has access to the rust source code.
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
};
});
}

0 comments on commit 05ae1cf

Please sign in to comment.