nixpkgs/pkgs/by-name
Yueh-Shun Li 91b3db1309 treewide: fix sourceRoot for fetchgit-based src
According to Nixpkgs manual[1] and NixOS 23.11 Release Note[2], the
`sourceRoot` attribute passed to `stdenv.mkDerivation` should be
specified as `"${src.name}"` or `"${src.name}/subdir"` when `src` is
produced using `fetchgit`-based fetchers.

`sourceRoot = "source"` or `sourceRoot = "source/subdir"` is based on
the assumption that the `name` attribute of these pre-unpacked fetchers
are always `"source"`, which is not the case. Expecting constant `name`
also makes the source FODs prone to irrelevent hashes during version
bumps.

[1]: https://nixos.org/manual/nixpkgs/unstable/#var-stdenv-sourceRoot
[2]: https://nixos.org/manual/nixos/stable/release-notes#sec-release-23.11
2024-03-09 07:53:25 +08:00
..
_4/_4th
_9/_9base
a4/a4
aa
ab/aba
ac
ad
ae
af
ag/ags
ai
al
am Merge pull request #288012 from r-ryantm/auto-update/amazon-ssm-agent 2024-03-07 23:54:51 +01:00
an
ao/aocl-utils
ap
ar
as
at
au
av
aw
ax/axmldec
ay
ba
bc/bc-ur
be
bi
bk/bk
bl
bm/bmake
bn/bngblaster
bo
bp/bpftop
br
bs/bsync
bu
by
c2 treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
c-
ca
cb/cbmbasic
cc/ccache
cd
ce
cg/cgl
ch
ci
cl
cm
cn/cntb
co
cp
cr
cs
ct/ctx
cu/cursewords
cy
cz/czkawka
da
db/dbus-cpp
dc/dc3dd
dd/ddns-updater
de
di
dj/djent
dm
dn/dns2tcp
do dorion: 4.1.2 -> 4.1.3 2024-03-07 12:34:32 +00:00
dp/dpp
dr/drone-scp
ds
dt/dtcmp
du
dv/dvb-apps
dx
dy
ea/easyeasm
eb
ec
ed
ei Merge pull request #289453 from r-ryantm/auto-update/eiwd 2024-03-07 16:36:20 +01:00
ek/eksctl
el
em
en
er
es
eu
ex
ez/eza
fa
fb/fbset
fc
fe
ff
fi
fl
fm
fn/fnott
fo
fr treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
fu/fuchsia-cursor
fw/fwupd
fy/fypp
ga
gb/gbar
gc
ge
gh
gi
gl
gm/gmic
gn/gnucap
go
gp
gr
gt
gu
gx/gxml
h8/h8mail
ha
hd/hdrop
he
hi/hifile
hj/hjson-go
ho
ht
hu/hugo
hy
i3
ia
ic icewm: 3.4.5 -> 3.4.6 2024-03-08 01:30:31 +00:00
id/idsk
if/ifrextractor-rs
ig
ii
im
in treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
io/ioq3-scion
ip/ipam
ir/ironbar
it/itch
ja
jd/jdt-language-server
ji
jj/jj
jn/jnr-posix
jo
js/jsoncons
ju/justbuild
ka
kc
kd/kdsingleapplication
ke
kg/kgeotag
ki
kl/klog-time-tracker
km/kmsvnc
kn/knossosnet
ko
kp/kplex
kr/krr krr: fix version name 2024-03-07 15:36:24 +03:00
ks/kseexpr
kt
ku
kx/kxstitch
la treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
lc/lcab
le
li treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
ll
ln/lngen
lo
ls
lt/ltris
lu lubelogger: 1.2.4 -> 1.2.5 2024-03-08 01:52:58 +00:00
lw/lwgrp
lz
m2
ma
mc
md
me treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
mf
mg/mgitstatus
mi
mk
ml/mlx42
mo treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
mp/mpifileutils
mq
ms
mu
my
n2/n2
na
nb/nbtscan
nc
ne
nf/nfft
nh
ni
nl
nm/nmap-parse
nn/nncp
no nomacs: migrate to by-name 2024-03-07 22:28:19 -03:00
np
nr
ns
nu
nv
nw
oa
ob
oc
oe/oelint-adv
of/offpunk
oh/oh-my-fish
oi
on
op Merge pull request #289512 from SFrijters/openttd-ttf 2024-03-07 21:41:09 +01:00
or
os
ot
ou
ov
ow/owncloud-client
pa
pd
pe
pf/pfft
pg
ph Merge pull request #277980 from eliandoran/dev/photocollage 2024-03-07 22:46:04 +01:00
pi pixi: 0.13.0 -> 0.15.2 2024-03-08 10:52:23 +08:00
pk/pkcrack
pl
pm
pn/pnfft
po
pp/ppsspp
pq pqiv: cleanup 2024-03-08 01:05:37 -05:00
pr
pt Merge pull request #289111 from Sascha8a/master 2024-03-07 22:40:56 +01:00
pu
pw
px/pxder
py
pz/pzip
qa/qadwaitadecorations
qc/qcm
qg/qgrep
qr
qs
qt/qtractor
qu
ra
rc
re
ri
rl/rl_json
rm/rmg
ro Merge pull request #287612 from aikooo7/add-rose-pine-cursor 2024-03-07 22:02:40 +01:00
rp/rpcs3
rq/rqbit
rs
rt/rtl-sdr-osmocom
ru treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
rw/rwpspread
ry/ryujinx
s3
sa
sc
sd
se
sg/sgfutils
sh shopware-cli: 0.4.25 -> 0.4.28 2024-03-08 06:41:38 +00:00
si
sl
sm
sn treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
so
sp
sq
sr
ss
st
su
sv treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
sw
sx
sy treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
ta
tc/tcsh
td/tdl
te
th
ti tigerbeetle: 0.14.181 -> 0.14.183 2024-03-07 18:34:50 +00:00
tk/tkdiff
tl
tm/tmuxifier
to treewide: fix sourceRoot for fetchgit-based src 2024-03-09 07:53:25 +08:00
tp
tr
tt/ttop
tu
tx/txr
ty
uc
ud
ue
ui
um/umpire
un
up
us/usql
ut
uu/uuu
uv/uv
ux/uxn
va
vc
ve
vg/vgm2x
vi
vl/vlc
vu/vulkan-volk
wa
wb/wb32-dfu-updater
we
wh
wi
wl
wo
wp/wp-cli
ws
wt/wtfis
x1/x16
xa/xarcan
xc
xd
xf/xfs-undelete
xi
xm
xo
xp/xplr
xr/xr-hardware
xs
xw/xwayland-run
ya
ye
yg/yggdrasil
yj/yj
yo
ys/ysfx
yt
yu/yunfaavatar
za
zb/zbus-xmlgen
zc/zcfan
ze/zesarux
zi
zo/zola
zp
zs/zs
zu/zug
zw/zwave-js-server
zx
README.md

Name-based package directories

The structure of this directory maps almost directly to top-level package attributes. Add new top-level packages to Nixpkgs using this mechanism whenever possible.

Packages found in the name-based structure are automatically included, without needing to be added to all-packages.nix. However if the implicit attribute defaults need to be changed for a package, this must still be declared in all-packages.nix.

Example

The top-level package pkgs.some-package may be declared by setting up this file structure:

pkgs
└── by-name
   ├── so
   ┊  ├── some-package
      ┊  └── package.nix

Where some-package is the package name and so is the lowercased 2-letter prefix of the package name.

The package.nix may look like this:

# A function taking an attribute set as an argument
{
  # Get access to top-level attributes for use as dependencies
  lib,
  stdenv,
  libbar,

  # Make this derivation configurable using `.override { enableBar = true }`
  enableBar ? false,
}:

# The return value must be a derivation
stdenv.mkDerivation {
  # ...
  buildInputs =
    lib.optional enableBar libbar;
}

You can also split up the package definition into more files in the same directory if necessary.

Once defined, the package can be built from the Nixpkgs root directory using:

nix-build -A some-package

See the general package conventions for more information on package definitions.

Changing implicit attribute defaults

The above expression is called using these arguments by default:

{
  lib = pkgs.lib;
  stdenv = pkgs.stdenv;
  libbar = pkgs.libbar;
}

But the package might need pkgs.libbar_2 instead. While the function could be changed to take libbar_2 directly as an argument, this would change the .override interface, breaking code like .override { libbar = ...; }. So instead it is preferable to use the same generic parameter name libbar and override its value in pkgs/top-level/all-packages.nix:

libfoo = callPackage ../by-name/so/some-package/package.nix {
  libbar = libbar_2;
};

Manual migration guidelines

Most packages are still defined in all-packages.nix and the category hierarchy. Please hold off migrating your maintained packages to this directory.

  1. An automated migration for the majority of packages is being worked on. In order to save on contributor and reviewer time, packages should only be migrated manually afterwards if they couldn't be migrated automatically.

  2. Manual migrations should only be lightly encouraged if the relevant code is being worked on anyways. For example with a package update or refactoring.

  3. Manual migrations should not remove definitions from all-packages.nix with custom arguments. That is a backwards-incompatible change because it changes the .override interface. Such packages may still be moved to pkgs/by-name however, while keeping the definition in all-packages.nix. See also changing implicit attribute defaults.

Limitations

There's some limitations as to which packages can be defined using this structure:

  • Only packages defined using pkgs.callPackage. This excludes packages defined using pkgs.python3Packages.callPackage ....

    Instead:

    • Either change the package definition to work with pkgs.callPackage.
    • Or use the category hierarchy.
  • Only top-level packages. This excludes packages for other package sets like pkgs.pythonPackages.*.

    Refer to the definition and documentation of the respective package set to figure out how such packages can be declared.

Validation

CI performs certain checks on the pkgs/by-name structure. This is done using the nixpkgs-check-by-name tool.

You can locally emulate the CI check using

$ ./pkgs/test/nixpkgs-check-by-name/scripts/run-local.sh master

See here for more info.

Recommendation for new packages with multiple versions

These checks of the pkgs/by-name structure can cause problems in combination:

  1. New top-level packages using callPackage must be defined via pkgs/by-name.
  2. Packages in pkgs/by-name cannot refer to files outside their own directory.

This means that outside pkgs/by-name, multiple already-present top-level packages can refer to some common file. If you open a PR to another instance of such a package, CI will fail check 1, but if you try to move the package to pkgs/by-name, it will fail check 2.

This is often the case for packages with multiple versions, such as

  foo_1 = callPackage ../tools/foo/1.nix { };
  foo_2 = callPackage ../tools/foo/2.nix { };

The best way to resolve this is to not use callPackage directly, such that check 1 doesn't trigger. This can be done by using inherit on a local package set:

  inherit
    ({
      foo_1 = callPackage ../tools/foo/1.nix { };
      foo_2 = callPackage ../tools/foo/2.nix { };
    })
    foo_1
    foo_2
    ;

While this may seem pointless, this can in fact help with future package set refactorings, because it establishes a clear connection between related attributes.

Further possible refactorings

This is not required, but the above solution also allows refactoring the definitions into a separate file:

  inherit (import ../tools/foo pkgs)
    foo_1 foo_2;
# pkgs/tools/foo/default.nix
pkgs: {
  foo_1 = callPackage ./1.nix { };
  foo_2 = callPackage ./2.nix { };
}

Alternatively using callPackages if callPackage isn't used underneath and you want the same .override arguments for all attributes:

  inherit (callPackages ../tools/foo { })
    foo_1 foo_2;
# pkgs/tools/foo/default.nix
{
  stdenv
}: {
  foo_1 = stdenv.mkDerivation { /* ... */ };
  foo_2 = stdenv.mkDerivation { /* ... */ };
}

Exposing the package set

This is not required, but the above solution also allows exposing the package set as an attribute:

  foo-versions = import ../tools/foo pkgs;
  # Or using callPackages
  # foo-versions = callPackages ../tools/foo { };

  inherit (foo-versions) foo_1 foo_2;