Skip to content

Commit

Permalink
nix flake with nightly, stable, and msrv devshells
Browse files Browse the repository at this point in the history
an .envrc file that uses the flake is provided for convenience

also includes nix formatting using alejandra, and a flake check that
enforces formatting of nix code
  • Loading branch information
nothingmuch committed Jan 2, 2025
1 parent d940ed2 commit bab0756
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake .
82 changes: 82 additions & 0 deletions flake.lock

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

70 changes: 70 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
description = "rust-payjoin";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = {
self,
nixpkgs,
flake-utils,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};

msrv = "1.63.0";
rustVersions = with pkgs.rust-bin;
builtins.mapAttrs (_name: rust-bin:
rust-bin.override {
extensions = ["rust-src" "rustfmt"];
})
{
msrv = stable.${msrv}.default;
stable = stable.latest.default;
nightly = nightly.latest.default;
};

mkShell = rust-bin:
pkgs.mkShell {
packages = with pkgs; [
(rust-bin.override {
extensions = ["rust-src" "rustfmt"];
})
];
};
devShells = builtins.mapAttrs (_name: rustVersion: mkShell rustVersion) rustVersions;

simpleCheck = args:
pkgs.stdenvNoCC.mkDerivation ({
doCheck = true;
dontFixup = true;
installPhase = "mkdir $out";
}
// args);
in {
devShells = devShells // {default = devShells.nightly;};
formatter = pkgs.alejandra;
checks = {
nix-fmt-check = simpleCheck {
name = "nix-fmt-check";
src = pkgs.lib.sources.sourceFilesBySuffices ./. [".nix"];
nativeBuildInputs = [pkgs.alejandra];
checkPhase = ''
alejandra -c .
'';
};
};
}
);
}

0 comments on commit bab0756

Please sign in to comment.