Skip to content

Commit

Permalink
restore previous inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
jost-s committed May 31, 2024
1 parent b9a5a33 commit 8c12001
Showing 1 changed file with 197 additions and 87 deletions.
284 changes: 197 additions & 87 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,114 +1,224 @@
{
description =
"Holochain is an open-source framework to develop peer-to-peer applications with high levels of security, reliability, and performance.";
# flake format https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-flake.html#flake-format
description = "Holonix - Holochain Nix flake";

# specify all input dependencies needed to create the outputs of the flake
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";

# lib to build nix packages from rust crates
# 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
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};

# rustup, rust and cargo
# Rust toolchain
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};

launcher = {
url = "github:holochain/launcher/holochain-weekly";
# 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";
flake = false;
};
};

# 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
# 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/
flake-parts.lib.mkFlake { inherit inputs; } {
# systems that his flake can be used on
systems = [ "aarch64-darwin" "x86_64-linux" "x86_64-darwin" ];

perSystem = { pkgs, system, ... }:
# for each system...
perSystem = { config, pkgs, system, ... }:
let
rustedNixpkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
# include Rust overlay in nixpkgs
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
rustToolchain = rustedNixpkgs.rust-bin.stable."1.78.0".minimal;

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";

buildInputs = [
pkgs.perl
]
++ (pkgs.lib.optionals pkgs.stdenv.isLinux
[
pkgs.glib
pkgs.go
pkgs.webkitgtk.dev
])
++ pkgs.lib.optionals pkgs.stdenv.isDarwin
[
apple_sdk.frameworks.AppKit
apple_sdk.frameworks.WebKit

(if pkgs.system == "x86_64-darwin" then
pkgs.darwin.apple_sdk_11_0.stdenv.mkDerivation
{
name = "go";
nativeBuildInputs = with pkgs; [
makeBinaryWrapper
go
];
dontBuild = true;
dontUnpack = true;
installPhase = ''
makeWrapper ${pkgs.go}/bin/go $out/bin/go
'';
}
else pkgs.go)
]
;

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;
# 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" ];
});
in
{
packages = {
inherit launcher;

# 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 = [
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;

commonArgs = {
pname = "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;
};
# Only build hc-launch command
cargoExtraArgs = "--bin hc-launch";

nativeBuildInputs = (
if pkgs.stdenv.isLinux then [ pkgs.pkg-config ]
else [ ]
);
buildInputs = [
pkgs.perl
]
++ (pkgs.lib.optionals pkgs.stdenv.isLinux
[
pkgs.glib
pkgs.go
pkgs.webkitgtk.dev
])
++ pkgs.lib.optionals pkgs.stdenv.isDarwin
[
apple_sdk.frameworks.AppKit
apple_sdk.frameworks.WebKit

(if pkgs.system == "x86_64-darwin" then
pkgs.darwin.apple_sdk_11_0.stdenv.mkDerivation
{
name = "go";
nativeBuildInputs = with pkgs; [
makeBinaryWrapper
go
];
dontBuild = true;
dontUnpack = true;
installPhase = ''
makeWrapper ${pkgs.go}/bin/go $out/bin/go
'';
}
else pkgs.go)
];

# do not check built package as it either builds successfully or not
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 8c12001

Please sign in to comment.