files: add option 'executable'
This also deprecates the `home.file.<name?>.mode` option, which is misleading because the Nix store only allows modes 'r--' and 'r-x'.
This commit is contained in:
parent
676f5c4b31
commit
ccb291ce66
|
@ -67,16 +67,34 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
mode = mkOption {
|
mode = mkOption {
|
||||||
type = types.str;
|
type = types.nullOr types.str;
|
||||||
default = "444";
|
default = null;
|
||||||
description = "The permissions to apply to the file.";
|
description = ''
|
||||||
|
The permissions to apply to the file.
|
||||||
|
</para><para>
|
||||||
|
DEPRECATED: use <varname>home.file.<name?>.executable</varname>
|
||||||
|
instead.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
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 = {
|
config = {
|
||||||
target = mkDefault name;
|
target = mkDefault name;
|
||||||
source = mkIf (config.text != null) (
|
source = mkIf (config.text != null) (
|
||||||
mkDefault (pkgs.writeText (storeFileName name) config.text)
|
mkDefault (pkgs.writeTextFile {
|
||||||
|
inherit (config) executable text;
|
||||||
|
name = storeFileName name;
|
||||||
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
@ -105,6 +123,19 @@ in
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
|
warnings =
|
||||||
|
let
|
||||||
|
badFiles =
|
||||||
|
map (f: f.target)
|
||||||
|
(filter (f: f.mode != null)
|
||||||
|
(attrValues cfg));
|
||||||
|
badFilesStr = toString badFiles;
|
||||||
|
in
|
||||||
|
mkIf (badFiles != []) [
|
||||||
|
("The 'mode' field is deprecated for 'home.file', "
|
||||||
|
+ "use 'executable' instead: ${badFilesStr}")
|
||||||
|
];
|
||||||
|
|
||||||
# This verifies that the links we are about to create will not
|
# This verifies that the links we are about to create will not
|
||||||
# overwrite an existing file.
|
# overwrite an existing file.
|
||||||
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
|
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
|
||||||
|
@ -238,7 +269,15 @@ in
|
||||||
"mkdir -p $out\n" +
|
"mkdir -p $out\n" +
|
||||||
concatStringsSep "\n" (
|
concatStringsSep "\n" (
|
||||||
mapAttrsToList (n: v:
|
mapAttrsToList (n: v:
|
||||||
''
|
let
|
||||||
|
mode =
|
||||||
|
if v.mode != null
|
||||||
|
then v.mode
|
||||||
|
else
|
||||||
|
if v.executable != null
|
||||||
|
then (if v.executable then "+x" else "-x")
|
||||||
|
else "+r"; # Acts as a no-op.
|
||||||
|
in ''
|
||||||
target="$(realpath -m "$out/${v.target}")"
|
target="$(realpath -m "$out/${v.target}")"
|
||||||
|
|
||||||
# Target file must be within $HOME.
|
# Target file must be within $HOME.
|
||||||
|
@ -251,7 +290,7 @@ in
|
||||||
mkdir -p "$(dirname "$out/${v.target}")"
|
mkdir -p "$(dirname "$out/${v.target}")"
|
||||||
ln -s "${v.source}" "$target"
|
ln -s "${v.source}" "$target"
|
||||||
else
|
else
|
||||||
install -D -m${v.mode} "${v.source}" "$target"
|
install -D -m${mode} "${v.source}" "$target"
|
||||||
fi
|
fi
|
||||||
''
|
''
|
||||||
) cfg
|
) cfg
|
||||||
|
|
|
@ -425,6 +425,23 @@ in
|
||||||
A new window manager module is available: 'xsession.windowManager.i3'.
|
A new window manager module is available: 'xsession.windowManager.i3'.
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
time = "2017-11-06T13:23:17+00:00";
|
||||||
|
condition = any (f: f.mode != null) (attrValues config.home.file);
|
||||||
|
message = ''
|
||||||
|
The
|
||||||
|
|
||||||
|
home.file.<name?>.mode
|
||||||
|
|
||||||
|
option is now deprecated. Please use
|
||||||
|
|
||||||
|
home.file.<name?>.executable
|
||||||
|
|
||||||
|
instead. The 'mode' option will be completely removed
|
||||||
|
December 6, 2017.
|
||||||
|
'';
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,13 +126,7 @@ in
|
||||||
})
|
})
|
||||||
|
|
||||||
{
|
{
|
||||||
home.file =
|
home.file = cfg.configFile;
|
||||||
let
|
|
||||||
f = n: v: {
|
|
||||||
inherit (v) source target;
|
|
||||||
mode = if v.executable then "777" else "444";
|
|
||||||
};
|
|
||||||
in mapAttrsToList f cfg.configFile;
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,7 +105,7 @@ in
|
||||||
'';
|
'';
|
||||||
|
|
||||||
home.file.".xsession" = {
|
home.file.".xsession" = {
|
||||||
mode = "555";
|
executable = true;
|
||||||
text = ''
|
text = ''
|
||||||
if [[ ! -v HM_XPROFILE_SOURCED ]]; then
|
if [[ ! -v HM_XPROFILE_SOURCED ]]; then
|
||||||
. ~/.xprofile
|
. ~/.xprofile
|
||||||
|
|
Loading…
Reference in a new issue