diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..7c5aa683b --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1668681692, + "narHash": "sha256-Ht91NGdewz8IQLtWZ9LCeNXMSXHUss+9COoqu6JLmXU=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "009399224d5e398d03b22badca40a37ac85412a1", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "locked": { + "lastModified": 1652776076, + "narHash": "sha256-gzTw/v1vj4dOVbpBSJX4J0DwUR6LIyXo7/SuuTJp1kM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "04c1b180862888302ddfb2e3ad9eaa63afc60cf8", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "v1.0.0", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1669900182, + "narHash": "sha256-EKxjHxRJnP1w+2nnm8pq4Uqkqa5McnfPXcO8cG8Mxzc=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "bcb6dbbe30ce7631e5a0865dff1ab9b63d92977d", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..3d42acde0 --- /dev/null +++ b/flake.nix @@ -0,0 +1,80 @@ +{ inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + + flake-utils.url = "github:numtide/flake-utils/v1.0.0"; + }; + + outputs = { nixpkgs, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + ghcVersion = "ghc90"; + + config = { }; + + overlay = self: super: { + haskell = super.haskell // { + packages = super.haskell.packages // { + "${ghcVersion}" = super.haskell.packages."${ghcVersion}".override (old: { + overrides = + self.lib.composeExtensions + (old.overrides or (_: _: { })) + (hself: hsuper: { + # The reason we stick these underneath a `local` attribute + # is to avoid infinite recursion (because `callCabal2nix` + # depends on all of these packages. + local = rec { + cabal2nix = + hself.callCabal2nix "cabal2nix" ./cabal2nix { + inherit + distribution-nixpkgs + hackage-db + language-nix + ; + }; + + distribution-nixpkgs = + hself.callCabal2nix + "distribution-nixpkgs" + ./distribution-nixpkgs + { inherit language-nix; }; + + hackage-db = + hself.callCabal2nix "hackage-db" ./hackage-db { }; + + language-nix = + hself.callCabal2nix "language-nix" ./language-nix { }; + }; + }); + }); + }; + }; + }; + + pkgs = + import nixpkgs { inherit config system; overlays = [ overlay ]; }; + + in + rec { + devShells = rec { + cabal2nix = + pkgs.haskell.packages."${ghcVersion}".local.cabal2nix.env; + + distribution-nixpkgs = + pkgs.haskell.packages."${ghcVersion}".local.distribution-nixpkgs.env; + + hackage-db = + pkgs.haskell.packages."${ghcVersion}".local.hackage-db.env; + + language-nix = + pkgs.haskell.packages."${ghcVersion}".local.language-nix.env; + + default = cabal2nix; + }; + } + ); +} diff --git a/shell.nix b/shell.nix index 76f794e5d..6234bb4d6 100644 --- a/shell.nix +++ b/shell.nix @@ -1,38 +1,10 @@ -{ pkgs ? import { } -, ghcVersion ? pkgs.haskellPackages.ghc.version -, withHls ? true -}: - -let - haskellPackages = pkgs.haskell.packages."ghc${ - builtins.replaceStrings [ "." ] [ "" ] ghcVersion - }"; - ghc = haskellPackages.ghcWithHoogle (hps: [ - hps.ansi-wl-pprint - hps.hopenssl - hps.hpack - hps.lens - hps.optparse-applicative - hps.pretty - hps.split - hps.yaml - hps.monad-par - hps.monad-par-extras - hps.tasty - hps.tasty-golden - hps.utf8-string - hps.tar - hps.hspec - hps.parsec-class - ]); - -in pkgs.mkShell { - packages = [ - ghc - pkgs.cabal-install - pkgs.haskell-ci - (pkgs.lib.getLib pkgs.openssl) - ] ++ pkgs.lib.optionals withHls [ - haskellPackages.haskell-language-server - ]; -} +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix