Introduction
This library provides a set of Nix functions to make creating flakes for languages such as Haskell, PureScript, Rust, and TypeScript easier.
perSystem.lib.haskellData
Makes a derivation containing a Haskell Cabal package with data modules (using Cabal data stanzas)
Type: function that evaluates to a(n) (attribute set) (read only)
Default:
<function, args: {cabalDataPatterns, cabalPackageName, cabalPackageVersion?, srcs}>
Example:
''
```haskell
haskellData {
srcs = [ ./. ];
cabalDataPatterns = [ "**/*.json" ];
cabalPackageName = "golden-json-data";
};
```
''
Declared by:
perSystem.lib.haskellFlake
TODO(jaredponn): write down documentation here
Type: function that evaluates to a(n) (attribute set) (read only)
Default:
<function>
Example:
''
TODO(jaredponn): write down an example here
''
Declared by:
perSystem.lib.haskellPlutusFlake
TODO(jaredponn): write down documentation here
Type: function that evaluates to a(n) (attribute set) (read only)
Default:
<function>
Example:
''
TODO(jaredponn): write down an example here
''
Declared by:
perSystem.lib.purescriptFlake
TODO(jaredponn): write down documentation here
Type: function that evaluates to a(n) (attribute set) (read only)
Default:
<function>
Example:
''
TODO(jaredponn): write down an example here
''
Declared by:
perSystem.lib.rustFlake
Creates a flake for a Rust project.
Arguments:
src: Source folder (unfiltered)extraSourceFilters(optional): Extra filters to add non-rust related files to the derivationcrane(optional): Crane version to be usedcrateName: Name of the projectversion: Major version of the projectrustChannel(default=stable): Rust profile (stable, nightly, etc.)rustVersion(default=latest): Rust versionnativeBuildInputs(optional): Additional native build inputsbuildInputs(optional): Additional build inputsextraSources(optional): Extra sources, allowing to use other rustFlake components to be used as dependenciesextraSourcesDir(default=.extras): Folder to store extra source librariesdata(optional): Data dependenciesdataDir(default=data): Folder to store the data dependenciesdevShellHook(optional): Shell script executed after entering the dev shelldevShellTools(optional): Packages made available in the dev shelltestTools(optional): Packages made available in checks and the dev shellcargoNextestExtraArgs(optional): Extra cargo nextest argumentsdoInstallCargoArtifacts(optional): Controls whether cargo’s target directory should be copied as an outputtarget(optional): Main Rust compilation target (Rust will figure out by default)extraTargets(optional): Extra Rust compilation targetsextraRustcFlags(optional): Extra rustc flagsextraCargoArgs(optional): Extra cargo argumentsextraEnvVars(optional): Extra environment variablesgenerateDocs(default=true): Generate RustdocrunTests(default=true): Run testsuite using cargo-nextestrunClippy(default=true): Run clippy linterexportTests(default=false): Build testsuite as standalone executables
Returns:
Returns an attribute set of the form
{
devShells."dev-${name}-rust" = derivation { ... };
packages."${name}-rust" = derivation { ... };
packages."${name}-rust-src" = derivation { ... };
packages."${name}-rust-build-env" = derivation { ... };
packages."${name}-rust-doc" = derivation { ... };
checks."${name}-rust-test" = derivation { ... };
checks."${name}-rust-clippy" = derivation { ... };
}
where
packages."${name}-rust"contains the binary executable of the project.packages."${name}-rust-src"contains the source folder, to be used as a dependency of other application in extraSourcespackages."${name}-rust-build-env"contains the source folder, to be used as a standalone library (not is extraSources)packages."${name}-rust-doc"contains the API references documentchecks."${name}-rust-test"runs tests using cargo nextestchecks."${name}-rust-clippy"runs clippy
Type: function that evaluates to a(n) (attribute set) (read only)
Default:
<function, args: {buildInputs?, cargoNextestExtraArgs?, crane?, crateName, data?, dataDir?, devShellHook?, devShellTools?, doInstallCargoArtifacts?, exportTests?, extraCargoArgs?, extraEnvVars?, extraRustcFlags?, extraSourceFilters?, extraSources?, extraSourcesDir?, extraTargets?, generateDocs?, nativeBuildInputs?, runClippy?, runTests?, rustChannel?, rustProfile?, rustVersion?, src, target?, testTools?, version?}>
Example:
''
{ ... }:
{
perSystem =
{ config, ... }:
let
rustFlake = config.lib.rustFlake {
src = ./.;
crateName = "rust-flake-project";
devShellHook = config.settings.shell.hook;
exportTests = true;
};
in
{
inherit (rustFlake) packages checks devShells;
};
}
''
Declared by:
perSystem.lib.typescriptFlake
Creates a flake for a TypeScript project.
Returns an attribute set of the form
{
devShells."${name}-typescript" = derivation { ... };
packages."${name}-typescript" = derivation { ... };
packages."${name}-typescript-exe" = derivation { ... };
packages."${name}-typescript-lib" = derivation { ... };
packages."${name}-typescript-tgz" = derivation { ... };
packages."${name}-typescript-node2nix" = derivation { ... };
checks."${name}-typescript-test" = derivation { ... };
}
where
-
packages."${name}-typescript"contains the project with anode_modules/provided by Nix (in theconfigurePhase), and itsbuildPhaserunsnpm run "$npmBuildScript"(wherenpmBuildScriptisbuildby default). Indeed, one can overlay the entire derivation (which contains all its dependencies) to postprocess their project as they see fit. For example, one may want to generate documentation instead of building the project, by running:packages."${name}-typescript".overrideAttrs (_self: _super: { npmBuildScript = "docs"; installPhase = '' mv ./docs "$out" ''; });where we assume that the
package.jsoncontainsscripts.docs = <some-script>which produces documentation in the./docsfolder. -
devShells."${name}-typescript"provides a developer shell with the environment variableNODE_PATHas the path to thenode_modules/produced by Nix, and the command${name}-npm-extra-dependencieswhich copies the transitive closure ofnpmExtraDependenciesto the folder./.extra-dependencies.Moreover, the
shellHookwill:- create a symbolic link named
node_modulespointing to$NODE_PATH; and - execute
${name}-npm-extra-dependencies.
As such, one should enter the development shell in the folder that the project exists in, so
npmmay use the provided dependencies from nix. - create a symbolic link named
-
packages."${name}-typescript-exe"ispackages."${name}-typescript"except runsnpm install --global --prefix="$out"for theinstallPhaseand copies some of the symbolic links so that the output makes sense. -
packages."${name}-typescript-tgz"ispackages."${name}-typescript"except runsnpm packafter thebuildPhaseto create a tarball of the project in the directory$out/tarballs/. -
packages."${name}-typescript-lib"ispackages."${name}-typescript-tgz"except that it unpacks the tarball to$out/lib/node_modules/<package-name> -
packages."${name}-typescript-test"ispackages."${name}-typescript"except it runsnpm testafter thebuildPhasesucceeding only ifnpm testsucceeds.
Type: function that evaluates to a(n) (attribute set) (read only)
Default:
<function, args: {data?, dataDir?, devShellHook?, devShellTools?, name, nodejs?, npmBuildScript?, npmExtraDependencies?, src, testTools?}>
Example:
"TODO(jaredponn)"
Declared by: