Skip to content

Commit 1bd57b0

Browse files
Add a projectArgs CLI argument to hix run (#2378)
* Add a new projectArgs CLI argument to pass arguments to the hix project in the flake generated by hix run * Use `input-output-hk/empty-flake` * Use #2379 * Look for `projectArgs.nix` --------- Co-authored-by: Hamish Mackenzie <Hamish.K.Mackenzie@gmail.com>
1 parent 5daedb0 commit 1bd57b0

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

hix/default.nix

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,16 @@ let
3131
flake|build|develop|run|profile)
3232
# Put the flake files for remote URLs in $HOME/.hix by default
3333
HIX_DIR="''${HIX_DIR:-$HOME/.hix}"
34+
HIX_TMPDIR="$(mktemp -d)"
35+
projectArgs=""
3436
while(($#)); do
3537
arg=$1
3638
case $arg in
39+
--projectArgs)
40+
projectArgs="$2"
41+
args+=(--override-input projectArgs "$HIX_TMPDIR")
42+
shift
43+
;;
3744
--out-link|-o|--eval-store|--include|-I|--inputs-from|--expr|--file|-f|--keep|-k|--phase|--profile|--unset|-u)
3845
args+=("$arg" "$2")
3946
shift
@@ -83,7 +90,7 @@ let
8390
fi
8491
# Make a temporary flake if we have not already
8592
mkdir -p $FLAKE
86-
HIX_FLAKE="$(mktemp -d)/flake.nix"
93+
HIX_FLAKE="$HIX_TMPDIR/flake.nix"
8794
sed 's|EVAL_SYSTEM|${pkgs.stdenv.hostPlatform.system}|' < ${hixProject}/flake.nix > $HIX_FLAKE
8895
if ! cmp $HIX_FLAKE $FLAKE/flake.nix &>/dev/null; then
8996
if [ -e $FLAKE/flake.lock ]; then
@@ -95,6 +102,9 @@ let
95102
cp $HIX_FLAKE $FLAKE/flake.nix
96103
chmod +w $FLAKE/flake.nix
97104
fi
105+
if [ "$projectArgs" != "" ]; then
106+
printf %s "$projectArgs" > "$HIX_TMPDIR/projectArgs.nix"
107+
fi
98108
nix $cmd "''${args[@]}"
99109
;;
100110
init|init-hix)

hix/empty-set/default.nix

Lines changed: 0 additions & 1 deletion
This file was deleted.

hix/project/flake.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,21 @@
55
inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
66
inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
77
inputs.flake-utils.url = "github:numtide/flake-utils";
8+
inputs.projectArgs.url = "github:input-output-hk/empty-flake";
9+
inputs.projectArgs.flake = false;
810
inputs.src.flake = false;
9-
outputs = { self, src, nixpkgs, flake-utils, haskellNix }:
11+
outputs = { self, src, nixpkgs, flake-utils, haskellNix, projectArgs }:
1012
flake-utils.lib.eachSystem [ "EVAL_SYSTEM" ] (system:
1113
let
1214
overlays = [ haskellNix.overlay
1315
(final: _prev: {
1416
hixProject =
15-
final.haskell-nix.hix.project {
17+
final.haskell-nix.hix.project ({
1618
inherit src;
17-
};
19+
} // (
20+
if builtins.pathExists (projectArgs + "/projectArgs.nix")
21+
then import (projectArgs + "/projectArgs.nix")
22+
else {}));
1823
})
1924
];
2025
pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };

0 commit comments

Comments
 (0)