Skip to content

Instantly share code, notes, and snippets.

@rpearce
Last active August 15, 2023 00:36
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save rpearce/114271b23004c3eb25e55686618786fc to your computer and use it in GitHub Desktop.
Flake for using Haskell in nix develop
:def hoogle \x -> return $ ":!hoogle --count=15 \"" ++ x ++ "\""
:def doc \x -> return $ ":!hoogle --info \"" ++ x ++ "\""
:set -Wall
:set -fno-warn-type-defaults -ferror-spans -freverse-errors -fprint-expanded-synonyms
:set prompt "\ESC[0;32m%s\n\ESC[m[ghci]\ESC[38;5;172mλ \ESC[m"
:set prompt-cont " \ESC[38;5;172m> \ESC[m"
{
description = "Simple haskell nix flake";
nixConfig.bash-prompt = "[nix]\\e\[38;5;172mλ \\e\[m";
inputs = {
nixpkgs.url = "nixpkgs/nixos-21.05";
flake-utils = {
url = "github:numtide/flake-utils";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { flake-utils, nixpkgs, self }:
flake-utils.lib.eachDefaultSystem (system:
let
config = {};
overlays = [];
pkgs = import nixpkgs { inherit config overlays system; };
in rec {
devShell = pkgs.haskellPackages.shellFor {
packages = p: [
];
buildInputs = with pkgs.haskellPackages; [
cabal-install
# Helpful tools for `nix develop` shells
#
#ghcid # https://github.com/ndmitchell/ghcid
#haskell-language-server # https://github.com/haskell/haskell-language-server
#hlint # https://github.com/ndmitchell/hlint
#ormolu # https://github.com/tweag/ormolu
];
withHoogle = true;
};
}
);
}
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <https://unlicense.org>
@rpearce
Copy link
Author

rpearce commented Jun 19, 2021

Instructions

With nix flakes enabled, from the command line, run

$ nix develop

...wait...

You'll then be dropped into the nix develop shell

[nix]λ

From here, you can use cabal to create a new project, etc, or you can run ghci to open the haskell REPL environment:

[nix]λ ghci
GHCi, version 8.10.4: https://www.haskell.org/ghc/  :? for help
macro 'doc' overwrites builtin command.  Use ':def!' to overwrite.
Loaded GHCi configuration from /Users/rpearce/projects/zurihac-beginners/.ghci
Prelude
[ghci]λ :t fmap
fmap :: Functor f => (a -> b) -> f a -> f b

@wuyoli
Copy link

wuyoli commented May 28, 2022

This is a very interesting flake. I would like to use it in some of my projects. How is this licensed? If you haven't decided yet i would like to suggest the MIT license since my projects are under MIT and GPL.

@rpearce
Copy link
Author

rpearce commented May 30, 2022

@wuyoli I added a license. I'm glad it helps!

@wuyoli
Copy link

wuyoli commented May 30, 2022

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment