2017-11-06 10:28:54 +01:00
|
|
|
{ homeDirectory, lib, pkgs }:
|
|
|
|
|
2021-10-27 13:58:56 +02:00
|
|
|
let
|
2024-01-13 00:57:02 +01:00
|
|
|
inherit (lib)
|
|
|
|
hasPrefix hm literalExpression mkDefault mkIf mkOption removePrefix types;
|
|
|
|
in {
|
2017-11-06 10:28:54 +01:00
|
|
|
# Constructs a type suitable for a `home.file` like option. The
|
|
|
|
# target path may be either absolute or relative, in which case it
|
|
|
|
# is relative the `basePath` argument (which itself must be an
|
|
|
|
# absolute path).
|
|
|
|
#
|
|
|
|
# Arguments:
|
2023-05-22 22:48:23 +02:00
|
|
|
# - opt the name of the option, for self-references
|
2017-11-06 10:28:54 +01:00
|
|
|
# - basePathDesc docbook compatible description of the base path
|
|
|
|
# - basePath the file base path
|
2024-01-13 00:57:02 +01:00
|
|
|
fileType = opt: basePathDesc: basePath:
|
|
|
|
types.attrsOf (types.submodule ({ name, config, ... }: {
|
2017-11-06 10:28:54 +01:00
|
|
|
options = {
|
2023-01-25 22:58:35 +01:00
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-01-25 22:58:35 +01:00
|
|
|
Whether this file should be generated. This option allows specific
|
|
|
|
files to be disabled.
|
|
|
|
'';
|
|
|
|
};
|
2017-11-06 10:28:54 +01:00
|
|
|
target = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
apply = p:
|
2024-01-13 00:57:02 +01:00
|
|
|
let absPath = if hasPrefix "/" p then p else "${basePath}/${p}";
|
|
|
|
in removePrefix (homeDirectory + "/") absPath;
|
2023-05-22 22:48:23 +02:00
|
|
|
defaultText = literalExpression "name";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2017-11-06 10:28:54 +01:00
|
|
|
Path to target file relative to ${basePathDesc}.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
text = mkOption {
|
|
|
|
default = null;
|
|
|
|
type = types.nullOr types.lines;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-07-31 00:54:23 +02:00
|
|
|
Text of the file. If this option is null then
|
2023-07-01 01:30:13 +02:00
|
|
|
[](#opt-${opt}._name_.source)
|
2020-07-31 00:54:23 +02:00
|
|
|
must be set.
|
|
|
|
'';
|
2017-11-06 10:28:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
source = mkOption {
|
|
|
|
type = types.path;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-07-31 00:54:23 +02:00
|
|
|
Path of the source file or directory. If
|
2023-07-01 01:30:13 +02:00
|
|
|
[](#opt-${opt}._name_.text)
|
2020-07-31 00:54:23 +02:00
|
|
|
is non-null then this option will automatically point to a file
|
|
|
|
containing that text.
|
2017-11-06 10:28:54 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
executable = mkOption {
|
|
|
|
type = types.nullOr types.bool;
|
|
|
|
default = null;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2023-07-01 01:30:13 +02:00
|
|
|
Set the execute bit. If `null`, defaults to the mode
|
|
|
|
of the {var}`source` file or to `false`
|
|
|
|
for files created through the {var}`text` option.
|
2017-11-06 10:28:54 +01:00
|
|
|
'';
|
|
|
|
};
|
2017-11-06 18:00:25 +01:00
|
|
|
|
|
|
|
recursive = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2017-11-06 18:00:25 +01:00
|
|
|
If the file source is a directory, then this option
|
|
|
|
determines whether the directory should be recursively
|
|
|
|
linked to the target location. This option has no effect
|
|
|
|
if the source is a file.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
If `false` (the default) then the target
|
2017-11-06 18:00:25 +01:00
|
|
|
will be a symbolic link to the source directory. If
|
2023-07-01 01:30:13 +02:00
|
|
|
`true` then the target will be a
|
2017-11-06 18:00:25 +01:00
|
|
|
directory structure matching the source's but whose leafs
|
|
|
|
are symbolic links to the files of the source directory.
|
|
|
|
'';
|
|
|
|
};
|
2018-02-17 00:32:29 +01:00
|
|
|
|
|
|
|
onChange = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2018-02-17 00:32:29 +01:00
|
|
|
Shell commands to run when file has changed between
|
|
|
|
generations. The script will be run
|
2023-07-01 01:30:13 +02:00
|
|
|
*after* the new files have been linked
|
2018-02-17 00:32:29 +01:00
|
|
|
into place.
|
2023-07-01 01:30:13 +02:00
|
|
|
|
|
|
|
Note, this code is always run when `recursive` is
|
2021-05-30 11:54:33 +02:00
|
|
|
enabled.
|
2018-02-17 00:32:29 +01:00
|
|
|
'';
|
|
|
|
};
|
2020-03-17 22:27:29 +01:00
|
|
|
|
|
|
|
force = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
visible = false;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2020-03-17 22:27:29 +01:00
|
|
|
Whether the target path should be unconditionally replaced
|
|
|
|
by the managed file source. Warning, this will silently
|
|
|
|
delete the target regardless of whether it is a file or
|
|
|
|
link.
|
|
|
|
'';
|
|
|
|
};
|
2017-11-06 10:28:54 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
|
|
|
target = mkDefault name;
|
2024-01-13 00:57:02 +01:00
|
|
|
source = mkIf (config.text != null) (mkDefault (pkgs.writeTextFile {
|
|
|
|
inherit (config) text;
|
|
|
|
executable = config.executable == true; # can be null
|
|
|
|
name = hm.strings.storeFileName name;
|
|
|
|
}));
|
2017-11-06 10:28:54 +01:00
|
|
|
};
|
2024-01-13 00:57:02 +01:00
|
|
|
}));
|
2017-11-06 10:28:54 +01:00
|
|
|
}
|