mirror of
https://github.com/nix-community/home-manager.git
synced 2025-11-08 19:46:05 +01:00
lib/types: add sourceFileOrLines
Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
e4b0102f69
commit
abe66194b9
1 changed files with 68 additions and 0 deletions
|
|
@ -169,4 +169,72 @@ rec {
|
|||
);
|
||||
in
|
||||
valueType;
|
||||
|
||||
sourceFile =
|
||||
targetDir: fileName:
|
||||
let
|
||||
targetFile = "${targetDir}/${fileName}";
|
||||
in
|
||||
types.submodule (
|
||||
{ config, ... }:
|
||||
{
|
||||
options = {
|
||||
target = mkOption {
|
||||
type = types.singleLineStr;
|
||||
internal = true;
|
||||
readOnly = true;
|
||||
};
|
||||
source = mkOption {
|
||||
type = types.nullOr types.path;
|
||||
default = null;
|
||||
description = ''
|
||||
The path to be linked to `${targetDir}` if {option}`source` is a directory,
|
||||
or to `${targetFile}` if it is a file.
|
||||
'';
|
||||
};
|
||||
text = mkOption {
|
||||
type = types.lines;
|
||||
default = "";
|
||||
description = ''
|
||||
Text to be included in `${targetFile}`.
|
||||
'';
|
||||
};
|
||||
recursive = lib.mkEnableOption ''
|
||||
Whether to recursively link files from {option}`source` (if it is a directory) in `${targetDir}`.
|
||||
'';
|
||||
};
|
||||
config = {
|
||||
target =
|
||||
if config.source != null && lib.pathIsDirectory config.source then targetDir else targetFile;
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
sourceFileOrLines =
|
||||
targetDir: fileName:
|
||||
let
|
||||
fileType = sourceFile targetDir fileName;
|
||||
union = types.either types.lines fileType;
|
||||
in
|
||||
union
|
||||
// {
|
||||
merge =
|
||||
loc: defs:
|
||||
fileType.merge loc (
|
||||
map (
|
||||
def:
|
||||
if types.lines.check def.value then
|
||||
{
|
||||
inherit (def) file;
|
||||
value = {
|
||||
text = def.value;
|
||||
source = null;
|
||||
recursive = false;
|
||||
};
|
||||
}
|
||||
else
|
||||
def
|
||||
) defs
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue