Skip to content

Add cross compilation and devShell to project.flake #1141

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 2 commits into from
Jun 17, 2021
Merged

Conversation

hamishmack
Copy link
Collaborator

The default shell devShell works by adding a default shell to all projects. You can pass the shell arguments to the project function using the new shell argument:

let myProject = haskell-nix.project {
  src = ./.;
  shell.tools = { cabal = {}; };
  shell.crossPlatforms = p: [ p.cross ];
};

This will include js-unknown-ghcjs-cabal in the devShell.

To add cross compiled outputs to the flake pass crossPlatforms to the flake function.

myProject.flake { crossPlatforms = p: [ p.cross ]; }

To cross compile a component include the platforms config string to the output name like this

nix build .#js-unknown-ghcjs:pkg-name:lib:pkg-name

The default shell `devShell` works by adding a default `shell` to all projects.  You can pass the shell arguments to the project function using the new `shell` argument:

```
let myProject = haskell-nix.project {
  src = ./.;
  shell.tools = { cabal = {}; };
  shell.crossPlatforms = p: [ p.cross ];
};
```

This will include js-unknown-ghcjs-cabal in the `devShell`.

To add cross compiled outputs to the flake pass `crossPlatforms` to the `flake` function.

```
myProject.flake { crossPlatforms = p: [ p.cross ]; }
```

To cross compile a component include the platforms `config` string to the output name like this

```
nix build .#js-unknown-ghcjs:pkg-name:lib:pkg-name
```
Copy link
Contributor

@rvl rvl left a comment

Choose a reason for hiding this comment

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

Looks cool!

About the cross-compiling Cabals such as js-unknown-ghcjs-cabal - could we make them use a different --builddir=DIR by default? So that they won't clobber an existing build.

# Default shell arguments
shell = mkOption {
# TODO make this a submodule
type = unspecified;
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice to have module option docs here, to help users know how to use it.

@hamishmack
Copy link
Collaborator Author

About the cross-compiling Cabals such as js-unknown-ghcjs-cabal - could we make them use a different --builddir=DIR by default?

Newer cabal versions should include $arch-$os under dist-newstyle/build:

% ls dist-newstyle/build 
js-ghcjs	x86_64-osx

@hamishmack hamishmack merged commit c3841b4 into master Jun 17, 2021
@iohk-bors iohk-bors bot deleted the hkm/flake-cross branch June 17, 2021 07:07
hamishmack added a commit that referenced this pull request Jun 20, 2021
There are now 4 project modules used to check the arguments passed to the various project functions:

* `project-common.nix` - Arguments used by all the project functions
* `stack-project.nix` - Used by the `stackProject` and `stackProject'` functions
* `cabal-project.nix` - Used by the `cabalProject` and `cabalProject'` functions
* `project.nix` - Just the `projectFileName` argument that is used by `project` and `project'` functions to determine whether to call `stackProject` or `cabalProject` function.

This also includes the `rawProject.args` that was mistakenly left out of #1141 causing #1142 and improvements for the docs for the use of the `shell` argument in `flake.nix` files.
booniepepper pushed a commit to booniepepper/haskell.nix that referenced this pull request Feb 4, 2022
…1141)

The default shell `devShell` works by adding a default `shell` to all projects.  You can pass the shell arguments to the project function using the new `shell` argument:

```
let myProject = haskell-nix.project {
  src = ./.;
  shell.tools = { cabal = {}; };
  shell.crossPlatforms = p: [ p.cross ];
};
```

This will include js-unknown-ghcjs-cabal in the `devShell`.

To add cross compiled outputs to the flake pass `crossPlatforms` to the `flake` function.

```
myProject.flake { crossPlatforms = p: [ p.cross ]; }
```

To cross compile a component include the platforms `config` string to the output name like this

```
nix build .#js-unknown-ghcjs:pkg-name:lib:pkg-name
```
booniepepper pushed a commit to booniepepper/haskell.nix that referenced this pull request Feb 4, 2022
…k#1144)

There are now 4 project modules used to check the arguments passed to the various project functions:

* `project-common.nix` - Arguments used by all the project functions
* `stack-project.nix` - Used by the `stackProject` and `stackProject'` functions
* `cabal-project.nix` - Used by the `cabalProject` and `cabalProject'` functions
* `project.nix` - Just the `projectFileName` argument that is used by `project` and `project'` functions to determine whether to call `stackProject` or `cabalProject` function.

This also includes the `rawProject.args` that was mistakenly left out of input-output-hk#1141 causing input-output-hk#1142 and improvements for the docs for the use of the `shell` argument in `flake.nix` files.
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