oauth2-mock-server/flake.nix
2024-01-28 01:54:48 +00:00

90 lines
2.5 KiB
Nix

# SPDX-FileCopyrightText: 2024 UniWorX Systems
# SPDX-FileContributor: David Mosbach <david.mosbach@uniworx.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later
{
description = "Insecure mock server for OAuth2";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
name = "oauth2-mock-server";
pkgs = import nixpkgs { inherit system; };
stackWrapper = pkgs.symlinkJoin {
name = "stack";
paths = [ pkgs.stack ];
buildInputs = with pkgs; [ makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "--no-install-ghc"
'';
};
buildInputs = [ stackWrapper ] ++ (
with pkgs; [ reuse zlib postgresql_16 ] ++ (
with haskell.packages."ghc927"; [ ghc haskell-language-server ]
)
);
libPath = pkgs.lib.makeLibraryPath buildInputs;
oms = pkgs.stdenv.mkDerivation {
inherit buildInputs;
inherit name;
pname = name;
src = ./.;
# dontUnpack = true;
buildPhase = ''
HOME=$out
LD_LIBRARY_PATH=${libPath}
mkdir -p $HOME/.stack
stack build --verbose
'';
installPhase = ''
mkdir -p $out/bin
mv .stack-work/install/${system}/*/*/bin/${name}-exe $out/bin/${name}
echo "moved"
'';
};
mkDB = builtins.readFile ./mkDB.sh;
killDB = builtins.readFile ./killDB.sh;
in {
packages.${system} = {
${name} = oms; # nixpkgs.legacyPackages.${system}.${name};
mkOauth2DB = pkgs.writeShellApplication {
name = "mkOauth2DB";
runtimeInputs = [ pkgs.postgresql_16 ];
text = ''
#!${pkgs.zsh}/bin/zsh -e
${mkDB}
'';
};
killOauth2DB = pkgs.writeShellApplication {
name = "killOauth2DB";
runtimeInputs = [ pkgs.postgresql_16 ];
text = ''
#!${pkgs.zsh}/bin/zsh -e
${killDB}
'';
};
default = self.packages.${system}.${name};
};
devShells.${system}.default = pkgs.mkShell {
buildInputs = buildInputs ++ (with self.packages.${system}; [mkOauth2DB killOauth2DB]);
LD_LIBRARY_PATH = libPath;
OAUTH2_HBA = ./hba_file;
OAUTH2_DB_SCHEMA = ./schema.sql;
shellHook = ''
${mkDB}
zsh
${killDB}
'';
};
};
}