MyNixOS website logo
Description

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)
Metadata

Version

0.0.4

Platforms (80)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    uefi
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-uefi
  • aarch64-windows
  • aarch64_be-none
  • arc-linux
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • sh4-linux
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-uefi
  • x86_64-windows