Literal Flake Input

Service translates an HTTP GET path into a nix derivation that can be used as a flake input. Such a workaround provides the ability to emulate command line arguments in nix flakes.

wget -q -O - 'https://lficom.me/name/Alice Wonder/age/18/alive/true/job/null/'
Response body
{ ... }:
  {
    name  = "Alice Wonder";
    age   = 18;
    alive = true;
    job   = null;
  }

nixpkgs derivations can accept command line arguments but nix flakes don't.

Flake template
# ...
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs";
  utils.url = "github:numtide/flake-utils";
  c = {
    url = "https://lficom.me/static/false/";
    flake = false;
  };
};
outputs = { self, nixpkgs, utils, c }:
  utils.lib.eachDefaultSystem (sys:
    let
      pkgs = nixpkgs.legacyPackages.${sys};
      cnf = import c { inherit pkgs; };
    in
    {
      packages.hello =
        pkgs.writeShellScriptBin
          "hello"
          "echo Hello ${cnf.name}";
    });
# ...
Override
nix build --override-input c \
  https://lficom.me/name/Bob/.tar

There is a commant line tool e, that helps with boilerplates and input validation:

nix build $(e -name Bob)

The tool supports literal keyword values (e.g. true and null), strings, numbers, arrays and attribute sets. String quotation is optional. All values are parsed and evaluated by e with nix to catch typos as soon as possible.

nix build $(e -an1 true \
              -an2 null \
              -an3 12 \
              -an4 hello world \
              -an5 [ 1 2 ] \
              -an6 "{x = 1; y = 2; }" \
              -an7 x: x + 1)

The above command generates an input link which is going to be resolved by the service into:

{...}: {
  an1 = true;
  an2 = null;
  an3 = 12;
  an4 = "hello wolrd";
  an5 = [1 2];
  an6 = {x = 1; y = 2; };
  an7 = x: x + 1;
}

If you copy an URL generated by e into a flake for default values, then drop .tar suffix.

Alternative URL prefix can be set via environment variable LFI_SITE.