nix-config: 526aefd5072646dd58a85bdfcb162b31fbfd4e61

     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:     preConfigure     = ''
    41:       cmakeFlags="$cmakeFlags -DSYSTEMD_UNITDIR='$out/lib/systemd/system'"
    42:       replace 'usr/bin' 'bin' -- CMakeLists.txt
    43:     '';
    44:   };
    45: };
    46: {
    47:   options.services.laminar = {
    48:     enable = mkOption {
    49:       type        = types.bool;
    50:       default     = false;
    51:       description = ''
    52:         Enable the Laminar continuous integration system as a systemd service.
    53:       '';
    54:     };
    55: 
    56:     package = mkOption {
    57:       type        = types.package;
    58:       default     = laminar;
    59:       description = ''
    60:         The package providing Laminar binaries.
    61:       '';
    62:     };
    63: 
    64:     home = mkOption {
    65:       type        = types.path;
    66:       default     = "/var/lib/laminar";
    67:       description = ''
    68:         The directory used to load config, store results, etc.
    69:       '';
    70:     };
    71: 
    72:     cfg = mkOption {
    73:       type        = types.path;
    74:       description = ''
    75:         Path to symlink as LAMINAR_HOME/cfg, used to control Laminar. We use a
    76:         symlink so that content can be managed externally, e.g. via version
    77:         control, without needing to rebuild the service. Note that raw paths
    78:         like './foo' will have a snapshot added to the Nix store; to prevent
    79:         this use a string like '"/.../foo"' or 'toString ./foo'.
    80:       '';
    81:     };
    82: 
    83:     custom = mkOption {
    84:       type        = types.nullOr types.path;
    85:       default     = null;
    86:       description = ''
    87:         Path to symlink as 'home'/custom, used for Web UI customisation. We use
    88:         a symlink so that content can be managed externally, e.g. via version
    89:         control.
    90:       '';
    91:     };
    92: 
    93:     bindHttp = mkOption {
    94:       type        = types.str;
    95:       default     = "*:8080";
    96:       description = ''
    97:         Value for LAMINAR_BIND_HTTP, used for Laminar's read-only WebUI. Has
    98:         the form IPADDR:PORT, unix:PATH/TO/SOCKET or unix-abstract:SOCKETNAME.
    99:         IPADDR may be * to bind on all interfaces.
   100:       '';
   101:     };
   102: 
   103:     title = mkOption {
   104:       type        = types.nullOr types.str;
   105:       default     = null;
   106:       example     = "My Build Server";
   107:       description = ''
   108:         Sets LAMINAR_TITLE, to use your preferred page title on the WebUI. For
   109:         further WebUI customization, consider using a custom style sheet.
   110:       '';
   111:     };
   112: 
   113:     user = mkOption {
   114:       default     = "laminar";
   115:       type        = types.str;
   116:       description = "User the laminar service should execute under.";
   117:     };
   118: 
   119:     group = mkOption {
   120:       default     = "laminar";
   121:       type        = types.str;
   122:       description = "Primary group of the laminar user.";
   123:     };
   124: 
   125:     extraGroups = mkOption {
   126:       type = types.listOf types.str;
   127:       default = [];
   128:       description = "List of extra groups that the laminar user should be in.";
   129:     };
   130:   };
   131: 
   132:   config = mkIf cfg.enable {
   133:     environment.systemPackages = [ laminar ];
   134: 
   135:     systemd.services.laminar = {
   136:       description   = "Laminar continuous integration service";
   137:       wantedBy      = [ "multi-user.target" ];
   138:       environment   = {
   139:         LAMINAR_BIND_HTTP = cfg.bindHttp;
   140:         LAMINAR_HOME      = cfg.home;
   141:         LAMINAR_TITLE     = cfg.title;
   142:       };
   143:       path     = [ cfg.package ];
   144:       preStart = ''
   145:         mkdir -vp "${cfg.home}"
   146:         chown -v "${cfg.user}"."${cfg.group}" "${cfg.home}"
   147: 
   148:         if [[ -h "${cfg.home}"/cfg ]]
   149:         then
   150:           rm -v "${cfg.home}"/cfg
   151:         fi
   152:         ln -sfv "${cfg.cfg}" ${cfg.home}/cfg
   153: 
   154:         if [[ -h "${cfg.home}"/custom ]]
   155:         then
   156:           rm -v "${cfg.home}"/custom
   157:         fi
   158:         ${if cfg.custom == null
   159:              then ""
   160:              else ''ln -sfv "${cfg.custom}" ${cfg.home}/custom''}
   161:       '';
   162:       serviceConfig = {
   163:         User                 = cfg.user;
   164:         Group                = cfg.group;
   165:         PermissionsStartOnly = true;  # Allow preStart to run as root
   166:         ExecStart            = "${cfg.package}/bin/laminard";
   167:       };
   168:     };
   169: 
   170:     users.extraGroups = optional (cfg.group == "laminar") {
   171:       name = "laminar";
   172:     };
   173: 
   174:     users.extraUsers = optional (cfg.user == "laminar") {
   175:       name            = "laminar";
   176:       description     = "Laminar User.";
   177:       isNormalUser    = true;
   178:       createHome      = false;
   179:       group           = cfg.group;
   180:       extraGroups     = cfg.extraGroups;
   181:       useDefaultShell = true;
   182:     };
   183:   };
   184: }

Generated by git2html.