Add the install_file module from the steam deck config.
This commit is contained in:
parent
45514d147c
commit
c3f715d010
@ -74,6 +74,7 @@
|
||||
./roles/zfs
|
||||
./roles/zrepl
|
||||
./roles/zsh
|
||||
./util/install_files
|
||||
./util/unfree_polyfill
|
||||
];
|
||||
|
||||
|
101
nix/configuration/util/install_files/default.nix
Normal file
101
nix/configuration/util/install_files/default.nix
Normal file
@ -0,0 +1,101 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
home-manager,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
filter
|
||||
attrNames
|
||||
;
|
||||
in
|
||||
{
|
||||
imports = [ ];
|
||||
|
||||
options.me = {
|
||||
install.file = lib.mkOption {
|
||||
type = lib.types.attrsOf (
|
||||
lib.types.submodule (
|
||||
{ name, config, ... }:
|
||||
{
|
||||
options = {
|
||||
enable = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
defaultText = "me.install.file.‹name›.enable";
|
||||
example = false;
|
||||
description = "Whether we want to install this file.";
|
||||
};
|
||||
mode = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "0444";
|
||||
defaultText = "me.install.file.‹name›.mode";
|
||||
example = "0750";
|
||||
description = "The read, write, execute permission flags.";
|
||||
};
|
||||
source = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
defaultText = "me.install.file.‹name›.source";
|
||||
example = ./files/foo.txt;
|
||||
description = "The source file to install into the destination.";
|
||||
};
|
||||
target = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
defaultText = "me.install.file.‹name›.target";
|
||||
example = ".local/share/foo/bar.txt";
|
||||
description = "The path where the file should be written.";
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
target = lib.mkDefault name;
|
||||
};
|
||||
}
|
||||
)
|
||||
);
|
||||
defaultText = "me.install.file.‹name›";
|
||||
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);
|
||||
in
|
||||
{
|
||||
home.activation = {
|
||||
installFiles = home-manager.lib.hm.dag.entryAfter [ "writeBoundary" ] (
|
||||
let
|
||||
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;
|
||||
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;
|
||||
in
|
||||
(lib.strings.concatStringsSep "\n" install_commands)
|
||||
);
|
||||
};
|
||||
}
|
||||
))
|
||||
];
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user