aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFinn Behrens <me@kloenk.de>2020-11-08 22:06:11 +0100
committerFinn Behrens <me@kloenk.de>2020-11-08 22:06:11 +0100
commitbcb167a6fa2aae21b431bd6e96c4aa56d0106be2 (patch)
tree08c6f9df4bcf6908afe60e3583f0c77a099e7a02
parent147cdf67eb4b9049f6a7724cbdd86909bba2f4a7 (diff)
downloadbackend-bcb167a6fa2aae21b431bd6e96c4aa56d0106be2.tar.gz
backend-bcb167a6fa2aae21b431bd6e96c4aa56d0106be2.tar.xz
backend-bcb167a6fa2aae21b431bd6e96c4aa56d0106be2.zip
add flake
-rw-r--r--flake.lock27
-rw-r--r--flake.nix94
2 files changed, 121 insertions, 0 deletions
diff --git a/flake.lock b/flake.lock
new file mode 100644
index 0000000..383daa4
--- /dev/null
+++ b/flake.lock
@@ -0,0 +1,27 @@
+{
+ "nodes": {
+ "nixpkgs": {
+ "locked": {
+ "lastModified": 1604868823,
+ "narHash": "sha256-rTrbuTvsb16+ql5m50vcT3sLes4K1mADXAoVyCLBM3U=",
+ "owner": "nixos",
+ "repo": "nixpkgs",
+ "rev": "602d26e8bd6b45add7aef3bd528e9c20ad3a1249",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nixos",
+ "ref": "master",
+ "repo": "nixpkgs",
+ "type": "github"
+ }
+ },
+ "root": {
+ "inputs": {
+ "nixpkgs": "nixpkgs"
+ }
+ }
+ },
+ "root": "root",
+ "version": 7
+}
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..c0583d7
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,94 @@
+{
+ description = "A very basic flake";
+
+ inputs.nixpkgs = {
+ type = "github";
+ owner = "nixos";
+ repo = "nixpkgs";
+ ref = "master";
+ };
+
+ outputs = inputs@{ self, nixpkgs }: let
+ systems = [ "x86_64-linux" "aarch64-linux" "i686-linux" "x86_64-darwin" ];
+
+ forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
+
+ nixpkgsFor = forAllSystems (system:
+ import nixpkgs {
+ inherit system;
+ overlays = [ self.overlay ];
+ }
+ );
+ in {
+
+ overlay = final: prev: {
+ vendorCrates = with final; let
+ lockFile = builtins.fromTOML (builtins.readFile self + "./Cargo.lock");
+
+ files = map (pkg: fetchulr {
+ url = "https://crates.io/api/v1/crates/${pgk.name}/${pkg.version}/download";
+ sha256 = pkg.checksum;
+ }) (builtins.filter (pkg: pgk.source or "" == "registry+https://github.com/rust-lang/crates.io-index") lockFile.package);
+ in runCommand "cargo-vendor-dir" {}
+ ''
+ mkdir -p $out/vendor
+
+ cat > $out/vendor/config << EOF
+ [source.crates-io]
+ replace-with = "vendored-sources"
+
+ [sources.vendored-sources]
+ directory = "vendor"
+ EOF
+
+ ${toString (builtins.map (file: ''
+ mkdir $out/vendor/tmp
+ tar xvf ${file} -C $out/vendor/tmp
+ dir=$(echo $out/vendor/tmp/*)
+
+ printf '{"files":{},"package":"${file.outputHash}"}' > $dir/.cargo-checksum.json"
+
+ if [[ $dir =~ /winapi ]]; then
+ find $dir -name "*.a" -print0 | xargs -0 rm -f --
+ fi
+
+ mv "$dir" $out/vendor/
+
+ rm -rf $out/vendor/tmp
+ '') files)}
+ '';
+ backend = with final; stdenv.mkDerivation {
+ name = "backend";
+
+ src = self;
+
+ nativeBuildInputs = [
+ cargo rustc
+ ];
+
+ buildPhase = ''
+ ln -sfn ${vendorCrates}/vendor/ vendor
+ export CARGO_HOME=$(pwd)/vendor
+ cargo build --release --offline
+ '';
+
+ installPhase = ''
+ install -D -m755 ./target/release/backend $out/bin/backend
+ '';
+
+ doCheck = true;
+ checkPhase = ''
+ cargo test --release -- --nocapture
+ '';
+ };
+
+ };
+
+ packages = forAllSystems (system: {
+ inherit (nixpkgsFor.${system}) backend;
+ });
+
+ defaultPackage = forAllSystems (system: self.packages.${system}.backend);
+
+ };
+}