Skip to content
Snippets Groups Projects
flake.nix 2.14 KiB
{
  description = "gbs-downloader";

  inputs = {
    # Nix Inputs
    nixpkgs.follows = "hs-flake-utils/nixpkgs";
    flake-utils.url = github:numtide/flake-utils;
    hs-flake-utils.url = "git+https://whetstone.private.storage/jcalderone/hs-flake-utils.git?ref=main";
  };

  outputs = {
    self,
    nixpkgs,
    flake-utils,
    hs-flake-utils,
  }: let
    ulib = flake-utils.lib;
    ghcVersion = "ghc8107";
  in
    ulib.eachSystem ["x86_64-linux" "aarch64-darwin"] (system: let
      # Get a nixpkgs customized for this system and including our overlay.
      pkgs = import nixpkgs {
        inherit system;
      };
      hslib = hs-flake-utils.lib {
        inherit pkgs;
        src = ./.;
        compilerVersion = ghcVersion;
        packageName = "gbs-downloader";
        hsPkgsOverrides = import ./nix/haskell-packages.nix {
          haskellLib = pkgs.haskell.lib;
        };
      };
    in {
      checks = hslib.checks {};
      devShells = hslib.devShells {
        extraBuildInputs = pkgs:
          with pkgs; [
            zlib
          ];
      };
      packages = hslib.packages {};
      apps.hlint = hslib.apps.hlint {};

      # Using the working directory of `nix run`, do a build with cabal and
      # then run the test suite.
      apps.cabal-test = {
        type = "app";
        program = "${
          pkgs.writeShellApplication {
            name = "cabal-build-and-test";
            # Only put packages with things that need to be on PATH here
            # because that's all that runtimeInputs buys us.  Packages with
            # different requirements need to be handled differently.
            runtimeInputs = with pkgs; [
              pkg-config
              haskell.compiler.${ghcVersion}
              cabal-install
            ];

            text = ''
              # Here we make zlib discoverable by pkg-config so cabal can find
              # headers and stuff.
              export PKG_CONFIG_PATH=${pkgs.lib.makeSearchPath "lib/pkgconfig" [pkgs.zlib.dev]}

              cabal update hackage.haskell.org
              cabal run gbs-downloader-test
            '';
          }
        }/bin/cabal-build-and-test";
      };
    });
}