Skip to content

Commit 5229625

Browse files
authored
Improve hix flake check (#2413)
* Improve `hix flake check` Adds: `--supportedSystems` `--overlays` `--config` To allow more control of the flake from the command line. * Bump head.hackage
1 parent 19ff56a commit 5229625

File tree

5 files changed

+96
-56
lines changed

5 files changed

+96
-56
lines changed

hix/default.nix

Lines changed: 73 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,87 @@ let
2222
cmd=$1
2323
shift
2424
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
2749
;;
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
3083
;;
31-
flake|build|develop|run|profile)
84+
*)
3285
# Put the flake files for remote URLs in $HOME/.hix by default
3386
HIX_DIR="''${HIX_DIR:-$HOME/.hix}"
3487
HIX_TMPDIR="$(mktemp -d)"
35-
projectArgs=""
88+
args=("--option" "allow-import-from-derivation" "true")
3689
while(($#)); do
3790
arg=$1
3891
case $arg in
3992
--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"
42106
shift
43107
;;
44108
--out-link|-o|--eval-store|--include|-I|--inputs-from|--expr|--file|-f|--keep|-k|--phase|--profile|--unset|-u)
@@ -102,42 +166,9 @@ let
102166
cp $HIX_FLAKE $FLAKE/flake.nix
103167
chmod +w $FLAKE/flake.nix
104168
fi
105-
if [ "$projectArgs" != "" ]; then
106-
printf %s "$projectArgs" > "$HIX_TMPDIR/projectArgs.nix"
107-
fi
169+
args+=(--override-input projectArgs "$(realpath "$HIX_TMPDIR")")
108170
nix $cmd "''${args[@]}"
109171
;;
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-
;;
141172
esac
142173
'';
143174
in (pkgs.symlinkJoin {

hix/project/flake.nix

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,30 @@
99
inputs.projectArgs.flake = false;
1010
inputs.src.flake = false;
1111
outputs = { self, src, nixpkgs, flake-utils, haskellNix, projectArgs }:
12-
flake-utils.lib.eachSystem [ "EVAL_SYSTEM" ] (system:
12+
flake-utils.lib.eachSystem (
13+
if builtins.pathExists (projectArgs + "/supportedSystems.nix")
14+
then import (projectArgs + "/supportedSystems.nix")
15+
else [ "EVAL_SYSTEM" ]) (system:
1316
let
1417
overlays = [ haskellNix.overlay
1518
(final: _prev: {
1619
hixProject =
17-
final.haskell-nix.hix.project ({
18-
inherit src;
19-
} // (
20-
if builtins.pathExists (projectArgs + "/projectArgs.nix")
21-
then import (projectArgs + "/projectArgs.nix")
22-
else {}));
20+
(final.haskell-nix.hix.project
21+
{ inherit src; }).appendModule (
22+
if builtins.pathExists (projectArgs + "/projectArgs.nix")
23+
then import (projectArgs + "/projectArgs.nix")
24+
else {}
25+
);
2326
})
2427
];
25-
pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
28+
pkgs = import nixpkgs { inherit system;
29+
overlays = overlays ++ (if builtins.pathExists (projectArgs + "/overlays.nix")
30+
then import (projectArgs + "/overlays.nix")
31+
else []);
32+
config = haskellNix.config // (if builtins.pathExists (projectArgs + "/config.nix")
33+
then import (projectArgs + "/config.nix")
34+
else {});
35+
};
2636
flake = pkgs.hixProject.flake {};
2737
in flake // {
2838
legacyPackages = pkgs;

lib/check.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ in stdenv.mkDerivation ((
3030
name = (drv.name + "-check");
3131

3232
passthru = {
33-
inherit (drv) identifier config configFiles executableToolDepends cleanSrc env exeName;
33+
inherit (drv) identifier config configFiles executableToolDepends cleanSrc env exeName meta;
3434
profiled = self drv.profiled;
3535
dwarf = self drv.dwarf;
3636
};

lib/default.nix

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ in {
471471
${component.passthru.identifier.component-id} = {
472472
type = "app";
473473
program = component.exePath;
474+
inherit (component) meta;
474475
};
475476
})
476477
acc
@@ -531,8 +532,7 @@ in {
531532
, apps ? mkFlakeApps haskellPackages
532533
, checks ? mkFlakeChecks (collectChecks' haskellPackages)
533534
, coverage ? {}
534-
, devShell ? project.shell
535-
, devShells ? { default = devShell; }
535+
, devShells ? { default = project.shell; }
536536
, checkedProject ? project.appendModule { checkMaterialization = true; }
537537
, ciJobs ? mkFlakeCiJobs project { inherit checks coverage packages devShells checkedProject; }
538538
, hydraJobs ? ciJobs
@@ -560,8 +560,7 @@ in {
560560
ciJobs
561561
# Used by:
562562
# `nix develop`
563-
devShells
564-
devShell; # TODO remove devShell once everyone has nix that supports `devShells.default`
563+
devShells;
565564
};
566565

567566
# Adapt a standard project shell (`project.shell` or `haskell-nix.shellFor`)

test/cabal.project.local

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ repository head.hackage.ghc.haskell.org
2929
f76d08be13e9a61a377a85e2fb63f4c5435d40f8feb3e12eb05905edb8cdea89
3030
26021a13b401500c8eb2761ca95c61f2d625bfef951b939a8124ed12ecf07329
3131
7541f32a4ccca4f97aea3b22f5e593ba2c0267546016b992dfadcd2fe944e55d
32-
--sha256: sha256-ywti4TWiuFGJtnHaMMPhk3Ms2hXfsXMC1LMcWnI9K6I=
32+
--sha256: sha256-V7cPUrMNDXF+LDrNKUE+co1MEmOquGUQ19Z6dJP8bFA=
3333

3434
repository ghcjs-overlay
3535
url: https://raw.githubusercontent.com/input-output-hk/hackage-overlay-ghcjs/ffb32dce467b9a4d27be759fdd2740a6edd09d0b

0 commit comments

Comments
 (0)