From 48298b31903538207d1385accb2604755733c92b Mon Sep 17 00:00:00 2001 From: Erwin Boskma Date: Fri, 19 Nov 2021 17:44:10 +0100 Subject: [PATCH] Added nix stuff --- .envrc | 1 + default.nix | 51 ++++++++++++++++++++++++++++++ flake.lock | 60 +++++++++++++++++++++++++++++++++++ flake.nix | 76 +++++++++++++++++++++++++++++++++++++++++++++ rust-toolchain.toml | 3 ++ 5 files changed, 191 insertions(+) create mode 100644 .envrc create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..c764232 --- /dev/null +++ b/default.nix @@ -0,0 +1,51 @@ +# (import ( +# fetchTarball { +# url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; +# sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } +# ) { +# src = ./.; +# }).defaultNix +{ lib +, naersk +, stdenv +, clangStdenv +, hostPlatform +, targetPlatform +, pkg-config +, libiconv +, rustfmt +, cargo +, rustc +, openssl +}: +let cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); +in +naersk.lib."${targetPlatform.system}".buildPackage rec { + src = ./.; + + buildInputs = [ + rustfmt + pkg-config + cargo + rustc + libiconv + openssl + ]; + + checkInputs = [ cargo rustc ]; + doCheck = true; + + CARGO_BUILD_INCREMENTAL = "false"; + RUST_BACKTRACE = "full"; + copyLibs = true; + + name = cargoToml.package.name; + version = cargoToml.package.version; + + meta = with lib; { + description = cargoToml.package.description; + homepage = cargoToml.package.homepage; + license = with licenses; [ mit ]; + maintainers = with maintainers; [ ]; + }; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5cd8c87 --- /dev/null +++ b/flake.lock @@ -0,0 +1,60 @@ +{ + "nodes": { + "naersk": { + "inputs": { + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1636968630, + "narHash": "sha256-/C8OVV8mo9M9MgQprHo4A5bM9waWMsw6PI4hb4DnGaA=", + "owner": "nmattia", + "repo": "naersk", + "rev": "55c4c0288ea3f115b5dd73af88052c4712994746", + "type": "github" + }, + "original": { + "owner": "nmattia", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1636976544, + "narHash": "sha256-9ZmdyoRz4Qu8bP5BKR1T10YbzcB9nvCeQjOEw2cRKR0=", + "path": "/nix/store/ha4ld6wd29q1igjmhjdvkvbxpxxxxbxf-source", + "rev": "931ab058daa7e4cd539533963f95e2bb0dbd41e6", + "type": "path" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1637186689, + "narHash": "sha256-NU7BhgnwA/3ibmCeSzFK6xGi+Bari9mPfn+4cBmyEjw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "7fad01d9d5a3f82081c00fb57918d64145dc904c", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "naersk": "naersk", + "nixpkgs": "nixpkgs_2" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2cca19a --- /dev/null +++ b/flake.nix @@ -0,0 +1,76 @@ +{ + + inputs = { + naersk.url = "github:nmattia/naersk/master"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + }; + + outputs = { self, nixpkgs, naersk }: + let + cargoToml = (builtins.fromTOML (builtins.readFile ./Cargo.toml)); + supportedSystems = [ "x86_64-linux" "aarch64-linux" ]; + forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: f system); + in + { + overlay = final: prev: { + "${cargoToml.package.name}" = final.callPackage ./. { inherit naersk; }; + }; + + 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 + ''; + "${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"; + } + ); + }; + +} diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..cf9cf4d --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "stable" +components = [ "rustfmt", "clippy" ] \ No newline at end of file