From d3832fbb532626e23fa267a0009e3606da08aed5 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Mon, 8 Jul 2024 10:41:29 +0200 Subject: [PATCH] add flake.nix --- .gitignore | 3 +- flake.lock | 104 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index 3b7e0f70..599e08cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ target __pycache__ .vscode -.idea \ No newline at end of file +.idea +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..464eacc3 --- /dev/null +++ b/flake.lock @@ -0,0 +1,104 @@ +{ + "nodes": { + "crane": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1720226507, + "narHash": "sha256-yHVvNsgrpyNTXZBEokL8uyB2J6gB1wEx0KOJzoeZi1A=", + "owner": "ipetkov", + "repo": "crane", + "rev": "0aed560c5c0a61c9385bddff471a13036203e11c", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": [] + }, + "locked": { + "lastModified": 1720420198, + "narHash": "sha256-OIuDb6pHDyGpo7YMFyuRzMLcHm7mRvlYOz0Ht7ps2sU=", + "owner": "nix-community", + "repo": "fenix", + "rev": "abc0549e3560189462a7d394cc9d50af4608d103", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1720368505, + "narHash": "sha256-5r0pInVo5d6Enti0YwUSQK4TebITypB42bWy5su3MrQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ab82a9612aa45284d4adf69ee81871a389669a9e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "fenix": "fenix", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..88a01e9c --- /dev/null +++ b/flake.nix @@ -0,0 +1,124 @@ +{ + description = "Build teos (The Eye of Satoshi) server and plugin"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.rust-analyzer-src.follows = ""; + }; + + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, nixpkgs, crane, fenix, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + inherit (pkgs) lib; + + craneLib = crane.mkLib pkgs; + src = craneLib.cleanCargoSource ./.; + + # Common arguments can be set here to avoid repeating them later + commonArgs = { + inherit src; + strictDeps = true; + + nativeBuildInputs = [ + pkgs.pkg-config + pkgs.openssl + pkgs.rustfmt # needed for tonic build + ]; + + buildInputs = [ + # Add additional build inputs here + pkgs.pkg-config + ] ++ lib.optionals pkgs.stdenv.isDarwin [ + # Additional darwin specific inputs can be set here + pkgs.libiconv + ]; + + # TODO: hack but without there are warnings and I can't make other method work + pname = "teos"; + version = "0.2.0"; + + PROTOC = "${pkgs.protobuf}/bin/protoc"; + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + }; + + craneLibLLvmTools = craneLib.overrideToolchain + (fenix.packages.${system}.complete.withComponents [ + "cargo" + "llvm-tools" + "rustc" + ]); + + # Build *just* the cargo dependencies (of the entire workspace), + # so we can reuse all of that work (e.g. via cachix) when running in CI + # It is *highly* recommended to use something like cargo-hakari to avoid + # cache misses when building individual top-level-crates + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + individualCrateArgs = commonArgs // { + inherit cargoArtifacts; + inherit (craneLib.crateNameFromCargoToml { inherit src; }) version; + # NB: we disable tests since we'll run them all via cargo-nextest + doCheck = false; + }; + + fileSetForCrate = crate: lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./Cargo.toml + ./Cargo.lock + ./teos-common + ./watchtower-plugin + ./teos + crate + ]; + }; + + # Build the top-level crates of the workspace as individual derivations. + # This allows consumers to only depend on (and build) only what they need. + # Though it is possible to build the entire workspace as a single derivation, + # so this is left up to you on how to organize things + plugin = craneLib.buildPackage (individualCrateArgs // { + pname = "watchtower-plugin"; + version = "0.2.0"; # TODO: hack but without there are warnings and I can't make other method work + cargoExtraArgs = "-p watchtower-plugin"; + src = fileSetForCrate ./watchtower-plugin; + }); + teos = craneLib.buildPackage (individualCrateArgs // { + pname = "teos"; + version = "0.2.0"; # TODO: hack but without there are warnings and I can't make other method work + cargoExtraArgs = "-p teos"; + src = fileSetForCrate ./teos; + }); + in + { + packages = { + inherit plugin teos; + default = teos; + }; + + apps = { + plugin = flake-utils.lib.mkApp { + drv = plugin; + }; + teos = flake-utils.lib.mkApp { + drv = teos; + }; + }; + + }); +} +