libfn / functional

Extending C++ library for functional programming
ISC License
60 stars 8 forks source link

Experimental Nix support #77

Closed godexsoft closed 5 months ago

godexsoft commented 5 months ago

This PR adds support for building and/or developing libfn using Nix. Some details on how to get it to do its thing are provided in NIX.md. Hopefully this does not break anything else. At least CI seems happy now and I was able to still build stuff from my devcontainer setup.

codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 100.0%. Comparing base (86f95b6) to head (c279139).

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/libfn/functional/pull/77/graphs/tree.svg?width=650&height=150&src=pr&token=3RHT38SEU0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libfn)](https://app.codecov.io/gh/libfn/functional/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libfn) ```diff @@ Coverage Diff @@ ## main #77 +/- ## ======================================= Coverage 100.0% 100.0% ======================================= Files 20 20 Lines 857 857 Branches 121 121 ======================================= Hits 857 857 ``` [![Impacted file tree graph](https://app.codecov.io/gh/libfn/functional/pull/77/graphs/tree.svg?width=650&height=150&src=pr&token=3RHT38SEU0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libfn)](https://app.codecov.io/gh/libfn/functional/pull/77?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=libfn)
godexsoft commented 5 months ago

I know nothing about building packages with nix so feel free to drop this suggestion, but would it be possible to move .nix files into a new nix directory ?

I'd love to. I tried to do so a few weeks back but being a nix noob myself i failed miserably so had to revert it. I'll try again as i'd also prefer the root of the project to remain as uncluttered as possible.

godexsoft commented 5 months ago

I know nothing about building packages with nix so feel free to drop this suggestion, but would it be possible to move .nix files into a new nix directory ?

I'd love to. I tried to do so a few weeks back but being a nix noob myself i failed miserably so had to revert it. I'll try again as i'd also prefer the root of the project to remain as uncluttered as possible.

So i was able to move most files out of the way and into nix. But the main flake and its lockfile apparently need to be at the root of the repo if we want to be able to avoid having to do something like nix build github:libfn/functional?dir=nix#clang. For the build environment it would probably look like nix develop ./nix#clang or something but i have not tried.

Let me know if you are ok with the flake in root or if you would like me to do more research on this.

godexsoft commented 5 months ago

btw., we could totally add all the remaining tooling to the build environment. Stuff like clangd, clang-tidy, clang-format and whatever else we need to develop the library comfortably. But this could also be done in a separate branch later on.

Bronek commented 5 months ago

I know nothing about building packages with nix so feel free to drop this suggestion, but would it be possible to move .nix files into a new nix directory ?

I'd love to. I tried to do so a few weeks back but being a nix noob myself i failed miserably so had to revert it. I'll try again as i'd also prefer the root of the project to remain as uncluttered as possible.

So i was able to move most files out of the way and into nix. But the main flake and its lockfile apparently need to be at the root of the repo if we want to be able to avoid having to do something like nix build github:libfn/functional?dir=nix#clang. For the build environment it would probably look like nix develop ./nix#clang or something but i have not tried.

Let me know if you are ok with the flake in root or if you would like me to do more research on this.

I'm OK with that.

Bronek commented 5 months ago

@godexsoft as you probably noticed, I changed install targets

Bronek commented 5 months ago

@godexsoft there's a problem:

bronekk@aleph ~ % nix run --extra-experimental-features nix-command --extra-experimental-features flakes github:libfn/functional/feature/nix-build
error: unable to execute '/nix/store/x2kbhqgfnbdnr7s7fmk02yncnfv45m9j-libfn/bin/libfn': No such file or directory
godexsoft commented 5 months ago

@godexsoft there's a problem:

bronekk@aleph ~ % nix run --extra-experimental-features nix-command --extra-experimental-features flakes github:libfn/functional/feature/nix-build
error: unable to execute '/nix/store/x2kbhqgfnbdnr7s7fmk02yncnfv45m9j-libfn/bin/libfn': No such file or directory

I think it's because there is nothing to run? We are not installing any executables as far as i know. When i use nix build github:libfn/functional/feature/nix-build -L it appears to do what we want. I can see it's now installing to the paths you setup. Once you do a nix build from the github url it places all outputs into the result folder on your CWD. You can try to replace run with build in your command and maybe add -L that will produce all the output to the console instead of just one line.