Files
mu4e/flake.nix
2026-08-20 15:05:32 -07:00

108 lines
4.0 KiB
Nix

{
description = "project with vendored meson subprojects";
inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; };
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
# One entry per .wrap file. `hash`/`patchHash` are the
# source_hash/patch_hash values from the .wrap, as-is (hex sha256 --
# Nix's `sha256 =` attr accepts hex directly).
subprojects = {
cli11 = {
dir = "CLI11-2.7.2";
src = pkgs.fetchurl {
url = "https://github.com/CLIUtils/CLI11/archive/refs/tags/v2.7.2.tar.gz";
sha256 = "46eef3101da70852ec7af026e09d485ccee81813331c8c6052d39344443b83da";
};
};
fmt = {
dir = "fmt-12.0.0";
src = pkgs.fetchurl {
url = "https://github.com/fmtlib/fmt/archive/12.0.0.tar.gz";
sha256 = "aa3e8fbb6a0066c03454434add1f1fc23299e85758ceec0d7d2d974431481e40";
};
patch = pkgs.fetchurl {
url = "https://wrapdb.mesonbuild.com/v2/fmt_12.0.0-1/get_patch";
sha256 = "307f288ebf3850abf2f0c50ac1fb07de97df9538d39146d802f3c0d6cada8998";
};
};
tabulate = {
dir = "tabulate-1.5";
src = pkgs.fetchurl {
url = "https://github.com/p-ranav/tabulate/archive/refs/tags/v1.5.tar.gz";
sha256 = "16b289f46306283544bb593f4601e80d6ea51248fde52e910cc569ef08eba3fb";
};
patch = pkgs.fetchurl {
url = "https://wrapdb.mesonbuild.com/v2/tabulate_1.5-1/get_patch";
sha256 = "3c7c5f90b320d9096bc4335ff2c1f0c5b8e0c869d25c92eb4fce519609fb22f7";
};
};
tl-expected = {
dir = "expected-1.3.1";
src = pkgs.fetchurl {
url = "https://github.com/TartanLlama/expected/archive/v1.3.1.tar.gz";
sha256 = "9a04f4f472fbb5c30bf60402f1ca626c4a76987f867978d0b8a35d7ab3fb8fe7";
};
patch = pkgs.fetchurl {
url = "https://wrapdb.mesonbuild.com/v2/tl-expected_1.3.1-1/get_patch";
sha256 = "91cfeae04ba6ea05792e68a37781236a7045b9e2e4e0c8b7093fd8c3e43b0bad";
};
};
tl-optional = {
dir = "optional-1.1.0";
src = pkgs.fetchurl {
url = "https://github.com/TartanLlama/optional/archive/refs/tags/v1.1.0.tar.gz";
sha256 = "88ece79f3de5ccaec4191951a222f95cc80c4381dafd3163bdb1ff87cedf3118";
};
patch = pkgs.fetchurl {
url = "https://wrapdb.mesonbuild.com/v2/tl-optional_1.1.0-1/get_patch";
sha256 = "b64e2a89e44279074d845de4fce85151a27ce65298849e87f6069a77967d4eb7";
};
};
};
# Build the shell commands that stage each subproject's source (and,
# if present, unzip its wrapdb "patch" overlay on top) into
# subprojects/<dir>, exactly like `meson subprojects download` would.
stageSubprojects = pkgs.lib.concatStrings (pkgs.lib.mapAttrsToList
(name: sp: ''
mkdir -p "subprojects/${sp.dir}"
tar xf ${sp.src} -C subprojects --strip-components=0
${pkgs.lib.optionalString (sp ? patch) ''
unzip -o -q ${sp.patch} -d "subprojects/${sp.dir}"
''}
'') subprojects);
in {
packages.${system}.default = pkgs.stdenv.mkDerivation {
name = "myproject";
src = self;
nativeBuildInputs = with pkgs; [
pkg-config
meson
ninja
unzip
python3
];
buildInputs = [ ];
postPatch = stageSubprojects + ''
# Scripts vendored via fetchurl (e.g. CLI11's scripts/ExtractVersion.py)
# keep their original #!/usr/bin/env python3 shebang, which doesn't
# resolve inside the Nix build sandbox. patchShebangs rewrites them
# to point at the python3 in nativeBuildInputs.
patchShebangs subprojects
'';
mesonFlags = [
"--wrap-mode=nodownload"
];
};
};
}