forked from cdepillabout/termonad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtermonad-with-packages.nix
136 lines (131 loc) · 4.31 KB
/
termonad-with-packages.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# This file produces a wrapper around Termonad that will know where to find a
# GHC with the libraries needed to recompile its config file.
#
# This is not NixOS only; it should work with nix on any system.
#
# There are 4 different ways this file can be used.
#
# 1. build directly with `nix-build`
#
# This method allows you to build termonad from the command line with
# `nix-build`. This is the easiest method.
#
# You can call `nix-build` like the following:
#
# $ nix-build .nix-helpers/termonad-with-packages.nix
#
# (This is the same as just calling `nix-build` on the `../default.nix` file.)
#
# This produces a `result` directory that contains the `termonad` exectuable as
# `result/bin/termonad`.
#
# By default, you will be able to use the Haskell packages `lens` and `colour`
# in your `~/.config/termonad/termonad.hs` configuration file.
#
# If you want to use alternative Haskell packages, you can specify them on the
# command line:
#
# $ nix-build .nix-helpers/termonad-with-packages.nix \
# --arg extraHaskellPackages 'haskellPackages: [ haskellPackages.colour haskellPackages.lens haskellPackages.pipes ]'
#
# This will make sure you can also use the Haskell packages `lens`, `colour`, and `pipes` in your
# `~/.config/termonad/termonad.hs` file. (Actually, if Termonad transitively
# depends on a library, you should be able to use it without having to specify
# it. Although you shouldn't depend on this.)
#
# 2. install with `nix-env`
#
# `nix-env` can be used to install Termonad into your environment:
#
# $ nix-env --file .nix-helpers/termonad-with-packages.nix --install
#
# If you want to specify extra Haskell packages that you can use in your
# `~/.config/termonad/termonad.hs` file, you can call `nix-env` like the
# following:
#
# $ nix-env --file .nix-helpers/termonad-with-packages.nix --install \
# --arg extraHaskellPackages 'haskellPackages: [ haskellPackages.colour haskellPackages.lens haskellPackages.pipes ]'
#
# 3. an overlay for your user
#
# Nix makes it easy to create overlays. First, create the following file at
# `~/.config/nixpkgs/overlays/termonad.nix`:
#
# ```nix
# self: super:
# let extraHaskellPackages = hp: [ hp.colour hp.lens hp.MonadRandom ]; in
# { termonad = import /some/path/to/termonad/.nix-helpers/termonad-with-packages.nix { inherit extraHaskellPackages; };
# }
# ```
#
# Now Termonad can be installed through Nix's standard methods, including `nix-env`:
#
# $ nix-env --file '<nixpkgs>' --install --attr termonad
#
# 4. system-wide in /etc/nixos/configuration.nix
#
# You can set the `nixpkgs.overlays` attribute in your
# `/etc/nixos/configuration.nix` file just like in (3) above.
#
# ```nix
# { config, pkgs, ... }:
# {
# nixpkgs.overlays = [ (import /home/youruser/.config/nixpkgs/overlays/termonad.nix) ];
# }
# ```
#
# You can also add Termonad directly to your system packages:
#
# ```nix
# { config, pkgs, ... }:
# {
# environment.systemPackages = with pkgs; [
# ...
# (import /some/path/to/termonad/.nix-helpers/termonad-with-packages.nix { })
# ...
# ];
# }
# ```
let
# Default Haskell packages that you can use in your Termonad configuration.
# This is only used if the user doesn't specify the extraHaskellPackages
# option.
defaultPackages = hpkgs: with hpkgs; [
colour
lens
];
in
{ extraHaskellPackages ? defaultPackages
, nixpkgs ? null
, additionalOverlays ? []
, compiler ? null
, buildExamples ? false
}@args:
with (import ./nixpkgs.nix { inherit compiler nixpkgs additionalOverlays buildExamples; });
let
# GHC environment that has termonad available, as well as the packages
# specified above in extraHaskellPackages.
env =
termonadKnownWorkingHaskellPkgSet.ghcWithPackages
(hpkgs: [ hpkgs.termonad ] ++ extraHaskellPackages hpkgs);
in
stdenv.mkDerivation {
name = "termonad-with-packages-ghc-${env.version}";
buildInputs = [ gdk_pixbuf gnome3.adwaita-icon-theme hicolor-icon-theme ];
nativeBuildInputs = [ wrapGAppsHook ];
dontBuild = true;
unpackPhase = ":";
# Using installPhase instead of buildCommand was recommended here:
# https://github.com/cdepillabout/termonad/pull/109
installPhase = ''
runHook preInstall
mkdir -p $out/bin
ln -sf ${env}/bin/termonad $out/bin/termonad
gappsWrapperArgs+=(
--set NIX_GHC "${env}/bin/ghc"
)
runHook postInstall
'';
preferLocalBuild = true;
allowSubstitutes = false;
}