Hi, I am trying to understand how to use overlays over my haskell project. I have asked in the #nixos irc channel but then I thought it will be better to documented here (so I can get back here to learn more). Here it goes:
-
I have haskell project consist of the following structure:
backend |-- auth-service | |-- auth-api | | |-- auth-api.nix #this is a cabal2nix generated file | |-- auth-client | | |-- auth-client.nix #this is a cabal2nix generated file | |-- auth-server | | |-- auth-server.nix #this is a cabal2nix generated file | |-- default.nix |-- backend.nix |-- packages.nix |-- other-service | |-- .... #another haskell project folder | |-- default.nix |-- ..... #another folder and files
There is also
frontend
, and other*-service
folder. -
Inside
default.nix
, which live inside myauth-service
folder I have the following code:newHaskellPackages: oldHaskellPackages: { auth-api = oldHaskellPackages.callPackage ./auth-api/auth-api.nix { }; auth-server = oldHaskellPackages.callPackage ./auth-server/auth-server.nix { }; auth-client = oldHaskellPackages.callPackage ./auth-client/auth-client.nix { }; }
According to this nixpkgs-mozilla example repo, I follow the
servo-overlay.nix
example, which assuming that mydefault.nix
will be overridinghaskellPackages
(I put the.nix
code no. 3 below) and in this packages,auth-server
andauth-client
will depend onauth-api
-
Inside
backend
folder, I have 2.nix
files which are:
a. backend.nix which will be my main build for all*-service
haskell project. I am planning to havedefault.nix
which contains derivation that will have$out/services/{__name of package__}
but I think for now I just want to build it usingbackend.nix
. The code as follows:let # GHC compiler version compiler = "ghc822"; # Import 3rd party dependencies from nixdeps folder beam = import ../nixdeps/beam.nix; # Modifikasi paket yang ada pada variabel haskellPackages overlays = [ (newPkgs: oldPkgs: { haskellPackages = oldPkgs.haskell.packages.${compiler}.override { overrides = newHaskellPkgs: oldHaskellPkgs: { auth-service = import ./auth-service {}; } // (import ./packages.nix newHaskellPkgs oldHaskellPkgs beam); -- got error here probably. }; }) ]; # Config declaration config = { allowUnfree = true; }; # Nixpkgs pointing stable channel nixpkgs = import ../nixdeps/nixpkgs.nix; pkgs = import nixpkgs { inherit config overlays; }; in { inherit (pkgs.haskellPackages) auth-service; }
note that all files in folder
nixdeps
are only a result ofnix-prefetch-git
function so I can call it either withcallCabal2Nix
orcallPackage
-
In addition to no. 3 above, what I want is that my
auth-service
and any other*-service
project use upstream github packages like in this case I use beam package and try to overridehaskellPackages
to use the upstream version of that package. I put it underpackages.nix
below:newHaskellPkgs: oldHaskellPkgs: beam: let optparse-generic_1_3_0 = oldHaskellPkgs.callCabal2nix "text" (import ../nixdeps/optparsegeneric.nix) {}; swagger2 = oldHaskellPkgs.callCabal2nix "swagger2" (import ../nixdeps/swagger2.nix) {}; # --- Beam Related Package --- # beam-core = oldHaskellPkgs.callCabal2nix "beam-core" "${beam}/beam-core" {}; beam-migrate = oldHaskellPkgs.callCabal2nix "beam-migrate" "${beam}/beam-migrate" {}; beam-postgres = oldHaskellPkgs.callCabal2nix "beam-postgres" "${beam}/beam-postgres" {}; in { inherit optparse-generic_1_3_0 swagger2 beam-core beam-migrate beam-postgres }
So I run nix-build backend.nix
and also try nix build -f backend.nix
but it doesn’t say error and also not generated result
folder.
I have tried this with the old ways modifiedHaskellPackages.callPackage
style which modifiedHaskellPackages = haskellPackages.override { ... }
and it works as it is intended to.
So now I’m a little bit confused how does the overlays pass through the arg newHaskellPkgs
and oldHaskellPkgs
to my haskell packages. Or did I miss some step above?
Any help to point me to the right direction is appreciated. I provide the gist here
BR,