Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nix flake build #139

Draft
wants to merge 13 commits into
base: master
Choose a base branch
from
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if has nix; then
use nix
fi
143 changes: 143 additions & 0 deletions flake.lock

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

94 changes: 94 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
inputs = {
nixpkgs.url = github:nixos/nixpkgs/release-22.05;
utils.url = github:numtide/flake-utils;
rust-overlay.url = github:oxalica/rust-overlay;
naersk.url = github:nix-community/naersk;


# sample rust-skia build: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/editors/neovim/neovide/default.nix#L114
# rust-skia pulls skia from a hard-coded url by default (but flakes disallow internet access!),
# so we have to ask it to look for system libraries then build skia locally
# skia = {
# url = github:rust-skia/skia;
# flake = false;
# };

# Used for shell.nix
flake-compat = {
url = github:edolstra/flake-compat;
flake = false;
};
};

outputs = { self, nixpkgs, rust-overlay, utils, naersk, ... } @ inputs:
let
name = "MFEKmetadata";
description = "Basic font metadata fetcher/updater for the MFEK project";
overlays = [ rust-overlay.overlays.default ];
# Our supported systems are the same supported systems as the Rust binaries
systems = builtins.attrNames inputs.rust-overlay.packages;
in utils.lib.eachSystem systems (system:
let
pkgs = import nixpkgs { inherit overlays system; };
rust_channel = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain;
naersk-lib = naersk.lib."${system}".override {
cargo = rust_channel;
rustc = rust_channel;
};
in {
defaultPackage = naersk-lib.buildPackage {
pname = name;
root = ./.;
nativeBuildInputs = with pkgs; [
python3
clang
llvmPackages.libclang
gn
ninja
libiconv
fontconfig
];

# https://github.com/rust-skia/rust-skia/blob/master/flake.nix
SKIA_NINJA_COMMAND = "${pkgs.ninja}/bin/ninja";
SKIA_GN_COMMAND = "${pkgs.gn}/bin/gn";
LIBCLANG_PATH = "${pkgs.llvmPackages.libclang}/lib/libclang.so";

CC = "${pkgs.clang}/bin/clang";
CXX = "${pkgs.clang}/bin/clang++";
# TODO: what's the difference between the two libclang paths?
# LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";

# might need this: https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/editors/aseprite/skia.nix
SKIA_USE_SYSTEM_LIBRARIES = true;
FORCE_SKIA_BUILD = true;
# SKIA_LIBRARY_SEARCH_PATH = "$out/";
# TODO: Where is Skia built if built locally?
# SKIA_SOURCE_DIR
};
# build error: "no such file or directory": /sources/skia-bindings-0.56.1/build_support/skia/config.rs:313:10
# https://github.com/rust-skia/rust-skia/blob/8eb0dd7fc98dd21e5e8bd2fc866323399b3795f6/skia-bindings/build_support/skia/config.rs#L303
# -- missing the skia dependency

devShells.default = pkgs.mkShell {
inherit name description;
buildInputs = with pkgs; [
rust_channel
rust-analyzer
cargo
lld
pkg-config
fontconfig
freetype
clang
gn
];
# for rust-analyzer; the target dir of the compiler for the project
OUT_DIR = "./target";
};

# For compatibility with older versions of the `nix` binary
devShell = self.devShells.${system}.default;
});
}
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
stable
12 changes: 12 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import
(
let
flake-compat = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.flake-compat;
in
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/${flake-compat.locked.rev}.tar.gz";
sha256 = flake-compat.locked.narHash;
}
)
{src = ./.;})
.shellNix