Browse Source

nix-hs: invert -H, load custom nixpkgs

  * The -H option now *enables* haddocs and the new default is to
    disable them.  This makes nix-hs compatible with haskellPackages.

  * If a project has a `nix/nixpkgs.nix' file, load it and use it
    instead of doing an `import <nixpkgs>'
master
Peter J. Jones 8 months ago
parent
commit
b5e5d9947d
3 changed files with 20 additions and 17 deletions
  1. 1
    1
      nix/interactive.nix
  2. 18
    15
      src/nix-hs.sh
  3. 1
    1
      templates/default.nix

+ 1
- 1
nix/interactive.nix View File

@@ -15,7 +15,7 @@
15 15
 , compiler     ? "default" # Which version of GHC to use, or "default".
16 16
 , profiling    ? false     # Enable profiling or not.
17 17
 , optimization ? true      # Enable optimization or not.
18
-, doHaddock    ? true      # Create documentation for dependencies.
18
+, doHaddock    ? false     # Create documentation for dependencies.
19 19
 , file                     # The package file (default.nix) to load.
20 20
 }:
21 21
 

+ 18
- 15
src/nix-hs.sh View File

@@ -24,11 +24,12 @@ export HASKELL_PROJECT_DIR
24 24
 option_compiler=default
25 25
 option_ci_compilers=()
26 26
 option_profiling=false
27
-option_haddocks=true
27
+option_haddocks=false
28 28
 option_debug=0
29 29
 option_tool=""
30 30
 option_nixshell_args=()
31 31
 option_publish=true
32
+option_import_nixpkgs=true
32 33
 
33 34
 ################################################################################
34 35
 usage () {
@@ -38,16 +39,17 @@ Usage: nix-hs [options] <command>
38 39
   -c VER  Use GHC version VER (also VER,VER,VER,etc.)
39 40
   -d      Enable debugging info for nix-hs
40 41
   -h      This message
41
-  -H      Disable building haddocks
42
+  -H      Enable building haddocks
42 43
   -I PATH Add PATH to NIX_PATH
43 44
   -P      Don't publish releases [default: publish]
44 45
   -p      Enable profiling [default: off]
45
-  -n PATH Shortcut for '-I nixpkgs=PATH'
46
+  -n PATH Shortcut for '-I nixpkgs=PATH' (implies -N)
47
+  -N      Don't load nix/nixpkgs.nix
46 48
   -t TYPE Force using build type TYPE (cabal|stack|make)
47 49
 
48 50
 Commands:
49 51
 
50
-  build:   Compile the package
52
+  build:   Compile the package (default command)
51 53
   check:   Run some compliance checks on the package
52 54
   clean:   Remove all build artifacts
53 55
   release: Build and upload a package to Hackage
@@ -153,6 +155,12 @@ find_stack_root() {
153 155
 nix_shell() {
154 156
   local extra_options=()
155 157
 
158
+  if [ -e nix/nixpkgs.nix ] && [ "$option_import_nixpkgs" = true ]; then
159
+    extra_options+=("--arg")
160
+    extra_options+=("pkgs")
161
+    extra_options+=("import $(pwd)/nix/nixpkgs.nix")
162
+  fi
163
+
156 164
   if [ "$option_debug" -eq 1 ]; then
157 165
     extra_options+=("--show-trace")
158 166
   fi
@@ -162,14 +170,6 @@ nix_shell() {
162 170
 
163 171
 ################################################################################
164 172
 nix_shell_extra() {
165
-  local extra_options=()
166
-
167
-  if [ "$option_debug" -eq 1 ]; then
168
-    extra_options+=("--show-trace")
169
-  fi
170
-
171
-  # FIXME: support all interactive.nix options.
172
-
173 173
   nix_shell --pure "$@" \
174 174
             --argstr file "$(pwd)/default.nix" \
175 175
             --argstr compiler "$option_compiler" \
@@ -189,7 +189,7 @@ prepare_nix_files() {
189 189
   fi
190 190
 
191 191
   if [ ! -r "default.nix" ]; then
192
-    sed -e "s/@PROJECT@/${HASKELL_PROJECT_NAME}/g" \
192
+    sed -e "s/@NIX_FILE@/${nix_file}/g" \
193 193
         < @templates@/default.nix > default.nix
194 194
   fi
195 195
 }
@@ -332,7 +332,7 @@ run_tool() {
332 332
 
333 333
 ################################################################################
334 334
 # Process the command line:
335
-while getopts "c:dHhI:Ppn:t:" o; do
335
+while getopts "c:dHhI:Ppn:Nt:" o; do
336 336
   case "${o}" in
337 337
     c) set_compiler_version "$OPTARG"
338 338
        ;;
@@ -341,7 +341,7 @@ while getopts "c:dHhI:Ppn:t:" o; do
341 341
        set -x
342 342
        ;;
343 343
 
344
-    H) option_haddocks=false
344
+    H) option_haddocks=true
345 345
        ;;
346 346
 
347 347
     h) usage
@@ -358,8 +358,11 @@ while getopts "c:dHhI:Ppn:t:" o; do
358 358
        ;;
359 359
 
360 360
     n) option_nixshell_args+=("-I" "nixpkgs=$OPTARG")
361
+       option_import_nixpkgs=false
361 362
        ;;
362 363
 
364
+    N) option_import_nixpkgs=false
365
+       ;;
363 366
 
364 367
     t) option_tool=$OPTARG
365 368
        ;;

+ 1
- 1
templates/default.nix View File

@@ -1,2 +1,2 @@
1 1
 { pkgs ? (import <nixpkgs> {}).pkgs }:
2
-pkgs.haskellPackages.callPackage ./@PROJECT@.nix { }
2
+pkgs.haskellPackages.callPackage ./@NIX_FILE@ { }

Loading…
Cancel
Save