diff --git a/snowfall-lib/flake/default.nix b/snowfall-lib/flake/default.nix index 65cbe30..262d0dd 100644 --- a/snowfall-lib/flake/default.nix +++ b/snowfall-lib/flake/default.nix @@ -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. @@ -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) + )); + }; } diff --git a/snowfall-lib/home/default.nix b/snowfall-lib/home/default.nix index b1f71a1..ec782ed 100644 --- a/snowfall-lib/home/default.nix +++ b/snowfall-lib/home/default.nix @@ -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;}; @@ -110,7 +114,8 @@ in { ++ modules; specialArgs = { - inherit name system; + inherit system; + name = unique-name; inherit (user-metadata) user host; format = "home"; @@ -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 @@ -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..home.config` since `mkAliasDefinitions`