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

[draft]: nix refactoring & ci changes #62

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
81 changes: 38 additions & 43 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{

description = "Cofree.Coffee Matrix Bot";

inputs = {
Expand All @@ -11,65 +10,61 @@
};
};

outputs = { self, nixpkgs, flake-utils }:
outputs = { self, nixpkgs, flake-utils, ... }:
let
ghcVersion = "924";
compiler = "ghc${ghcVersion}";
# default systems compatible with pre-commit-hooks.nix
# https://github.com/cachix/pre-commit-hooks.nix/pull/122
defaultSystems = [
"aarch64-linux"
# "aarch64-darwin"
"i686-linux"
"x86_64-darwin"
"x86_64-linux"
];
compiler = "ghc924";
overrides = hfinal: hprev: {
cofree-bot = hfinal.callCabal2nix "cofree-bot" ./. { };
};
in
flake-utils.lib.eachSystem defaultSystems (system:
let
pkgs = import nixpkgs { inherit system; };

# need to do the evalPkgs trick so that IFD works with `nix flake check`
# https://github.com/NixOS/nix/issues/4265
evalPkgs = import nixpkgs { system = "x86_64-linux"; };

# Our haskell packages override, needs to use evalPkgs because
# cabal2nix uses IFD
hsPkgs = evalPkgs.haskell.packages.${compiler}.override {
overrides = hfinal: hprev: {
cofree-bot = hfinal.callCabal2nix "cofree-bot" ./. { };
{
overlays.default = final: prev: {
haskell = prev.haskell // {
packages = prev.haskell.packages // {
ghc8107 = prev.haskell.packages.ghc8107.override { inherit overrides; };
ghc904 = prev.haskell.packages.ghc904.override { inherit overrides; };
ghc924 = prev.haskell.packages.ghc924.override { inherit overrides; };
};
};
};
} // flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};

scripts = import ./nix/scripts.nix {
s = pkgs.writeShellScriptBin;
ormolu = pkgs.ormolu;
};
in
rec {

# Note: cannot reference anything that depends on `evalPkgs` like `hsPkgs`
# otherwise non-x86_64-linux users will not be able to build the dev env
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
cabal2nix
cabal-install
ghcid
haskell.compiler.${compiler}
haskell.packages.${compiler}.haskell-language-server
ormolu
zlib
] ++ (builtins.attrValues scripts);
{
devShells = flake-utils.lib.flattenTree {
default = pkgs.mkShell {
buildInputs = with pkgs; [
# haskell development tools.
cabal-install
ghcid
ormolu
nixpkgs-fmt
(haskell.packages.${compiler}.ghcWithPackages (hpkgs: with hpkgs; [
haskell-language-server
]))
# system-level dependencies.
zlib.dev
] ++ (builtins.attrValues scripts);
};
};

packages = flake-utils.lib.flattenTree {
docker = import ./nix/docker.nix {
inherit pkgs;
cofree-bot = hsPkgs.cofree-bot;
cofree-bot = pkgs.haskell.packages.${compiler}.cofree-bot;
};
Comment on lines 61 to 64
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably doesn't make sense to have this under eachDefaultSystem since the docker stuff very likely only works on Linux systems

cofree-bot = hsPkgs.cofree-bot;
cofree-bot = pkgs.haskell.packages.${compiler}.cofree-bot;
};

defaultPackage = packages.cofree-bot;
defaultPackage = self.packages.cofree-bot;
});
}