Skip to content

Add flake support to hix #1572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 2022
Merged

Add flake support to hix #1572

merged 3 commits into from
Aug 4, 2022

Conversation

hamishmack
Copy link
Collaborator

This adds support for using nix flakes commands with hix. This is done by creating a hidden .hix-flake directory and passing the source in using --override-input.

It also includes a hix init command to add a flake.nix and nix/hix.nix configuration file.

This adds support for using nix flakes commands with hix.  This is done by creating a hidden `.hix-flake` directory and passing the source in using `--override-input`.

It also includes a `hix init` command to add a `flake.nix` and `nix/hix.nix` configuration file.
@hamishmack hamishmack requested a review from yvan-sraka August 2, 2022 09:15
Copy link
Contributor

@yvan-sraka yvan-sraka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! With few comments/suggestions, I am currently failing to fully test to build hello example project…

* Making `flake` and `non flake` configurations to check `haskell.nix`
treats them the same.

## Installing Nix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can add a small n.b. to remind user that hix require having nix in PATH with experimental-features = [ "nix-command" "flakes" ]; enabled?

```
niv init
niv add input-output-hk/haskell.nix -n haskellNix
nix run github:input-output-hk/haskell.nix#hix -- init
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it using:

nix run "github:input-output-hk/haskell.nix/hkm/hix-flake#hix" -- init

zsh will complain if nix run argument not enclosed in quotes:

zsh: no matches found: github:input-output-hk/haskell.nix/hkm/hix-flake#hix

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just discover that's not default zsh who complain when argument contains : not enclosed in quotes, that's the GRML config I'm using …

hix/default.nix Outdated
cp $HIX_NIX nix/hix.nix
echo '`nix/hix.nix` project configuation:'
fi
cat nix/hix.nix
Copy link
Contributor

@yvan-sraka yvan-sraka Aug 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest replacing cat by ${pkgs.bat}/bin/bat for fancy nix syntax highlighting.

});

# --- Flake Local Nix Configuration ----------------------------
nixConfig = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a comment here to introduce binary cache to the user and let them eventually opt out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a comment, but nix should give the user an option not to add the cache when they build it.

@@ -0,0 +1,30 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unclear to me at first sight what was the difference between this file and hix/project/flake.nix

niv init
niv add input-output-hk/haskell.nix -n haskellNix
nix run github:input-output-hk/haskell.nix#hix -- init
nix develop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All nix commands fail on my computer: error: getting status of '/nix/store/m5kk00h3yvjbyw4frcf00hzaigf0p7p0-source/hello-1.0.0.2': No such file or directory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, hello-1.0.0.2 folder was in another flake subdirectory and I guess direnv mess a bit with dev shells … now I have this issue:

yvan@X230 ~/IOHK/hello-1.0.0.2 % nix develop
warning: Using saved setting for 'allow-import-from-derivation = true' from ~/.local/share/nix/trusted-settings.json.
warning: Using saved setting for 'extra-substituters = https://cache.iog.io' from ~/.local/share/nix/trusted-settings.json.
warning: Using saved setting for 'extra-trusted-public-keys = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=' from ~/.local/share/nix/trusted-settings.json.
error: The option `crossPlatforms' does not exist. Definition values:
       - In `<unknown-file>': <function>
(use '--show-trace' to show detailed location information)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Full log with --show-trace:

error: The option `crossPlatforms' does not exist. Definition values:
       - In `<unknown-file>': <function>

       … while evaluating the attribute 'config'

       at /nix/store/l4ysisamwr0jdf6w2za4zygj9ajlf0wb-source/lib/modules.nix:357:9:

          356|         options = checked options;
          357|         config = checked (removeAttrs config [ "_module" ]);
             |         ^
          358|         _module = checked (config._module);

       … while evaluating 'hasSuffix'

       at /nix/store/l4ysisamwr0jdf6w2za4zygj9ajlf0wb-source/lib/strings.nix:235:5:

          234|     # Input string
          235|     content:
             |     ^
          236|     let

       … from call site

       at /nix/store/im0h1rigra4mw84y1ml8k2mr6ryjrpdc-source/overlays/haskell.nix:839:16:

          838|           in
          839|             if final.lib.hasSuffix ".yaml" selectedFileName
             |                ^
          840|               then stackProject' ([

       … while evaluating 'project''

       at /nix/store/im0h1rigra4mw84y1ml8k2mr6ryjrpdc-source/overlays/haskell.nix:811:20:

          810|         # used (as it will use a default `cabal.project`).
          811|         project' = projectModule:
             |                    ^
          812|           let

       … from call site

       at /nix/store/im0h1rigra4mw84y1ml8k2mr6ryjrpdc-source/overlays/haskell.nix:852:33:

          851|         # for `cabalPackage` and `stackPackage`.
          852|         project = args: let p = project' args;
             |                                 ^
          853|           in p.hsPkgs // p;

       … while evaluating 'project'

       at /nix/store/im0h1rigra4mw84y1ml8k2mr6ryjrpdc-source/overlays/haskell.nix:852:19:

          851|         # for `cabalPackage` and `stackPackage`.
          852|         project = args: let p = project' args;
             |                   ^
          853|           in p.hsPkgs // p;

       … from call site

       at /nix/store/im0h1rigra4mw84y1ml8k2mr6ryjrpdc-source/overlays/hix.nix:38:8:

           37|       projectDefaults = importDefaults (toString (src.origSrcSubDir or src) + "/nix/hix.nix");
           38|     in final.haskell-nix.project [
             |        ^
           39|             (import ../modules/hix-project.nix)

       … while evaluating 'project'

       at /nix/store/im0h1rigra4mw84y1ml8k2mr6ryjrpdc-source/overlays/hix.nix:3:5:

            2|   project =
            3|     { src
             |     ^
            4|     , userDefaults ? {}

       … from call site

       at /nix/store/07ym39kzdnn7h45zz6v78286d3vs1sax-source/flake.nix:19:15:

           18|             hixProject =
           19|               final.haskell-nix.hix.project {
             |               ^
           20|                 src = ./.;

       … while evaluating the attribute 'hixProject.flake'

       at /nix/store/07ym39kzdnn7h45zz6v78286d3vs1sax-source/flake.nix:18:13:

           17|           (final: prev: {
           18|             hixProject =
             |             ^
           19|               final.haskell-nix.hix.project {

       … while evaluating anonymous lambda

       at /nix/store/07ym39kzdnn7h45zz6v78286d3vs1sax-source/flake.nix:14:52:

           13|     in
           14|       flake-utils.lib.eachSystem supportedSystems (system:
             |                                                    ^
           15|       let

       … from call site

       at /nix/store/0zdncmv2n5sncs0sdphvggc61ix1fpsm-source/default.nix:128:17:

          127|         let
          128|           ret = f system;
             |                 ^
          129|           op = attrs: key:

       … while evaluating 'op'

       at /nix/store/0zdncmv2n5sncs0sdphvggc61ix1fpsm-source/default.nix:126:19:

          125|       # Merge together the outputs for all systems.
          126|       op = attrs: system:
             |                   ^
          127|         let

       … from call site

       at /nix/store/0zdncmv2n5sncs0sdphvggc61ix1fpsm-source/default.nix:144:5:

          143|     in
          144|     builtins.foldl' op { } systems
             |     ^
          145|   ;

       … while evaluating 'eachSystem'

       at /nix/store/0zdncmv2n5sncs0sdphvggc61ix1fpsm-source/default.nix:98:25:

           97|   #
           98|   eachSystem = systems: f:
             |                         ^
           99|     let

       … from call site

       at /nix/store/07ym39kzdnn7h45zz6v78286d3vs1sax-source/flake.nix:14:7:

           13|     in
           14|       flake-utils.lib.eachSystem supportedSystems (system:
             |       ^
           15|       let

       … while evaluating 'outputs'

       at /nix/store/07ym39kzdnn7h45zz6v78286d3vs1sax-source/flake.nix:5:13:

            4|   inputs.flake-utils.url = "github:numtide/flake-utils";
            5|   outputs = { self, nixpkgs, flake-utils, haskellNix }:
             |             ^
            6|     let

       … from call site

       at «string»:45:21:

           44|
           45|           outputs = flake.outputs (inputs // { self = result; });
             |                     ^
           46|

       … while evaluating anonymous lambda

       at «string»:10:13:

            9|     builtins.mapAttrs
           10|       (key: node:
             |             ^
           11|         let

       … from call site

       … while evaluating anonymous lambda

       at «string»:2:23:

            1|
            2| lockFileStr: rootSrc: rootSubdir:
             |                       ^
            3|

       … from call site

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to say when testing this you need to also pass something to point haskellNix to the PR branch. Something like:

nix develop --override-input haskellNix "github:input-output-hk/haskell.nix/hkm/hix-flake"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that everything works as expected :)

@hamishmack hamishmack merged commit 05c0555 into master Aug 4, 2022
@iohk-bors iohk-bors bot deleted the hkm/hix-flake branch August 4, 2022 22:17
This was referenced Aug 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants