Safe Haskell | None |
---|---|
Language | Haskell2010 |
We want to generate a nix file with the following attributes:
- easy to parse by humans
- as short as possible
- updating the yarn.lock generates diffs that are as short as possible
Readability means a clear structure, with definitions at the top.
Reducing the filesize means we can’t duplicate any information and keep identifiers very short. This interferes with readability, but can be amended by giving the full names in the static section and then giving them short identifiers in a second section.
Nice diffing includes having line-based output (if possible one line per package/dependency), as well as keeping the order of items stable (alphabetically sorting package names and dependencies).
- convertLockfile :: ResolvedLockfile -> Map Text PkgRef
- mkPackageSet :: Map Text PkgRef -> NExpr
Documentation
convertLockfile :: ResolvedLockfile -> Map Text PkgRef Source #
Convert a ResolvedLockfile
to its final, nix-ready form.
File Structure
{ fetchgit, fetchurl }: # self & super: see notes on fix self: super: let # shorten the name of known package registries registries = { yarn = n: v: "https://registry.yarnpkg.com/${n}/-/${n}-${v}.tgz"; }; sanitizePackageName = builtins.replaceStrings ["" "/"] ["-" "-"]; # We want each package definition to be one line, by putting # the boilerplate into these functions for different remotes. nodeFilePackage = … nodeGitPackage = … # an identity function for e.g. git repos or unknown registries identityRegistry = url: _: _: url; # shortcut section s = self; ir = identityRegistry; f = nodeFilePackage; g = nodeGitPackage; y = registries.yarnpkg; … # the actual package definitions in { "accepts
~1.3.3" = s."accepts1.3.3"; "accepts
1.3.3" = f "accepts" "1.3.3" y "sha" []; "babel-core^6.14.0" = s."babel-core
6.24.1"; "babel-core6.24.1" = f "babel-core" "6.24.1" y "a0e457c58ebdbae575c9f8cd75127e93756435d8" [ s."accepts
~1.3.3" ]; }
mkPackageSet :: Map Text PkgRef -> NExpr Source #
Convert a list of packages prepared with convertLockfile
to a nix expression.
NOTE: fix
self: super:
follows the fixpoint scheme first introduced
by the haskellPackage
set in nixpkgs
.
See the Overlays
documentation in the nixpkgs
manual for explanations of how this works.
Note: originally, this was a shallow fix like
let attrs = self: { "foo bar" = 1; bar = self."foo bar" + 2; }; in fix attrs
which was just in place to work around referencing attrset attributes through string names. The new method is a lot more general and allows deep overrides of arbitrary packages in the dependency set.