Skip to content

Commit

Permalink
imp: make output dynamic according to outputsBuilder
Browse files Browse the repository at this point in the history
towards #79
  • Loading branch information
blaggacao committed Jul 14, 2021
1 parent 5f3e7f9 commit e4fb79d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 4 additions & 10 deletions lib/systemFlake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ let
modules = modules ++ [ ./autoRegistry.options.nix ];
};

foldHosts = foldl' mergeAny { };

optionalAttrs = check: value: if check then value else { };

otherArguments = removeAttrs args [
Expand Down Expand Up @@ -251,7 +249,8 @@ mergeAny otherArguments (

systemOutputs = (if outputsBuilder == null then deprecatedBuilders else outputsBuilder) pkgs;

mkOutput = output:
mkOutputs = attrs: output:
attrs //
mergeAny
# prevent override of nested outputs in otherArguments
(optionalAttrs (otherArguments ? ${output}.${system})
Expand All @@ -261,16 +260,11 @@ mergeAny otherArguments (

in
{ inherit pkgs; }
// mkOutput "packages"
// mkOutput "defaultPackage"
// mkOutput "apps"
// mkOutput "defaultApp"
// mkOutput "devShell"
// mkOutput "checks"
// (foldl' mkOutputs { } (attrNames systemOutputs))
)
# produces attrset in the shape of
# { nixosConfigurations = {}; darwinConfigurations = {}; ... }
# according to profile.output or the default `nixosConfigurations`
// foldHosts (attrValues (mapAttrs configurationBuilder hosts))
// foldl' mergeAny { } (attrValues (mapAttrs configurationBuilder hosts))
)

10 changes: 9 additions & 1 deletion tests/derivation-outputs/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
#################


# Should Get merged with `packagesBuilder`
# Should Get merged with corresponding outputsBuilder ouput
packages.x86_64-linux.coreutils2 = self.pkgs.x86_64-linux.nixpkgs.coreutils;
customSystemOutput.x86_64-linux.bar = "bar-string";

outputsBuilder = channels: {

customSystemOutput = { foo = "foo-string"; };

packages = {
inherit (channels.nixpkgs) coreutils;
};
Expand Down Expand Up @@ -59,6 +62,7 @@
packages = getOutput "packages";
defaultPackage = getOutput "defaultPackage";
devShell = getOutput "devShell";
customSystemOutput = getOutput "customSystemOutput";

isTrue = cond:
if cond
Expand All @@ -67,6 +71,10 @@
in
{

# Custom System Ouput
customSystemOutput_valid = isEqual customSystemOutput.foo "foo-string";
customSystemOutput_merged = isEqual customSystemOutput.bar "bar-string";

# Packages
defaultPackage_valid = isEqual defaultPackage.pname "coreutils";

Expand Down

0 comments on commit e4fb79d

Please sign in to comment.