NixOS / nix

Nix, the purely functional package manager
https://nixos.org/
GNU Lesser General Public License v2.1
12.63k stars 1.51k forks source link

type validation #1475

Open qknight opened 7 years ago

qknight commented 7 years ago

motivation

in nix one can use the apply -> x: if (x > 5) then x else abort "argument must be > 5" function to validate values assigned to a typed option. this is great for types which can be easilty validate inside the nix language already but in the scenario below i want to use an external program nginx to validate it.

here is my mkOption:

  extraMappings = mkOption {
    type = types.listOf (types.submodule (import ../backends/lib/proxyOptionsType.nix {inherit lib;}).proxyOptionsSubmodule );
    default = [];
    example = ''
      [{
          port   = 3333;
          path   = "/tour";
          domain = "nixcloud.io";
          ip = "127.0.0.1";
      }];
    '';
    description = ''
      Can be used to append proxy-mappings, created manually, for services not supporting `proxyOptions` in `nixcloud` namespace.
    '';
  };

i put together a test using a mkDerivation, in which i basically execute: nginx -t -c nginx.conf. however, this can't use this for the apply function as mkDerivation returns a string/path like /nix/store/02f0af0af-foo/ and apply requires x itself!

in theory i could use builtins.exec but it is disabled by default. so what can i do about that?

copumpkin commented 7 years ago

You can have your derivation produce valid Nix code representing the result of the nginx check and import the result of it, but that has some awkward properties that makes it less than ideal. For local NixOS configuration it's probably fine, but some folks might not like it going into nixpkgs like that.

stale[bot] commented 3 years ago

I marked this as stale due to inactivity. → More info