瀏覽代碼

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
next
Peter J. Jones 7 月之前
父節點
當前提交
4a9ea2c8c6
簽署人: 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 @@
################################################################################
# This file is a nixpkgs overlay.
{ pkgs ? import <nixpkgs> { }
}:

################################################################################
#
# This file is part of the package nix-hs. It is subject to the license
# terms in the LICENSE file found in the top-level directory of this
# distribution and at:
#
# git://git.devalot.com/nix-hs.git
#
# No part of this package, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in
# the LICENSE file.

self: super: {
nix-hs = with self; callPackage ./nix/package.nix { };
}
pkgs.callPackage ./nix/package.nix { }

+ 15
- 23
nix/interactive.nix 查看文件

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

@@ -24,7 +23,7 @@ with pkgs.lib;
let

# Some handy bindings:
cabal = "${haskell.cabal-install}/bin/cabal";
cabal = "${basePackages.cabal-install}/bin/cabal";

cabalConfigureFlags = concatStringsSep " "
[ (optionalString optimization "--enable-optimization")
@@ -63,6 +62,11 @@ let
set -e
cabal repl "$@"
}

do_cabal_haddock() {
set -e
cabal haddock
}
'';

# Select a compiler:
@@ -71,28 +75,16 @@ let
then pkgs.haskellPackages
else pkgs.haskell.packages."ghc${compiler}";

# Overrides to control properties such as profiling. This is a bit
# of a mess because Haskell overrides in Nix don't seem to compose
# well: https://github.com/NixOS/nixpkgs/issues/26561
haskell = basePackages.override (orig: {
overrides = composeExtensions (orig.overrides or (_: _: {}))
(self: super: {
mkDerivation = { shellHook ? ""
, ...
}@args:
super.mkDerivation (args // {
inherit doHaddock;
shellHook = shellHook + shellFunctions;
enableLibraryProfiling = profiling;
enableExecutableProfiling = profiling;
});
});
});

# Override the Haskell package set with the one from above:
alteredPackages = pkgs // { haskellPackages = haskell; };
alteredPackages = pkgs // { haskellPackages = basePackages; };

# Load the local file:
drv = import file { pkgs = alteredPackages; };
# Load the local file and override its shell environment:
drv = (import file { pkgs = alteredPackages; }).overrideAttrs (orig: {
passthru = orig.passthru // {
env = orig.passthru.env.overrideAttrs (_env: {
shellHook = _env.shellHook + shellFunctions;
});
};
});

in drv.env

+ 1
- 4
nix/package.nix 查看文件

@@ -20,7 +20,7 @@ with lib;
let
drv = stdenvNoCC.mkDerivation rec {
name = "nix-hs-${version}";
version = "0.2.0";
version = "0.3.0";

phases = [ "installPhase" ];

@@ -29,17 +29,14 @@ let

export bash=${bash}
export cabal2nix=${cabal2nix}
export stack=${haskellPackages.stack}
export templates=$out/templates
export interactive=$out/lib/interactive.nix
export stacknix=$out/lib/stack.nix

substituteAll ${../src/nix-hs.sh} $out/bin/nix-hs
chmod 0555 $out/bin/nix-hs

install -m0444 ${../templates/default.nix} $out/templates/default.nix
install -m0444 ${../nix/interactive.nix} $out/lib/interactive.nix
install -m0400 ${../nix/stack.nix} $out/lib/stack.nix
'';
};
in {

+ 0
- 19
nix/stack.nix 查看文件

@@ -1,19 +0,0 @@
{ pkgs ? (import <nixpkgs> {}).pkgs
, ghc ? pkgs.ghc
, file
}:

let
# Load the local package:
package = import file { pkgs = pkgs; };

# Pull build inputs from the local package: (not sure why, but there
# are some nulls in the buildInputs that we need to remove).
buildInputs = builtins.filter (p: p != null)
package.buildInputs;

in pkgs.haskell.lib.buildStackProject {
name = package.name;
buildInputs = buildInputs;
inherit ghc;
}

+ 18
- 0
overlay.nix 查看文件

@@ -0,0 +1,18 @@
################################################################################
# This file is a nixpkgs overlay.

################################################################################
#
# This file is part of the package nix-hs. It is subject to the license
# terms in the LICENSE file found in the top-level directory of this
# distribution and at:
#
# git://git.devalot.com/nix-hs.git
#
# No part of this package, including this file, may be copied, modified,
# propagated, or distributed except according to the terms contained in
# the LICENSE file.

self: super: {
nix-hs = with self; callPackage ./nix/package.nix { };
}

+ 11
- 106
src/nix-hs.sh 查看文件

@@ -26,7 +26,6 @@ option_ci_compilers=()
option_profiling=false
option_haddocks=false
option_debug=0
option_tool=""
option_nixshell_args=()
option_publish=true
option_import_nixpkgs=true
@@ -45,7 +44,6 @@ Usage: nix-hs [options] <command>
-p Enable profiling [default: off]
-n PATH Shortcut for '-I nixpkgs=PATH' (implies -N)
-N Don't load nix/nixpkgs.nix
-t TYPE Force using build type TYPE (cabal|stack|make)

Commands:

@@ -133,24 +131,6 @@ set_compiler_version() {
fi
}

################################################################################
# Check to see if the project root is *not* the same directory as the
# project directory. This is a common directory layout with stack
# where one stack.yaml file is used to point to several projects.
find_stack_root() {
# See if the parent directory has a stack file:
export STACK_YAML=${STACK_YAML:-stack.yaml}

if [ -r "$STACK_YAML" ]; then
return 0
elif [ ! -r "$STACK_YAML" ] && [ -r ../"$STACK_YAML" ]; then
export STACK_YAML="../$STACK_YAML"
return 0
fi

return 1
}

################################################################################
nix_shell() {
local extra_options=()
@@ -174,7 +154,6 @@ nix_shell_extra() {
--argstr file "$(pwd)/default.nix" \
--argstr compiler "$option_compiler" \
--arg profiling "$option_profiling" \
--arg doHaddock "$option_haddocks" \
@interactive@
}

@@ -251,47 +230,9 @@ run_cabal() {

*)
nix_shell_extra --command "do_cabal_$1"
;;
esac
}

################################################################################
# TOOL: stack
run_stack() {
prepare_nix_files
local stack_flags=()

if [ "$option_profiling" = true ]; then
if [ "${1:-build}" = build ]; then
stack_flags+=("--library-profiling")
stack_flags+=("--executable-profiling")
fi
fi

case "${1:-build}" in
shell)
nix_shell_extra
;;

*)
@stack@/bin/stack \
--nix --nix-shell-file=@stacknix@ \
--nix-shell-options "--argstr file $(pwd)/default.nix" \
"$@" "${stack_flags[@]}"
;;
esac
}

################################################################################
# TOOL: make
run_make() {
case "${1:-build}" in
build)
make
;;

*)
make "$@"
if [ "$option_haddocks" = "true" ]; then
nix_shell_extra --command "do_cabal_haddock"
fi
;;
esac
}
@@ -313,7 +254,6 @@ command_supports_multiple_runs() {

################################################################################
run_tool() {
local tool=$1; shift
local command=$1; shift

if [ "${#option_ci_compilers[@]}" -gt 0 ] && \
@@ -322,17 +262,17 @@ run_tool() {
for ver in "${option_ci_compilers[@]}"; do
option_compiler="$ver"
banner "GHC: $ver"
"run_${tool}" "clean"
"run_${tool}" "$command" "$@"
run_cabal "clean"
run_cabal "$command" "$@"
done
else
"run_${tool}" "$command" "$@"
run_cabal "$command" "$@"
fi
}

################################################################################
# Process the command line:
while getopts "c:dHhI:Ppn:Nt:" o; do
while getopts "c:dHhI:Ppn:N" o; do
case "${o}" in
c) set_compiler_version "$OPTARG"
;;
@@ -364,9 +304,6 @@ while getopts "c:dHhI:Ppn:Nt:" o; do
N) option_import_nixpkgs=false
;;

t) option_tool=$OPTARG
;;

*) exit 1
;;
esac
@@ -381,38 +318,6 @@ find_project
# For tools that treat this script like `cabal':
if [ "${1:-build}" = cabal ] && [ "$#" -eq 2 ]; then shift; fi

################################################################################
# Figure out which tool we should be using:
if [ -n "$option_tool" ]; then
tool=$option_tool
else
if find_stack_root; then
tool="stack"
elif [ -r Makefile ] || [ -r GNUmakefile ]; then
tool="make"
else
tool="cabal"
fi
fi

case "$tool" in
cabal)
: # No settings needed
;;

stack)
: # No settings needed
;;

make)
: # No settings needed
;;

*)
die "unknown build tool: $tool"
;;
esac

################################################################################
# Main dispatch code:
command="${1:-build}"
@@ -421,20 +326,20 @@ if [ "${1:-}" = "--" ]; then shift; fi

case "$command" in
new-build|build)
run_tool "$tool" "build" "$@"
run_tool "build" "$@"
;;

new-repl|repl)
run_tool "$tool" "repl" "$@"
run_tool "repl" "$@"
;;

new-test|test)
run_tool "$tool" "test" "$@"
run_tool "test" "$@"
;;


shell|clean|check|release)
run_tool "$tool" "$command" "$@"
run_tool "$command" "$@"
;;

*)

Loading…
取消
儲存