Skip to content

Commit

Permalink
add flake with cabal
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Apr 12, 2023
1 parent 4884a77 commit cf497ce
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ If you are building with stack then use `stack build --flag telegram-bot-simple:
Contributions are welcome!
Feel free to ping me on GitHub, file an issue or submit a PR :)

### Nix

You can use a [Nix flake](https://nixos.wiki/wiki/Flakes) from this repo to get several development tools.

1. [Enable flakes](https://nixos.wiki/wiki/Flakes#Enable_flakes).

2. Run `nix develop`. This command will make available `cabal`, `ghc`, and `haskell-language-server`.

3. Run `cabal run example-echo-bot` to start a bot.

## Compatibility

| telegram-bot-api | telegram-bot-simple |
Expand Down
2 changes: 2 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
packages:
telegram-bot-api/
telegram-bot-simple/

flags: +examples
62 changes: 62 additions & 0 deletions flake.lock

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

66 changes: 66 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
inputs = {
flake-utils.url = "github:numtide/flake-utils/cfacdce06f30d2b68473a46042957675eebb3401";
nixpkgs.url = "github:NixOS/nixpkgs/1fb781f4a148c19e9da1d35a4cbe15d0158afc4e";
};
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};

telegram-bot-api = "telegram-bot-api";
telegram-bot-simple = "telegram-bot-simple";

systemDepends = [ pkgs.zlib ];
override = {
overrides = self: super:
let inherit (pkgs.haskell.lib) overrideCabal; in
{
"${telegram-bot-api}" = overrideCabal
(super.callCabal2nix telegram-bot-api ./${telegram-bot-api} { })
(x: { librarySystemDepends = systemDepends ++ (x.librarySystemDepends or [ ]); });
"${telegram-bot-simple}" = overrideCabal
(self.callCabal2nix telegram-bot-simple ./${telegram-bot-simple} {
"${telegram-bot-api}" = self."${telegram-bot-api}";
})
(x: { librarySystemDepends = systemDepends ++ (x.librarySystemDepends or [ ]); });
};
};

ghcVersion = "ghc927";
hpkgs = pkgs.haskell.packages.${ghcVersion};

getHaskellPackagesDeps = packages_:
with pkgs.lib.lists; pkgs.lib.lists.unique (
subtractLists packages_ (
concatLists (map
(package:
__filter pkgs.lib.attrsets.isDerivation (concatLists (
__attrValues package.getCabalDeps
)))
packages_)
)
);

ghcForPackages = hpkgs_: override_: packageNames_:
(hpkgs_.override override_).ghcWithPackages (ps:
getHaskellPackagesDeps (map (x: ps.${x}) packageNames_)
);

ghc = ghcForPackages hpkgs override [ telegram-bot-api telegram-bot-simple ];

tools = [
hpkgs.cabal-install
# ghc should go before haskell-language-server - https://github.com/NixOS/nixpkgs/issues/225895
ghc
hpkgs.haskell-language-server
];

devShells.default = pkgs.mkShell {
buildInputs = tools;
shellHook = "export LANG=C.utf8";
};
in
{
inherit devShells;
});
}

0 comments on commit cf497ce

Please sign in to comment.