Skip to content

Commit

Permalink
Add Nix flake (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
stackptr authored Aug 9, 2023
1 parent 7209fd9 commit 7470f9a
Show file tree
Hide file tree
Showing 12 changed files with 337 additions and 0 deletions.
95 changes: 95 additions & 0 deletions flake.lock

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

41 changes: 41 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
inputs = {
/* The most recent stable channel */
stable.url =
"github:nixos/nixpkgs/nixos-23.05";

/* The unstable channel, the very latest of everything */
unstable.url =
"github:nixos/nixpkgs/nixos-unstable";

/* Hash obtained from https://www.nixhub.io/packages/ghc */
ghc926.url =
"github:nixos/nixpkgs/796b4a3c1d903c4b9270cd2548fe46f524eeb886";

flake-utils.url = "github:numtide/flake-utils";
};
outputs = inputs:
inputs.flake-utils.lib.eachDefaultSystem (system:
let
nixpkgsArgs = {
inherit system;
config = { };
};

/* An attribute set containing various historic versions of the huge Nix
package database. This is passed as an argument to functions in the
./nix directory which can then select which versions they want to pull
each dependency from. */

nixpkgs = {
stable = import inputs.stable nixpkgsArgs;
unstable = import inputs.unstable nixpkgsArgs;
ghc926 = import inputs.ghc926 nixpkgsArgs;
};

in
{
devShells.default =
import ./nix/shell.nix { inherit nixpkgs; };
});
}
2 changes: 2 additions & 0 deletions nix/cabal.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ nixpkgs }:
nixpkgs.stable.cabal-install
30 changes: 30 additions & 0 deletions nix/disabled-haskell-tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
These are overrides for Haskell packages that are marked as broken in nixpkgs
solely because their tests fail. The test failures are typically just because
the tests don't work in a pure nix environment, and so here we override them by
skipping the tests and marking the package as not broken.
*/
{ nixpkgs }:
let
list = [
"Blammo"
"datadog"
"dotenv"
"hspec-junit-formatter"
];
inherit (builtins) map listToAttrs;
inherit (nixpkgs.stable.haskell.lib) overrideCabal;
in

self: super:
listToAttrs (
map
(name: {
inherit name;
value = overrideCabal super.${name}
(drv: { doCheck = false; broken = false; });
})
list
)
15 changes: 15 additions & 0 deletions nix/fourmolu.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ nixpkgs }:
let
inherit (nixpkgs.stable) haskell;
inherit (haskell.lib) justStaticExecutables overrideCabal;
in
justStaticExecutables
(haskell.packages.ghc96.override {
inherit (nixpkgs.unstable) all-cabal-hashes;
overrides = self: super: {
fourmolu =
overrideCabal
(super.callHackage "fourmolu" "0.13.0.0" { })
(drv: { doCheck = false; });
};
}).fourmolu
23 changes: 23 additions & 0 deletions nix/ghc-with-packages.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
This package contains GHC and a bunch of Haskell packages.
It is important for the GHC version to match exactly what is expected by our
current Stack resolver.
It is less important for the packages to stay in sync with Stack, because if
Stack doesn't find what it wants in the shell environment, Stack will happily
build the dependencies it wants on its own. However, the better the nix shell
can stay in sync with Stack, the more benefit we can get out of it in terms of
build reproducibility and being able to utilize the nix binary cache for speed.
*/
{ nixpkgs }:
let
haskellPackages = nixpkgs.ghc926.haskellPackages.override {
inherit (nixpkgs.unstable) all-cabal-hashes;
overrides = import ./haskell-package-overrides.nix
{ inherit nixpkgs; };
};
in
haskellPackages.ghcWithPackages (import ./haskell-package-selection.nix)
3 changes: 3 additions & 0 deletions nix/haskell-language-server.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{ nixpkgs }:
nixpkgs.stable.haskell-language-server.override
{ supportedGhcVersions = [ "926" ]; }
36 changes: 36 additions & 0 deletions nix/haskell-native-dependencies.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
This package provides native dependencies of Haskell packages.
If Stack gives you an error message like...
- setup: The program '...' is required but it could not be found.
- The pkg-config package '...' is required but it could not be found.
- Missing dependency on a foreign library: Missing (or bad) C library: ...
... then you probably need to add something to this file.
To test that a Haskell package actually builds correctly within the nix
shell environment, it can help to first remove the package from the cache.
You can do that by running this command:
stack exec -- ghc-pkg unregister --force <haskell package name>
Then run `stack build <haskell package name>` to recompile.
*/
{ nixpkgs }:
let
pkgs = nixpkgs.stable;
in
pkgs.symlinkJoin {
name = "freckle-app-native-deps";
paths = [
pkgs.pcre
pkgs.pcre.dev
pkgs.postgresql
pkgs.rdkafka
pkgs.zlib
pkgs.zlib.dev
];
}
7 changes: 7 additions & 0 deletions nix/haskell-package-overrides.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ nixpkgs }:
let
inherit (nixpkgs.stable.lib) fold composeExtensions;
in
fold composeExtensions (_: _: { }) [
(import ./disabled-haskell-tests.nix { inherit nixpkgs; })
]
69 changes: 69 additions & 0 deletions nix/haskell-package-selection.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
p: with p; [
Blammo
Glob
MonadRandom
QuickCheck
aeson
aws-xray-client-persistent
aws-xray-client-wai
bugsnag
bytestring
case-insensitive
cassava
conduit
conduit-extra
containers
datadog
doctest
dotenv
ekg-core
envparse
errors
exceptions
extra
filepath
hashable
hspec
hspec-core
hspec-expectations-lifted
hspec-junit-formatter
http-client
http-conduit
http-link-header
http-types
hw-kafka-client
immortal
lens
lens-aeson
memcache
monad-control
monad-validate
mtl
network-uri
nonempty-containers
path-pieces
persistent
persistent-postgresql
postgresql-simple
primitive
resourcet
resource-pool
retry
safe
scientist
semigroupoids
template-haskell
text
time
transformers
transformers-base
typed-process
unliftio
unliftio-core
unordered-containers
vector
wai
wai-extra
yaml
yesod-core
]
14 changes: 14 additions & 0 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{ nixpkgs }:
nixpkgs.stable.mkShell {
name = "freckle-app-shell";
buildInputs =
map (x: import x { inherit nixpkgs; })
[
./cabal.nix
./fourmolu.nix
./ghc-with-packages.nix
./haskell-language-server.nix
./haskell-native-dependencies.nix
./stack.nix
];
}
2 changes: 2 additions & 0 deletions nix/stack.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{ nixpkgs }:
nixpkgs.stable.stack

0 comments on commit 7470f9a

Please sign in to comment.