182 lines
5.5 KiB
Nix
182 lines
5.5 KiB
Nix
{
|
|
description = "Yama and Datman";
|
|
|
|
inputs = {
|
|
utils.url = "github:numtide/flake-utils";
|
|
naersk = {
|
|
url = "github:nix-community/naersk";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
# Current Rust in nixpkgs is too old unfortunately — let's use the Fenix overlay's packages...
|
|
fenix = {
|
|
url = "github:nix-community/fenix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
nixpkgs.url = "nixpkgs/nixos-23.11";
|
|
poetry2nix = {
|
|
url = "github:nix-community/poetry2nix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, utils, naersk, fenix, poetry2nix }:
|
|
utils.lib.eachDefaultSystem (system: let
|
|
pkgs = nixpkgs.legacyPackages."${system}";
|
|
|
|
inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication;
|
|
|
|
#fenixRustToolchain = fenix.packages."${system}".minimal.toolchain
|
|
# fenixRustToolchain =
|
|
# fenix."${system}".complete.withComponents [
|
|
# "cargo"
|
|
# "clippy"
|
|
# "rust-src"
|
|
# "rustc"
|
|
# "rustfmt"
|
|
# ];
|
|
# fenixRustToolchain = fenix.packages."${system}".stable.toolchain;
|
|
fenixRustToolchain =
|
|
fenix.packages."${system}".stable.withComponents [
|
|
"cargo"
|
|
"clippy"
|
|
"rust-src"
|
|
"rustc"
|
|
"rustfmt"
|
|
"rust-analyzer"
|
|
];
|
|
# rust-toolchain = pkgs.symlinkJoin {
|
|
# name = "rust-toolchain";
|
|
# paths = [fenixRustToolchain.rustc fenixRustToolchain.cargo fenixRustToolchain.clippy fenixRustToolchain.rustfmt fenixRustToolchain.rustPlatform.rustcSrc];
|
|
# };
|
|
|
|
#naersk-lib = naersk.lib."${system}";
|
|
naersk-lib = pkgs.callPackage naersk {
|
|
cargo = fenixRustToolchain;
|
|
rustc = fenixRustToolchain;
|
|
};
|
|
|
|
rustComponents = naersk-lib.buildPackage {
|
|
pname = "yama";
|
|
root = ./.;
|
|
|
|
overrideMain = attrs: {
|
|
# Set up the dev database, needed for compile-time query checking.
|
|
preConfigure = ''
|
|
export PATH="${pkgs.sqlx-cli}/bin:$PATH"
|
|
pushd yama_localcache
|
|
bash dev_db.sh
|
|
popd
|
|
'';
|
|
|
|
# Temporary, whilst we still need to occasionally rely on a debugger:
|
|
# don't strip debug symbols, at the cost of a much larger binary!
|
|
dontStrip = true;
|
|
};
|
|
|
|
buildInputs = with pkgs; [
|
|
openssl
|
|
pkg-config
|
|
sqlite
|
|
];
|
|
};
|
|
|
|
mysqlHelper = mkPoetryApplication {
|
|
projectDir = ./datman-helper-mysql;
|
|
};
|
|
|
|
postgresHelper = mkPoetryApplication {
|
|
projectDir = ./datman-helper-postgres;
|
|
};
|
|
|
|
# We want to produce a package with all of these together, with wrappers that let them
|
|
# refer to each other by name (i.e. have each other on the path).
|
|
# Datman needs the helpers on the path.
|
|
# The helpers need lz4 on the path.
|
|
allInOne = pkgs.stdenv.mkDerivation {
|
|
name = "datman-aio";
|
|
|
|
src = "${pkgs.emptyDirectory}";
|
|
|
|
installPhase = ''
|
|
# set -eu
|
|
mkdir $out $out/bin
|
|
ln -s ${rustComponents}/bin/{yama,datman,yamascan} $out/bin
|
|
ln -s ${mysqlHelper}/bin/datman-helper-mysql-{backup,restore} $out/bin
|
|
ln -s ${postgresHelper}/bin/datman-helper-postgres-{backup,restore} $out/bin
|
|
ln -s ${pkgs.lz4}/bin/lz4 $out/bin/
|
|
runHook postInstall
|
|
'';
|
|
|
|
buildInputs = [ pkgs.makeWrapper ];
|
|
|
|
postInstall = ''
|
|
# set -eu
|
|
for fnbase in {datman,yama,yamascan,datman-helper-{mysql,postgres}-{backup,restore}}; do
|
|
fn="$out/bin/$fnbase"
|
|
wrapProgram $fn --suffix PATH : $out/bin
|
|
mv "$out/bin/$fnbase" "$out/bin/7$fnbase"
|
|
done
|
|
'';
|
|
};
|
|
in rec {
|
|
# `nix build`
|
|
packages.yama = allInOne;
|
|
|
|
defaultPackage = packages.yama;
|
|
|
|
# NixOS Modules
|
|
# nixosModules = {
|
|
# yama = import ./nixos_modules/yama.nix self;
|
|
# };
|
|
|
|
# `nix run`
|
|
apps.yama = utils.lib.mkApp {
|
|
drv = rustComponents;
|
|
};
|
|
defaultApp = apps.yama;
|
|
|
|
# `nix develop`
|
|
devShell = pkgs.mkShell {
|
|
buildInputs = [
|
|
fenixRustToolchain
|
|
#rust-toolchain
|
|
|
|
pkgs.pkg-config
|
|
|
|
pkgs.alsa-lib
|
|
pkgs.sqlite
|
|
pkgs.sqlx-cli
|
|
#pkgs.libclang # ??
|
|
];
|
|
|
|
nativeBuildInputs = [
|
|
pkgs.openssl
|
|
pkgs.python3
|
|
];
|
|
|
|
# Needed for bindgen when binding to avahi
|
|
LIBCLANG_PATH="${pkgs.llvmPackages_latest.libclang.lib}/lib";
|
|
|
|
# Don't know if this var does anything by itself, but you need to feed this value in to IntelliJ IDEA and it's probably easier to pull out of an env var than look it up each time.
|
|
RUST_SRC_PATH = "${fenixRustToolchain}/lib/rustlib/src/rust/library";
|
|
|
|
# Cargo culted:
|
|
# Add to rustc search path
|
|
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
|
|
]);
|
|
# Add to bindgen search path
|
|
BINDGEN_EXTRA_CLANG_ARGS =
|
|
# Includes with normal include path
|
|
(builtins.map (a: ''-I"${a}/include"'') [
|
|
])
|
|
# Includes with special directory paths
|
|
++ [
|
|
''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"''
|
|
#''-I"${pkgs.glib.dev}/include/glib-2.0"''
|
|
#''-I${pkgs.glib.out}/lib/glib-2.0/include/''
|
|
];
|
|
#nativeBuildInputs = with pkgs; [ rustc cargo ];
|
|
};
|
|
});
|
|
}
|