|
22 | 22 | cmd=$1
|
23 | 23 | shift
|
24 | 24 | case $cmd in
|
25 |
| - update) |
26 |
| - nix-env -iA hix -f https://github.com/input-output-hk/haskell.nix/tarball/master |
| 25 | + init|init-hix) |
| 26 | + if [ "$cmd" == "init" ]; then |
| 27 | + FLAKE_NIX="$(mktemp -d)/flake.nix" |
| 28 | + sed 's|EVAL_SYSTEM|${pkgs.stdenv.hostPlatform.system}|' < ${hixInit}/flake.nix > $FLAKE_NIX |
| 29 | + if [ -e flake.nix ]; then |
| 30 | + if ! diff -u flake.nix $FLAKE_NIX; then |
| 31 | + echo 'ERROR: Not replacing existing `flake.nix`.' |
| 32 | + exit 1 |
| 33 | + fi |
| 34 | + else |
| 35 | + cp $FLAKE_NIX flake.nix |
| 36 | + echo '`flake.nix` file created.' |
| 37 | + fi |
| 38 | + fi |
| 39 | + HIX_NIX="$(mktemp -d)/hix.nix" |
| 40 | + sed 's|EVAL_SYSTEM|${pkgs.stdenv.hostPlatform.system}|' < ${hixInit}/nix/hix.nix > $HIX_NIX |
| 41 | + if [ -e nix/hix.nix ]; then |
| 42 | + echo '`nix/hix.nix` project configuration already exists:' |
| 43 | + else |
| 44 | + mkdir -p nix |
| 45 | + cp $HIX_NIX nix/hix.nix |
| 46 | + echo '`nix/hix.nix` project configuation:' |
| 47 | + fi |
| 48 | + ${pkgs.bat}/bin/bat nix/hix.nix |
27 | 49 | ;;
|
28 |
| - dump-path|eval|log|path-info|search|show-derivation|sign-paths|verify|why-depends) |
29 |
| - nix $cmd -f ${hixProject} ${args} "$@" |
| 50 | + help) |
| 51 | + cat <<EOF |
| 52 | + Usage: hix <command> [args...] |
| 53 | +
|
| 54 | + hix is a wrapper around for the nix command that allows you |
| 55 | + to work on haskell projects using nix without the need to add |
| 56 | + nix files to the project. |
| 57 | +
|
| 58 | + Any nix <command> that takes 'installables' as an argumnet should |
| 59 | + work and behave as if the project had a 'flake.nix' file that |
| 60 | + was set up to work with haskell.nix. |
| 61 | +
|
| 62 | + You can add a 'nix/hix.nix' file to your project and 'hix' will |
| 63 | + include that file as nix module containing project arguments. |
| 64 | +
|
| 65 | + Other commands: |
| 66 | + init Add flake.nix and nix/hix.nix file to allow |
| 67 | + nix commands to work (without hix). |
| 68 | + help This message |
| 69 | +
|
| 70 | + Advanced options: |
| 71 | + --projectArgs <nix> Haskell.nix arguments as Nix expression |
| 72 | + --supportedSystems <nix> Supported systems as Nix expression |
| 73 | + --overlays <nix> Overlay definitions |
| 74 | + --config <nix> Custom nix configuration |
| 75 | +
|
| 76 | + Examples: |
| 77 | + hix flake show . |
| 78 | + hix build '.#hello:exe:hello' |
| 79 | + hix run '.#hello:exe:hello' |
| 80 | + hix flake check --projectArgs '{ compiler-nix-name = "ghc9122"; }' |
| 81 | +
|
| 82 | + EOF |
30 | 83 | ;;
|
31 |
| - flake|build|develop|run|profile) |
| 84 | + *) |
32 | 85 | # Put the flake files for remote URLs in $HOME/.hix by default
|
33 | 86 | HIX_DIR="''${HIX_DIR:-$HOME/.hix}"
|
34 | 87 | HIX_TMPDIR="$(mktemp -d)"
|
35 |
| - projectArgs="" |
| 88 | + args=("--option" "allow-import-from-derivation" "true") |
36 | 89 | while(($#)); do
|
37 | 90 | arg=$1
|
38 | 91 | case $arg in
|
39 | 92 | --projectArgs)
|
40 |
| - projectArgs="$2" |
41 |
| - args+=(--override-input projectArgs "$HIX_TMPDIR") |
| 93 | + printf %s "$2" > "$HIX_TMPDIR/projectArgs.nix" |
| 94 | + shift |
| 95 | + ;; |
| 96 | + --supportedSystems) |
| 97 | + printf %s "$2" > "$HIX_TMPDIR/supportedSystems.nix" |
| 98 | + shift |
| 99 | + ;; |
| 100 | + --overlays) |
| 101 | + printf %s "$2" > "$HIX_TMPDIR/overlays.nix" |
| 102 | + shift |
| 103 | + ;; |
| 104 | + --config) |
| 105 | + printf %s "$2" > "$HIX_TMPDIR/config.nix" |
42 | 106 | shift
|
43 | 107 | ;;
|
44 | 108 | --out-link|-o|--eval-store|--include|-I|--inputs-from|--expr|--file|-f|--keep|-k|--phase|--profile|--unset|-u)
|
|
102 | 166 | cp $HIX_FLAKE $FLAKE/flake.nix
|
103 | 167 | chmod +w $FLAKE/flake.nix
|
104 | 168 | fi
|
105 |
| - if [ "$projectArgs" != "" ]; then |
106 |
| - printf %s "$projectArgs" > "$HIX_TMPDIR/projectArgs.nix" |
107 |
| - fi |
| 169 | + args+=(--override-input projectArgs "$(realpath "$HIX_TMPDIR")") |
108 | 170 | nix $cmd "''${args[@]}"
|
109 | 171 | ;;
|
110 |
| - init|init-hix) |
111 |
| - if [ "$cmd" == "init" ]; then |
112 |
| - FLAKE_NIX="$(mktemp -d)/flake.nix" |
113 |
| - sed 's|EVAL_SYSTEM|${pkgs.stdenv.hostPlatform.system}|' < ${hixInit}/flake.nix > $FLAKE_NIX |
114 |
| - if [ -e flake.nix ]; then |
115 |
| - if ! diff -u flake.nix $FLAKE_NIX; then |
116 |
| - echo 'ERROR: Not replacing existing `flake.nix`.' |
117 |
| - exit 1 |
118 |
| - fi |
119 |
| - else |
120 |
| - cp $FLAKE_NIX flake.nix |
121 |
| - echo '`flake.nix` file created.' |
122 |
| - fi |
123 |
| - fi |
124 |
| - HIX_NIX="$(mktemp -d)/hix.nix" |
125 |
| - sed 's|EVAL_SYSTEM|${pkgs.stdenv.hostPlatform.system}|' < ${hixInit}/nix/hix.nix > $HIX_NIX |
126 |
| - if [ -e nix/hix.nix ]; then |
127 |
| - echo '`nix/hix.nix` project configuration already exists:' |
128 |
| - else |
129 |
| - mkdir -p nix |
130 |
| - cp $HIX_NIX nix/hix.nix |
131 |
| - echo '`nix/hix.nix` project configuation:' |
132 |
| - fi |
133 |
| - ${pkgs.bat}/bin/bat nix/hix.nix |
134 |
| - ;; |
135 |
| - repl) |
136 |
| - nix $cmd ${hixProject} ${args} "$@" |
137 |
| - ;; |
138 |
| - *) |
139 |
| - nix $cmd "$@" |
140 |
| - ;; |
141 | 172 | esac
|
142 | 173 | '';
|
143 | 174 | in (pkgs.symlinkJoin {
|
|
0 commit comments