Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] nix support #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 16 additions & 54 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
description = "A very basic flake with a shell";
description = "A very basic flake";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
naersk = {
url = "github:nmattia/naersk";
rust2nix = {
url = "github:anirudhb/rust2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
fenix = {
Expand All @@ -14,67 +14,27 @@
};
};

outputs = { self, nixpkgs, flake-utils, fenix, naersk }: flake-utils.lib.eachDefaultSystem (system:
outputs = { self, nixpkgs, flake-utils, fenix, rust2nix }: flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.lib;
fenixPkgs = fenix.packages.${system};
# FIXME: once nmattie/naersk#191 is merged
rust = fenixPkgs.combine [
fenixPkgs.latest.rustc
fenixPkgs.latest.cargo
];
naerskLib = naersk.lib."${system}".override {
rust2nixLib = rust2nix.lib.${system};
in rec {
packages.haas-api = rust2nixLib.mkRustApp {
pname = "haas_api";
src = ./.;
cargo = rust;
rustc = rust;
#buildInputs = [
# pkgs.darwin.apple_sdk.frameworks.Security
#];
#LDFLAGS = "-F ${pkgs.darwin.apple_sdk.frameworks.Security}/Library/Frameworks";
#NIX_DEBUG = "1";
};
haas-api-spec = {
pname = "haas_api";
root = ./.;
buildInputs = with pkgs; [
postgresql
] ++ lib.optionals (lib.hasSuffix system "linux") (with pkgs; [
pkg-config
openssl.dev
]);
};
in rec {
packages.haas-api = naerskLib.buildPackage haas-api-spec;
# FIXME: compile on non-macOS
packages.haas-api-docker =
let
pkgsCross = pkgs.pkgsCross.musl64;
target = "x86_64-unknown-linux-musl";
toolchain = with fenixPkgs; combine [
latest.rustc
latest.cargo
targets.${target}.latest.rust-std
];
cc-naerskLib = naersk.lib."${system}".override {
cargo = toolchain;
rustc = toolchain;
};
cc-haas-api = cc-naerskLib.buildPackage {
pname = "haas_api";
root = ./.;
buildInputs = with pkgsCross; [
postgresql
pkg-config
openssl.dev
];
CARGO_BUILD_TARGET = target;
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER = "${pkgsCross.stdenv.cc}/bin/${target}-gcc";
#OPENSSL_STATIC = "1";
#OPENSSL_LIB_DIR = "${pkgsCross.openssl.dev}/lib";
#OPENSSL_INCLUDE_DIR = "${pkgsCross.openssl.dev}/lib";
};
in
pkgs.dockerTools.buildImage {
name = "haas-api";
config = {
Cmd = [ "${cc-haas-api}/bin/haas_api" ];
};
};
defaultPackage = packages.haas-api;

apps.haas-api = flake-utils.lib.mkApp {
Expand All @@ -86,6 +46,8 @@
nativeBuildInputs = with pkgs; [
fenixPkgs.stable.defaultToolchain
fenixPkgs.rust-analyzer
jq
libiconv
];
};
});
Expand Down