summaryrefslogtreecommitdiffstats
path: root/lib/eval-source.nix
blob: ff853185be7acc88234be3f3ebd2ee6a8d689563 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
with import <stockholm/lib>;
let
  eval = _file: source: evalModules {
    modules = singleton {
      inherit _file;
      imports = map (source: { inherit source; }) (toList source);
      options.source = mkOption {
        type = types.attrsOf types.source;
        default = {};
      };
    };
  };
  sanitize = x: getAttr (typeOf x) {
    set = mapAttrs
            (const sanitize)
            (filterAttrs (name: value: name != "_module" && value != null) x);
    string = x;
  };
in
  # This function's return value can be used as pkgs.populate input.
  _file: source: sanitize (eval _file source).config.source