nixos: Use mkDefault to set the default directory permissions

This means we don't have to pass them around as function arguments,
making things a bit cleaner.
This commit is contained in:
talyz 2022-11-13 18:16:18 +01:00
parent 6138eb8e73
commit a65d7088db
No known key found for this signature in database
GPG key ID: 2DED2151F4671A2B

View file

@ -2,8 +2,8 @@
let
inherit (lib) attrNames attrValues zipAttrsWith flatten mkOption
types foldl' unique noDepEntry concatMapStrings listToAttrs
escapeShellArg escapeShellArgs replaceStrings recursiveUpdate all
mkDefault mapAttrsToList types foldl' unique concatMapStrings
listToAttrs escapeShellArg escapeShellArgs recursiveUpdate all
filter filterAttrs concatStringsSep concatMapStringsSep isString
catAttrs optional literalExpression;
@ -67,10 +67,9 @@ in
};
};
};
dirPermsOpts = { user, group, mode }: {
dirPermsOpts = {
user = mkOption {
type = str;
default = user;
description = ''
If the directory doesn't exist in persistent
storage it will be created and owned by the user
@ -79,7 +78,6 @@ in
};
group = mkOption {
type = str;
default = group;
description = ''
If the directory doesn't exist in persistent
storage it will be created and owned by the
@ -88,7 +86,6 @@ in
};
mode = mkOption {
type = str;
default = mode;
example = "0700";
description = ''
If the directory doesn't exist in persistent
@ -97,7 +94,7 @@ in
'';
};
};
fileOpts = perms: {
fileOpts = {
options = {
file = mkOption {
type = str;
@ -105,10 +102,10 @@ in
The path to the file.
'';
};
parentDirectory = dirPermsOpts perms;
parentDirectory = dirPermsOpts;
};
};
dirOpts = perms: {
dirOpts = {
options = {
directory = mkOption {
type = str;
@ -116,16 +113,17 @@ in
The path to the directory.
'';
};
} // (dirPermsOpts perms);
} // dirPermsOpts;
};
rootFile = submodule [
commonOpts
(fileOpts defaultPerms)
fileOpts
{ parentDirectory = mkDefault defaultPerms; }
];
rootDir = submodule [
rootDir = submodule ([
commonOpts
(dirOpts defaultPerms)
];
dirOpts
] ++ (mapAttrsToList (n: v: { ${n} = mkDefault v; }) defaultPerms));
in
{
options =
@ -142,12 +140,13 @@ in
};
userFile = submodule [
commonOpts
(fileOpts userDefaultPerms)
fileOpts
{ parentDirectory = mkDefault userDefaultPerms; }
];
userDir = submodule [
userDir = submodule ([
commonOpts
(dirOpts userDefaultPerms)
];
dirOpts
] ++ (mapAttrsToList (n: v: { ${n} = mkDefault v; }) userDefaultPerms));
in
{
options =