|
| 1 | +{ |
| 2 | + outputs = { self, ...}: let |
| 3 | + versions = builtins.fromJSON (builtins.readFile ./versions.json); |
| 4 | + nixpkgs = let |
| 5 | + inherit (versions.nixpkgs) owner repo rev; |
| 6 | + in builtins.getFlake "github:${owner}/${repo}/${rev}"; |
| 7 | + |
| 8 | + inherit (nixpkgs) lib; |
| 9 | + nixpkgsConfig = import ./nixpkgs-config.nix; |
| 10 | + |
| 11 | + pkgsFor = system: import nixpkgs { |
| 12 | + inherit system; |
| 13 | + overlays = [ self.overlays.default ]; |
| 14 | + config = { |
| 15 | + inherit (nixpkgsConfig) permittedInsecurePackages; |
| 16 | + }; |
| 17 | + }; |
| 18 | + |
| 19 | + forAllSystems = lib.genAttrs lib.systems.flakeExposed; |
| 20 | + in { |
| 21 | + overlays.default = import ./pkgs/overlay.nix; |
| 22 | + nixosModules.default = import ./nixos/default.nix; |
| 23 | + |
| 24 | + legacyPackages = forAllSystems (system: import ./. { |
| 25 | + inherit nixpkgs system; |
| 26 | + overlays = [ self.overlays.default ]; |
| 27 | + config = { |
| 28 | + inherit (nixpkgsConfig) permittedInsecurePackages; |
| 29 | + }; |
| 30 | + }); |
| 31 | + |
| 32 | + packages = forAllSystems (system: let |
| 33 | + pkgs = pkgsFor system; |
| 34 | + in { |
| 35 | + options = let |
| 36 | + testConfigFor = system: let |
| 37 | + pkgs = pkgsFor system; |
| 38 | + versions = import ./versions.nix { inherit pkgs; }; |
| 39 | + testlib = import ./tests/testlib.nix { inherit (pkgs) lib; }; |
| 40 | + in lib.nixosSystem { |
| 41 | + inherit pkgs system; |
| 42 | + specialArgs.nixos-mailserver = versions.nixos-mailserver; |
| 43 | + |
| 44 | + modules = [ |
| 45 | + { |
| 46 | + options.virtualisation.vlans = lib.mkOption { |
| 47 | + type = lib.types.anything; |
| 48 | + default = []; |
| 49 | + }; |
| 50 | + |
| 51 | + config.networking.domain = "test.fcio.net"; |
| 52 | + |
| 53 | + imports = [ |
| 54 | + (testlib.fcConfig { |
| 55 | + id = 1; |
| 56 | + net.fe = true; |
| 57 | + extraEncParameters.environment_url = "test.fcio.net"; |
| 58 | + }) |
| 59 | + ]; |
| 60 | + } |
| 61 | + ]; |
| 62 | + }; |
| 63 | + |
| 64 | + rawOpts = lib.optionAttrSetToDocList (testConfigFor system).options; |
| 65 | + |
| 66 | + substSpecial = x: |
| 67 | + if lib.isDerivation x then { _type = "derivation"; name = x.name; } |
| 68 | + else if builtins.isAttrs x then lib.mapAttrs (name: substSpecial) x |
| 69 | + else if builtins.isList x then map substSpecial x |
| 70 | + else if lib.isFunction x then "<function>" |
| 71 | + else x; |
| 72 | + |
| 73 | + filteredOpts = lib.filter (opt: opt.visible && !opt.internal) rawOpts; |
| 74 | + optionsList = lib.flip map filteredOpts |
| 75 | + (opt: opt |
| 76 | + // lib.optionalAttrs (opt ? example) { example = substSpecial opt.example; } |
| 77 | + // lib.optionalAttrs (opt ? default) { default = substSpecial opt.default; } |
| 78 | + // lib.optionalAttrs (opt ? type) { type = substSpecial opt.type; } |
| 79 | + ); |
| 80 | + |
| 81 | + optionsNix = builtins.listToAttrs (map (o: { name = o.name; value = removeAttrs o ["name" "visible" "internal"]; }) optionsList); |
| 82 | + finalOptions = lib.mapAttrsToList (name: option: option // { inherit name; }) optionsNix; |
| 83 | + in pkgs.writeText "options.json" (builtins.unsafeDiscardStringContext (builtins.toJSON finalOptions)); |
| 84 | + }); |
| 85 | + }; |
| 86 | +} |
0 commit comments