Skip to content

Commit

Permalink
build: add flake.nix
Browse files Browse the repository at this point in the history
run `nix develop` to get a development environment
  • Loading branch information
Matthieu Coudron committed Mar 14, 2022
1 parent c4bcf64 commit 0fca1ef
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 30 deletions.
60 changes: 60 additions & 0 deletions flake.lock

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

47 changes: 47 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
description = "Generate Nix build instructions from a Cabal file";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";

flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};

outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system: let

pkgs = nixpkgs.legacyPackages.${system};

ghc8107 = pkgs.haskell.packages."ghc8107";

# modifier used in haskellPackages.developPackage
myModifier = hsPkgs: drv:
pkgs.haskell.lib.addBuildTools drv ([
hsPkgs.cabal-install
hsPkgs.haskell-language-server
]);

mkPackage = hsPkgs:
hsPkgs.developPackage {
root = pkgs.lib.cleanSource ./. ;
name = "cabal2nix";
returnShellEnv = false;
withHoogle = true;
modifier = myModifier hsPkgs;
};

in {
packages = {
cabal2nix = self.packages.${system}.cabal2nix-8107;
cabal2nix-8107 = mkPackage ghc8107;
};

devShell = self.packages.${system}.cabal2nix.envFunc {};

defaultPackage = self.packages.${system}.cabal2nix;
});
}
38 changes: 8 additions & 30 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
{ pkgs ? import <nixpkgs> {} }:

(import (
let
haskellPackages = pkgs.haskellPackages;
ghc = haskellPackages.ghcWithHoogle (hps: [
hps.ansi-wl-pprint
hps.distribution-nixpkgs
hps.hackage-db
hps.hopenssl
hps.hpack
hps.language-nix
hps.lens
hps.optparse-applicative
hps.pretty
hps.split
hps.yaml
hps.monad-par
hps.monad-par-extras
hps.tasty
hps.tasty-golden
]);

in pkgs.stdenv.mkDerivation {
name = "shell";
buildInputs = [
ghc
haskellPackages.cabal-install
haskellPackages.haskell-language-server
(pkgs.lib.getLib pkgs.openssl)
];
}
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

0 comments on commit 0fca1ef

Please sign in to comment.