Skip to content

treewide: add meta.mainProgram to many packages#166865

Merged
Lassulus merged 1 commit intoNixOS:masterfrom
malob:treewide-mainProgram
Apr 15, 2022
Merged

treewide: add meta.mainProgram to many packages#166865
Lassulus merged 1 commit intoNixOS:masterfrom
malob:treewide-mainProgram

Conversation

@malob
Copy link
Copy Markdown
Member

@malob malob commented Apr 1, 2022

Description of changes

I often like to use nix run to use a package that's currently not installed on my system. Sometimes I run into cases where nix run fails due to the package's name differing from that of the executable. I've filed a few PRs manually adding mainProgram to few packages' meta attribute set to get them working with nix run. This is kind of annoying to do, so I got to thinking about whether there was a way I could automate this. This is my first attempt.

I created a hacky script that uses nix-{index,locate} to try and:

  • find all packages that included a single executable in /bin;
  • check if the single executable's name was an exact match for the packages name in nixpkgs; and
  • if it wasn't an exact match,
    • check whether the package's meta attribute set contained a mainProgram attribute; and
    • if it didn't, adds the mainProgram attribute, set to the name of the single executable.

I excluded packages defined in places like pkgs/development/{libraries,haskell-modules} and a few others to reduce false positives.

I then manually looked through the diff to sanity check the changes, spot checking many with nix run (especially the ones that looked the most suspect) and removed a few where the single executable didn't really make sense to define as the mainProgram.

This process will have missed a bunch of cases, e.g.,

  • cases where the package has a single executable, but it was wrapped, so a second executable was present in /bin with the suffix "-wrapped";
  • cases where my in-place substitution with sed failed;
  • among many others.

But even at that, this PR should enable nix run to work with 143 additional packages.

Things done
  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 22.05 Release Notes (or backporting 21.11 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
    • (Release notes changes) Ran nixos/doc/manual/md-to-db.sh to update generated release notes
  • Fits CONTRIBUTING.md.

@malob malob requested a review from a user April 1, 2022 19:59
@malob malob requested review from FRidh and jonringer as code owners April 1, 2022 19:59
@github-actions github-actions bot added 6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: nim Nim programing language 6.topic: python Python is a high-level, general-purpose programming language. labels Apr 1, 2022
@malob
Copy link
Copy Markdown
Member Author

malob commented Apr 1, 2022

Oops, looks like there's a bunch of trailing whitespace, dealing with that now.

@malob malob force-pushed the treewide-mainProgram branch 2 times, most recently from bc802e0 to 924c085 Compare April 1, 2022 20:10
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Apr 1, 2022
@malob malob force-pushed the treewide-mainProgram branch from 924c085 to f3827b5 Compare April 1, 2022 22:41
@malob malob force-pushed the treewide-mainProgram branch from f3827b5 to e167143 Compare April 13, 2022 20:55
@malob malob force-pushed the treewide-mainProgram branch from e167143 to 0e802ea Compare April 14, 2022 17:24
@Lassulus Lassulus merged commit 92734ac into NixOS:master Apr 15, 2022
@malob malob deleted the treewide-mainProgram branch April 24, 2022 23:49
@06kellyjac
Copy link
Copy Markdown
Member

06kellyjac commented Apr 27, 2022

This was incorrect for fulcio

λ git show HEAD
commit 24b407708661f6ffa2f1a19869caa7599096f7b3 (HEAD -> master, upstream/master, origin/master, origin/HEAD)
Merge: 941c24d3496 ad1f6eb1220
Author: Sandro <sandro.jaeckel@gmail.com>
Date:   Wed Apr 27 16:58:32 2022 +0200

    Merge pull request #170613 from NickCao/tun2socks

    tun2socks: init at 2.4.1

λ nix-build -A fulcio
this path will be fetched (4.27 MiB download, 16.08 MiB unpacked):
  /nix/store/18qlpw0vw3qf6mnvxlv0mhx7alqi0vw8-fulcio-0.3.0
copying path '/nix/store/18qlpw0vw3qf6mnvxlv0mhx7alqi0vw8-fulcio-0.3.0' from 'https://cache.nixos.org'...
/nix/store/18qlpw0vw3qf6mnvxlv0mhx7alqi0vw8-fulcio-0.3.0
λ ls ./result/bin
 fulcio

@malob
Copy link
Copy Markdown
Member Author

malob commented Apr 27, 2022

@06kellyjac, interesting, looks like it was changed in 0.2.0, and my nix-index database was a little out of date. Seems to be addressed in #170639. Sorry for the mixup.

@06kellyjac
Copy link
Copy Markdown
Member

No problem. I thought id let you know incase you run the script again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: erlang General-purpose, concurrent, functional high-level programming language 6.topic: nim Nim programing language 6.topic: python Python is a high-level, general-purpose programming language. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants