Skip to content
Open
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
30 changes: 28 additions & 2 deletions snowfall-lib/flake/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
snowfall-lib,
snowfall-config,
}: let
inherit (core-inputs.nixpkgs.lib) assertMsg foldl filterAttrs const;
inherit (core-inputs.nixpkgs.lib) assertMsg foldl filterAttrs const mapAttrs mapAttrs' hasSuffix removeSuffix nameValuePair;
in rec {
flake = rec {
## Remove the `self` attribute from an attribute set.
Expand Down Expand Up @@ -197,5 +197,31 @@ in rec {
inherit overlays;
};
in
flake-outputs;
flake-outputs
// {
packages =
flake-outputs.packages
// (builtins.listToAttrs (
builtins.map (system: {
name = system;
value =
flake-outputs.packages.${system}
// {
homeConfigurations = let
homeNames = filterAttrs (_: home: home.system == system) homes;
homeConfigurations = mapAttrs (home-name: _: flake-outputs.homeConfigurations.${home-name}) homeNames;
renamedHomeConfigurations =
mapAttrs' (
name: value:
if hasSuffix "@${system}" name
then nameValuePair (removeSuffix "@${system}" name) value
else nameValuePair name value
)
homeConfigurations;
in
renamedHomeConfigurations;
};
}) (builtins.attrNames flake-outputs.pkgs)
));
};
}
23 changes: 17 additions & 6 deletions snowfall-lib/home/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ in {
system ? "x86_64-linux",
}: let
user-metadata = split-user-and-host name;
unique-name =
if user-metadata.host == ""
then "${user-metadata.user}@${system}"
else name;

# NOTE: home-manager has trouble with `pkgs` recursion if it isn't passed in here.
pkgs = user-inputs.self.pkgs.${system}.${channelName} // {lib = home-lib;};
Expand All @@ -110,7 +114,8 @@ in {
++ modules;

specialArgs = {
inherit name system;
inherit system;
name = unique-name;
inherit (user-metadata) user host;

format = "home";
Expand Down Expand Up @@ -161,16 +166,22 @@ in {
get-target-homes-metadata = target: let
homes = snowfall-lib.fs.get-directories target;
existing-homes = builtins.filter (home: builtins.pathExists "${home}/default.nix") homes;
create-home-metadata = path: {
path = "${path}/default.nix";
create-home-metadata = path: let
# We are building flake outputs based on file contents. Nix doesn't like this
# so we have to explicitly discard the string's path context to allow us to
# use the name as a variable.
name = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
basename = builtins.unsafeDiscardStringContext (builtins.baseNameOf path);
# We are building flake outputs based on file contents. Nix doesn't like this
# so we have to explicitly discard the string's path context to allow us to
# use the name as a variable.
system = builtins.unsafeDiscardStringContext (builtins.baseNameOf target);
name =
if !(hasInfix "@" basename)
then "${basename}@${system}"
else basename;
in {
path = "${path}/default.nix";
inherit name system;
};
home-configurations = builtins.map create-home-metadata existing-homes;
in
Expand Down Expand Up @@ -301,8 +312,8 @@ in {
...
}: let
host-matches =
(created-user.specialArgs.host == host)
|| (created-user.specialArgs.host == "" && created-user.specialArgs.system == system);
(name == "${user-name}@${host}")
|| (name == "${user-name}@${system}");

# NOTE: To conform to the config structure of home-manager, we have to
# remap the options coming from `snowfallorg.user.<name>.home.config` since `mkAliasDefinitions`
Expand Down