diff options
author | Nicolas B. Pierron <nicolas.b.pierron@gmail.com> | 2014-12-20 19:16:43 +0100 |
---|---|---|
committer | Nicolas B. Pierron <nicolas.b.pierron@gmail.com> | 2014-12-20 19:16:43 +0100 |
commit | 640428d3c515c1837c9c2bff28f765d53fc93355 (patch) | |
tree | 865d5b7db2e6f208c1064ed251e88764a09e866d /nixos/modules/installer | |
parent | cd2f7ce9f9f10894c6d2a5995f06fb9d2a7f6795 (diff) | |
download | nixlib-640428d3c515c1837c9c2bff28f765d53fc93355.tar nixlib-640428d3c515c1837c9c2bff28f765d53fc93355.tar.gz nixlib-640428d3c515c1837c9c2bff28f765d53fc93355.tar.bz2 nixlib-640428d3c515c1837c9c2bff28f765d53fc93355.tar.lz nixlib-640428d3c515c1837c9c2bff28f765d53fc93355.tar.xz nixlib-640428d3c515c1837c9c2bff28f765d53fc93355.tar.zst nixlib-640428d3c515c1837c9c2bff28f765d53fc93355.zip |
nixos-option: Handle 'attrsOf submodule' options.
Diffstat (limited to 'nixos/modules/installer')
-rw-r--r-- | nixos/modules/installer/tools/nixos-option.sh | 78 |
1 files changed, 66 insertions, 12 deletions
diff --git a/nixos/modules/installer/tools/nixos-option.sh b/nixos/modules/installer/tools/nixos-option.sh index 4478059813d1..e565eca97204 100644 --- a/nixos/modules/installer/tools/nixos-option.sh +++ b/nixos/modules/installer/tools/nixos-option.sh @@ -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; |