From d845e108b63348dbcb3b0db0d18b6d7ad7237d55 Mon Sep 17 00:00:00 2001 From: Sam Willcocks Date: Wed, 17 Nov 2021 22:55:49 +0000 Subject: [PATCH] Simplify flake --- flake.lock | 18 ++++++++++++- flake.nix | 78 +++++++++--------------------------------------------- 2 files changed, 30 insertions(+), 66 deletions(-) diff --git a/flake.lock b/flake.lock index e5ec9fe..25600b1 100644 --- a/flake.lock +++ b/flake.lock @@ -39,7 +39,23 @@ "root": { "inputs": { "naersk": "naersk", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1637014545, + "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "bba5dcc8e0b20ab664967ad83d24d64cb64ec4f4", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 6c91462..9149a1f 100644 --- a/flake.nix +++ b/flake.nix @@ -3,76 +3,24 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + utils.url = "github:numtide/flake-utils"; naersk.url = "github:nmattia/naersk"; naersk.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = { self, nixpkgs, naersk }: + outputs = { self, nixpkgs, utils, naersk }: let cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); - supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" ]; - forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); in - { - overlay = final: prev: { - "${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; }; + utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages."${system}"; + naersk-lib = naersk.lib."${system}"; + in rec { + packages."${cargoToml.package.name}" = naersk-lib.buildPackage { + pname = "${cargoToml.package.name}"; + root = ./.; + buildInputs = [ pkgs.openssl ]; }; - - packages = forAllSystems (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlay - ]; - }; - in - { - "${cargoToml.package.name}" = pkgs."${cargoToml.package.name}"; - }); - - - defaultPackage = forAllSystems (system: (import nixpkgs { - inherit system; - overlays = [ self.overlay ]; - })."${cargoToml.package.name}"); - - checks = forAllSystems (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - self.overlay - ]; - }; - in - { - format = pkgs.runCommand "check-format" - { - buildInputs = with pkgs; [ rustfmt cargo ]; - } '' - ${pkgs.rustfmt}/bin/cargo-fmt fmt --manifest-path ${./.}/Cargo.toml -- --check - ${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt --check ${./.} - touch $out # it worked! - ''; - "${cargoToml.package.name}" = pkgs."${cargoToml.package.name}"; - }); - devShell = forAllSystems (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ self.overlay ]; - }; - in - pkgs.mkShell { - inputsFrom = with pkgs; [ - pkgs."${cargoToml.package.name}" - ]; - buildInputs = with pkgs; [ - rustfmt - nixpkgs-fmt - ]; - LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib"; - }); - }; -} \ No newline at end of file + defaultPackage = packages."${cargoToml.package.name}"; + }); +}