Skip to content

Commit

Permalink
chore: packaging hac as nix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
wllfaria committed May 30, 2024
1 parent 05b2c28 commit 7c9d52c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ members = ["hac-config", "hac-core", "hac-client", "hac-colors", "hac-cli"]
default-members = ["hac-client"]
resolver = "2"

[workspace.metadata.crane]
name = "hac"

[workspace.package]
version = "0.1.0"

[workspace.dependencies]
hac-config = { path = "hac-config" }
hac-core = { path = "hac-core" }
Expand Down
75 changes: 75 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
nixpkgs,
rust-overlay,
crane,
...
}: let
inherit (nixpkgs) lib;
withSystem = f:
lib.fold lib.recursiveUpdate {}
(map f ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]);
in
withSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
inherit (pkgs) stdenv lib;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
buildDeps =
[pkgs.openssl]
++ lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
SystemConfiguration
]);
crate = craneLib.buildPackage {
# Filter src to only .rs, .toml, and .scm files to avoid needless recompiles
src = let
schemeFilter = path: _type: builtins.match ".*scm$" path != null;
schemeOrCargo = path: type:
(schemeFilter path type) || (craneLib.filterCargoSources path type);
in
lib.cleanSourceWith {
src = craneLib.path ./.;
filter = schemeOrCargo;
};
strictDeps = true;
buildInputs = buildDeps;
nativeBuildInputs = lib.optionals stdenv.isLinux [pkgs.pkg-config];
doNotSign = stdenv.isDarwin; # Build seems to break when this is true on Darwin
};
in {
apps.${system}.default = let
name = crate.pname or crate.name;
exe = crate.passthru.exePath or "/bin/${name}";
in {
type = "app";
program = "${crate}${exe}";
};
packages.${system}.default = crate;
checks.${system} = {inherit crate;};
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs;
[
toolchain
rust-analyzer-unwrapped
]
++ buildDeps;
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
}
);
}
4 changes: 4 additions & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[toolchain]
channel = "stable"
components = ["rust-src"]
profile = "default"

0 comments on commit 7c9d52c

Please sign in to comment.