Skip to content

Commit

Permalink
feat: build fedimint-clientd oci images
Browse files Browse the repository at this point in the history
  • Loading branch information
okjodom committed May 6, 2024
1 parent 21d3851 commit e8bed55
Showing 1 changed file with 77 additions and 27 deletions.
104 changes: 77 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
inputs.fenix.follows = "fenix";
};

flake-utils.url = "github:numtide/flake-utils";
flake-utils = { url = "github:numtide/flake-utils"; };

fedimint = {
url =
Expand All @@ -33,33 +33,27 @@
};
lib = pkgs.lib;
flakeboxLib = flakebox.lib.${system} { };
rustSrc = flakeboxLib.filterSubPaths {
root = builtins.path {
name = "fedimint-clientd";
path = ./.;
};
paths = [ "Cargo.toml" "Cargo.lock" ".cargo" "src" ];
};

toolchainArgs = let llvmPackages = pkgs.llvmPackages_11;
in {
extraRustFlags = "--cfg tokio_unstable";
toolchainArgs =
let llvmPackages = pkgs.llvmPackages_11;
in {
extraRustFlags = "--cfg tokio_unstable";

components = [ "rustc" "cargo" "clippy" "rust-analyzer" "rust-src" ];
components = [ "rustc" "cargo" "clippy" "rust-analyzer" "rust-src" ];

args = {
nativeBuildInputs =
[ pkgs.wasm-bindgen-cli pkgs.geckodriver pkgs.wasm-pack ]
++ lib.optionals (!pkgs.stdenv.isDarwin) [ pkgs.firefox ];
args = {
nativeBuildInputs =
[ pkgs.wasm-bindgen-cli pkgs.geckodriver pkgs.wasm-pack ]
++ lib.optionals (!pkgs.stdenv.isDarwin) [ pkgs.firefox ];
};
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
# on Darwin newest stdenv doesn't seem to work
# linking rocksdb
stdenv = pkgs.clang11Stdenv;
clang = llvmPackages.clang;
libclang = llvmPackages.libclang.lib;
clang-unwrapped = llvmPackages.clang-unwrapped;
};
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
# on Darwin newest stdenv doesn't seem to work
# linking rocksdb
stdenv = pkgs.clang11Stdenv;
clang = llvmPackages.clang;
libclang = llvmPackages.libclang.lib;
clang-unwrapped = llvmPackages.clang-unwrapped;
};

# all standard toolchains provided by flakebox
toolchainsStd = flakeboxLib.mkStdFenixToolchains toolchainArgs;
Expand All @@ -74,24 +68,80 @@
[ pkgs.darwin.apple_sdk.frameworks.SystemConfiguration ];
nativeBuildInputs = [ pkgs.pkg-config ];
};

commonSrc = builtins.path { path = ./.; name = "fedimint-clientd"; };

filterWorkspaceDepsBuildFilesRegex = [ "Cargo.lock" "Cargo.toml" ".cargo" ".cargo/.*" ".config" ".config/.*" ".*/Cargo.toml" ];

filterSrcWithRegexes = regexes: src:
let
basePath = toString src + "/";
in
lib.cleanSourceWith {
filter = (path: type:
let
relPath = lib.removePrefix basePath (toString path);
includePath =
(type == "directory") ||
lib.any
(re: builtins.match re relPath != null)
regexes;
in
# uncomment to debug:
# builtins.trace "${relPath}: ${lib.boolToString includePath}"
includePath
);
inherit src;
};

# Filter only files needed to build project dependencies
#
# To get good build times it's vitally important to not have to
# rebuild derivation needlessly. The way Nix caches things
# is very simple: if any input file changed, derivation needs to
# be rebuild.
#
# For this reason this filter function strips the `src` from
# any files that are not relevant to the build.
#
# Like `filterWorkspaceFiles` but doesn't even need *.rs files
# (because they are not used for building dependencies)
filterWorkspaceDepsBuildFiles = src: filterSrcWithRegexes filterWorkspaceDepsBuildFilesRegex src;


# Filter only files relevant to building the workspace
filterWorkspaceBuildFiles = src: filterSrcWithRegexes (filterWorkspaceDepsBuildFilesRegex ++ [ ".*\.rs" ]) src;

outputs = (flakeboxLib.craneMultiBuild { toolchains = toolchainsStd; })
(craneLib':
let
craneLib = (craneLib'.overrideArgs {
pname = "flexbox-multibuild";
src = rustSrc;
src = filterWorkspaceBuildFiles commonSrc;
}).overrideArgs commonArgs;
in rec {
in
rec {
workspaceDeps = craneLib.buildWorkspaceDepsOnly { };

workspaceBuild =
craneLib.buildWorkspace { cargoArtifacts = workspaceDeps; };

fedimint-clientd = craneLib.buildPackageGroup {
pname = "fedimint-clientd";
packages = [ "fedimint-clientd" ];
mainProgram = "fedimint-clientd";
};

fedimint-clientd-oci = pkgs.dockerTools.buildLayeredImage {
name = "fedimint-clientd";
contents = [ fedimint-clientd ];
config = {
Cmd = [ "${fedimint-clientd}/bin/fedimint-clientd" ];
};
};
});
in {
in
{
legacyPackages = outputs;
packages = { default = outputs.fedimint-clientd; };
devShells = flakeboxLib.mkShells {
Expand Down

0 comments on commit e8bed55

Please sign in to comment.