Clean up the Nix flake, recommended practices, provide overlay#6
Clean up the Nix flake, recommended practices, provide overlay#6daylinmorgan merged 14 commits intodaylinmorgan:mainfrom
Conversation
Some of these changes aren't really independent, but I'll try. Here are some high-level thoughts: These changes broke ❯ nix flake check
error:
… while checking flake output 'overlays'
at /nix/store/pps7hwqysf2l449krqg70yx3z2gslhbj-source/flake.nix:20:7:
19| in {
20| overlays = {
| ^
21| default = pkgs: pkgs0: {
… while checking the overlay 'overlays.default'
at /nix/store/pps7hwqysf2l449krqg70yx3z2gslhbj-source/flake.nix:21:9:
20| overlays = {
21| default = pkgs: pkgs0: {
| ^
22| monolisa-nerdfont-patch = pkgs.stdenv.mkDerivation {
error: overlay does not take an argument named 'final'
❯ nix flake show
git+file:///home/daylin/stuff/fonts/monolisa-nerdfont-patch?ref=refs/heads/spikespaz/main&rev=fa54af9cba60c7ff2e2928a5dbe95800f4bc57dd
├───devShells
│ ├───aarch64-linux
│ │ └───default omitted (use '--all-systems' to show)
│ └───x86_64-linux
│ └───default: development environment 'nix-shell'
├───formatter
│ ├───aarch64-linux omitted (use '--all-systems' to show)
error:
… while evaluating the attribute 'packages.x86_64-linux.default'
at /nix/store/96dn6crb2c2l9mwv64a0yq7rnwbf9v6h-source/flake.nix:73:11:
72| packages = rec {
73| default = nixfmt;
| ^
74| nixfmt = pkgs.haskellPackages.nixfmt;
… while evaluating the attribute 'haskellPackages.nixfmt'
at /nix/store/96dn6crb2c2l9mwv64a0yq7rnwbf9v6h-source/flake.nix:31:15:
30| packageOverrides = self: super: {
31| nixfmt = self.callCabal2nix "nixfmt" src { };
| ^
32| };
(stack trace truncated; use '--show-trace' to show the full trace)
error: cannot build '/nix/store/qqkh6wvkk8y3ansvbcxxq2ysgdnh07dy-cabal2nix-nixfmt.drv^out' during evaluation because the option 'allow-import-from-derivation' is disabledWith regards to adding Using |
There was a problem hiding this comment.
I'd prefer to keep a forAllSystems function that that takes pkgs something like:
forAllSystems = f:
genAttrs (import systems)
(system:
f (import nixpkgs {
localSystem.system = system;
overlays = [ self.overlays.default ];
}));Removing the formatter output removes the standalone use for the eachSystem function and then negates the redundant let pkgs = pkgsFor.${system} everywhere else.
|
The problem with Alejandra is that it causes very noisy diffs, which is a pain I contend with every time I rebase a PR. Bear with me. |
|
Take this one for example. It messes with indentation so much. I really don't like Alejandra. |
|
And this one, the diff was much nicer before. |
The commits are as they are because I have experience with people telling me no to Nixfmt, and this makes the rebase easier when I inevitably replace it with Alejandra. :) |
|
If you don't already know, Alejandra makes manual merges painful. |
|
That should be all the changes you asked for done. |
|
Thanks! |
| src = ./.; | ||
| nativeBuildInputs = with final; [makeWrapper]; | ||
| buildInputs = with final; [fontforge python3]; | ||
| nativeBuildInputs = with pkgs; [makeWrapper]; |
There was a problem hiding this comment.
I just noticed, this change is bad, don't ever use an external pkgs from inside an overlay. You should treat final as if it were pkgs, otherwise you evaluate Nixpkgs stages twice. See here for some relevant discussion.
There was a problem hiding this comment.
Never mind the above comment. I now see line 26. If this is your preference (and you should be consistent with your change on lines 16-22) consider using the naming scheme that I have come up with in the thread I have already linked. It does make sense to rename final to pkgs, but as final/self and prev/super can also be used for overrideAttrs (and others) inside overlays, to avoid shadowing, consider pkgs: pkgs0.
There was a problem hiding this comment.
consider using the naming scheme that I have come up with in the thread I have already linked. It does make sense to rename
finaltopkgs, but asfinal/selfandprev/supercan also be used foroverrideAttrs(and others) inside overlays, to avoid shadowing, considerpkgs: pkgs0.
For one they aren't used within this overlay so avoiding name confusion is a moot point. And secondly, your scheme is incompatible with nix flake check as I previously demonstrated when you first submitted a PR with this change.
There was a problem hiding this comment.
No, nixfmt caused the check failure. Not this.
| postFixup = '' | ||
| wrapProgram $out/bin/monolisa-nerdfont-patch \ | ||
| --set PATH ${lib.makeBinPath (with final; [fontforge])} | ||
| --set PATH ${makeBinPath (with final; [fontforge])} |
There was a problem hiding this comment.
This is subjective, and I understand that it is preference, but parts of Nixpkgs are moving away from this, which is why I changed it. The idea is to keep it clear what is in lib and what is in the prelude. You may safely ignore this comment, especially since I can't find the relevant discussion that I read and I can provide no evidence other than anecdotal.
There was a problem hiding this comment.
Perhaps the issue I am thinking of in Nixpkgs is the over-usage of with which causes name-clashing. I don't remember well.
| devShells = eachSystem (_: pkgs: { | ||
| default = pkgs.mkShell { | ||
| packages = with pkgs; [fontforge python3 pre-commit]; | ||
| buildInputs = with pkgs; [fontforge python3 pre-commit]; |
There was a problem hiding this comment.
Question, not a suggestion or correction: why did you choose to use buildInputs over packages?
Now a little pushy: mkShell is a smart function, is documented, and it does not suggest using buildInputs (though this is common practice). See the manual.
There was a problem hiding this comment.
It make no difference they are all just merged.
| }); | ||
|
|
||
| formatter = eachSystem (system: _: alejandra.packages.${system}.default); | ||
| }; |
There was a problem hiding this comment.
I understand not wanting to take the formatter's flake as an input, however consider re-introducing the formatter output because it is special. You can use the package from Nixpkgs instead. The output allows nix fmt to work. This is useful: I manually run nix fmt to keep myself organized while I am working on dirty code, and additionally, configure my editor to format the code using the nix fmt command when the file is saved. This allows me to write long lines, and then semi-automatically format to keep my head clear and the code readable.
There was a problem hiding this comment.
I am well aware of how nix fmt works.
|
I have added comments, as I am sure your inbox is well-aware. I probably spammed you while struggling with the GitHub UI. It seemed to post them in the wrong locations, and when I went to correct them, refreshing the page showed that I had double-posted, edited, or even had it correct in the first place. I have absolutely no idea what was happening; I do sincerely apologize. |
This is how I organize my Nix flakes and allow for the utmost compatibility for any desired use-case. When I say "recommended practices", they are my own, but also very similar to the "best practices" purported by the community.
I recommend reviewing each commit individually.