Skip to content

Commit

Permalink
does this now work?
Browse files Browse the repository at this point in the history
  • Loading branch information
jost-s committed May 31, 2024
1 parent 82e4e8c commit b9a5a33
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 207 deletions.
53 changes: 8 additions & 45 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

226 changes: 64 additions & 162 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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
];
};
};
};
};
}

0 comments on commit b9a5a33

Please sign in to comment.