Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imp: make system output dynamic #82

Merged
merged 2 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions devShell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ let
set -e
cd $DEVSHELL_ROOT/tests/${name}
nix flake lock --update-input utils
nix flake show
nix flake check
nix flake show "$@"
nix flake check "$@"
git rm -f flake.lock
'';
};
Expand All @@ -39,8 +39,8 @@ let
set -e
cd $DEVSHELL_ROOT/examples/${example}
nix flake lock --update-input utils
nix flake show
nix build .#nixosConfigurations.${host}.config.system.build.toplevel --dry-run
nix flake show "$@"
nix build .#nixosConfigurations.${host}.config.system.build.toplevel --dry-run "$@"
git rm -f flake.lock
'';
};
Expand Down
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