-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathfile-type.nix
More file actions
67 lines (63 loc) · 2.17 KB
/
file-type.nix
File metadata and controls
67 lines (63 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
{ pkgs, config, lib, ... }:
let
inherit (lib) hasPrefix literalExpression mkDefault mkIf mkOption removePrefix types;
in
{
# all rights reserved to nix-community
# copy of https://github.com/nix-community/home-manager/blob/master/modules/lib/file-type.nix
# Constructs a type suitable for a `devshell.file` like option. The
# target path may be absolute, in which case it
# is relative to project root
# Arguments:
# - basePathDesc docbook compatible description of the base path
# - basePath the file base path
fileType = basePathDesc: types.attrsOf (types.submodule (
{ name, config, ... }: {
options = {
target = mkOption {
type = types.str;
defaultText = literalExpression "<name>";
description = ''
Path to target file relative to ${basePathDesc}.
'';
};
text = mkOption {
default = null;
type = types.nullOr types.lines;
description = ''
Text of the file. If this option is null then
<link linkend="devshell.file._name_.source">devshel.file.<name?>.source</link>
must be set.
'';
};
source = mkOption {
type = types.path;
description = ''
Path of the source file or directory. If
<link linkend="devshell.file._name_.text">devshell.file.<name?>.text</link>
is non-null then this option will automatically point to a file
containing that text.
'';
};
executable = mkOption {
type = types.nullOr types.bool;
default = null;
description = ''
Set the execute bit. If <literal>null</literal>, defaults to the mode
of the <varname>source</varname> file or to <literal>false</literal>
for files created through the <varname>text</varname> option.
'';
};
};
config = {
target = mkDefault name;
source = mkIf (config.text != null) (
mkDefault (pkgs.writeTextFile {
inherit (config) executable text;
name = name;
})
);
};
}
));
}