Преглед на файлове

Remove support for stack and make, align with current nixpkgs

A few noteworthy changes:

  * Drop support for using stack or make.  I never really needed these
    and if you have a cabal file everything else should just work.

  * Stop overriding base Haskell packages.  This means that both
    nix-build and nix-hs use the exact same dependencies.  Once you
    build them with either tool, the other doesn't have to do
    rebuilding.

  * The default.nix file is now a proper package file.  The previous
    version which was an overlay is now in overlay.nix
master
Peter J. Jones преди 2 месеца
родител
ревизия
4a9ea2c8c6
Signed by: Peter Jones <pjones@devalot.com> GPG Key ID: 9DAFAA8D01941E49
променени са 6 файла, в които са добавени 48 реда и са изтрити 169 реда
  1. 3
    17
      default.nix
  2. 15
    23
      nix/interactive.nix
  3. 1
    4
      nix/package.nix
  4. 0
    19
      nix/stack.nix
  5. 18
    0
      overlay.nix
  6. 11
    106
      src/nix-hs.sh

+ 3
- 17
default.nix Целия файл

@@ -1,18 +1,4 @@
1
-################################################################################
2
-# This file is a nixpkgs overlay.
1
+{ pkgs ? import <nixpkgs> { }
2
+}:
3 3
 
4
-################################################################################
5
-#
6
-# This file is part of the package nix-hs. It is subject to the license
7
-# terms in the LICENSE file found in the top-level directory of this
8
-# distribution and at:
9
-#
10
-#   git://git.devalot.com/nix-hs.git
11
-#
12
-# No part of this package, including this file, may be copied, modified,
13
-# propagated, or distributed except according to the terms contained in
14
-# the LICENSE file.
15
-
16
-self: super: {
17
-  nix-hs = with self; callPackage ./nix/package.nix { };
18
-}
4
+pkgs.callPackage ./nix/package.nix { }

+ 15
- 23
nix/interactive.nix Целия файл

@@ -15,7 +15,6 @@
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    ? false     # Create documentation for dependencies.
19 18
 , file                     # The package file (default.nix) to load.
20 19
 }:
21 20
 
@@ -24,7 +23,7 @@ with pkgs.lib;
24 23
 let
25 24
 
26 25
   # Some handy bindings:
27
-  cabal = "${haskell.cabal-install}/bin/cabal";
26
+  cabal = "${basePackages.cabal-install}/bin/cabal";
28 27
 
29 28
   cabalConfigureFlags = concatStringsSep " "
30 29
     [ (optionalString optimization "--enable-optimization")
@@ -63,6 +62,11 @@ let
63 62
       set -e
64 63
       cabal repl "$@"
65 64
     }
65
+
66
+    do_cabal_haddock() {
67
+      set -e
68
+      cabal haddock
69
+    }
66 70
   '';
67 71
 
68 72
   # Select a compiler:
@@ -71,28 +75,16 @@ let
71 75
       then pkgs.haskellPackages
72 76
       else pkgs.haskell.packages."ghc${compiler}";
73 77
 
74
-  # Overrides to control properties such as profiling.  This is a bit
75
-  # of a mess because Haskell overrides in Nix don't seem to compose
76
-  # well: https://github.com/NixOS/nixpkgs/issues/26561
77
-  haskell = basePackages.override (orig: {
78
-    overrides = composeExtensions (orig.overrides or (_: _: {}))
79
-      (self: super: {
80
-        mkDerivation = { shellHook ? ""
81
-                       , ...
82
-                       }@args:
83
-          super.mkDerivation (args // {
84
-            inherit doHaddock;
85
-            shellHook = shellHook + shellFunctions;
86
-            enableLibraryProfiling = profiling;
87
-            enableExecutableProfiling = profiling;
88
-          });
89
-    });
90
-  });
91
-
92 78
   # Override the Haskell package set with the one from above:
93
-  alteredPackages = pkgs // { haskellPackages = haskell; };
79
+  alteredPackages = pkgs // { haskellPackages = basePackages; };
94 80
 
95
-  # Load the local file:
96
-  drv = import file { pkgs = alteredPackages; };
81
+  # Load the local file and override its shell environment:
82
+  drv = (import file { pkgs = alteredPackages; }).overrideAttrs (orig: {
83
+    passthru = orig.passthru // {
84
+      env = orig.passthru.env.overrideAttrs (_env: {
85
+        shellHook = _env.shellHook + shellFunctions;
86
+      });
87
+    };
88
+  });
97 89
 
98 90
 in drv.env

+ 1
- 4
nix/package.nix Целия файл

@@ -20,7 +20,7 @@ with lib;
20 20
 let
21 21
   drv = stdenvNoCC.mkDerivation rec {
22 22
     name = "nix-hs-${version}";
23
-    version = "0.2.0";
23
+    version = "0.3.0";
24 24
 
25 25
     phases = [ "installPhase" ];
26 26
 
@@ -29,17 +29,14 @@ let
29 29
 
30 30
       export bash=${bash}
31 31
       export cabal2nix=${cabal2nix}
32
-      export stack=${haskellPackages.stack}
33 32
       export templates=$out/templates
34 33
       export interactive=$out/lib/interactive.nix
35
-      export stacknix=$out/lib/stack.nix
36 34
 
37 35
       substituteAll ${../src/nix-hs.sh} $out/bin/nix-hs
38 36
       chmod 0555 $out/bin/nix-hs
39 37
 
40 38
       install -m0444 ${../templates/default.nix} $out/templates/default.nix
41 39
       install -m0444 ${../nix/interactive.nix} $out/lib/interactive.nix
42
-      install -m0400 ${../nix/stack.nix} $out/lib/stack.nix
43 40
     '';
44 41
   };
45 42
 in {

+ 0
- 19
nix/stack.nix Целия файл

@@ -1,19 +0,0 @@
1
-{ pkgs ? (import <nixpkgs> {}).pkgs
2
-, ghc  ? pkgs.ghc
3
-, file
4
-}:
5
-
6
-let
7
-  # Load the local package:
8
-  package = import file { pkgs = pkgs; };
9
-
10
-  # Pull build inputs from the local package: (not sure why, but there
11
-  # are some nulls in the buildInputs that we need to remove).
12
-  buildInputs = builtins.filter (p: p != null)
13
-    package.buildInputs;
14
-
15
-in pkgs.haskell.lib.buildStackProject {
16
-  name = package.name;
17
-  buildInputs = buildInputs;
18
-  inherit ghc;
19
-}

+ 18
- 0
overlay.nix Целия файл

@@ -0,0 +1,18 @@
1
+################################################################################
2
+# This file is a nixpkgs overlay.
3
+
4
+################################################################################
5
+#
6
+# This file is part of the package nix-hs. It is subject to the license
7
+# terms in the LICENSE file found in the top-level directory of this
8
+# distribution and at:
9
+#
10
+#   git://git.devalot.com/nix-hs.git
11
+#
12
+# No part of this package, including this file, may be copied, modified,
13
+# propagated, or distributed except according to the terms contained in
14
+# the LICENSE file.
15
+
16
+self: super: {
17
+  nix-hs = with self; callPackage ./nix/package.nix { };
18
+}

+ 11
- 106
src/nix-hs.sh Целия файл

@@ -26,7 +26,6 @@ option_ci_compilers=()
26 26
 option_profiling=false
27 27
 option_haddocks=false
28 28
 option_debug=0
29
-option_tool=""
30 29
 option_nixshell_args=()
31 30
 option_publish=true
32 31
 option_import_nixpkgs=true
@@ -45,7 +44,6 @@ Usage: nix-hs [options] <command>
45 44
   -p      Enable profiling [default: off]
46 45
   -n PATH Shortcut for '-I nixpkgs=PATH' (implies -N)
47 46
   -N      Don't load nix/nixpkgs.nix
48
-  -t TYPE Force using build type TYPE (cabal|stack|make)
49 47
 
50 48
 Commands:
51 49
 
@@ -133,24 +131,6 @@ set_compiler_version() {
133 131
   fi
134 132
 }
135 133
 
136
-################################################################################
137
-# Check to see if the project root is *not* the same directory as the
138
-# project directory.  This is a common directory layout with stack
139
-# where one stack.yaml file is used to point to several projects.
140
-find_stack_root() {
141
-  # See if the parent directory has a stack file:
142
-  export STACK_YAML=${STACK_YAML:-stack.yaml}
143
-
144
-  if [ -r "$STACK_YAML" ]; then
145
-    return 0
146
-  elif [ ! -r "$STACK_YAML" ] && [ -r ../"$STACK_YAML" ]; then
147
-    export STACK_YAML="../$STACK_YAML"
148
-    return 0
149
-  fi
150
-
151
-  return 1
152
-}
153
-
154 134
 ################################################################################
155 135
 nix_shell() {
156 136
   local extra_options=()
@@ -174,7 +154,6 @@ nix_shell_extra() {
174 154
             --argstr file "$(pwd)/default.nix" \
175 155
             --argstr compiler "$option_compiler" \
176 156
             --arg profiling "$option_profiling" \
177
-            --arg doHaddock "$option_haddocks" \
178 157
             @interactive@
179 158
 }
180 159
 
@@ -251,47 +230,9 @@ run_cabal() {
251 230
 
252 231
     *)
253 232
       nix_shell_extra --command "do_cabal_$1"
254
-      ;;
255
-  esac
256
-}
257
-
258
-################################################################################
259
-# TOOL: stack
260
-run_stack() {
261
-  prepare_nix_files
262
-  local stack_flags=()
263
-
264
-  if [ "$option_profiling" = true ]; then
265
-    if [ "${1:-build}" = build ]; then
266
-      stack_flags+=("--library-profiling")
267
-      stack_flags+=("--executable-profiling")
268
-    fi
269
-  fi
270
-
271
-  case "${1:-build}" in
272
-    shell)
273
-      nix_shell_extra
274
-      ;;
275
-
276
-    *)
277
-      @stack@/bin/stack \
278
-        --nix --nix-shell-file=@stacknix@ \
279
-        --nix-shell-options "--argstr file $(pwd)/default.nix" \
280
-        "$@" "${stack_flags[@]}"
281
-      ;;
282
-  esac
283
-}
284
-
285
-################################################################################
286
-# TOOL: make
287
-run_make() {
288
-  case "${1:-build}" in
289
-    build)
290
-      make
291
-      ;;
292
-
293
-    *)
294
-      make "$@"
233
+      if [ "$option_haddocks" = "true" ]; then
234
+        nix_shell_extra --command "do_cabal_haddock"
235
+      fi
295 236
       ;;
296 237
   esac
297 238
 }
@@ -313,7 +254,6 @@ command_supports_multiple_runs() {
313 254
 
314 255
 ################################################################################
315 256
 run_tool() {
316
-  local tool=$1; shift
317 257
   local command=$1; shift
318 258
 
319 259
   if [ "${#option_ci_compilers[@]}" -gt 0 ] && \
@@ -322,17 +262,17 @@ run_tool() {
322 262
     for ver in "${option_ci_compilers[@]}"; do
323 263
       option_compiler="$ver"
324 264
       banner "GHC: $ver"
325
-      "run_${tool}" "clean"
326
-      "run_${tool}" "$command" "$@"
265
+      run_cabal "clean"
266
+      run_cabal "$command" "$@"
327 267
     done
328 268
   else
329
-    "run_${tool}" "$command" "$@"
269
+    run_cabal "$command" "$@"
330 270
   fi
331 271
 }
332 272
 
333 273
 ################################################################################
334 274
 # Process the command line:
335
-while getopts "c:dHhI:Ppn:Nt:" o; do
275
+while getopts "c:dHhI:Ppn:N" o; do
336 276
   case "${o}" in
337 277
     c) set_compiler_version "$OPTARG"
338 278
        ;;
@@ -364,9 +304,6 @@ while getopts "c:dHhI:Ppn:Nt:" o; do
364 304
     N) option_import_nixpkgs=false
365 305
        ;;
366 306
 
367
-    t) option_tool=$OPTARG
368
-       ;;
369
-
370 307
     *) exit 1
371 308
        ;;
372 309
   esac
@@ -381,38 +318,6 @@ find_project
381 318
 # For tools that treat this script like `cabal':
382 319
 if [ "${1:-build}" = cabal ] && [ "$#" -eq 2 ]; then shift; fi
383 320
 
384
-################################################################################
385
-# Figure out which tool we should be using:
386
-if [ -n "$option_tool" ]; then
387
-  tool=$option_tool
388
-else
389
-  if find_stack_root; then
390
-    tool="stack"
391
-  elif [ -r Makefile ] || [ -r GNUmakefile ]; then
392
-    tool="make"
393
-  else
394
-    tool="cabal"
395
-  fi
396
-fi
397
-
398
-case "$tool" in
399
-  cabal)
400
-    : # No settings needed
401
-    ;;
402
-
403
-  stack)
404
-    : # No settings needed
405
-    ;;
406
-
407
-  make)
408
-    : # No settings needed
409
-    ;;
410
-
411
-  *)
412
-    die "unknown build tool: $tool"
413
-    ;;
414
-esac
415
-
416 321
 ################################################################################
417 322
 # Main dispatch code:
418 323
 command="${1:-build}"
@@ -421,20 +326,20 @@ if [ "${1:-}" = "--" ]; then shift; fi
421 326
 
422 327
 case "$command" in
423 328
   new-build|build)
424
-    run_tool "$tool" "build" "$@"
329
+    run_tool "build" "$@"
425 330
     ;;
426 331
 
427 332
   new-repl|repl)
428
-    run_tool "$tool" "repl" "$@"
333
+    run_tool "repl" "$@"
429 334
     ;;
430 335
 
431 336
   new-test|test)
432
-    run_tool "$tool" "test" "$@"
337
+    run_tool "test" "$@"
433 338
     ;;
434 339
 
435 340
 
436 341
   shell|clean|check|release)
437
-    run_tool "$tool" "$command" "$@"
342
+    run_tool "$command" "$@"
438 343
     ;;
439 344
 
440 345
   *)

Loading…
Отказ
Запис