@hackage literal-flake-input0.0.4

Web service converting URLs into archived nix attrsets

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.

In addtition to the web service there is a command line tool e (stands for escape/encode). The e helps with URL encoding.

Installation

Service

The service is already deployed at lficom.me

NixOS module

NixOS with flakes

Modify /etc/nixos/flake.nix as follows:

  # ...
  inputs = {
    # ...
    literal-flake-input.url = "github:yaitskov/literal-flake-input";
  };
  # ...
        modules = [
          literal-flake-input.nixosModules.${system}.default
          ({ ... }: {
            programs.literal-flake-input {
              enable = true;
              port = 3000;
          })
          ./configuration.nix
        ];
NixOS without flakes

  let
    lfi = builtins.fetchGit "htts://github.com/yaitskov/literal-flake-input.git?ref=master";
  in {
  imports =
    [ # ... ./hardware-configuration.nix
      "${lfi}/nixos/non-flake-lfi.nix"
    ];
  programs = {
    literal-flake-input = {
      port = 3000;
      enable = true;
    };
  };

How to use

The project flake is using itself. Another project using lfi is vpn-router.

Flake template

  # ...
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    utils.url = "github:numtide/flake-utils";
    c = {
      url = "https://lficom.me/name/Bill/";
      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}";
      });
  # ...

Overriding default values

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.

Development environment

$ nix develop
$ emacs &
$ cabal build
$ cabal test
$ nix build
$ ./result/bin/literal-flake-input run
$ nix build $(./result/bin/e -static true)