nix-config: 2c1b4a328481fd0a2b1dc08eb1e01522e7dd49c7

     1: { config, lib, pkgs, ... }:
     2: 
     3: with builtins;
     4: with lib;
     5: with rec {
     6:   cfg = config.services.laminar;
     7: 
     8:   # Workaround for https://groups.google.com/forum/#!topic/nix-devel/fAMADzFhcFo
     9:   stdenv6 = with pkgs; overrideCC stdenv gcc6;
    10: 
    11:   capnproto = with pkgs; stdenv6.mkDerivation {
    12:     name = "capnproto";
    13:     src  = fetchFromGitHub {
    14:       owner  = "capnproto";
    15:       repo   = "capnproto";
    16:       rev    = "3079784";
    17:       sha256 = "0d7v9310gq12qwhxbsjcdxwaz9fhyxq13x2lz8cdhm6hbsg8756z";
    18:     };
    19:     buildInputs = [ autoconf automake libtool ];
    20:     patchPhase  = ''
    21:       cd c++/
    22:       autoreconf -i
    23:     '';
    24:     hardeningDisable = [ "all" ];
    25:   };
    26: 
    27:   laminar = stdenv6.mkDerivation rec {
    28:     name    = "laminar-${version}";
    29:     version = "0.6";
    30:     src     = pkgs.fetchFromGitHub {
    31:       owner  = "ohwgiles";
    32:       repo   = "laminar";
    33:       rev    = "bbbef11";  # v0.6
    34:       sha256 = "07nnqccm0dgyzkj6k3gcrs6f22h2ac7hdq05zq4wjs1xdyqdksl0";
    35:     };
    36:     buildInputs = [ capnproto ] ++ (with pkgs; [
    37:       boost cmake rapidjson nix-helpers.replace sqlite websocketpp zlib
    38:     ]);
    39:     hardeningDisable = [ "all" ];
    40:     __noChroot       = true;  # TODO: Prefetch deps (e.g. vue.js)
    41:     preConfigure     = ''
    42:       cmakeFlags="$cmakeFlags -DSYSTEMD_UNITDIR='$out/lib/systemd/system'"
    43:       replace 'usr/bin' 'bin' -- CMakeLists.txt
    44:     '';
    45:   };
    46: };
    47: {
    48:   options.services.laminar = {
    49:     enable = mkOption {
    50:       type        = types.bool;
    51:       default     = false;
    52:       description = ''
    53:         Enable the Laminar continuous integration system as a systemd service.
    54:       '';
    55:     };
    56: 
    57:     package = mkOption {
    58:       type        = types.package;
    59:       default     = laminar;
    60:       description = ''
    61:         The package providing Laminar binaries.
    62:       '';
    63:     };
    64: 
    65:     home = mkOption {
    66:       type        = types.path;
    67:       default     = "/var/lib/laminar";
    68:       description = ''
    69:         The directory used to load config, store results, etc.
    70:       '';
    71:     };
    72: 
    73:     cfg = mkOption {
    74:       type        = types.path;
    75:       description = ''
    76:         Path to symlink as LAMINAR_HOME/cfg, used to control Laminar. We use a
    77:         symlink so that content can be managed externally, e.g. via version
    78:         control, without needing to rebuild the service. Note that raw paths
    79:         like './foo' will have a snapshot added to the Nix store; to prevent
    80:         this use a string like '"/.../foo"' or 'toString ./foo'.
    81:       '';
    82:     };
    83: 
    84:     custom = mkOption {
    85:       type        = types.nullOr types.path;
    86:       default     = null;
    87:       description = ''
    88:         Path to symlink as 'home'/custom, used for Web UI customisation. We use
    89:         a symlink so that content can be managed externally, e.g. via version
    90:         control.
    91:       '';
    92:     };
    93: 
    94:     bindHttp = mkOption {
    95:       type        = types.str;
    96:       default     = "*:8080";
    97:       description = ''
    98:         Value for LAMINAR_BIND_HTTP, used for Laminar's read-only WebUI. Has
    99:         the form IPADDR:PORT, unix:PATH/TO/SOCKET or unix-abstract:SOCKETNAME.
   100:         IPADDR may be * to bind on all interfaces.
   101:       '';
   102:     };
   103: 
   104:     title = mkOption {
   105:       type        = types.nullOr types.str;
   106:       default     = null;
   107:       example     = "My Build Server";
   108:       description = ''
   109:         Sets LAMINAR_TITLE, to use your preferred page title on the WebUI. For
   110:         further WebUI customization, consider using a custom style sheet.
   111:       '';
   112:     };
   113: 
   114:     user = mkOption {
   115:       default     = "laminar";
   116:       type        = types.str;
   117:       description = "User the laminar service should execute under.";
   118:     };
   119: 
   120:     group = mkOption {
   121:       default     = "laminar";
   122:       type        = types.str;
   123:       description = "Primary group of the laminar user.";
   124:     };
   125: 
   126:     extraGroups = mkOption {
   127:       type = types.listOf types.str;
   128:       default = [];
   129:       description = "List of extra groups that the laminar user should be in.";
   130:     };
   131:   };
   132: 
   133:   config = mkIf cfg.enable {
   134:     environment.systemPackages = [ laminar ];
   135: 
   136:     systemd.services.laminar = {
   137:       description   = "Laminar continuous integration service";
   138:       wantedBy      = [ "multi-user.target" ];
   139:       environment   = {
   140:         LAMINAR_BIND_HTTP = cfg.bindHttp;
   141:         LAMINAR_HOME      = cfg.home;
   142:         LAMINAR_TITLE     = cfg.title;
   143:       };
   144:       path     = [ cfg.package ];
   145:       preStart = ''
   146:         mkdir -vp "${cfg.home}"
   147:         chown -v "${cfg.user}"."${cfg.group}" "${cfg.home}"
   148: 
   149:         if [[ -h "${cfg.home}"/cfg ]]
   150:         then
   151:           rm -v "${cfg.home}"/cfg
   152:         fi
   153:         ln -sfv "${cfg.cfg}" ${cfg.home}/cfg
   154: 
   155:         if [[ -h "${cfg.home}"/custom ]]
   156:         then
   157:           rm -v "${cfg.home}"/custom
   158:         fi
   159:         ${if cfg.custom == null
   160:              then ""
   161:              else ''ln -sfv "${cfg.custom}" ${cfg.home}/custom''}
   162:       '';
   163:       serviceConfig = {
   164:         User                 = cfg.user;
   165:         Group                = cfg.group;
   166:         PermissionsStartOnly = true;  # Allow preStart to run as root
   167:         ExecStart            = "${cfg.package}/bin/laminard";
   168:       };
   169:     };
   170: 
   171:     users.extraGroups = optionalAttrs (cfg.group == "laminar") {
   172:       laminar = {
   173:         name = "laminar";
   174:       };
   175:     };
   176: 
   177:     users.extraUsers = optionalAttrs (cfg.user == "laminar") {
   178:       "${cfg.user}" = {
   179:         name            = "laminar";
   180:         description     = "Laminar User.";
   181:         isNormalUser    = true;
   182:         createHome      = false;
   183:         group           = cfg.group;
   184:         extraGroups     = cfg.extraGroups;
   185:         useDefaultShell = true;
   186:       };
   187:     };
   188:   };
   189: }

Generated by git2html.