Skip to content

Commit a94fc19

Browse files
authored
Fix hix support for github (#1627)
With this change we can build and run the latest `cabal` from github using haskell.nix with: ``` hix run github:haskell/cabal#cabal-install:exe:cabal -- --version ``` You can install it in your profile with: ``` hix profile install github:haskell/cabal#cabal-install:exe:cabal ``` Because the `flake.nix` file is stored in `$HOME/.hix/github:haskell/cabal` we can lock it with: ``` hix flake lock github:haskell/cabal ```
1 parent a2a29bd commit a94fc19

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

.buildkite/pipeline.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,9 @@ steps:
5050
- nix-instantiate release.nix -A required-unstable-ghc8107-x86_64-darwin-native --show-trace --builders ''
5151
agents:
5252
system: x86_64-linux
53+
54+
- label: 'Check hix -- run github:haskell/cabal/3.8#cabal-install:exe:cabal -- --version'
55+
command:
56+
- "HIX_DIR=$(mktemp -d) nix run .#hix --accept-flake-config -- run github:haskell/cabal/3.8#cabal-install:exe:cabal --accept-flake-config --override-input haskellNix . -- --version"
57+
agents:
58+
system: x86_64-linux

hix/default.nix

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ let
2727
dump-path|eval|log|path-info|search|show-derivation|sign-paths|verify|why-depends)
2828
nix $cmd -f ${hixProject} ${args} "$@"
2929
;;
30-
flake|build|develop|run)
30+
flake|build|develop|run|profile)
31+
# Put the flake files for remote URLs in $HOME/.hix by default
32+
HIX_DIR="''${HIX_DIR:-$HOME/.hix}"
3133
while(($#)); do
3234
arg=$1
3335
case $arg in
@@ -45,22 +47,26 @@ let
4547
;;
4648
github:*#*)
4749
SRC="''${arg%%#*}"
48-
args+=("path:${hixProject}#''${arg#*#}" --override-input src "$SRC")
49-
is_github=true
50+
FLAKE=$HIX_DIR/$SRC
51+
args+=("path:$FLAKE#''${arg#*#}" --override-input src "$SRC")
52+
has_input_src=true
5053
;;
5154
github:*)
5255
SRC="$arg"
53-
args+=("path:${hixProject}" --override-input src "$SRC")
54-
is_github=true
56+
FLAKE=$HIX_DIR/$SRC
57+
args+=("path:$FLAKE" --override-input src "$SRC")
58+
has_input_src=true
5559
;;
5660
*#*)
5761
SRC="''${arg%%#*}"
58-
args+=("path:$SRC/.hix-flake#''${arg#*#}" --override-input src "$SRC")
62+
FLAKE=$SRC/.hix-flake
63+
args+=("path:$FLAKE#''${arg#*#}" --override-input src "$SRC")
5964
has_input_src=true
6065
;;
6166
.*)
6267
SRC="$arg"
63-
args+=("path:$SRC/.hix-flake" --override-input src "$SRC")
68+
FLAKE=$SRC/.hix-flake
69+
args+=("path:$FLAKE" --override-input src "$SRC")
6470
has_input_src=true
6571
;;
6672
*)
@@ -69,27 +75,24 @@ let
6975
esac
7076
shift
7177
done
72-
if [ "$is_github" != true ]; then
73-
if [ "$has_input_src" != true ]; then
74-
SRC=.
75-
args+=("path:$SRC/.hix-flake" --override-input src "$SRC")
76-
fi
77-
# Make a temporary flake if we have not already
78-
if [ ! -d $SRC/.hix-flake ]; then
79-
mkdir $SRC/.hix-flake
80-
fi
81-
HIX_FLAKE="$(mktemp -d)/flake.nix"
82-
sed 's|EVAL_SYSTEM|${pkgs.stdenv.hostPlatform.system}|' < ${hixProject}/flake.nix > $HIX_FLAKE
83-
if ! cmp $HIX_FLAKE $SRC/.hix-flake/flake.nix &>/dev/null; then
84-
if [ -e $SRC/.hix-flake/flake.lock ]; then
85-
echo "Updating $SRC/.hix-flake/flake.nix and deleting old $SRC/.hix-flake/flake.lock"
86-
rm $SRC/.hix-flake/flake.lock
87-
else
88-
echo "Updating $SRC/.hix-flake/flake.nix"
89-
fi
90-
cp $HIX_FLAKE $SRC/.hix-flake/flake.nix
91-
chmod +w $SRC/.hix-flake/flake.nix
78+
if [ "$has_input_src" != true ]; then
79+
SRC=.
80+
FLAKE=$SRC/.hix-flake
81+
args+=("path:$FLAKE" --override-input src "$SRC")
82+
fi
83+
# Make a temporary flake if we have not already
84+
mkdir -p $FLAKE
85+
HIX_FLAKE="$(mktemp -d)/flake.nix"
86+
sed 's|EVAL_SYSTEM|${pkgs.stdenv.hostPlatform.system}|' < ${hixProject}/flake.nix > $HIX_FLAKE
87+
if ! cmp $HIX_FLAKE $FLAKE/flake.nix &>/dev/null; then
88+
if [ -e $FLAKE/flake.lock ]; then
89+
echo "Updating $FLAKE/flake.nix and deleting old $FLAKE/flake.lock"
90+
rm $FLAKE/flake.lock
91+
else
92+
echo "Updating $FLAKE/flake.nix"
9293
fi
94+
cp $HIX_FLAKE $FLAKE/flake.nix
95+
chmod +w $FLAKE/flake.nix
9396
fi
9497
nix $cmd "''${args[@]}"
9598
;;

overlays/haskell.nix

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,10 @@ final: prev: {
801801

802802
# `project'` and `project` automatically select between `cabalProject`
803803
# and `stackProject` (when possible) by looking for `stack.yaml` or
804-
# `cabal.project` files. If both exist we can pass in one of:
804+
# `cabal.project` files. If both exist it uses the `cabal.project` file.
805+
# To override this pass in:
805806
# `projectFileName = "stack.yaml;"`
806-
# `projectFileName = "cabal.project";`
807-
# to let it know which to choose (or pick another name). If the
808-
# selected file ends in a `.yaml` it is assumed to be for `stackProject`.
807+
# If the selected file ends in a `.yaml` it is assumed to be for `stackProject`.
809808
# If neither `stack.yaml` nor `cabal.project` exist `cabalProject` is
810809
# used (as it will use a default `cabal.project`).
811810
project' = projectModule:
@@ -829,8 +828,8 @@ final: prev: {
829828
then projectFileName # Prefer the user selected project file name
830829
else
831830
if stackYamlExists && cabalProjectExists
832-
then throw ("haskell-nix.project : both `stack.yaml` and `cabal.project` files exist "
833-
+ "set `projectFileName = \"stack.yaml\";` or `projectFileName = \"cabal.project\";`")
831+
then __trace ("haskell-nix.project : both `stack.yaml` and `cabal.project` files exist. Using `cabal.project`. "
832+
+ "set `projectFileName = \"stack.yaml\";` to override this.`") "cabal.project"
834833
else
835834
if stackYamlExists
836835
then "stack.yaml" # stack needs a stack.yaml

0 commit comments

Comments
 (0)