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

add flake #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
48 changes: 48 additions & 0 deletions flake.lock

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

121 changes: 121 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
{
description = "Nix CMake Template";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts = {
url = "github:hercules-ci/flake-parts";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, flake-parts, nixpkgs, ... }:
flake-parts.lib.mkFlake { inherit self; } {
systems = [ "x86_64-linux" ];
imports = [
];
perSystem = { config, self', inputs', pkgs, system, ... }:
let
pkgs = inputs'.nixpkgs.legacyPackages;
inherit (pkgs) lib;

makeStatic =
let
staticPostgresql = (pkgs.postgresql_11.overrideAttrs (o: {
dontDisableStatic = true;
# https://www.postgresql-archive.org/building-libpq-a-static-library-td5970933.html
postConfigure = o.postConfigure + ''
echo -e 'libpq.a: $(OBJS)\n\tar rcs $@ $^' >> ./src/interfaces/libpq/Makefile
'';
buildPhase = ''
make world
make -C ./src/interfaces/libpq libpq.a
'';
postInstall = o.postInstall + ''
cp src/interfaces/libpq/libpq.a $out/lib/
cp src/interfaces/libpq/libpq.a $lib/lib/
'';
})).override { gssSupport = false; };

staticPqxx = (pkgs.libpqxx.overrideAttrs (o: { configureFlags = [ ]; })).override {
stdenv = pkgs.makeStaticLibraries pkgs.stdenv;
postgresql = staticPostgresql;
};
staticOpenssl = pkgs.openssl.override { static = true; };
in
drv: (drv.override {
static = true;
libpqxx = staticPqxx;
}).overrideAttrs (o: {
buildInputs = o.buildInputs ++ [
pkgs.glibc.static
staticOpenssl
staticPostgresql
];
doCheck = false;
});

serverVariants =
let
fromInputs = { stdenv, boost16x, static }:
let
p = pkgs.callPackage ./server/derivation.nix { };
noDots = lib.replaceChars [ "." ] [ "_" ];
staticStr = lib.optionalString static "-static";
name = "${p.name}-${noDots stdenv.cc.cc.name}-${noDots boost16x.name}${staticStr}";
maybeMakeStatic = drv: if static then makeStatic drv else drv;
drv = maybeMakeStatic (p.override { inherit boost16x stdenv; });
in
lib.nameValuePair name drv;

inputVariants = lib.cartesianProductOfSets {
stdenv = with pkgs;
map (overrideCC stdenv) [ gcc9 gcc10 gcc11 ]
++ map (overrideCC clangStdenv) [ clang_11 clang_12 clang_13 ];
boost16x = with pkgs; [ boost168 boost169 ];
static = [ true false ];
};
in
builtins.listToAttrs (builtins.map fromInputs inputVariants);

integrationTests =
let integrationTest = mdbServer: import ./integration_test.nix {
inherit pkgs mdbServer;
mdbWebservice = self'.packages.mdb-webserver;
};
in
pkgs.lib.mapAttrs' (k: v: pkgs.lib.nameValuePair ("integrationtest-${k}") (integrationTest v));
in
{
packages = serverVariants // {
mdb-server = pkgs.callPackage ./server/derivation.nix { };
mdb-server-no-python =
let # this is useful because libpqxx with python support depends on python2.7
# but we don't want python in its closure if we package it into a small
# docker image!
libpqxxWithoutPython = pkgs.libpqxx.override {
postgresql = pkgs.postgresql.override {
libxml2 = pkgs.libxml2.override { pythonSupport = false; };
};
};
in self'.packages.mdb-server.override { libpqxx = libpqxxWithoutPython; };
mdb-webserver = pkgs.python3Packages.callPackage ./python_client/derivation.nix { };
};
checks = { } // (integrationTests serverVariants);
};
flake = {
dockerImages =
let
makeDockerImage = name: entrypoint: nixpkgs.legacyPackages.x86_64-linux.dockerTools.buildImage {
inherit name;
tag = "latest";
config = { Entrypoint = [ entrypoint ]; };
};
in
{
mdb-webservice = makeDockerImage "mdb-webservice" "${self.packages.x86_64-linux.mdb-webserver}/bin/webserver";
mdb-server = makeDockerImage "mdb-server" "${self.packages.x86_64-linux.mdb-server-no-python}/bin/messagedb-server";
mdb-server-static = makeDockerImage "mdb-server" "${self.packages.x86_64-linux.mdb-server-gcc-9_5_0-boost-1_69_0-static}/bin/messagedb-server";
};
};
};
}