mirror of
https://github.com/nix-community/home-manager
synced 2024-11-26 21:19:45 +01:00
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
4 changed files with 64 additions and 14 deletions
|
@ -67,16 +67,34 @@ in
|
|||
};
|
||||
|
||||
mode = mkOption {
|
||||
type = types.str;
|
||||
default = "444";
|
||||
description = "The permissions to apply to the file.";
|
||||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
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 = {
|
||||
target = mkDefault name;
|
||||
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
|
||||
# overwrite an existing file.
|
||||
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
|
||||
|
@ -238,7 +269,15 @@ in
|
|||
"mkdir -p $out\n" +
|
||||
concatStringsSep "\n" (
|
||||
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 file must be within $HOME.
|
||||
|
@ -251,7 +290,7 @@ in
|
|||
mkdir -p "$(dirname "$out/${v.target}")"
|
||||
ln -s "${v.source}" "$target"
|
||||
else
|
||||
install -D -m${v.mode} "${v.source}" "$target"
|
||||
install -D -m${mode} "${v.source}" "$target"
|
||||
fi
|
||||
''
|
||||
) cfg
|
||||
|
|
|
@ -425,6 +425,23 @@ in
|
|||
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 =
|
||||
let
|
||||
f = n: v: {
|
||||
inherit (v) source target;
|
||||
mode = if v.executable then "777" else "444";
|
||||
};
|
||||
in mapAttrsToList f cfg.configFile;
|
||||
home.file = cfg.configFile;
|
||||
}
|
||||
];
|
||||
}
|
||||
|
|
|
@ -105,7 +105,7 @@ in
|
|||
'';
|
||||
|
||||
home.file.".xsession" = {
|
||||
mode = "555";
|
||||
executable = true;
|
||||
text = ''
|
||||
if [[ ! -v HM_XPROFILE_SOURCED ]]; then
|
||||
. ~/.xprofile
|
||||
|
|
Loading…
Reference in a new issue