Skip to content

Instantly share code, notes, and snippets.

@Mic92
Last active May 30, 2021 20:47
Show Gist options
  • Select an option

  • Save Mic92/34a2604189b9603415fa7cf891a5468a to your computer and use it in GitHub Desktop.

Select an option

Save Mic92/34a2604189b9603415fa7cf891a5468a to your computer and use it in GitHub Desktop.
What if flake outputs were a module?
# specialArgs provided as module parameters:
# - pkgs = inputs.nixpkgs.legacyPackages.${system};
# - inputs = flake.inputs with ${system} stripped
# This design requires two phases:
# 1. First evaluation collects all `meta.platforms`. While doing this, we set `pkgs = {};` and `inputs == {}`.
# 2. Than we evaluate for every output attribute and for every platform listed in `meta.platforms`.
# TODO: How to make outputs extensible?
# Do we even want this? Maybe having a standard interface would be better?
{ config, pkgs, inputs, ... }: {
meta.platforms = [ "x86_64-linux" ]; # defaults to nixpkgs.lib.defaultPlatforms;
checks = {
meta.platforms = [ "x86_64-linux" ]; # defaults to config.meta.platforms;
meta.default = config.checks.hello;
hello = pkgs.hello;
};
apps = {
meta.platforms = [ "x86_64-linux" ]; # defaults to config.meta.platforms;
meta.default = config.apps.hello;
hello = {
type = "app"; # defaults to "app"
program = "${pkgs.hello}/bin/hello";
};
};
packages = {
meta.platforms = [ "x86_64-linux" ]; # defaults to config.meta.platforms;
meta.default = config.packages.hello;
hello = pkgs.hello;
};
devShell = pkgs.mkShell {
meta.platforms = [ "x86_64-linux" ]; # defaults to config.meta.platforms;
buildInputs = [ pkgs.hello ];
};
overlays = {
meta.default = config.overlays.default;
foo = {};
};
templates = {
meta.default = config.templates.hello;
hello = {
path = "<store-path>";
description = "template description goes here?";
};
};
nixosModule = {
meta.default = config.modules.hello;
hello = { ... }: {
imports = [
inputs.input.modules
];
};
};
nixosConfiguration = {
hello = inputs.nixpkgs.lib.nixosSystem {
system = "foo";
modules = [
config.modules.fancy-module
./configuration.nix
];
};
};
hydraJob = {
helloHydra = {
hello = config.packages.hello;
};
};
}
{
# ...
outputs = flake-modules.lib.outputs {
imports = [
./flake-module.nix
];
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment