Add nanopos package and module and make clightning service

This commit is contained in:
Jonas Nick 2018-12-01 17:26:29 +00:00
parent 21f9462651
commit b0594aaacd
2 changed files with 117 additions and 0 deletions

84
modules/nanopos.nix Normal file
View File

@ -0,0 +1,84 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.nanopos;
defaultItemsFile = pkgs.writeText "items.yaml" ''
tea:
price: 0.02 # denominated in the currency specified by --currency
title: Green Tea # title is optional, defaults to the key
coffee:
price: 1
bamba:
price: 3
beer:
price: 7
hat:
price: 15
tshirt:
price: 25
'';
in {
options.services.nanopos = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
If enabled, the nanopos service will be installed.
'';
};
port = mkOption {
type = types.port;
default = 9116;
description = ''
"The port on which to listen for connections.";
'';
};
itemsFile = mkOption {
type = types.path;
default = defaultItemsFile;
description = ''
"The items file (see nanopos README).";
'';
};
};
config = mkIf cfg.enable {
users.users.nanopos =
{
description = "nanopos User";
group = "nanopos";
extraGroups = [ "keys" ];
};
users.groups.nanopos = {
name = "nanopos";
};
systemd.services.nanopos =
{ description = "Run nanopos";
wantedBy = [ "multi-user.target" ];
requires = [ "lightning-charge.service" ];
after = [ "lightning-charge.service" ];
serviceConfig =
{
EnvironmentFile = "/secrets/lightning-charge-api-token-for-nanopos";
ExecStart = "${pkgs.nanopos.package}/bin/nanopos -y ${cfg.itemsFile} -p ${toString cfg.port}";
User = "nanopos";
Restart = "on-failure";
RestartSec = "10s";
PrivateTmp = "true";
ProtectSystem = "full";
NoNewPrivileges = "true";
PrivateDevices = "true";
};
};
};
}

33
pkgs/nanopos.nix Normal file
View File

@ -0,0 +1,33 @@
{pkgs ? import <nixpkgs> {
inherit system;
}, system ? builtins.currentSystem, nodejs ? pkgs."nodejs-8_x"}:
with pkgs;
let
d1 = stdenv.mkDerivation {
name = "nanotip-sources";
src = fetchurl {
url = "https://registry.npmjs.org/nanopos/-/nanopos-0.1.3.tgz";
sha256 = "602d250190d4991b288ed7c493226bcbf03e73181f5d4d54d34334404fc06bb6";
};
buildInputs = [ nodePackages.node2nix git ];
unpackPhase = ''
mkdir -p $out
tar -xzf $src -C $out
'';
installPhase = ''
mkdir -p $out
cd $out/package
${nodePackages.node2nix}/bin/node2nix -8 package.json
'';
};
# import from derivation (IFD)
packages = import (d1 + "/package/default.nix") {
inherit pkgs system;
};
in
packages