feat(nix): set up flake-compat

This commit is contained in:
Harsh Shandilya 2023-02-16 14:26:30 +00:00
parent 4d035126a5
commit 6c7ce91a48
4 changed files with 83 additions and 52 deletions

8
default.nix Normal file
View File

@ -0,0 +1,8 @@
(import (let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) {src = ./.;})
.defaultNix

View File

@ -18,7 +18,9 @@
},
"crane": {
"inputs": {
"flake-compat": "flake-compat",
"flake-compat": [
"flake-compat"
],
"flake-utils": [
"flake-utils"
],
@ -94,6 +96,7 @@
"inputs": {
"advisory-db": "advisory-db",
"crane": "crane",
"flake-compat": "flake-compat",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"rust-overlay": "rust-overlay"

114
flake.nix
View File

@ -2,10 +2,12 @@
description = "text-editor";
inputs = {
nixpkgs = { url = "github:NixOS/nixpkgs/nixpkgs-unstable"; };
flake-utils = { url = "github:numtide/flake-utils"; };
nixpkgs = {url = "github:NixOS/nixpkgs/nixpkgs-unstable";};
flake-utils = {url = "github:numtide/flake-utils";};
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs = {
@ -13,71 +15,81 @@
flake-utils.follows = "flake-utils";
};
};
crane = {
url = "github:ipetkov/crane";
inputs = {
flake-utils.follows = "flake-utils";
flake-compat.follows = "flake-compat";
nixpkgs.follows = "nixpkgs";
rust-overlay.follows = "rust-overlay";
};
};
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs =
{ self, nixpkgs, crane, flake-utils, advisory-db, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
outputs = {
self,
nixpkgs,
crane,
flake-utils,
advisory-db,
rust-overlay,
...
}:
flake-utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs {
inherit system;
overlays = [(import rust-overlay)];
};
rustStable =
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustStable;
src = ./.;
cargoArtifacts = craneLib.buildDepsOnly { inherit src buildInputs; };
buildInputs = [ ];
rustStable =
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain rustStable;
src = ./.;
cargoArtifacts = craneLib.buildDepsOnly {inherit src buildInputs;};
buildInputs = [];
text-editor = craneLib.buildPackage {
inherit src;
doCheck = false;
};
text-editor-clippy = craneLib.cargoClippy {
inherit cargoArtifacts src buildInputs;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};
text-editor-fmt = craneLib.cargoFmt { inherit src; };
text-editor-audit = craneLib.cargoAudit { inherit src advisory-db; };
text-editor-nextest = craneLib.cargoNextest {
inherit cargoArtifacts src buildInputs;
partitions = 1;
partitionType = "count";
};
in {
checks = {
inherit text-editor text-editor-audit text-editor-clippy
text-editor-fmt text-editor-nextest;
};
text-editor = craneLib.buildPackage {
inherit src;
doCheck = false;
};
text-editor-clippy = craneLib.cargoClippy {
inherit cargoArtifacts src buildInputs;
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
};
text-editor-fmt = craneLib.cargoFmt {inherit src;};
text-editor-audit = craneLib.cargoAudit {inherit src advisory-db;};
text-editor-nextest = craneLib.cargoNextest {
inherit cargoArtifacts src buildInputs;
partitions = 1;
partitionType = "count";
};
in {
checks = {
inherit
text-editor
text-editor-audit
text-editor-clippy
text-editor-fmt
text-editor-nextest
;
};
packages.default = text-editor;
packages.default = text-editor;
apps.default = flake-utils.lib.mkApp { drv = text-editor; };
apps.default = flake-utils.lib.mkApp {drv = text-editor;};
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks;
devShells.default = pkgs.mkShell {
inputsFrom = builtins.attrValues self.checks;
nativeBuildInputs = with pkgs; [
cargo-nextest
cargo-release
rustStable
];
};
});
nativeBuildInputs = with pkgs; [
cargo-nextest
cargo-release
rustStable
];
};
});
}

8
shell.nix Normal file
View File

@ -0,0 +1,8 @@
(import (let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz";
sha256 = lock.nodes.flake-compat.locked.narHash;
}) {src = ./.;})
.shellNix