Skip to content

Commit

Permalink
Allow to specify some flake outputs from Nickel
Browse files Browse the repository at this point in the history
Add `flake` field to `project.ncl` that allows to specify certain
flake outputs. For example, you can add lines like these to run `hello`
as an app or a check:

  flake.apps.hello.program = nix-s%"%{import_nix "nixpkgs#hello"}/bin/hello"%,
  flake.checks.hello = import_nix "nixpkgs#hello",

I will be gragually migrating apps and checks from our `flake.nix` to
`project.ncl` using this.

Part of #58
  • Loading branch information
YorikSar committed Sep 25, 2023
1 parent 8c67177 commit 8deb2fb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
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: TBD, see https://matrix.to/#/!LYbBGmwIxxrVNjIdah:matrix.org/$qInwUWPPw9O7DkO6hGItRQOyhhP_nkSmtcUcVVIIpnE
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 8deb2fb

Please sign in to comment.