-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1435 from cachix/outputs
Outputs
- Loading branch information
Showing
7 changed files
with
188 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Outputs | ||
|
||
!!! info "New in version 1.1" | ||
|
||
Outputs allow you to define Nix derivations using the module system, | ||
exposing Nix packages or sets of packages to be consumed by other tools for installation/distribution. | ||
|
||
|
||
## Defining outputs | ||
|
||
You can define outputs in your `devenv.nix` file using the `outputs` attribute. Here's a simple example: | ||
|
||
```nix | ||
{ pkgs, ... }: { | ||
outputs = { | ||
myproject.myapp = import ./myapp { inherit pkgs; }; | ||
git = pkgs.git; | ||
}; | ||
} | ||
``` | ||
|
||
In this example, we're defining two outputs: `myproject.myapp` and `git`. | ||
|
||
## Building outputs | ||
|
||
To build all defined outputs, run: | ||
|
||
```shell-session | ||
$ devenv build | ||
/nix/store/mzq5bpi49h26cy2mfj5a2r0q69fh3a9k-git-2.44.0 | ||
/nix/store/mzq5bpi49h26cy2mfj5a2r0q69fh3a9k-myapp-1.0 | ||
``` | ||
|
||
This command will build all outputs and display their paths in the Nix store. | ||
|
||
To build specific output(s), you can specify them explicitly: | ||
|
||
```shell-session | ||
$ devenv build outputs.git | ||
/nix/store/mzq5bpi49h26cy2mfj5a2r0q69fh3a9k-git-2.44.0 | ||
``` | ||
|
||
This will build only the `git` output, making it easy to consume for installation or distribution. | ||
|
||
## Defining outputs as custom module options | ||
|
||
You can also define outputs using the module system's options. | ||
This approach allows for more flexibility and integration with other parts of your configuration. | ||
|
||
Here's an example: | ||
|
||
```nix | ||
{ pkgs, lib, config, ... }: { | ||
options = { | ||
myapp.package = pkgs.lib.mkOption { | ||
type = config.lib.types.outputOf lib.types.package; | ||
description = "The package for myapp"; | ||
default = import ./myapp { inherit pkgs; }; | ||
defaultText = "myapp"; | ||
}; | ||
}; | ||
config = { | ||
outputs.git = pkgs.git; | ||
} | ||
} | ||
``` | ||
|
||
In this case, `myapp.package` is defined as an output option. When building, devenv will automatically include this output along with any others defined in the `outputs` attribute. | ||
|
||
If you don't want to specify the output option type, you can use `config.lib.types.output` instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ pkgs, lib, config, ... }: { | ||
options = { | ||
outputs = lib.mkOption { | ||
type = config.lib.types.outputOf lib.types.attrs; | ||
default = { | ||
git = pkgs.git; | ||
foo = { | ||
ncdu = pkgs.ncdu; | ||
}; | ||
}; | ||
description = '' | ||
Nix outputs for `devenv build` consumption. | ||
''; | ||
}; | ||
}; | ||
|
||
config.lib.types = { | ||
output = lib.types.anything // { | ||
name = "output"; | ||
description = "output"; | ||
descriptionClass = "output"; | ||
}; | ||
outputOf = t: lib.types.mkOptionType { | ||
name = "outputOf"; | ||
description = "outputOf ${lib.types.optionDescriptionPhrase (class: class == "noun" || class == "conjunction") t}"; | ||
descriptionClass = "outputOf"; | ||
check = t.check; | ||
merge = t.merge; | ||
emptyValue = t.emptyValue; | ||
getSubOptions = t.getSubOptions; | ||
getSubModules = t.getSubModules; | ||
substSubModules = t.substSubModules; | ||
nestedTypes.elemType = t; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,7 @@ in | |
|
||
imports = [ | ||
./info.nix | ||
./outputs.nix | ||
./processes.nix | ||
./scripts.nix | ||
./update-check.nix | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ pkgs, lib, config, ... }: { | ||
options = { | ||
myapp.package = pkgs.lib.mkOption { | ||
type = config.lib.types.outputOf lib.types.package; | ||
description = "The package for myapp1"; | ||
default = pkgs.writeText "myapp1" "touch $out"; | ||
defaultText = "myapp1"; | ||
}; | ||
myapp2.package = pkgs.lib.mkOption { | ||
type = config.lib.types.output; | ||
description = "The package for myapp2"; | ||
default = pkgs.writeText "myapp2" "touch $out"; | ||
defaultText = "myapp2"; | ||
}; | ||
}; | ||
config = { | ||
enterTest = '' | ||
devenv build | grep -E '(myapp1|git|myapp2|ncdu)' | ||
devenv build myapp2.package | grep myapp2 | ||
''; | ||
outputs = { | ||
myproject.git = pkgs.git; | ||
ncdu = pkgs.ncdu; | ||
}; | ||
}; | ||
} |