Skip to content

Conversation

@NotAShelf
Copy link
Contributor

Hello!

While working on a small patch for witr I've noticed that the Nix flake is a bit inefficient, so I've cleaned it up a little. This might seem rather opitionated and drastic, but it's made with good intentions I assure you. A short summary of my changes:

  1. I've changed import nixpkgs { inherit system; }; to nixpkgs.legacyPackages.${system} because the latter is a tiny bit more efficient. This post generally covers what the issue is, and the alternative pattern I've used. Long thing short, we aren't using overlays, so the import pattern is unnecessary. And less efficient.

  2. Changes pkgs.lib invocations to nixpkgs.lib, since former is always in scope due to the argset. We don't have to partially instantiate pkgs for lib. Though the position of the let in might be bothersome. Let me know if you want this changed.

  3. Changed the source filter to a more aggressive one to prevent unnecessary rebuilds. In the previous version, you would rebuild the package even when an irrelevant package has changed (say, your README.md) because the source filter actually covers so little. See here for the things covered. Instead, we make a "static" filter that specifies the files needed for the build, and the source is changed only when one of the relevant files are changed. This is nice to avoid unnecessary rebuilds.

  4. Add a postInstall step to install the manpages. This is not done automatically, so we have to use the installShellFiles hook. This is trivial and cost-free, so might as well.

  5. Added the meta field with description and license fields. Those are critical for various commands, i.e., the former is displayed in nix flake show nicely and the latter avoids getting unfree warnings. Also went ahead and added the homepage because, well, documentation is nice.

Lastly, I had to reformat the file with a conventional formatter because I could not figure out what you were using, and my formatter nuked the file after I have made all of my changes. If you'd like me to reformat, I can do that or I can add pkgs.nixfmt as the standard formatter for the flake so it works with nix fmt automatically.

Change-Id: Ic8a9ddb1e3e3bc56b81888230706cdf96a6a6964

@GunniBusch
Copy link
Contributor

GunniBusch commented Jan 1, 2026

@NotAShelf does this solve #26 (comment)? or one of #81

@NotAShelf NotAShelf force-pushed the notashelf/push-nrpqmmoylwlw branch 2 times, most recently from d7227a4 to 041160e Compare January 1, 2026 22:38
@NotAShelf
Copy link
Contributor Author

NotAShelf commented Jan 1, 2026

No, it doesn't.

I had tested the build, but it didn't occur to me to test the built binary. Though I think it's a trivial fix, allow me a moment.

Edit:

Fixed.

$ nix build .# --builders "" --substituters "https://cache.nixos.org" -Lv
checking outputs of '/nix/store/hm9l7hc0rayzx21hrnwbljvkrqyy2pan-witr-dirty.drv'...
witr-dirty> Running phase: unpackPhase
witr-dirty> unpacking source archive /nix/store/m3lfwir9hsdhr5f5gcaslxr90d7w2srz-source
witr-dirty> source root is source
witr-dirty> Running phase: patchPhase
witr-dirty> Running phase: updateAutotoolsGnuConfigScriptsPhase
witr-dirty> Running phase: configurePhase
witr-dirty> Running phase: buildPhase
witr-dirty> Building subPackage ./cmd/witr
witr-dirty> Running phase: checkPhase
witr-dirty> ?           github.com/pranshuparmar/witr/cmd/witr  [no test files]
witr-dirty> Running phase: installPhase
witr-dirty> Running phase: fixupPhase
witr-dirty> shrinking RPATHs of ELF executables and libraries in /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty
witr-dirty> shrinking /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty/bin/witr
witr-dirty> checking for references to /build/ in /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty...
witr-dirty> patching script interpreter paths in /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty
witr-dirty> stripping (with command strip and flags -S -p) in  /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty/bin
$ result/bin/witr 8080

Error:
  no running process or service named "8080"

No matching process or service found. Please check your query or try a different name/port/PID.
For usage and options, run: witr --help

@GunniBusch
Copy link
Contributor

No, it doesn't.

I had tested the build, but it didn't occur to me to test the built binary. Though I think it's a trivial fix, allow me a moment.

Edit:

Fixed.

$ nix build .# --builders "" --substituters "https://cache.nixos.org" -Lv
checking outputs of '/nix/store/hm9l7hc0rayzx21hrnwbljvkrqyy2pan-witr-dirty.drv'...
witr-dirty> Running phase: unpackPhase
witr-dirty> unpacking source archive /nix/store/m3lfwir9hsdhr5f5gcaslxr90d7w2srz-source
witr-dirty> source root is source
witr-dirty> Running phase: patchPhase
witr-dirty> Running phase: updateAutotoolsGnuConfigScriptsPhase
witr-dirty> Running phase: configurePhase
witr-dirty> Running phase: buildPhase
witr-dirty> Building subPackage ./cmd/witr
witr-dirty> Running phase: checkPhase
witr-dirty> ?           github.com/pranshuparmar/witr/cmd/witr  [no test files]
witr-dirty> Running phase: installPhase
witr-dirty> Running phase: fixupPhase
witr-dirty> shrinking RPATHs of ELF executables and libraries in /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty
witr-dirty> shrinking /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty/bin/witr
witr-dirty> checking for references to /build/ in /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty...
witr-dirty> patching script interpreter paths in /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty
witr-dirty> stripping (with command strip and flags -S -p) in  /nix/store/lc691nwxvc5vkxyjb76dpsi7g3dw6xlm-witr-dirty/bin
$ result/bin/witr 8080

Error:
  no running process or service named "8080"

No matching process or service found. Please check your query or try a different name/port/PID.
For usage and options, run: witr --help

@NotAShelf great. I will check the nix issue as done.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ic8a9ddb1e3e3bc56b81888230706cdf96a6a6964
@NotAShelf NotAShelf force-pushed the notashelf/push-nrpqmmoylwlw branch from 041160e to ea216e2 Compare January 1, 2026 22:49
@NotAShelf
Copy link
Contributor Author

I've squashed my changes. Should be fully fixed now.

@pranshuparmar
Copy link
Owner

@NotAShelf Thanks for the detailed explanation and for tightening this up.

I’m not much experienced with Nix, you're definitely the expert here. The changes make sense from your explaination, so I’ll go ahead and merge this.

For formatting, I’ll add the standard formatter. Feel free to review that, and if you think any adjustments are needed, you’re welcome to open a follow-up PR.

@pranshuparmar pranshuparmar merged commit 26a0387 into pranshuparmar:main Jan 2, 2026
@pranshuparmar pranshuparmar mentioned this pull request Jan 2, 2026
@pranshuparmar
Copy link
Owner

@NotAShelf I've merged this to main but still facing the build error. If possible could you please check this-

error: Cannot build '/nix/store/71r7x23xccfgfpscm33rj900msj8cnxx-witr-git-32c9c28.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/la80mrjzks1rnplvd86fn4p2rcpv5bij-witr-git-32c9c28
       Last 19 log lines:
       > Running phase: unpackPhase
       > unpacking source archive /nix/store/rgdg9zfmwm6jxicsbg5j65wzwpi1ccdk-source
       > source root is source
       > Running phase: patchPhase
       > Running phase: updateAutotoolsGnuConfigScriptsPhase
       > Running phase: configurePhase
       > Running phase: buildPhase
       > Building subPackage ./cmd
       > go: inconsistent vendoring in /build/source:
       >      github.com/spf13/cobra@v1.10.2: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >      github.com/cpuguy83/go-md2man/v2@v2.0.7: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >     github.com/inconshreveable/mousetrap@v1.1.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >         github.com/russross/blackfriday/v2@v2.1.0: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >   github.com/spf13/pflag@v1.0.10: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >      go.yaml.in/yaml/v3@v3.0.4: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
       >
       >   To ignore the vendor directory, use -mod=readonly or -mod=mod.
       >  To sync the vendor directory, run:
       >              go mod vendor
       For full logs, run:
         nix log /nix/store/71r7x23xccfgfpscm33rj900msj8cnxx-witr-git-32c9c28.drv

@NotAShelf
Copy link
Contributor Author

Seems like you're missing the vendor directory in the source filter. Nix unfortunately doesn't have very good error reporting, but it should be trivial to fix by adding the vendor directory to the new source filter.

Remember that if you add a new directory critical for a build, it'll also need to be added to the filter so a quick note in the flake.nix might be nice.

@pranshuparmar
Copy link
Owner

Seems like you're missing the vendor directory in the source filter. Nix unfortunately doesn't have very good error reporting, but it should be trivial to fix by adding the vendor directory to the new source filter.

Remember that if you add a new directory critical for a build, it'll also need to be added to the filter so a quick note in the flake.nix might be nice.

Thanks for the assist, it is working now.

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.

3 participants