generated from Patagia/template-nix
187 lines
5.1 KiB
Nix
187 lines
5.1 KiB
Nix
{
|
|
inputs = {
|
|
advisory-db = {
|
|
url = "github:rustsec/advisory-db";
|
|
flake = false;
|
|
};
|
|
crane.url = "github:ipetkov/crane";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
nix-filter.url = "github:numtide/nix-filter";
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
|
|
rust-overlay.url = "github:oxalica/rust-overlay";
|
|
treefmt-nix.url = "github:numtide/treefmt-nix";
|
|
};
|
|
|
|
outputs =
|
|
{
|
|
self,
|
|
advisory-db,
|
|
crane,
|
|
flake-utils,
|
|
nix-filter,
|
|
nixpkgs,
|
|
rust-overlay,
|
|
treefmt-nix,
|
|
}:
|
|
flake-utils.lib.eachDefaultSystem (
|
|
system:
|
|
let
|
|
target = "x86_64-unknown-linux-musl";
|
|
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [ (import rust-overlay) ];
|
|
crossSystem.config = target;
|
|
};
|
|
staticPkgs = pkgs.pkgsStatic;
|
|
|
|
craneLib = (crane.mkLib staticPkgs).overrideToolchain (
|
|
p:
|
|
p.rust-bin.stable.latest.default.override {
|
|
targets = [ target ];
|
|
}
|
|
);
|
|
|
|
src = pkgs.lib.fileset.toSource {
|
|
root = ./.;
|
|
fileset = pkgs.lib.fileset.unions [
|
|
./api.json
|
|
./controller/.sqlx
|
|
./controller/migrations
|
|
(craneLib.fileset.commonCargoSources ./.)
|
|
];
|
|
};
|
|
|
|
commonArgs = {
|
|
inherit src;
|
|
|
|
strictDeps = true;
|
|
|
|
nativeBuildInputs = with staticPkgs.pkgsBuildHost; [ pkg-config ];
|
|
buildInputs = with staticPkgs.pkgsHostHost; [ openssl ];
|
|
|
|
CARGO_BUILD_TARGET = target;
|
|
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
|
|
"CARGO_TARGET_${pkgs.lib.toUpper (builtins.replaceStrings [ "-" ] [ "_" ] target)}_LINKER" =
|
|
"${staticPkgs.stdenv.cc.targetPrefix}cc";
|
|
|
|
OPENSSL_STATIC = true;
|
|
OPENSSL_DIR = "${staticPkgs.openssl.dev}";
|
|
OPENSSL_LIB_DIR = "${staticPkgs.openssl.out}/lib";
|
|
OPENSSL_INCLUDE_DIR = "${staticPkgs.openssl.dev}/include/";
|
|
};
|
|
|
|
buildCrate =
|
|
name: path:
|
|
craneLib.buildPackage commonArgs
|
|
// {
|
|
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
|
|
doCheck = false; # We use cargo-nextest for all tests
|
|
pname = name;
|
|
cargoExtraArgs = "-p ${name}";
|
|
};
|
|
|
|
patagia-agent = buildCrate "patagia-agent" ./agent;
|
|
patagia-controller = buildCrate "patagia-controller" ./controller;
|
|
hostd = buildCrate "hostd" ./hostd;
|
|
xtask = buildCrate "xtask" ./xtask;
|
|
in
|
|
{
|
|
packages = {
|
|
inherit
|
|
hostd
|
|
patagia-agent
|
|
patagia-controller
|
|
xtask
|
|
;
|
|
|
|
hostd-service =
|
|
let
|
|
hostd-service = pkgs.writeText "hostd.service" ''
|
|
[Unit]
|
|
Description=Patagia Hostd
|
|
|
|
[Service]
|
|
Environment=RUST_LOG=debug
|
|
ExecStart=${hostd}/bin/hostd
|
|
Restart=always
|
|
RestartSec=30s
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
'';
|
|
in
|
|
pkgs.portableService {
|
|
pname = "hostd";
|
|
version = "v0.0.1";
|
|
units = [ hostd-service ];
|
|
};
|
|
|
|
};
|
|
|
|
checks = {
|
|
inherit
|
|
hostd
|
|
patagia-agent
|
|
patagia-controller
|
|
xtask
|
|
;
|
|
|
|
audit = craneLib.cargoAudit (commonArgs // { inherit advisory-db; });
|
|
|
|
clippy = craneLib.cargoClippy commonArgs // {
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
};
|
|
|
|
fmt = craneLib.cargoFmt commonArgs;
|
|
|
|
nextest = craneLib.cargoNextest commonArgs // {
|
|
partitions = 1;
|
|
partitionType = "count";
|
|
};
|
|
|
|
openapi = pkgs.runCommand "openapi" commonArgs ''
|
|
${self.packages.${system}.xtask}/bin/xtask open-api |
|
|
${pkgs.diffutils}/bin/diff -u $src/api.json - |
|
|
tee $out
|
|
'';
|
|
};
|
|
|
|
formatter =
|
|
(treefmt-nix.lib.evalModule pkgs {
|
|
projectRootFile = "flake.nix";
|
|
|
|
programs = {
|
|
nixfmt.enable = true;
|
|
nixfmt.package = pkgs.nixfmt-rfc-style;
|
|
shfmt.enable = true;
|
|
rustfmt.enable = true;
|
|
};
|
|
settings.formatter.rustfmt.command = pkgs.lib.mkForce "${pkgs.rust-toolchain}/bin/rustfmt";
|
|
}).config.build.wrapper;
|
|
|
|
devShells.default = pkgs.mkShell {
|
|
nativeBuildInputs = commonArgs.nativeBuildInputs;
|
|
buildInputs = with pkgs; [
|
|
bacon
|
|
cargo-edit
|
|
cargo-features-manager
|
|
cargo-hakari
|
|
cargo-machete
|
|
cargo-nextest
|
|
cargo-watch
|
|
hyperfine
|
|
just
|
|
nixfmt-rfc-style
|
|
rust-dev-toolchain
|
|
sqls
|
|
sqlx-cli
|
|
watchexec
|
|
];
|
|
RUST_BACKTRACE = 1;
|
|
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc; # Required for rust-analyzer
|
|
};
|
|
|
|
}
|
|
);
|
|
}
|