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 support #370

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

85 changes: 85 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
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;

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

outputs = { self, nixpkgs, rust-overlay, utils, naersk, ... } @ inputs: let
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;
glif-test = pkgs.writeScriptBin "glif-test" ''
RUST_LOG=debug RUST_BACKTRACE=1 cargo run -- examples/Q_.glif
'';
naersk-lib = naersk.lib."${system}".override {
cargo = rust_channel;
rustc = rust_channel;
};
vulkan-dev = with pkgs; [
vulkan-headers
vulkan-loader
vulkan-tools
];

in rec {
name = "MFEKglif";
description = "Glyph editor for the Modular Font Editor K project.";

defaultPackage = naersk-lib.buildPackage {
pname = name;
inherit description;

root = ./.;
buildInputs = with pkgs; [
pkg-config
glibc
gn
ninja
];

LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (with pkgs; [ pkg-config ] ++ vulkan-dev)}:$LD_LIBRARY_PATH";
PKG_CONFIG_PATH = "${pkgs.glibc}:PKG_CONFIG_PATH";
};

devShells.default = pkgs.mkShell {
inherit name description;
buildInputs = with pkgs; [
# all of rust unstable
rust_channel
rust-analyzer
cargo
lld
pkg-config
glibc
gtk3.dev
SDL2
glif-test
] ++ vulkan-dev;

LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath (with pkgs; [ pkg-config ] ++ vulkan-dev)}:$LD_LIBRARY_PATH";
PKG_CONFIG_PATH = "${pkgs.glibc}:PKG_CONFIG_PATH";

# for rust-analyzer; the target dir of the compiler for the project
OUT_DIR = "./target";
# don't warn for dead code, unused imports or unused variables
RUSTFLAGS = "-A dead_code -A unused_imports -A unused_variables";
# force cross compilation when there is potential for it
CARGO_FEATURE_FORCE_CROSS = "true";
};

# For compatibility with older versions of the `nix` binary
devShell = self.devShells.${system}.default;
});
}
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