From a1886854d9fa5f02fe755352b44f6aabf2711514 Mon Sep 17 00:00:00 2001 From: Akshay Date: Tue, 19 Oct 2021 20:39:11 +0530 Subject: fix flake builds --- flake.lock | 77 ++++++++++++-------------------------- flake.nix | 122 ++++++++++++++++++++++++++++++++++++------------------------- notes.txt | 1 + 3 files changed, 96 insertions(+), 104 deletions(-) diff --git a/flake.lock b/flake.lock index 54aabdc..e8d9eb6 100644 --- a/flake.lock +++ b/flake.lock @@ -16,6 +16,21 @@ "type": "github" } }, + "import-cargo": { + "locked": { + "lastModified": 1594305518, + "narHash": "sha256-frtArgN42rSaEcEOYWg8sVPMUK+Zgch3c+wejcpX3DY=", + "owner": "edolstra", + "repo": "import-cargo", + "rev": "25d40be4a73d40a2572e0cc233b83253554f06c5", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "import-cargo", + "type": "github" + } + }, "mozillapkgs": { "flake": false, "locked": { @@ -32,74 +47,28 @@ "type": "github" } }, - "naersk": { - "inputs": { - "nixpkgs": "nixpkgs" - }, - "locked": { - "lastModified": 1631004250, - "narHash": "sha256-LGh0CjAZwh13AVkTi9w9lITEC7x6bwSQyFViOZ6HyNo=", - "owner": "nmattia", - "repo": "naersk", - "rev": "08afb3d1dbfe016108b72e05b02ba0f6ecb3c8e1", - "type": "github" - }, - "original": { - "owner": "nmattia", - "repo": "naersk", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1631279684, - "narHash": "sha256-IxRRCEW+8crDkbYj+uzwkfjZ8swugtnAmfRpPOpKq6I=", - "owner": "NixOS", + "lastModified": 1633422745, + "narHash": "sha256-gA6Ok64nPbkjHk3Oanq4641EeYkjcKhisDF9wBjLxEk=", + "owner": "nixos", "repo": "nixpkgs", - "rev": "ded7b6cb1bf3d6d03328b3f592069f2c4956a97f", + "rev": "8e1eab9eae4278c9bb1dcae426848a581943db5a", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" - } - }, - "nixpkgs_2": { - "locked": { - "lastModified": 1631279684, - "narHash": "sha256-IxRRCEW+8crDkbYj+uzwkfjZ8swugtnAmfRpPOpKq6I=", - "owner": "NixOS", + "owner": "nixos", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", - "rev": "ded7b6cb1bf3d6d03328b3f592069f2c4956a97f", "type": "github" - }, - "original": { - "id": "nixpkgs", - "type": "indirect" } }, "root": { "inputs": { "flake-compat": "flake-compat", + "import-cargo": "import-cargo", "mozillapkgs": "mozillapkgs", - "naersk": "naersk", - "nixpkgs": "nixpkgs_2", - "utils": "utils" - } - }, - "utils": { - "locked": { - "lastModified": 1629481132, - "narHash": "sha256-JHgasjPR0/J1J3DRm4KxM4zTyAj4IOJY8vIl75v/kPI=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "997f7efcb746a9c140ce1f13c72263189225f482", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" + "nixpkgs": "nixpkgs" } } }, diff --git a/flake.nix b/flake.nix index 82d7a1f..f7f62aa 100644 --- a/flake.nix +++ b/flake.nix @@ -1,80 +1,102 @@ { inputs = { - utils.url = "github:numtide/flake-utils"; - naersk.url = "github:nmattia/naersk"; + + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + mozillapkgs = { url = "github:mozilla/nixpkgs-mozilla"; flake = false; }; + flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; + + import-cargo.url = github:edolstra/import-cargo; + }; outputs = { self , nixpkgs - , utils - , naersk , mozillapkgs + , import-cargo , ... }: - utils.lib.eachDefaultSystem (system: let - pkgs = nixpkgs.legacyPackages."${system}"; - - # Get a specific rust version - mozilla = pkgs.callPackage (mozillapkgs + "/package-set.nix") { }; + inherit (import-cargo.builders) importCargo; + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: + import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }); + mozilla = p: p.callPackage (mozillapkgs + "/package-set.nix") { }; chanspec = { - date = "2021-03-31"; + date = "2021-09-30"; channel = "nightly"; - sha256 = "oK5ebje09MRn988saJMT3Zze/tRE7u9zTeFPV1CEeLc="; # set zeros after modifying channel or date + sha256 = "Elqn7GDBDE/QT1XTDyj0EvivbC//uwjWX8d+J3Pi0dY="; # set zeros after modifying channel or date }; + in + { - rustChannel = mozilla.rustChannelOf chanspec; - rust = rustChannel.rust; - rust-src = rustChannel.rust-src; + overlay = final: prev: + let + rustChannel = (mozilla final.pkgs).rustChannelOf chanspec; + inherit (rustChannel) rust rustc rust-src; + in + { - naersk-lib = naersk.lib."${system}".override { - cargo = rust; - rustc = rust; - }; + statix = with final; pkgs.stdenv.mkDerivation { + pname = "statix"; + version = "v0.1.0"; + src = ./.; + nativeBuildInputs = [ + (importCargo { lockFile = ./Cargo.lock; inherit pkgs; }).cargoHome + rust + cargo + ]; + buildPhase = '' + cargo build -p statix --release --offline + ''; + installPhase = '' + install -Dm775 ./target/release/statix $out/bin/statix + ''; + }; - nativeBuildInputs = with pkgs; [ ]; + }; - in - rec { - packages.statix = naersk-lib.buildPackage { - pname = "statix"; - version = "0.1.0"; - root = ./.; - inherit nativeBuildInputs; - }; + packages = forAllSystems (system: { + inherit (nixpkgsFor."${system}") statix; + }); - defaultPackage = packages.statix; - apps.statix = utils.lib.mkApp { - drv = packages.statix; - }; + defaultPackage = + forAllSystems (system: self.packages."${system}".statix); - apps.check = { - type = "app"; - program = "${pkgs.cargo-watch}/bin/cargo-watch"; - }; + devShell = forAllSystems (system: + let + pkgs = nixpkgsFor.${system}; + rustChannel = (mozilla pkgs).rustChannelOf chanspec; + in + with pkgs; + mkShell rec { + buildInputs = + (with pkgs; [ + rust-analyzer + rustfmt + cargo + cargo-watch + ]) ++ (with rustChannel; [ + rust + rust-src + ]); + RUST_SRC_PATH = "${rustChannel.rust-src}/lib/rustlib/src/rust/library"; + RUST_LOG = "info"; + RUST_BACKTRACE = 1; + }); - defaultApp = apps.statix; - devShell = pkgs.mkShell { - nativeBuildInputs = nativeBuildInputs ++ [ - rust - rust-src - pkgs.rust-analyzer - pkgs.rustfmt - pkgs.cargo - pkgs.cargo-watch - ]; - RUST_SRC_PATH = "${rust-src}/lib/rustlib/src/rust/library"; - RUST_LOG = "info"; - RUST_BACKTRACE = 1; - }; - }); + + }; } diff --git a/notes.txt b/notes.txt index d8c2f0a..73d9439 100644 --- a/notes.txt +++ b/notes.txt @@ -8,6 +8,7 @@ Interface - load files to be read as VFS - path interner - traits to go from Report to text/errfmt +- offline documentation/explaination for lints Fix --- -- cgit v1.2.3