Aleksandr Lebedev 2025-08-10 00:07:29 +02:00
parent 02d941739f
commit 9a06683ed6
5 changed files with 59 additions and 21 deletions

21
flake.lock generated
View file

@ -3,11 +3,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1650374568,
"narHash": "sha256-Z+s0J8/r907g149rllvwhb4pKi8Wam5ij0st8PwAh+E=",
"lastModified": 1747046372,
"narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "b4a34015c698c7793d592d66adbab377907a2be8",
"rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
"type": "github"
},
"original": {
@ -39,32 +39,31 @@
"flake-utils": "flake-utils"
},
"locked": {
"lastModified": 1715533576,
"narHash": "sha256-fT4ppWeCJ0uR300EH3i7kmgRZnAVxrH+XtK09jQWihk=",
"lastModified": 1738591040,
"narHash": "sha256-4WNeriUToshQ/L5J+dTSWC5OJIwT39SEP7V7oylndi8=",
"owner": "gytis-ivaskevicius",
"repo": "flake-utils-plus",
"rev": "3542fe9126dc492e53ddd252bb0260fe035f2c0f",
"rev": "afcb15b845e74ac5e998358709b2b5fe42a948d1",
"type": "github"
},
"original": {
"owner": "gytis-ivaskevicius",
"repo": "flake-utils-plus",
"rev": "3542fe9126dc492e53ddd252bb0260fe035f2c0f",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1716181197,
"narHash": "sha256-IXOUlMlt0f5n9BoJ56+CseCLV9aaBDoEygIWV/hnUso=",
"lastModified": 1754767907,
"narHash": "sha256-8OnUzRQZkqtUol9vuUuQC30hzpMreKptNyET2T9lB6g=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "461aad7a53142b9f9e2a666c810e86b20f5da76b",
"rev": "c5f08b62ed75415439d48152c2a784e36909b1bc",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "release-23.11",
"ref": "release-25.05",
"repo": "nixpkgs",
"type": "github"
}

View file

@ -2,11 +2,11 @@
description = "Snowfall Lib";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/release-23.11";
nixpkgs.url = "github:nixos/nixpkgs/release-25.05";
# NOTE: `nix flake lock --update-input flake-utils-plus` is currently NOT
# giving us the appropriate revision. We need a fix from a recent PR in
# FUP, so this revision is being hard coded here for now.
flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus?rev=3542fe9126dc492e53ddd252bb0260fe035f2c0f";
flake-utils-plus.url = "github:gytis-ivaskevicius/flake-utils-plus";
flake-compat = {
url = "github:edolstra/flake-compat";

View file

@ -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)
));
};
}

View file

@ -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
@ -275,6 +286,7 @@ in {
config = {
home-manager.extraSpecialArgs = {
inherit system target format virtual systems host;
inherit (snowfall-config) namespace;
lib = home-lib;
@ -301,8 +313,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`

View file

@ -32,6 +32,7 @@ in {
user-inputs
// {
inherit channels;
inherit (snowfall-config) namespace;
inputs = user-inputs;
lib = snowfall-lib.internal.system-lib;
}