mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-15 21:57:02 +03:00
nixos-option: Handle 'attrsOf submodule' options.
This commit is contained in:
parent
cd2f7ce9f9
commit
640428d3c5
@ -83,6 +83,58 @@ EOF
|
||||
fi
|
||||
}
|
||||
|
||||
header="
|
||||
let
|
||||
nixos = import <nixos> {};
|
||||
nixpkgs = import <nixpkgs> {};
|
||||
in with nixpkgs.lib;
|
||||
"
|
||||
|
||||
# This function is used for converting the option definition path given by
|
||||
# the user into accessors for reaching the definition and the declaration
|
||||
# corresponding to this option.
|
||||
generateAccessors(){
|
||||
evalNix --strict --show-trace <<EOF
|
||||
$header
|
||||
|
||||
let
|
||||
path = "${option:+$option}";
|
||||
pathList = splitString "." path;
|
||||
|
||||
walkOptions = attrsNames: result:
|
||||
if attrsNames == [] then
|
||||
result
|
||||
else
|
||||
let name = head attrsNames; rest = tail attrsNames; in
|
||||
if isOption result.options then
|
||||
walkOptions rest {
|
||||
options = result.options.type.getSubOptions "";
|
||||
opt = ''(\${result.opt}.type.getSubOptions "")'';
|
||||
cfg = ''\${result.cfg}."\${name}"'';
|
||||
}
|
||||
else
|
||||
walkOptions rest {
|
||||
options = result.options.\${name};
|
||||
opt = ''\${result.opt}."\${name}"'';
|
||||
cfg = ''\${result.cfg}."\${name}"'';
|
||||
}
|
||||
;
|
||||
|
||||
walkResult = (if path == "" then x: x else walkOptions pathList) {
|
||||
options = nixos.options;
|
||||
opt = ''nixos.options'';
|
||||
cfg = ''nixos.config'';
|
||||
};
|
||||
|
||||
in
|
||||
''let option = \${walkResult.opt}; config = \${walkResult.cfg}; in''
|
||||
EOF
|
||||
}
|
||||
|
||||
header="$header
|
||||
$(eval echo $(generateAccessors))
|
||||
"
|
||||
|
||||
evalAttr(){
|
||||
local prefix="$1"
|
||||
local strict="$2"
|
||||
@ -92,10 +144,10 @@ evalAttr(){
|
||||
test -n "$strict" && strict=true
|
||||
|
||||
evalNix ${strict:+--strict} <<EOF
|
||||
$header
|
||||
|
||||
let
|
||||
reach = attrs: attrs${option:+.$option}${suffix:+.$suffix};
|
||||
nixos = import <nixos> {};
|
||||
nixpkgs = import <nixpkgs> {};
|
||||
value = $prefix${suffix:+.$suffix};
|
||||
strict = ${strict:-false};
|
||||
cleanOutput = x: with nixpkgs.lib;
|
||||
if isDerivation x then x.outPath
|
||||
@ -106,12 +158,12 @@ let
|
||||
else x
|
||||
else x;
|
||||
in
|
||||
cleanOutput (reach nixos.$prefix)
|
||||
cleanOutput value
|
||||
EOF
|
||||
}
|
||||
|
||||
evalOpt(){
|
||||
evalAttr "options" "" "$@"
|
||||
evalAttr "option" "" "$@"
|
||||
}
|
||||
|
||||
evalCfg(){
|
||||
@ -121,8 +173,11 @@ evalCfg(){
|
||||
|
||||
findSources(){
|
||||
local suffix=$1
|
||||
echo "(import <nixos> {}).options${option:+.$option}.$suffix" |
|
||||
evalNix --strict
|
||||
evalNix --strict <<EOF
|
||||
$header
|
||||
|
||||
option.$suffix
|
||||
EOF
|
||||
}
|
||||
|
||||
# Given a result from nix-instantiate, recover the list of attributes it
|
||||
@ -152,13 +207,12 @@ nixMap() {
|
||||
# the output of nixos-option with other tools such as nixos-gui.
|
||||
if $xml; then
|
||||
evalNix --xml --no-location <<EOF
|
||||
$header
|
||||
|
||||
let
|
||||
reach = attrs: attrs${option:+.$option};
|
||||
nixos = import <nixos> {};
|
||||
nixpkgs = import <nixpkgs> {};
|
||||
sources = builtins.map (f: f.source);
|
||||
opt = reach nixos.options;
|
||||
cfg = reach nixos.config;
|
||||
opt = option;
|
||||
cfg = config;
|
||||
in
|
||||
|
||||
with nixpkgs.lib;
|
||||
|
Loading…
Reference in New Issue
Block a user