liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

extract-options.nix (1600B)


      1 let
      2   overlay = import ../overlay.nix;
      3   pkgs = import <nixpkgs> ( {
      4     overlays = [overlay];
      5     config = {
      6       allowUnsupportedSystem = true; # mipsel
      7       permittedInsecurePackages = [
      8         "python-2.7.18.6"       # kernel backports needs python <3
      9       ];
     10     };
     11   });
     12   inherit (pkgs) lib;
     13   inherit (lib) types;
     14   modulenames =
     15     builtins.attrNames
     16       (lib.filterAttrsRecursive
     17         (n: t:
     18           (t=="directory") ||
     19           ((t=="regular") && ((builtins.match ".*\\.nix$" n) != null)))
     20         (builtins.readDir ../modules));
     21   modulefiles = builtins.map (n: builtins.toPath "${../modules}/${n}") modulenames;
     22   eval = (lib.evalModules {
     23     modules = [
     24       { _module.args = { inherit pkgs; lib = pkgs.lib; }; }
     25     ] ++ modulefiles;
     26   });
     27   conf = eval.config;
     28   optToDoc = name: opt : {
     29     inherit name;
     30     description = opt.description or null;
     31     default = opt.default or null;
     32     visible =
     33       if (opt ? visible && opt.visible == "shallow")
     34       then true
     35       else opt.visible or true;
     36     readOnly = opt.readOnly or false;
     37     type = opt.type.description or "unspecified";
     38   };
     39   spliceServiceDefn = item :
     40     if item.type == "parametrisable s6-rc service definition"
     41     then
     42       let sd = lib.attrByPath item.loc ["not found"] conf;
     43       in item // {
     44         parameters =
     45           let x = lib.mapAttrsToList optToDoc sd.parameters; in x;
     46       }
     47     else
     48       item;
     49   o = builtins.map spliceServiceDefn
     50     (pkgs.lib.optionAttrSetToDocList eval.options);
     51 in {
     52   doc = pkgs.writeText "options.yaml" ''
     53     # ${./..}
     54     ${builtins.toJSON o}
     55   '';
     56 }