Commit 300c4972 authored by Profpatsch's avatar Profpatsch

containers/helpers: refactor helpers into own default.nix

The helpers folder can now potentially be used as overlay (provided `withTests`
goes into upstream …).
parent 58d6e2c8
......@@ -25,19 +25,7 @@ let
payment-processor-hbci = self.callPackage ../packages/payment-processor-hbci {};
# lots of small and big helper functions
helpers = (lib.mapAttrs (_: pkg: self.callPackage pkg {}) {
genUtf8Localedb = ./helpers/gen-utf8-localedb.nix;
postgresTemplate = ./helpers/postgres-template.nix;
prependPrefix = ./helpers/prepend-prefix.nix;
debugDockerImage = ./helpers/debug-docker-image.nix;
createStandaloneDockerImage = ./helpers/create-standalone-docker-image.nix;
fetchgitUpdater = ./helpers/fetchgit-updater;
# TODO: give better name
script = ./helpers/write-script-argparse;
}) // {
inherit (self.callPackage ./helpers/nix-json-trans.nix {})
json2json json2string;
};
helpers = import ./helpers self.helpers self;
})];
};
};
......
let
pkgs = import <nixpkgs> {};
in pkgs.lib.fix (a: import ./. a pkgs)
{ pkgs }:
{ pkgs, helpers }:
# Thin, leaky wrapper arount `buildDockerImage`
# that sets up a minimal sane environment for running
# programs without depending on an OS base image (like Alpine).
......
{ pkgs }:
{ pkgs, helpers }:
# Make a generated docker image debuggable,
# by including bash and coreutils.
# `docker run -it <image>`
......
# the functions in this module
helpers:
# nixpkgs
pkgs:
# Lots of small and big helper functions.
# See their source files for docs.
# This is an overlay if called with the following function:
# self: _: { helpers = import ./. self.helpers self; }
let
call = path: import path { inherit pkgs helpers; };
in {
# -- GENERAL --
# generate an optparser for a bash script
script = {
inherit (call ./write-script-argparse)
withOptions optionChecks tests;
};
# transform json files with nix code (jq but with nix)
inherit (call ./nix-json-trans.nix)
json2json json2string;
# prepend a folder to all files in a derivation output
prependPrefix = call ./prepend-prefix.nix;
# -- UPDATER --
# updater for fetchgit packages
fetchgitUpdater = call ./fetchgit-updater;
# -- DOCKER --
# awesome wrapper around dockerTools
createStandaloneDockerImage = call ./create-standalone-docker-image.nix;
# add debugging layer to docker image
debugDockerImage = call ./debug-docker-image.nix;
# generate a subset locale db
genUtf8Localedb = call ./gen-utf8-localedb.nix;
# -- MISC --
# generate (and init) postgresql database
postgresTemplate = call ./postgres-template.nix;
}
{ stdenv, helpers, writeText, nix-prefetch-scripts }:
{ pkgs, helpers }:
# Updater for git sources
let
args = writeText "args.nix" ''
{ nixPrefetchGit = "${nix-prefetch-scripts}/bin/nix-prefetch-git"; }
args = pkgs.writeText "args.nix" ''
{ nixPrefetchGit = "${pkgs.nix-prefetch-scripts}/bin/nix-prefetch-git"; }
'';
in helpers.script.withOptions {
name = "fetchgit-updater";
description = "Update the json description of a git source.";
synopsis = "Update the json description of a git source.";
options = {
file = {
description = "The json file to update.";
......
{ glibcLocales }:
{ pkgs, helpers }:
# Generate a localedb for the given UTF-8 locale string.
# a locale string formatted like `en_US.UTF-8`
locale:
glibcLocales.override {
pkgs.glibcLocales.override {
locales = [ (locale + "/UTF-8") ];
allLocales = false;
}
{ lib, pkgs, stdenv, helpers, libPath ? <nixpkgs/lib> }:
{ pkgs, helpers, libPath ? <nixpkgs/lib> }:
# Scripts to transform json via nix eval.
# See the tests below for examples.
......@@ -35,7 +35,7 @@ let
};
script = ''
#!${stdenv.shell}
#!${pkgs.stdenv.shell}
# nix needs a path, containing / (`args` could be e.g. 'myfolder').
ARGS="$(realpath "$args")"
......@@ -146,7 +146,7 @@ let
passingArguments =
let
args = pkgs.writeText "args.nix" ''
{ shell = "${stdenv.shell}"; }
{ shell = "${pkgs.stdenv.shell}"; }
'';
echoshell = pkgs.writeText "echoshell.nix" ''
{ shell }: _: '''
......@@ -162,7 +162,7 @@ let
--args ${args} \
--trans ${echoshell} \
--json empty.json \
| ${stdenv.shell} -s \
| ${pkgs.stdenv.shell} -s \
| grep echoshell
'';
};
......
{ lib, pkgs }:
{ pkgs, helpers }:
# Generates a postgresql template by executing initdb.
# Initialization of the database server (e.g. adding roles
# and databases) can be done by an init script like:
......@@ -19,11 +19,11 @@ postgresqlConf
}:
let
localedb = pkgs.helpers.genUtf8Localedb locale;
localedb = helpers.genUtf8Localedb locale;
config =
let
format = with lib.generators; toKeyValue {
format = with pkgs.lib.generators; toKeyValue {
mkKeyValue = mkKeyValueDefault {
mkValueString = v: if builtins.isString v then "'${v}'" else toString v;
} "=";
......
{ pkgs }:
{ pkgs, helpers }:
# Prepend folders to a derivations’s contents.
# folder prefix
......
{ pkgs }:
{ pkgs, helpers }:
let
# main documentation in here
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment