Skip to content
Snippets Groups Projects
flake.nix 5.58 KiB
Newer Older
  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";
    tahoe-directory = {
      url = "git+https://whetstone.private.storage/PrivateStorage/tahoe-directory.git";
      inputs.nixpkgs.follows = "hs-flake-utils/nixpkgs";
    };

    tahoe-chk.follows = "tahoe-directory/tahoe-chk";
    tahoe-ssk.follows = "tahoe-directory/tahoe-ssk";
    tahoe-capabilities.follows = "tahoe-directory/tahoe-capabilities";
    tahoe-great-black-swamp = {
      url = "git+https://whetstone.private.storage/PrivateStorage/tahoe-great-black-swamp?ref=refs/tags/0.3.0.0";
      inputs.nixpkgs.follows = "hs-flake-utils/nixpkgs";
      inputs.tahoe-chk.follows = "tahoe-chk";
  };

  outputs = {
    self,
    nixpkgs,
    flake-utils,
    hs-flake-utils,
    tahoe-capabilities,
    tahoe-directory,
  }: 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 = hfinal: hprev: {
          tahoe-chk = tahoe-chk.outputs.packages.${system}.default;
          tahoe-ssk = tahoe-ssk.outputs.packages.${system}.default;
          tahoe-directory = tahoe-directory.outputs.packages.${system}.default;
          tahoe-capabilities = tahoe-capabilities.outputs.packages.${system}.default;
          tahoe-great-black-swamp = tahoe-great-black-swamp.outputs.packages.${system}.default;

          # A broken dependency of a tahoe-great-black-swamp executable that
          # we don't use.  Flip the broken bit so we can get a build.
          language-ecmascript = pkgs.haskell.unmarkBroken hprev.language-ecmascript;
      };
    in {
      checks = hslib.checks {};
      devShells = hslib.devShells {
Jean-Paul Calderone's avatar
Jean-Paul Calderone committed
          nix run .#generate-cabal-project
        extraBuildInputs = pkgs:
          with pkgs; [
            # We configure cabal to use zlib:pkg-config so we better supply
            # pkg-config in the dev shell or `cabal ...` builds will surely
            # fail.
            pkg-config

            # And also that pesky zlib dependency.
      packages = hslib.packages {};
      apps.hlint = hslib.apps.hlint {};
Jean-Paul Calderone's avatar
Jean-Paul Calderone committed
      apps.generate-cabal-project = {
        type = "app";
        program = "${
          pkgs.writeShellApplication {
            name = "generate-cabal-project";
            text = ''
              cat >cabal.project.local <<EOF
              -- This file is auto-generated by the flake devShell's shellHook.  Do
              -- not edit this file.  Make changes in flake.nix.
              packages:
                -- These aren't released on hackage yet so we have to get them
                -- another way.  Here, we get them from the Nix store.
                -- tahoe-chk
                ${tahoe-chk}
                -- tahoe-ssk
                ${tahoe-ssk}
                -- tahoe-capabilities
                ${tahoe-capabilities}
                -- tahoe-directory
                ${tahoe-directory}
                -- tahoe-great-black-swamp
                ${tahoe-great-black-swamp}
              EOF
            '';
          }
        }/bin/generate-cabal-project";
      };

      apps.entr-test = {
        type = "app";
        program = "${
          pkgs.writeShellApplication {
            name = "entr-test";
            runtimeInputs = with pkgs; [
              entr
              cabal-install
              haskell.compiler.${ghcVersion}
            ];

            text = ''
              find . -iname '*.hs' -or -iname '*.cabal' | entr bash -c "cabal run tests; if [ \$? != 0 ]; then printf '\e[31m%s\e[0m\n' \"FAILED: \$?\"; else printf '\e[32m%s\e[0m\n' 'SUCCESS'; fi"
            '';
          }
        }/bin/entr-test";
      };

      # 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
Jean-Paul Calderone's avatar
Jean-Paul Calderone committed
            # 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
            ];
Jean-Paul Calderone's avatar
Jean-Paul Calderone committed
              nix run .#generate-cabal-project

              # 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]}

              # Get (or update if we have one) a package database so cabal can
              # solve our dependencies.
              cabal update hackage.haskell.org
Jean-Paul Calderone's avatar
Jean-Paul Calderone committed
              # Run the default test suite.  The local cabal project file
              # written above should have enabled tests so the build plan will
              # support them.
              cabal run tests
            '';
          }
        }/bin/cabal-build-and-test";
      };
    });
}