mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-11-16 06:47:09 +03:00
nixos-option: Handle 'attrsOf submodule' options.
This commit is contained in:
parent
cd2f7ce9f9
commit
640428d3c5
@ -83,6 +83,58 @@ EOF
|
|||||||
fi
|
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(){
|
evalAttr(){
|
||||||
local prefix="$1"
|
local prefix="$1"
|
||||||
local strict="$2"
|
local strict="$2"
|
||||||
@ -92,10 +144,10 @@ evalAttr(){
|
|||||||
test -n "$strict" && strict=true
|
test -n "$strict" && strict=true
|
||||||
|
|
||||||
evalNix ${strict:+--strict} <<EOF
|
evalNix ${strict:+--strict} <<EOF
|
||||||
|
$header
|
||||||
|
|
||||||
let
|
let
|
||||||
reach = attrs: attrs${option:+.$option}${suffix:+.$suffix};
|
value = $prefix${suffix:+.$suffix};
|
||||||
nixos = import <nixos> {};
|
|
||||||
nixpkgs = import <nixpkgs> {};
|
|
||||||
strict = ${strict:-false};
|
strict = ${strict:-false};
|
||||||
cleanOutput = x: with nixpkgs.lib;
|
cleanOutput = x: with nixpkgs.lib;
|
||||||
if isDerivation x then x.outPath
|
if isDerivation x then x.outPath
|
||||||
@ -106,12 +158,12 @@ let
|
|||||||
else x
|
else x
|
||||||
else x;
|
else x;
|
||||||
in
|
in
|
||||||
cleanOutput (reach nixos.$prefix)
|
cleanOutput value
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
evalOpt(){
|
evalOpt(){
|
||||||
evalAttr "options" "" "$@"
|
evalAttr "option" "" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
evalCfg(){
|
evalCfg(){
|
||||||
@ -121,8 +173,11 @@ evalCfg(){
|
|||||||
|
|
||||||
findSources(){
|
findSources(){
|
||||||
local suffix=$1
|
local suffix=$1
|
||||||
echo "(import <nixos> {}).options${option:+.$option}.$suffix" |
|
evalNix --strict <<EOF
|
||||||
evalNix --strict
|
$header
|
||||||
|
|
||||||
|
option.$suffix
|
||||||
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
# Given a result from nix-instantiate, recover the list of attributes it
|
# 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.
|
# the output of nixos-option with other tools such as nixos-gui.
|
||||||
if $xml; then
|
if $xml; then
|
||||||
evalNix --xml --no-location <<EOF
|
evalNix --xml --no-location <<EOF
|
||||||
|
$header
|
||||||
|
|
||||||
let
|
let
|
||||||
reach = attrs: attrs${option:+.$option};
|
|
||||||
nixos = import <nixos> {};
|
|
||||||
nixpkgs = import <nixpkgs> {};
|
|
||||||
sources = builtins.map (f: f.source);
|
sources = builtins.map (f: f.source);
|
||||||
opt = reach nixos.options;
|
opt = option;
|
||||||
cfg = reach nixos.config;
|
cfg = config;
|
||||||
in
|
in
|
||||||
|
|
||||||
with nixpkgs.lib;
|
with nixpkgs.lib;
|
||||||
|
Loading…
Reference in New Issue
Block a user