Fil-C on Nix

Filnix wiki

mbrock/filnix

scripts/query-package.nix

Query comprehensive package information from nixpkgs
Usage: nix eval --json .#lib.x86_64-linux.queryPackage --apply 'f: f "bash"'

λpkgs packageName
let
7extractInput=
λx
builtins.isPathx
→
11type=
"setup-hook"
12path=
builtins.baseNameOfbuiltins.toStringx
13fullPath=
builtins.toStringx
builtins.isAttrsx
→
17type=
"derivation"
18name=
x.pname or x.name or "unnamed"
builtins.isStringx
→
22type=
"string"
23value=
else
27type=
"unknown"
28typeOf=
builtins.typeOfx
used by buildInputs

Extract list-like attributes safely

32extractList=
λpkg attr
let
35val=
pkg.${attr} or null
in
val ≡ null
→
[ ]
builtins.isListval
→
else
used by buildConfig

Extract NIX_ environment variables

45extractNixVars=
λpkg
let
48allAttrs=
builtins.attrNamespkg
used by nixAttrs
49nixAttrs=
builtins.filtername: builtins.substring0 4 name ≡ "NIX_" allAttrs
uses allAttrs
in
builtins.listToAttrs
map
λname
55name=
56value=
used by nixVars

Extract derivation structure

61extractDerivation=
λpkg
62type=
pkg.type or null
63system=
pkg.system or null
64builder=
builtins.toStringpkg.builder or ""
65args=
pkg.args or [ ]
66drvPath=
pkg.drvPath or null

Custom build phases (if defined)

69phases=
70preConfigure=
pkg.preConfigure or null
71configurePhase=
pkg.configurePhase or null
72postConfigure=
pkg.postConfigure or null
73preBuild=
pkg.preBuild or null
74buildPhase=
pkg.buildPhase or null
75postBuild=
pkg.postBuild or null
76preInstall=
pkg.preInstall or null
77installPhase=
pkg.installPhase or null
78postInstall=
pkg.postInstall or null
79preFixup=
pkg.preFixup or null
80fixupPhase=
pkg.fixupPhase or null
81postFixup=
pkg.postFixup or null
used by derivation

Get function arguments from package definition

86getFunctionArgs=
λpkg
let
89position=
pkg.meta.position or ""
used by filePath
90filePath=
if position ≢ "" then builtins.headbuiltins.split":" position else null
uses position used by pkgFunc
92pkgFunc=
if filePath ≢ null then importfilePath else null
uses filePath
in
if pkgFunc ≢ null then builtins.functionArgspkgFunc else { }
used by args

Format function args as required/optional

97formatArgs=
λargs
let
100required=
builtins.filtername: args.${name} ≡ false builtins.attrNamesargs
103optional=
builtins.filtername: args.${name} ≡ true builtins.attrNamesargs
in
inherit required optional;
used by functionArgs

Extract relative path from nix store position

112extractPath=
λposition
let
115parts=
builtins.split"-source/" position
116hasSource=
builtins.lengthparts > 1
uses parts used by afterSource
117afterSource=
if hasSource then builtins.elemAtparts 2 else ""
uses hasSource parts used by pathParts
118pathParts=
builtins.split":" afterSource
in
if afterSource ≢ "" then builtins.headpathParts else ""
used by path
122pkg=
pkgs.${packageName} or throw"Package '${packageName}' not found in nixpkgs"
125position=
pkg.meta.position or ""
uses pkg used by meta path

Extract source info separately first

129s=
pkg.src or null
130srcName=
if s ≢ null then s.name else null
uses s used by src
131srcUrls=
if s ≢ null then s.urls or if s ? url then s.url else [ ] else [ ]
uses s used by src
133srcHash=
if s ≢ null then s.outputHash or null else null
uses s used by src
134srcOutPath=
if s ≢ null then "${s}" else null
uses s used by src
in

Basic info

140version=
pkg.version or "unknown"
uses pkg
141pname=
pkg.pname or packageName
uses pkg

Function signature

Build inputs (with structured types)

148buildInputs=
149native=
mapextractInput pkg.nativeBuildInputs or [ ]
150build=
mapextractInput pkg.buildInputs or [ ]
151propagated=
mapextractInput pkg.propagatedBuildInputs or [ ]

Build configuration

155buildConfig=
156configureFlags=
extractListpkg "configureFlags"
157makeFlags=
extractListpkg "makeFlags"
158cmakeFlags=
extractListpkg "cmakeFlags"
159mesonFlags=
extractListpkg "mesonFlags"
160patches=
mapbuiltins.toString extractListpkg "patches"

Build flags

164buildFlags=
165outputs=
pkg.outputs or "out"
166doCheck=
pkg.doCheck or null
167doInstallCheck=
pkg.doInstallCheck or null
168enableParallelBuilding=
pkg.enableParallelBuilding or null
169enableParallelChecking=
pkg.enableParallelChecking or null
170separateDebugInfo=
pkg.separateDebugInfo or null
171strictDeps=
pkg.strictDeps or null
172hardeningDisable=
pkg.hardeningDisable or [ ]
uses pkg

NIX environment variables

Derivation structure (how it's actually built)

Metadata

182meta=
183description=
pkg.meta.description or null
184homepage=
pkg.meta.homepage or null
185license=
pkg.meta ? license
→
builtins.isAttrspkg.meta.license
→
pkg.meta.license.shortName or pkg.meta.license.spdxId or "unknown"
else
pkg.meta.license
else
null
193mainProgram=
pkg.meta.mainProgram or null
194position=

Source information

198src=
s ≢ null
→
else
null