garage/flake.nix
Alex Auvolat 53985917c9
Some checks failed
ci/woodpecker/push/debug Pipeline failed
WIP try crate2nix but doesn't work
2025-01-13 12:31:08 +01:00

108 lines
3.5 KiB
Nix

{
description =
"Garage, an S3-compatible distributed object store for self-hosted deployments";
# Nixpkgs 24.11 as of 2025-01-12 has rustc v1.82
inputs.nixpkgs.url =
"github:NixOS/nixpkgs/7c4869c47090dd7f9f1bdfb49a22aea026996815";
inputs.flake-compat.url = "github:nix-community/flake-compat";
inputs.cargo2nix = {
# As of 2022-10-18: two small patches over unstable branch, one for clippy and one to fix feature detection
#url = "github:Alexis211/cargo2nix/a7a61179b66054904ef6a195d8da736eaaa06c36";
# As of 2023-04-25:
# - my two patches were merged into unstable (one for clippy and one to "fix" feature detection)
# - rustc v1.66
# url = "github:cargo2nix/cargo2nix/8fb57a670f7993bfc24099c33eb9c5abb51f29a2";
# Mainline cargo2nix as of of 2025-01-12 (branch release-0.11.0)
url = "github:cargo2nix/cargo2nix/ae19a9e1f8f0880c088ea155ab66cee1fa001f59";
# Rust overlay as of 2025-01-12
inputs.rust-overlay.url =
"github:oxalica/rust-overlay/162ab0edc2936508470199b2e8e6c444a2535019";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-compat.follows = "flake-compat";
};
inputs.flake-utils.follows = "cargo2nix/flake-utils";
inputs.rust-overlay.follows = "cargo2nix/rust-overlay";
outputs = { self, nixpkgs, cargo2nix, flake-utils, rust-overlay, ... }:
let
git_version = self.lastModifiedDate;
compile = import ./nix/compile.nix;
in
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
nativeBuild =
pkgs.callPackage ./Cargo.nix {
release = false;
};
crossBuild = target:
let
crossPkgs = import nixpkgs {
inherit system;
crossSystem = {
config = target;
};
overlays = [ rust-overlay.overlays.default ];
};
buildRustCrateForPkgs = pkgs: pkgs.buildRustCrate.override {
rustc = pkgs.rust-bin.stable."1.77.0".default;
cargo = pkgs.rust-bin.stable."1.77.0".default;
};
in
crossPkgs.callPackage ./Cargo.nix {
inherit buildRustCrateForPkgs;
release = false;
};
in
{
packages =
{
# default = native release build
default = nativeBuild.workspaceMembers."garage".build;
# cross-platform builds
amd64 = (crossBuild "x86_64-linux").workspaceMembers."garage".build;
i386 = (crossBuild "i686-linux").workspaceMembers."garage".build;
};
# ---- developpment shell, for making native builds only ----
devShells =
let
shellWithPackages = (packages: (compile {
inherit system git_version;
pkgsSrc = nixpkgs;
cargo2nixOverlay = cargo2nix.overlays.default;
}).workspaceShell { inherit packages; });
in
{
default = shellWithPackages
(with pkgs; [
rustfmt
clang
mold
]);
# import the full shell using `nix develop .#full`
full = shellWithPackages (with pkgs; [
rustfmt
rust-analyzer
clang
mold
# ---- extra packages for dev tasks ----
cargo-audit
cargo-outdated
cargo-machete
nixpkgs-fmt
]);
};
});
}