From b9a5a338e67a73d454dff881a9982cf23ced8d3c Mon Sep 17 00:00:00 2001 From: Jost Schulte Date: Fri, 31 May 2024 13:12:23 -0600 Subject: [PATCH] does this now work? --- flake.lock | 53 ++----------- flake.nix | 226 +++++++++++++++-------------------------------------- 2 files changed, 72 insertions(+), 207 deletions(-) diff --git a/flake.lock b/flake.lock index 0e65636..0c441d5 100644 --- a/flake.lock +++ b/flake.lock @@ -33,9 +33,8 @@ "type": "github" }, "original": { - "owner": "hercules-ci", - "repo": "flake-parts", - "type": "github" + "id": "flake-parts", + "type": "indirect" } }, "flake-utils": { @@ -56,53 +55,19 @@ "type": "github" } }, - "holochain-src": { - "flake": false, - "locked": { - "lastModified": 1716469959, - "narHash": "sha256-mT7e0ew8ffMY5esWUiB8uNWNvRhBqCPIu2lYZ3nAenw=", - "owner": "holochain", - "repo": "holochain", - "rev": "1663c381ababd530c9dfbe87c8b2a683ac1bf6f3", - "type": "github" - }, - "original": { - "owner": "holochain", - "ref": "main", - "repo": "holochain", - "type": "github" - } - }, - "lair-keystore-src": { - "flake": false, - "locked": { - "lastModified": 1709335027, - "narHash": "sha256-rKMhh7TLuR1lqze2YFWZCGYKZQoB4dZxjpX3sb7r7Jk=", - "owner": "holochain", - "repo": "lair", - "rev": "826be915efc839d1d1b8a2156b158999b8de8d5b", - "type": "github" - }, - "original": { - "owner": "holochain", - "ref": "lair_keystore-v0.4.4", - "repo": "lair", - "type": "github" - } - }, - "launcher-src": { + "launcher": { "flake": false, "locked": { - "lastModified": 1716406557, - "narHash": "sha256-6eWndYspznXKYIJcuPCWFZ3lxdh7TrlEUGP1zaE5Mgs=", + "lastModified": 1715106263, + "narHash": "sha256-a7iQ8pKGz6fghJrtXq0Xamp57GE8Hd3w5YQASzz5Wlk=", "owner": "holochain", "repo": "launcher", - "rev": "f20844aa5041432547c55176d71e67b32e302f77", + "rev": "92bd39e1c66912d61c35c4725d7b106959888670", "type": "github" }, "original": { "owner": "holochain", - "ref": "holochain-0.3", + "ref": "holochain-weekly", "repo": "launcher", "type": "github" } @@ -139,9 +104,7 @@ "inputs": { "crane": "crane", "flake-parts": "flake-parts", - "holochain-src": "holochain-src", - "lair-keystore-src": "lair-keystore-src", - "launcher-src": "launcher-src", + "launcher": "launcher", "nixpkgs": "nixpkgs", "rust-overlay": "rust-overlay" } diff --git a/flake.nix b/flake.nix index e8c1700..a626f47 100644 --- a/flake.nix +++ b/flake.nix @@ -1,161 +1,68 @@ { - # flake format https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-format - description = "Holonix - Holochain Nix flake"; + description = + "Holochain is an open-source framework to develop peer-to-peer applications with high levels of security, reliability, and performance."; - # specify all input dependencies needed to create the outputs of the flake inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; - # utility to iterate over multiple target platforms - flake-parts.url = "github:hercules-ci/flake-parts"; - - # lib to build a nix package from a rust crate + # lib to build nix packages from rust crates crane = { url = "github:ipetkov/crane"; inputs.nixpkgs.follows = "nixpkgs"; }; - # Rust toolchain + # rustup, rust and cargo rust-overlay = { url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; - # Holochain sources - holochain-src = { - url = "github:holochain/holochain/main"; - flake = false; - }; - - # Lair keystore sources - lair-keystore-src = { - url = "github:holochain/lair/lair_keystore-v0.4.4"; - flake = false; - }; - - # Holochain Launcher CLI - launcher-src = { - url = "github:holochain/launcher/holochain-0.3"; + launcher = { + url = "github:holochain/launcher/holochain-weekly"; flake = false; }; }; - # outputs that this flake should produce - outputs = inputs @ { self, nixpkgs, flake-parts, rust-overlay, crane, holochain-src, lair-keystore-src, launcher-src, ... }: - # refer to flake-parts docs https://flake.parts/ + # refer to flake-parts docs https://flake.parts/ + outputs = inputs @ { self, nixpkgs, flake-parts, rust-overlay, ... }: + # all possible parameters for a module: https://flake.parts/module-arguments.html#top-level-module-arguments flake-parts.lib.mkFlake { inherit inputs; } { - # systems that his flake can be used on systems = [ "aarch64-darwin" "x86_64-linux" "x86_64-darwin" ]; - # for each system... - perSystem = { config, pkgs, system, ... }: + perSystem = { pkgs, system, ... }: let - # include Rust overlay in nixpkgs - overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { - inherit system overlays; + rustedNixpkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; }; + rustToolchain = rustedNixpkgs.rust-bin.stable."1.78.0".minimal; - # define Rust toolchain version and targets to be used in this flake - rust = (pkgs.rust-bin.stable."1.78.0".minimal.override - { - targets = [ "wasm32-unknown-unknown" ]; - }); + craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rustToolchain; + + apple_sdk = + if system == "x86_64-darwin" + then pkgs.darwin.apple_sdk_10_12 + else pkgs.darwin.apple_sdk_11_0; + + commonArgs = { + pname = "hc-launch"; + src = inputs.launcher; + cargoExtraArgs = "--bin hc-launch"; - # instruct crane to use Rust toolchain specified above - craneLib = (crane.mkLib pkgs).overrideToolchain rust; - - # define how to build Holochain binaries - holochain = - let - # Crane filters out all non-cargo related files. Define include filter with files needed for build. - nonCargoBuildFiles = path: _type: builtins.match ".*(json|sql|wasm.gz)$" path != null; - includeFilesFilter = path: type: - (craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type); - in - craneLib.buildPackage { - pname = "holochain"; - version = "workspace"; - # Use Holochain sources as defined in input dependencies and include only those files defined in the - # filter previously. - src = pkgs.lib.cleanSourceWith { - src = holochain-src; - filter = includeFilesFilter; - }; - # additional packages needed for build - buildInputs = [ + buildInputs = [ + pkgs.perl + ] + ++ (pkgs.lib.optionals pkgs.stdenv.isLinux + [ + pkgs.glib pkgs.go - pkgs.perl - ]; - # do not check built package as it either builds successfully or not - doCheck = false; - }; - - # define how to build Lair keystore binary - lair-keystore = - let - # Crane filters out all non-cargo related files. Define include filter with files needed for build. - nonCargoBuildFiles = path: _type: builtins.match ".*(sql|md)$" path != null; - includeFilesFilter = path: type: - (craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type); - in - craneLib.buildPackage { - pname = "lair-keystore"; - version = "workspace"; - # only build lair-keystore binary - cargoExtraArgs = "--bin lair-keystore"; - # Use Lair keystore sources as defined in input dependencies and include only those files defined in the - # filter previously. - src = pkgs.lib.cleanSourceWith { - src = lair-keystore-src; - filter = includeFilesFilter; - }; - # additional packages needed for build - # perl needed for openssl on all platforms - buildInputs = [ pkgs.perl ] - ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [ - # additional packages needed for darwin platforms - pkgs.libiconv - pkgs.darwin.apple_sdk.frameworks.Security - # additional packages needed for darwin platforms on x86_64 - pkgs.darwin.apple_sdk_11_0.frameworks.CoreFoundation - ]); - # do not check built package as it either builds successfully or not - doCheck = false; - }; - - # define how to build Holochain Launcher binary - launcher = - let - # Crane filters out all non-cargo related files. Define include filter with files needed for build. - nonCargoBuildFiles = path: _type: builtins.match ".*(js|json|png)$" path != null; - includeFilesFilter = path: type: - (craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type); - apple_sdk = - if system == "x86_64-darwin" - then pkgs.darwin.apple_sdk_10_12 - else pkgs.darwin.apple_sdk_11_0; - craneLib = (inputs.crane.mkLib pkgs).overrideToolchain rust; - in - craneLib.buildPackage { - pname = "hc-launch"; - version = "workspace"; - stdenv = - if pkgs.stdenv.isDarwin then - pkgs.overrideSDK pkgs.stdenv "11.0" - else - pkgs.stdenv; + pkgs.webkitgtk.dev + ]) + ++ pkgs.lib.optionals pkgs.stdenv.isDarwin + [ + apple_sdk.frameworks.AppKit + apple_sdk.frameworks.WebKit - # only build hc-launch binary - cargoExtraArgs = "--bin hc-launch"; - # Use Launcher sources as defined in input dependencies and include only those files defined in the - # filter previously. - src = pkgs.lib.cleanSourceWith { - src = launcher-src; - # filter = includeFilesFilter; - }; - nativeBuildInputs = [ - pkgs.pkg-config (if pkgs.system == "x86_64-darwin" then pkgs.darwin.apple_sdk_11_0.stdenv.mkDerivation { @@ -169,44 +76,39 @@ installPhase = '' makeWrapper ${pkgs.go}/bin/go $out/bin/go ''; - } else pkgs.go) - ]; - # additional packages needed for build - # perl needed for openssl on all platforms - buildInputs = [ - pkgs.glib - pkgs.perl + } + else pkgs.go) ] - ++ (pkgs.lib.optionals pkgs.stdenv.isLinux [ - pkgs.pkg-config - pkgs.webkitgtk.dev - ]) - ++ (pkgs.lib.optionals pkgs.stdenv.isDarwin [ - # additional packages needed for darwin platforms - apple_sdk.frameworks.AppKit - apple_sdk.frameworks.WebKit - ]); - # do not check built package as it either builds successfully or not - doCheck = false; - }; + ; + + nativeBuildInputs = ( + if pkgs.stdenv.isLinux then [ pkgs.pkg-config ] + else [ ] + ); + + doCheck = false; + }; + + # derivation building all dependencies + deps = craneLib.buildDepsOnly + (commonArgs // { }); + + # derivation with the main crates + launcher = craneLib.buildPackage + (commonArgs // { + cargoArtifacts = deps; + + stdenv = + if pkgs.stdenv.isDarwin then + pkgs.overrideSDK pkgs.stdenv "11.0" + else + pkgs.stdenv; + }); in { packages = { - # inherit holochain; - # inherit lair-keystore; - # inherit rust; inherit launcher; }; - - devShells = { - default = pkgs.mkShell { - packages = [ - # holochain - # lair-keystore - # rust - ]; - }; - }; }; }; }