From a4855b834f27675243dde04a6b83882d1986d072 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Thu, 16 Feb 2023 14:08:24 +0000 Subject: [PATCH] feat: migrate to Nix Flakes --- default.nix | 8 ++++ flake.lock | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 102 ++++++++++++++++++++++++++++++++++++++++ shell.nix | 25 ++++------ 4 files changed, 249 insertions(+), 17 deletions(-) create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.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 new file mode 100644 index 0000000..0dfd429 --- /dev/null +++ b/flake.lock @@ -0,0 +1,131 @@ +{ + "nodes": { + "advisory-db": { + "flake": false, + "locked": { + "lastModified": 1676378311, + "narHash": "sha256-PVHBALbhX3fSOeOTXQA+VIqLuuZefVIK5jnnGFQmaaM=", + "owner": "rustsec", + "repo": "advisory-db", + "rev": "0e63414bd16551677ee717de97dbd8df97caf732", + "type": "github" + }, + "original": { + "owner": "rustsec", + "repo": "advisory-db", + "type": "github" + } + }, + "crane": { + "inputs": { + "flake-compat": [ + "flake-compat" + ], + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ], + "rust-overlay": [ + "rust-overlay" + ] + }, + "locked": { + "lastModified": 1676515499, + "narHash": "sha256-Qk9kVSAT/Iz2AwrtnOfCih6KB2Odu4mN8fBvRjiMdZ0=", + "owner": "ipetkov", + "repo": "crane", + "rev": "cfb6efcfc706e21c84682171581168e591b265d9", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1676283394, + "narHash": "sha256-XX2f9c3iySLCw54rJ/CZs+ZK6IQy7GXNY4nSOyu2QG4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3db36a8b464d0c4532ba1c7dda728f4576d6d073", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1676487294, + "narHash": "sha256-fbD0tVsowxAUXwfw2C9EdEAH8UEJNsCm0zJcfkJy3Pg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "63b5955814db30d2e2ff7157aaa5665b502ed2f4", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "advisory-db": "advisory-db", + "crane": "crane", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1676514619, + "narHash": "sha256-/zVNJdETe/7txiP8NVjAjrAPudLIvjKJWgztuTi75Qw=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "3bab7ae4a80de02377005d611dc4b0a13082aa7c", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e709593 --- /dev/null +++ b/flake.nix @@ -0,0 +1,102 @@ +{ + description = "gitice"; + + inputs = { + 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 = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + }; + + crane = { + url = "github:ipetkov/crane"; + inputs = { + flake-compat.follows = "flake-compat"; + flake-utils.follows = "flake-utils"; + 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)]; + }; + + rustStable = + pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + craneLib = (crane.mkLib pkgs).overrideToolchain rustStable; + src = ./.; + nativeBuildInputs = with pkgs; + [ + perl + pkg-config + openssl + ]; + buildInputs = [pkgs.openssl] ++ pkgs.lib.optionals pkgs.stdenv.isDarwin + [pkgs.darwin.apple_sdk.frameworks.Security]; + cargoArtifacts = craneLib.buildDepsOnly {inherit src buildInputs nativeBuildInputs;}; + + gitice = craneLib.buildPackage { + inherit src buildInputs nativeBuildInputs; + doCheck = false; + }; + gitice-clippy = craneLib.cargoClippy { + inherit cargoArtifacts src buildInputs nativeBuildInputs; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }; + gitice-fmt = craneLib.cargoFmt {inherit src;}; + gitice-audit = + craneLib.cargoAudit {inherit src advisory-db;}; + gitice-nextest = craneLib.cargoNextest { + inherit cargoArtifacts src buildInputs nativeBuildInputs; + partitions = 1; + partitionType = "count"; + }; + in { + checks = { + inherit gitice gitice-audit gitice-clippy gitice-fmt gitice-nextest; + }; + + packages.default = gitice; + + apps.default = flake-utils.lib.mkApp {drv = gitice;}; + + devShells.default = pkgs.mkShell { + inputsFrom = builtins.attrValues self.checks; + + nativeBuildInputs = with pkgs; [ + cargo-nextest + cargo-release + rustStable + ]; + }; + }); +} diff --git a/shell.nix b/shell.nix index ad67780..98958bc 100644 --- a/shell.nix +++ b/shell.nix @@ -1,17 +1,8 @@ -with import { overlays = [ (import ) ]; }; -mkShell { - buildInputs = [ - (rust-bin.stable.latest.default.override { - extensions = - [ "rust-src" "rustc-dev" "rustfmt-preview" "llvm-tools-preview" ]; - targets = - pkgs.lib.optionals pkgs.stdenv.isDarwin [ "aarch64-apple-darwin" ] - ++ pkgs.lib.optionals pkgs.stdenv.isLinux - [ "x86_64-unknown-linux-gnu" ]; - }) - pkg-config - openssl - clang_13 - ] ++ lib.optionals stdenv.isDarwin - [ pkgs.darwin.apple_sdk.frameworks.Security ]; -} +(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