nix-config/modules-hm/images.nix

64 lines
1.4 KiB
Nix
Raw Normal View History

2024-07-26 22:12:48 +02:00
{ lib, config, ... }:
let
inherit (lib)
2024-04-11 23:11:53 +02:00
mkEnableOption
mkMerge
attrNames
flip
filterAttrs
mkIf
mkOption
types
removeSuffix
hasPrefix
mapAttrs'
listToAttrs
;
2024-07-26 22:12:48 +02:00
in
{
2024-04-11 23:11:53 +02:00
home-manager.sharedModules = [
{
options.images = {
enable = mkEnableOption "Enable images";
images = mkOption {
type = types.attrsOf types.path;
readOnly = true;
default = flip mapAttrs' (filterAttrs (n: _: hasPrefix "images-" n) config.age.secrets) (
name: value: {
inherit (value) name;
value = value.path;
}
);
};
};
}
];
imports = [
(
2024-07-26 22:12:48 +02:00
{ config, ... }:
{
2024-04-11 23:11:53 +02:00
age.secrets = mkMerge (
2024-07-26 22:12:48 +02:00
flip map (attrNames config.home-manager.users) (
2024-04-11 23:11:53 +02:00
user:
2024-07-26 22:12:48 +02:00
mkIf config.home-manager.users.${user}.images.enable (
listToAttrs (
flip map (attrNames (filterAttrs (_: type: type == "regular") (builtins.readDir ../secrets/img)))
(file: {
name = "images-${user}-${file}";
value = {
name = removeSuffix ".age" file;
rekeyFile = ../secrets/img/${file};
owner = user;
group = user;
};
})
2024-04-11 23:11:53 +02:00
)
2024-07-26 22:12:48 +02:00
)
2024-04-11 23:11:53 +02:00
)
);
}
)
];
}