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

chore: move to crane for building the package #42

Merged
merged 1 commit into from
Dec 4, 2023
Merged
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
57 changes: 22 additions & 35 deletions flake.lock

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

20 changes: 17 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@
flake-parts.url = "github:hercules-ci/flake-parts";
devshell.url = "github:numtide/devshell";
# Utils for building Rust stuff
naersk.url = "github:nmattia/naersk/master";

crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
# fenix = {
# url = "github:nix-community/fenix";
# inputs.nixpkgs.follows = "nixpkgs";
# inputs.rust-analyzer-src.follows = "";
# };
# advisory-db = {
# url = "github:rustsec/advisory-db";
# flake = false;
# };

# The Rust source for xremap
xremap = {
url = "github:k0kubun/xremap?ref=v0.8.12";
Expand Down Expand Up @@ -39,11 +53,11 @@
];
perSystem = { config, self', inputs', pkgs, system, ... }:
let
naersk-lib = pkgs.callPackage inputs.naersk { };
craneLib = inputs.crane.lib.${system};
in
{
formatter = pkgs.nixpkgs-fmt;
packages = import ./overlay { inherit (inputs) xremap; inherit naersk-lib pkgs; };
packages = import ./overlay { inherit (inputs) xremap; inherit craneLib pkgs; };
# This way all packages get immediately added to the overlay except for the one called literally called "default"
overlayAttrs = builtins.removeAttrs config.packages [ "default" ];
devshells.default = {
Expand Down
28 changes: 21 additions & 7 deletions overlay/default.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
# Overlay file that contains the definition of building a package
{ xremap, naersk-lib, pkgs }:
{ xremap, craneLib, pkgs }:
let
packageWithFeature = feature: naersk-lib.buildPackage {
root = xremap;
cargoBuildOptions = (x: x ++ pkgs.lib.optional (feature != null) "--features ${feature}");
commonArgs = {
src = xremap;
strictDeps = true;

buildInputs = [
# Add additional build inputs here
];

# Additional environment variables can be set directly
# MY_CUSTOM_VAR = "some value";
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;

packageWithFeature = feature: craneLib.buildPackage (commonArgs // {
inherit cargoArtifacts;
cargoExtraArgs = "--locked${if (feature != null) then " --features ${feature}" else ""}";
# cargoBuildOptions = (x: x ++ pkgs.lib.optional (feature != null) "--features ${feature}");
# The following two options are for introspection to be able to see if sway/gnome were actually pulled in
# To see that - visually inspect the deps directory inside result/target/ and check for swayipc/zbus
# See cargo.toml for feature-specific deps
copyTarget = true;
compressTarget = false;
# copyTarget = true;
# compressTarget = false;
meta.mainProgram = "xremap";
};
});
in
rec {
# No features
Expand Down