Skip to content

Commit

Permalink
Separate nix files into {default, shell, nixpkgs}.nix (#43)
Browse files Browse the repository at this point in the history
This helps in extending `default.nix` in any way we want to
- `nix-build` uses `default.nix`
- `nix-shell` uses `shell.nix`

So it's all separated and if need be, only update the files as required and if `nixpkgs`
version is to be changed then `nixpkgs.nix` it is
  • Loading branch information
iAmMrinal0 authored and neongreen committed Oct 3, 2019
1 parent 4e4e395 commit 67dc9e3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 41 deletions.
40 changes: 9 additions & 31 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
{
withHoogle ? true
{ withHoogle ? false
, static ? false
}:
let
inherit (import <nixpkgs> {}) fetchFromGitHub;
nixpkgs = fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "db858b4d3032aec35be7e98a65eb9b91b63671ef";
sha256 = "0gqcbf5nyqff1a4ps6szcrv59ay97fr26jdwrs7qp8fijzcpdnkh";
};
nixpkgs = import ./nixpkgs.nix;
staticPackage = pkg: pkg.overrideAttrs (old: {
enableSharedExecutables = false;
enableSharedLibraries = false;
Expand Down Expand Up @@ -91,25 +84,10 @@ let
if static
then staticPackage pkgs.haskellPackages.fencer
else pkgs.haskellPackages.fencer;
in
if pkgs.lib.inNixShell
then
drv.env.overrideAttrs(attrs:
{ buildInputs =
[
pkgs.haskellPackages.cabal-install
pkgs.haskellPackages.cabal2nix
pkgs.haskellPackages.ghcid
pkgs.haskellPackages.hlint
] ++
[
pkgs.haskellPackages.zlib
] ++
[
pkgs.wget
] ++
attrs.buildInputs;
})
else
# https://github.com/Gabriel439/haskell-nix/blob/master/project3/README.md#minimizing-the-closure
pkgs.haskell.lib.justStaticExecutables drv
in {
pkgs = pkgs;
fencer =
if pkgs.lib.inNixShell
then drv
else pkgs.haskell.lib.justStaticExecutables drv;
}
13 changes: 3 additions & 10 deletions docker.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
let
inherit (import <nixpkgs> {}) fetchFromGitHub;
nixpkgs = fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
rev = "db858b4d3032aec35be7e98a65eb9b91b63671ef";
sha256 = "0gqcbf5nyqff1a4ps6szcrv59ay97fr26jdwrs7qp8fijzcpdnkh";
};
pkgs = import nixpkgs { };
# TODO: this rebuilds 'fencer', can we avoid that?
fencer = import ./default.nix { };

drv = import ./default.nix { };
pkgs = drv.pkgs;
fencer = drv.fencer;
in
pkgs.dockerTools.buildImage {
name = "juspay/fencer";
Expand Down
6 changes: 6 additions & 0 deletions nixpkgs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let
nixpkgs = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/db858b4d3032aec35be7e98a65eb9b91b63671ef";
sha256 = "0gqcbf5nyqff1a4ps6szcrv59ay97fr26jdwrs7qp8fijzcpdnkh";
};
in nixpkgs
15 changes: 15 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
let
drv = import ./default.nix { withHoogle = true; };
pkgs = drv.pkgs;
in drv.fencer.env.overrideAttrs (attrs: {
buildInputs = [
pkgs.haskellPackages.cabal-install
pkgs.haskellPackages.cabal2nix
pkgs.haskellPackages.ghcid
pkgs.haskellPackages.hlint
] ++ [
pkgs.haskellPackages.zlib
] ++ [
pkgs.wget
] ++ attrs.buildInputs;
})

0 comments on commit 67dc9e3

Please sign in to comment.