alex-courtis / way-displays

way-displays: Auto Manage Your Wayland Displays
MIT License
240 stars 12 forks source link

add flake.nix #86

Closed edrex closed 1 year ago

edrex commented 1 year ago

I'm not sure if you'll be interested, but this has a number of benefits:

This is WIP but I wanted to put it up to see if you are interested or if you don't want the clutter. It would be helpful for me to contribute.

edrex commented 1 year ago

This is basically R4R, just want to add a few more things before final review.

Later

alex-courtis commented 1 year ago
  • add include-what-you-use to checks

That one might be a stretch goal... it's a bit finicky.

alex-courtis commented 1 year ago

This is WIP but I wanted to put it up to see if you are interested or if you don't want the clutter. It would be helpful for me to contribute.

This is fantastic! The run/develop is great, but the killer feature is CI and pre-commit.

What are you thinking of for pre-commit? We've been using https://github.com/pre-commit/pre-commit on another project: mandatory for CI, optional for users.

alex-courtis commented 1 year ago

Run works beautifully, --check not so:

nix develop --check github:edrex/way-displays/flake
no check/test target in Makefile, doing nothing

Could that be something to do with GNUmakefile vs Makefile?

edrex commented 1 year ago

I'm so glad you're up for it! I'd be happy to be "component maintainer" for the flake file (not a gatekeeper, just taking responsibility for keeping it working/responding to issues). Also, I just did a doc pass and heavily commented the file so you or anyone trying to figure it out who's not deep in Nix already has some context and starting points for reading.

What are you thinking of for pre-commit?

Yeah, that! flake-parts has a module for it.

This is my first time setting up nix CI on an active project, so I mostly know about it in theory. This is good practice for me.

--check not so

It works on my machine LOL. So much for reproducibility. I'm not sure. nix --version?

Could that be something to do with GNUmakefile vs Makefile?

It knows about GNUmakefile. See the stdenv setup.sh link in the latest push for details.

edrex commented 1 year ago

It works on my machine

Oops, I've only been running it on a checked out copy (which implicitly uses the PWD). I can reproduce with remote flake, and will TAL when I have more brain cells reporting tomorrow.

edrex commented 1 year ago

nix develop --check github:edrex/way-displays/flake

Sleeping on it, I realized this is by design. nix develop FLAKE_URL provides the devshell from the URL, but runs in the PWD. This way you can use a devshell on a repo/branch that doesn't have the flake, by running the above.

edrex commented 1 year ago

Ok this is ready. Package, devShell, and pre-commit hooks (editorconfig only to start)

nix develop will install the hooks.

Needs docs still.

edrex commented 1 year ago

clang-format would be easier to add than cppcheck since it has a hook bundled. Not sure how they differ.

edrex commented 1 year ago

I've been messing around with clang-format, but ran out of time for today. I think let's table that for another PR and just do a docs pass and get this merged (I'm about to be camping).

edrex commented 1 year ago

Other than needing doc pass, there's one remaining issue which is that the flake check pre-commit adds (runnable via nix flake check) doesn't seem to get the packages.default nativeBuildInputs, and so the unit-tests hook fails in that context. Opened upstream. We can just turn off the flake check though.

Also, WIP branch for clang-format here: https://github.com/edrex/way-displays/compare/flake...edrex:way-displays:clang-format?expand=1

alex-courtis commented 1 year ago

I'm so glad you're up for it! I'd be happy to be "component maintainer" for the flake file (not a gatekeeper, just taking responsibility for keeping it working/responding to issues). Also, I just did a doc pass and heavily commented the file so you or anyone trying to figure it out who's not deep in Nix already has some context and starting points for reading.

That would be great, thank you. This is my first time seeing or using nix.

alex-courtis commented 1 year ago

clang-format would be easier to add than cppcheck since it has a hook bundled. Not sure how they differ.

I'm a fan of stylers but not for c, as they are too intrusive and don't allow readability tweaks.

Boring old vim indenting is enough.

alex-courtis commented 1 year ago

Things are working nicely with https://github.com/alex-courtis/arch/blob/58ef524a787afe7edb1f5af541a5cc9c7ab3fb69/config/nix/nix.conf however I cannot figure out how to change the shell from bash to zsh. Ideas?

edrex commented 1 year ago

change the shell from bash to zsh

It's a whole thing. Nix likes having one standard shell because it can reliably integrate with it, but users would like to be able to overlay devshell environments on their personalized shell env, etc, so it creates a tension. I believe there is serious work being done to handle shell-independent environments in a generalized way, but I'm haven't been following it.

Swapping out bash for zsh in the derivation should be pretty straightforward, but really what we'd like is to be able to load a project environment into your personal shell, whatever it happens to be.

I'll look into it, because it has been on my list anyway for awhile.

alex-courtis commented 1 year ago

I'll look into it, because it has been on my list anyway for awhile.

No dramas... I was merely curious. Sounds like it's a Big Issue.

Good to merge after todo tidy.

edrex commented 1 year ago

Here is the upstream issue if you're curious: https://github.com/NixOS/nix/issues/4609

It looks like to start a subshell inheriting the project environment you can do

nix develop --command zsh

I'm tethering at camp on a newly-acquired macbook that I haven't provisioned, SSHing into my linux laptop at home, so minimal operational readiness ATM.

Good to merge after todo tidy.

I'll do a tidy pass tomorrowish, and merge. Docs later, and CI config.

edrex commented 1 year ago

Realized I was trying to do too much at once, and the pre-commit-hooks.nix stuff isn't as solid as I'd like, so I deferred it (https://github.com/edrex/way-displays/tree/pre-commit). This branch is now just about adding a basic flake, and I'd like to configure GH actions as part of it, since that will ensure it gets exercised.

edrex commented 1 year ago

To test the workflow, I pushed to a branch in the main repo, https://github.com/alex-courtis/way-displays/tree/flake, which should trigger a build. I think, though, that Actions need to be enabled in the repo config. @alex-courtis could you check that out when you have a chance?

edrex commented 1 year ago

Oh, also it ran when I pushed to my copy of the repo: https://github.com/edrex/way-displays/actions/runs/4803332016/jobs/8547712019

The build step runs the unit tests, and should fail if any tests fail. It would be nice, though, if the test report was shown in the logs. I just wanted to get the basic flow working and then iterate in future PRs.