4r/flake.nix

197 lines
6.4 KiB
Nix

{
description = "4r";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/22.05;
utils.url = github:numtide/flake-utils;
relude-src = {
url = github:kowainik/relude/v1.1.0.0;
flake = false;
};
doctest-src = {
url = github:sol/doctest/0.20.0;
flake = false;
};
servant-src = {
url = github:haskell-servant/servant;
flake = false;
};
polysemy-zoo-src = {
url = github:polysemy-research/polysemy-zoo/006421384e61f4a7f66670e69af926735c91a65e;
flake = false;
};
polysemy-src.url = github:polysemy-research/polysemy/v1.7.1.0;
servant-polysemy-src = {
url = github:AJChapman/servant-polysemy/v0.1.3;
flake = false;
};
};
outputs = inputs@{ nixpkgs, utils, ... }:
utils.lib.eachDefaultSystem (system:
let nixpkgs' = import nixpkgs {
inherit system;
};
this = ghcVersion:
let pkgs = nixpkgs'.haskell.packages.${ghcVersion}.override {
overrides = (import ./nix/dependencies.nix inputs ghcVersion);
};
_4r-api = pkgs.mkDerivation {
pname = "4r-api";
version = "0.1.0";
src = ./4r-api;
isExecutable = false;
isLibrary = true;
libraryHaskellDepends = with pkgs; [
aeson
base
http-api-data
polysemy
relude
servant
servant-client
servant-polysemy
];
doHaddock = false;
doHoogle = false;
license = nixpkgs.lib.licenses.gpl3Plus;
passthru = { inherit pkgs; };
};
_4r = pkgs.mkDerivation {
pname = "4r";
version = "0.1.0";
src = ./4r;
isExecutable = true;
executableHaskellDepends = with pkgs; [
_4r-api
aeson
ansi-terminal
base
commonmark
commonmark-extensions
cryptohash-sha512
http-api-data
http-client
optparse-applicative
polysemy
relude
servant
servant-client
servant-polysemy
unordered-containers
];
license = nixpkgs.lib.licenses.gpl3Plus;
passthru = { inherit pkgs; };
};
_4r-feed = pkgs.mkDerivation {
pname = "4r-feed";
version = "0.1.0";
src = ./4r-feed;
isExecutable = true;
executableHaskellDepends = with pkgs; [
_4r-api
ansi-terminal
base
commonmark
commonmark-extensions
optparse-applicative
polysemy
relude
servant
servant-polysemy
];
license = nixpkgs.lib.licenses.gpl3Plus;
passthru = { inherit pkgs; };
};
in
{ inherit _4r _4r-api _4r-feed; };
thisNative = this "ghc922";
in
{
packages = {
inherit thisNative;
default = thisNative._4r;
};
apps =
let binaryToApp = bin: { type = "app"; program = "${bin}/bin/${bin.pname}"; };
in
rec {
_4r = binaryToApp thisNative._4r;
_4r-feed = binaryToApp thisNative._4r-feed;
default = _4r;
};
devShells =
let unwords = nixpkgs'.lib.concatStringsSep " ";
options = [
"-Wall"
"-Wcompat"
"-Wincomplete-uni-patterns"
"-Wredundant-constraints"
"-Wmissing-export-lists"
"-Wincomplete-record-updates"
"-Wmissing-deriving-strategies"
];
extensions = [
"-XNoImplicitPrelude"
"-XNoFieldSelectors"
"-XOverloadedRecordDot"
"-XDuplicateRecordFields"
"-XBangPatterns"
"-XBinaryLiterals"
"-XBlockArguments"
"-XConstraintKinds"
"-XDataKinds"
"-XDeriveFunctor"
"-XDeriveGeneric"
"-XDerivingStrategies"
"-XFlexibleContexts"
"-XFlexibleInstances"
"-XGADTs"
"-XGeneralizedNewtypeDeriving"
"-XHexFloatLiterals"
"-XImportQualifiedPost"
"-XInstanceSigs"
"-XKindSignatures"
"-XLambdaCase"
"-XMultiParamTypeClasses"
"-XNumericUnderscores"
"-XOverloadedStrings"
"-XScopedTypeVariables"
"-XStandaloneDeriving"
"-XTupleSections"
"-XTypeApplications"
"-XTypeOperators"
"-XTypeSynonymInstances"
"-XUndecidableInstances"
];
default = thisNative._4r.env;
ghciIn = dir: default.overrideAttrs (_: {
shellHook = ''
ghci ${unwords (options ++ extensions)} $(find ${dir} -name '*.hs')
exit $?
'';
});
in
{
inherit default;
_4r = ghciIn "4r";
_4r-api = ghciIn "4r-api";
_4r-feed = ghciIn "4r-feed";
fourmolu = default.overrideAttrs (a: {
nativeBuildInputs = a.nativeBuildInputs ++ [ thisNative._4r.passthru.pkgs.fourmolu ];
shellHook = ''
fourmolu --mode inplace \
--indentation 2 --check-idempotence --import-export-comma-style leading \
${unwords (map (e: "-o ${e}") (options ++ extensions))} \
$(find . -name '*.hs')
exit $?
'';
});
};
});
}