2025-04-11 17:45:47 -04:00
|
|
|
|
{
|
|
|
|
|
config,
|
|
|
|
|
lib,
|
|
|
|
|
pkgs,
|
|
|
|
|
home-manager,
|
|
|
|
|
...
|
|
|
|
|
}:
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
inherit (lib)
|
|
|
|
|
filter
|
|
|
|
|
attrNames
|
|
|
|
|
;
|
|
|
|
|
in
|
|
|
|
|
{
|
|
|
|
|
imports = [ ];
|
|
|
|
|
|
2025-04-11 18:00:36 -04:00
|
|
|
|
options.me.install = {
|
|
|
|
|
user = lib.mkOption {
|
|
|
|
|
type = lib.types.attrsOf (
|
|
|
|
|
lib.types.submodule (
|
|
|
|
|
{ username, config, ... }:
|
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
enable = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = true;
|
|
|
|
|
defaultText = "me.install.file.‹username›.enable";
|
|
|
|
|
example = false;
|
|
|
|
|
description = "Whether we want to install files in this user's home directory.";
|
|
|
|
|
};
|
|
|
|
|
target_username = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
defaultText = "me.install.file.‹username›.target_username";
|
|
|
|
|
example = "root";
|
|
|
|
|
description = "The username for the user whose home directory will contain the file.";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
target_username = lib.mkDefault username;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
defaultText = "me.install.user.‹username›";
|
|
|
|
|
default = { };
|
|
|
|
|
# TODO: example
|
|
|
|
|
};
|
|
|
|
|
file = lib.mkOption {
|
2025-04-11 17:45:47 -04:00
|
|
|
|
type = lib.types.attrsOf (
|
|
|
|
|
lib.types.submodule (
|
2025-04-11 18:09:52 -04:00
|
|
|
|
{ path, config, ... }:
|
2025-04-11 17:45:47 -04:00
|
|
|
|
{
|
|
|
|
|
options = {
|
|
|
|
|
enable = lib.mkOption {
|
|
|
|
|
type = lib.types.bool;
|
|
|
|
|
default = true;
|
2025-04-11 18:09:52 -04:00
|
|
|
|
defaultText = "me.install.file.‹path›.enable";
|
2025-04-11 17:45:47 -04:00
|
|
|
|
example = false;
|
|
|
|
|
description = "Whether we want to install this file.";
|
|
|
|
|
};
|
2025-04-11 18:09:52 -04:00
|
|
|
|
method = lib.mkOption {
|
|
|
|
|
type = lib.types.enum [
|
|
|
|
|
"symlink"
|
|
|
|
|
"overwrite"
|
|
|
|
|
# "bind_mount" TODO: for directories?
|
|
|
|
|
];
|
|
|
|
|
default = "symlink";
|
|
|
|
|
defaultText = "me.install.file.‹path›.method";
|
|
|
|
|
example = "overwrite";
|
|
|
|
|
description = "The way in which the file should be installed.";
|
|
|
|
|
};
|
2025-04-11 17:45:47 -04:00
|
|
|
|
mode = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
|
|
|
|
default = "0444";
|
2025-04-11 18:09:52 -04:00
|
|
|
|
defaultText = "me.install.file.‹path›.mode";
|
2025-04-11 17:45:47 -04:00
|
|
|
|
example = "0750";
|
|
|
|
|
description = "The read, write, execute permission flags.";
|
|
|
|
|
};
|
|
|
|
|
source = lib.mkOption {
|
|
|
|
|
type = lib.types.path;
|
2025-04-11 18:09:52 -04:00
|
|
|
|
defaultText = "me.install.file.‹path›.source";
|
2025-04-11 17:45:47 -04:00
|
|
|
|
example = ./files/foo.txt;
|
|
|
|
|
description = "The source file to install into the destination.";
|
|
|
|
|
};
|
|
|
|
|
target = lib.mkOption {
|
|
|
|
|
type = lib.types.str;
|
2025-04-11 18:09:52 -04:00
|
|
|
|
defaultText = "me.install.file.‹path›.target";
|
2025-04-11 17:45:47 -04:00
|
|
|
|
example = ".local/share/foo/bar.txt";
|
|
|
|
|
description = "The path where the file should be written.";
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
2025-04-11 18:09:52 -04:00
|
|
|
|
target = lib.mkDefault path;
|
2025-04-11 17:45:47 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
);
|
2025-04-11 18:09:52 -04:00
|
|
|
|
defaultText = "me.install.file.‹path›";
|
2025-04-11 17:45:47 -04:00
|
|
|
|
default = { };
|
|
|
|
|
example = lib.literalExpression ''
|
|
|
|
|
{
|
|
|
|
|
".config/foo/bar.txt" = {
|
|
|
|
|
source = ./files/bar.txt
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = lib.mkMerge [
|
|
|
|
|
(lib.mkIf (config.me.install.file != { }) (
|
|
|
|
|
let
|
|
|
|
|
cfg = config.me.install.file;
|
|
|
|
|
install_file_targets = filter (target: config.me.install.file."${target}".enable) (attrNames cfg);
|
2025-04-11 18:34:27 -04:00
|
|
|
|
install_commands = builtins.map (
|
|
|
|
|
target:
|
|
|
|
|
let
|
|
|
|
|
target_config = config.me.install.file."${target}";
|
|
|
|
|
source = lib.strings.escapeShellArg "${target_config.source}";
|
|
|
|
|
destination = lib.strings.escapeShellArg "${target_config.target}";
|
|
|
|
|
mode = lib.strings.escapeShellArg "${target_config.mode}";
|
|
|
|
|
in
|
|
|
|
|
# $DRY_RUN_CMD ${pkgs.toyboy}/bin/install $VERBOSE_ARG -D -m ${mode} ${source} ${destination}
|
|
|
|
|
''
|
|
|
|
|
$DRY_RUN_CMD install $VERBOSE_ARG -D --compare -m ${mode} ${source} ${destination}
|
|
|
|
|
''
|
|
|
|
|
) install_file_targets;
|
2025-04-11 17:45:47 -04:00
|
|
|
|
in
|
|
|
|
|
{
|
2025-04-11 18:34:27 -04:00
|
|
|
|
systemd.services.me-install-file = {
|
|
|
|
|
enable = true;
|
|
|
|
|
description = "me-install-file";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
wants = [ "multi-user.target" ];
|
|
|
|
|
after = [ "multi-user.target" ];
|
|
|
|
|
# path = with pkgs; [
|
|
|
|
|
# zfs
|
|
|
|
|
# ];
|
|
|
|
|
unitConfig.DefaultDependencies = "no";
|
|
|
|
|
serviceConfig = {
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
|
};
|
|
|
|
|
script = (lib.strings.concatStringsSep "\n" install_commands);
|
|
|
|
|
# preStop = ''
|
|
|
|
|
# rm -f /home/talexander/.docker/config.json
|
|
|
|
|
# '';
|
2025-04-11 17:45:47 -04:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
))
|
|
|
|
|
];
|
|
|
|
|
}
|