Skip to content

Commit

Permalink
Revert "Revert "Merge pull request #19 from Pacman99/default-hosts""
Browse files Browse the repository at this point in the history
This reverts commit fe983e5.
  • Loading branch information
David Arnold committed Apr 9, 2021
1 parent fe983e5 commit 72702fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
5 changes: 5 additions & 0 deletions examples/fully-featured-flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
allowUnfree = true;
};

# Passed to all hosts
defaultHostAttrs {
channelName = "unstable";
};

# Profiles, gets parsed into `nixosConfigurations`
nixosHosts = {
# Profile name / System hostname
Expand Down
31 changes: 21 additions & 10 deletions systemFlake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

, nixosConfigurations ? { }
, sharedExtraArgs ? { }
, defaultHostAttrs ? { }
, nixosProfiles ? { } # will be deprecated soon, use nixosHosts, instead.
, nixosHosts ? nixosProfiles
, channels ? { }
Expand All @@ -24,18 +25,29 @@
}@args:

let
evalHostArgs =
{ channelName ? "nixpkgs"
, modules ? []
, system ? defaultSystem
, extraArgs ? {}
, ...
}: defaultHostAttrs
// {
inherit channelName system;
modules = sharedModules ++ modules;
extraArgs = sharedExtraArgs // extraArgs;
};

inherit (flake-utils-plus.lib) eachSystem;

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

channelNameFromProfile = profile: profile.channelName or "nixpkgs";
systemFromProfile = profile: profile.system or defaultSystem;

otherArguments = builtins.removeAttrs args [
"defaultSystem"
"sharedExtraArgs"
"inputs"
"nixosHosts"
"defaultHostAttrs"
"channels"
"channelsConfig"
"self"
Expand All @@ -51,12 +63,12 @@ let
"checksBuilder"
];

nixosConfigurationBuilder = hostname: profile: (
nixosConfigurationBuilder = hostname: profile:
let hostAttrs = evalHostArgs profile; in
# It would be nice to get `nixosSystem` reference from `selectedNixpkgs` but it is not possible at this moment
inputs."${channelNameFromProfile profile}".lib.nixosSystem (genericConfigurationBuilder hostname profile)
);
inputs."${hostAttrs.channelName}".lib.nixosSystem (genericConfigurationBuilder hostname hostAttrs);

getNixpkgs = profile: self.pkgs."${systemFromProfile profile}"."${channelNameFromProfile profile}";
getNixpkgs = profile: self.pkgs."${profile.system}"."${profile.channelName}";

genericConfigurationBuilder = hostname: profile: (
let selectedNixpkgs = getNixpkgs profile; in
Expand Down Expand Up @@ -87,9 +99,8 @@ let
];
})
]
++ sharedModules
++ (profile.modules or [ ]);
extraArgs = { inherit inputs; } // sharedExtraArgs // profile.extraArgs or { };
++ profile.modules;
extraArgs = { inherit inputs; } // profile.extraArgs;
}
);
in
Expand Down

0 comments on commit 72702fe

Please sign in to comment.