Skip to content

Commit

Permalink
Merge pull request #140 from nickel-lang/flake-ncl
Browse files Browse the repository at this point in the history
Allow to specify some flake outputs from Nickel
  • Loading branch information
thufschmitt authored Sep 27, 2023
2 parents 107165b + 0a38264 commit ad3253f
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 73 deletions.
115 changes: 55 additions & 60 deletions examples/c-hello-world/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 16 additions & 13 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@
flake-utils.lib.eachSystem systems (system: let
lib = self.lib.${system};
pkgs = nixpkgs.legacyPackages.${system};
nickelOutputs = lib.importNcl {
inherit baseDir flakeInputs lockFileContents;
};
in
{
apps.regenerate-lockfile = lib.regenerateLockFileApp lockFileContents;
}
// pkgs.lib.optionalAttrs (builtins.readDir baseDir ? "project.ncl") rec {
nickelOutputs = lib.importNcl {
inherit baseDir flakeInputs lockFileContents;
};
packages =
if nickelOutputs ? packages && nickelOutputs.packages ? default
then {
default = nickelOutputs.packages.default;
# Can't do just `{inherit nickelOutputs;} // nickelOutputs.flake` because of infinite recursion over self
pkgs.lib.optionalAttrs (builtins.readDir baseDir ? "project.ncl") {
inherit nickelOutputs;
packages = nickelOutputs.packages or {} // nickelOutputs.flake.packages or {};
checks = nickelOutputs.flake.checks or {};
# Can't define this app in Nickel, yet
apps =
{
regenerate-lockfile = lib.regenerateLockFileApp lockFileContents;
}
else {};
devShells = nickelOutputs.shells or {};
// nickelOutputs.flake.apps or {};
# We can't just copy `shells` to `flake.devShells` in the contract
# because of a bug in Nickel: https://github.com/tweag/nickel/issues/1630
devShells = nickelOutputs.shells or {} // nickelOutputs.flake.devShells or {};
});

computedOutputs = outputsFromNickel ./. inputs {
Expand Down
8 changes: 8 additions & 0 deletions lib/contracts.ncl
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,13 @@ from the Nix world) or a derivation defined in Nickel.
"default" | NickelDerivation = dev,
},

FlakeOutputs = {
packages | { _ | Derivation } | optional,
checks | { _ | Derivation } | optional,
devShells | { _ | Derivation } | optional,
apps | { _ | { type = "app", program | NixString } } | optional,
},

# TODO: have the actual contract for the result of an expression. It's pretty
# open (could be an integer, a derivation, a record of derivations, etc.) but
# it still obeys some rules: if the `type` field is set to a known predefined
Expand All @@ -320,6 +327,7 @@ from the Nix world) or a derivation defined in Nickel.
shells
| OrganistShells
| optional,
flake | FlakeOutputs | optional,
..
},
}

0 comments on commit ad3253f

Please sign in to comment.