Skip to content

refactor: nix flake for build and dev - #2219

Open
karlskewes wants to merge 5 commits into
pop-os:masterfrom
karlskewes:nix-flake
Open

refactor: nix flake for build and dev#2219
karlskewes wants to merge 5 commits into
pop-os:masterfrom
karlskewes:nix-flake

Conversation

@karlskewes

@karlskewes karlskewes commented Mar 23, 2026

Copy link
Copy Markdown

Across the Cosmic repo's the flakes are all a little different and there are various PR's (e.g: #1993 #1374) .
If the maintainers are happy to have the files, then I think it would be great to align them.

I think basic criteria should be something like:

  • no unnecessary dependencies where standard nix will do (e.g: crane, flake-utils for systems)
  • no optional developer tools, e.g: bacon or similar
  • nix build support
  • nix develop support
  • if possible: a canonical source for nixpkgs - is this practical?

Open to suggestions and alternatives.

AI Disclosure

  • I have disclosed use of any AI generated code in my commit messages.
    • If you are using an LLM, and do not fully understand the changes it is making to the code base, do not create a PR.
    • In our experience, AI generated code often results in overly complex code that lacks enough context for a proper fix or feature inclusion. This results in considerably longer code reviews. Due to this, AI authored or partially authored PRs may be closed without comment.
  • I understand these changes in full and will be able to respond to review comments.
  • My change is accurately described in the commit message.
  • My contribution is tested and working as described.
  • I have read the Developer Certificate of Origin and certify my contribution under its conditions.

@MasterofNull

Copy link
Copy Markdown

Hi @karlskewes! I've been working on similar improvements and have some suggestions for this flake based on the nixpkgs cosmic-comp package:

Improvements I'd suggest:

  1. Add inputs.nixpkgs.follows to rust-overlay to avoid duplicate nixpkgs evaluations
  2. Add udev to buildInputs - required for device access (missing from current version)
  3. Fix xrdb path - should be xorg.xrdb instead of bare xrdb
  4. Use pname/version instead of just name (follows nixpkgs conventions)
  5. Add separateDebugInfo = true for better debugging
  6. Add makeFlags and dontCargoInstall = true to match how nixpkgs builds it
  7. Add meta attribute with license, homepage, platforms, mainProgram
  8. Add formatter output for nix fmt support
  9. Add overlays.default for easy integration with other flakes
  10. Enhance devShell with rust-analyzer and cargo-watch

I've implemented these changes in my fork: https://github.com/MasterofNull/cosmic-comp/tree/nix-flake

Feel free to cherry-pick any of these improvements, or I can submit them as suggestions/PR to your branch if that would help!

@karlskewes

karlskewes commented Mar 26, 2026

Copy link
Copy Markdown
Author

Hi @karlskewes! I've been working on similar improvements and have some suggestions for this flake based on the nixpkgs cosmic-comp package:

Improvements I'd suggest:

1. **Add `inputs.nixpkgs.follows`** to rust-overlay to avoid duplicate nixpkgs evaluations

2. **Add `udev` to buildInputs** - required for device access (missing from current version)

3. **Fix `xrdb` path** - should be `xorg.xrdb` instead of bare `xrdb`

4. **Use `pname`/`version`** instead of just `name` (follows nixpkgs conventions)

5. **Add `separateDebugInfo = true`** for better debugging

6. **Add `makeFlags` and `dontCargoInstall = true`** to match how nixpkgs builds it

7. **Add `meta` attribute** with license, homepage, platforms, mainProgram

8. **Add `formatter` output** for `nix fmt` support

9. **Add `overlays.default`** for easy integration with other flakes

10. **Enhance devShell** with rust-analyzer and cargo-watch

I've implemented these changes in my fork: https://github.com/MasterofNull/cosmic-comp/tree/nix-flake

Feel free to cherry-pick any of these improvements, or I can submit them as suggestions/PR to your branch if that would help!

Looks great, thank you. I cherry-picked the commit.
We're also still blocked on some dependency pinning:

  • https://github.com/pop-os//cosmic-protocols double slash
  • patch for cosmic-client-toolkit ... points to the same source`

Across the Cosmic repo's the flakes are all a little different and there are various PR's.
If the maintainers are happy to have the files, then I think it would be great to align them.

I think basic criteria would be something like:

  • no unnecessary dependencies where standard nix will do (e.g: crane, flake-utils for systems)
  • EDIT: no optional developer tools, e.g: bacon or similar
  • nix build support
  • nix develop support
  • if possible: a canonical source for nixpkgs - is this practical?

@MasterofNull

Copy link
Copy Markdown

@karlskewes Thanks for cherry-picking the changes! I've pushed a follow-up fix for the double-slash issue you mentioned:

Fix: 85587d2e - Remove double slashes from cosmic-protocols patch URLs

The Cargo.toml patch section had typos:

- cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", branch = "main" }
+ cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols", branch = "main" }

Feel free to cherry-pick this as well. The cosmic-client-toolkit pointing to cosmic-protocols repo appears intentional since it's part of that workspace.

@Elias-Graf

Elias-Graf commented Apr 4, 2026

Copy link
Copy Markdown
Contributor

Is there any particular reason we're not using crane anymore? Otherwise we could have also included checks:

checks = {
	formatting = craneLib.cargoFmt { inherit src; };
	linting = craneLib.cargoClippy {
		inherit src cargoArtifacts;
		cargoClippyExtraArgs = "--all-targets -- -D warnings";
	};
	testing = craneLib.cargoTest {
		inherit src cargoArtifacts;
	};
};

Anyway, it would be cool if this got merged, since the current flake is broken :). I was just about to make a PR updating it, but seeing this makes that redundant :D.

Comment thread flake.nix Outdated
@karlskewes

Copy link
Copy Markdown
Author

Is there any particular reason we're not using crane anymore? Otherwise we could have also included checks:

@Elias-Graf, I've updated the PR description based on another comment.
After seeing various flakes across the Cosmic repo's with various dependencies I thought to simplify it back to straight nix first.
I'm not a maintainer either and an alternative PR may be better :)

Comment thread flake.nix Outdated
@karlskewes
karlskewes marked this pull request as ready for review June 6, 2026 22:06
@karlskewes
karlskewes force-pushed the nix-flake branch 2 times, most recently from f7c5a71 to a898d96 Compare July 10, 2026 07:00
@karlskewes

karlskewes commented Jul 10, 2026

Copy link
Copy Markdown
Author

I've rebased this branch on 1.2.0 rather than an arbitrary master commit as I'm using it for development and it simplifies dependencies.

I'll rebase on master if/when there's appetite to merge.

Additionally have removed the redundant patch for cargo-protocols as it's already pinned in Cargo.toml.
This could/should be raised as a separate PR to master but per the current pinned protocols commit SHA.

@karlskewes
karlskewes force-pushed the nix-flake branch 2 times, most recently from 8c45cc2 to 7ce73ef Compare July 10, 2026 09:55
@karlskewes
karlskewes force-pushed the nix-flake branch 5 times, most recently from ee242e4 to 78fa20c Compare August 1, 2026 22:18
@jacobgkau

Copy link
Copy Markdown
Member

@karlskewes We can take a look at reviewing this to merge and closing the obsolete #1374 if you want to rebase this on master and remove any extraneous changes.

@nuwawa @faukah Feel free to provide any input. We'll assume you don't object to these changes if we don't hear back.

@karlskewes
karlskewes marked this pull request as draft August 19, 2026 03:09
@karlskewes
karlskewes force-pushed the nix-flake branch 2 times, most recently from 4a60a72 to 4832463 Compare August 23, 2026 22:51
@karlskewes
karlskewes marked this pull request as ready for review August 23, 2026 23:10
Comment thread Cargo.toml
Comment on lines -144 to -146
[patch."https://github.com/pop-os/cosmic-protocols"]
cosmic-protocols = { git = "https://github.com/pop-os//cosmic-protocols", branch = "main" }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The patch seems unnecessary and breaks nix build due to // or duplicate source if remove //.
Set branch = "main" in further up on L24 and update Cargo.lock as well.

This commit could be a separate PR if preferred.

@karlskewes

Copy link
Copy Markdown
Author

@karlskewes We can take a look at reviewing this to merge and closing the obsolete #1374 if you want to rebase this on master and remove any extraneous changes.

@nuwawa @faukah Feel free to provide any input. We'll assume you don't object to these changes if we don't hear back.

Thanks @jacobgkau, rebased on master and ready for review.
One change that's not Nix specific but I think is reasonable: #2219 (comment)

karlskewes and others added 5 commits August 26, 2026 12:08
Improvements to the nix flake for building cosmic-comp:

- Add inputs.nixpkgs.follows to rust-overlay to reduce duplication
- Use explicit github: URL format for nixpkgs
- Add missing udev to buildInputs (required for device access)
- Fix xrdb path (xorg.xrdb instead of bare xrdb)
- Use pname/version instead of just name (follows nixpkgs convention)
- Add separateDebugInfo for better debugging experience
- Add makeFlags and dontCargoInstall (matches nixpkgs package)
- Add meta attribute with license, homepage, platforms, mainProgram
- Add formatter output for 'nix fmt' support
- Add overlays.default for easy integration with other flakes
- Improve devShell with rust-analyzer, cargo-watch, and shellHook
- Remove redundant rustToolchain from buildInputs (already in toolchain)
- Clean up formatting and remove unnecessary parentheses

These changes align the flake more closely with the nixpkgs cosmic-comp
package while maintaining the development-focused nature of this flake.
- use longer variable name for clarity
- use updated package name for `xrdb`
- include Makefile and data (*.ron files) for install
- drop cargo-watch
  `cargo-watch` is an optional developer tool not required to run or
  develop cosmic-comp. Additionally it is no longer maintained.
There's only one reference to cosmic-protocols so the patch is
unnecessary and breaks `nix build` and other tooling.

Error below, GitHub's git server rejects `//` in URL's.
```
$ nix build
warning: Git tree '/home/karl/src/github.com/karlskewes/cosmic-comp' is dirty
fatal: remote error:
 pop-os//cosmic-protocols is not a valid repository name
Visit https://support.github.com/ for help
warning: could not read HEAD ref from repo at 'https://github.com/pop-os//cosmic-protocols', u
 'master'
fatal: remote error:
 pop-os//cosmic-protocols is not a valid repository name
Visit https://support.github.com/ for help
```

@jacobgkau jacobgkau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Before, nix build, nix shell, and nix develop all failed with an error. On this branch, they all complete without error. So the Nix flake update seems like an improvement to me.

I also tested this through our normal build process and am not seeing any side effects from dropping the cosmic-protocols patch (but the engineering team can chime in if there's a reason that needs to still be in place).

@jacobgkau
jacobgkau requested review from a team and removed request for anglesideangle August 26, 2026 19:26
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.

5 participants