Add function to generate machine option lists + use it for services.
This commit is contained in:
parent
e6efbd736d
commit
13a25fe675
2 changed files with 12 additions and 6 deletions
7
fn.nix
7
fn.nix
|
@ -69,4 +69,11 @@ rec {
|
||||||
true)
|
true)
|
||||||
))
|
))
|
||||||
ld);
|
ld);
|
||||||
|
makeOptionTypeList = path: (lists.forEach
|
||||||
|
# get a list of all files ending in .nix in path
|
||||||
|
(filter (filePath: hasSuffix ".nix" filePath)
|
||||||
|
(lsfRec path true))
|
||||||
|
# remove leading path and trailing ".nix", replace every slash with "::"
|
||||||
|
(replaceStrings [ "${path}/" "/" ".nix" ] [ "" "::" "" ])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,8 @@ with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.machine;
|
cfg = config.machine;
|
||||||
metapkgs = let
|
pkgsetList = fn.makeOptionTypeList (toString ../pkgsets);
|
||||||
pPath = (toString ../pkgsets);
|
serviceList = fn.makeOptionTypeList (toString ../services);
|
||||||
in (lists.forEach (fn.lsfRec pPath true) (v: replaceStrings [ "${pPath}/" "/" ".nix" ] [ "" "::" "" ] v));
|
|
||||||
pkgOption = pname: {
|
pkgOption = pname: {
|
||||||
name = pname;
|
name = pname;
|
||||||
value = rec {
|
value = rec {
|
||||||
|
@ -30,16 +29,16 @@ let
|
||||||
in {
|
in {
|
||||||
options.machine = {
|
options.machine = {
|
||||||
pkgs = mkOption {
|
pkgs = mkOption {
|
||||||
type = (types.listOf (types.enum metapkgs));
|
type = (types.listOf (types.enum pkgsetList));
|
||||||
default = [ "base" ];
|
default = [ "base" ];
|
||||||
description = ''
|
description = ''
|
||||||
The list of metapackages to be installed.
|
The list of metapackages to be installed.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
# Package names containing '::' are sub packages and should not have their own pkgset.
|
# Package names containing '::' are sub packages and should not have their own pkgset.
|
||||||
pkgsets = listToAttrs (map pkgOption (lists.filter (v: !(strings.hasInfix "::" v)) metapkgs));
|
pkgsets = listToAttrs (map pkgOption (lists.filter (v: !(strings.hasInfix "::" v)) pkgsetList));
|
||||||
services = mkOption {
|
services = mkOption {
|
||||||
type = types.listOf types.str;
|
type = (types.listOf (types.enum serviceList));
|
||||||
default = [];
|
default = [];
|
||||||
description = ''
|
description = ''
|
||||||
List of services to be enabled.
|
List of services to be enabled.
|
||||||
|
|
Loading…
Reference in a new issue