From 6c7ce91a4884fe520f85eeeb6adbf5f3b15381fc Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 16 Feb 2023 14:26:30 +0000 Subject: [PATCH] feat(nix): set up flake-compat --- default.nix | 8 ++++ flake.lock | 5 ++- flake.nix | 114 +++++++++++++++++++++++++++++----------------------- shell.nix | 8 ++++ 4 files changed, 83 insertions(+), 52 deletions(-) create mode 100644 default.nix create mode 100644 shell.nix diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..674a56e --- /dev/null +++ b/default.nix @@ -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 diff --git a/flake.lock b/flake.lock index 1895a5b..0dfd429 100644 --- a/flake.lock +++ b/flake.lock @@ -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" diff --git a/flake.nix b/flake.nix index fd5c8f0..8b64663 100644 --- a/flake.nix +++ b/flake.nix @@ -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 + ]; + }; + }); } diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..98958bc --- /dev/null +++ b/shell.nix @@ -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