summaryrefslogtreecommitdiff
path: root/custom
diff options
context:
space:
mode:
Diffstat (limited to 'custom')
-rw-r--r--custom/bar-service.nix99
-rw-r--r--custom/bar/default.nix47
-rw-r--r--custom/bar/generated.nix35
-rw-r--r--custom/bar/generated.nix.gup5
-rw-r--r--custom/trivmix-service.nix8
5 files changed, 191 insertions, 3 deletions
diff --git a/custom/bar-service.nix b/custom/bar-service.nix
new file mode 100644
index 00000000..2a492ce1
--- /dev/null
+++ b/custom/bar-service.nix
@@ -0,0 +1,99 @@
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.bar;
7in {
8 options.services.bar = {
9 enable = mkEnableOption "the Bar Inventory System";
10
11 user = mkOption {
12 type = types.str;
13 default = "bar";
14 description = "User to execute the daemon under";
15 };
16
17 group = mkOption {
18 type = types.str;
19 default = "bar";
20 description = "Group to execute the daemon under";
21 };
22
23 stateDir = mkOption {
24 type = types.path;
25 default = "/var/lib/bar";
26 description = "Directory for the daemon to store semi-transient state (encryption keys etc.)";
27 };
28
29 port = mkOption {
30 type = types.int;
31 default = 8080;
32 description = "Port for the daemon to listen on";
33 };
34
35 host = mkOption {
36 type = types.str;
37 default = "localhost";
38 description = "Host to bind to";
39 };
40
41 approot = mkOption {
42 type = types.str;
43 default = "/";
44 description = "Subdirectory of the daemon-managed site relative to HTTP /; only useful when using a reverse proxy";
45 };
46
47 thermoprintBaseURL = mkOption {
48 type = with types; nullOr types.str;
49 default = null;
50 example = "http://localhost:80/thermoprint/api";
51 description = "Thermoprint base url";
52 };
53 };
54
55 config = mkIf cfg.enable {
56 assertions = [
57 { assertion = config.services.postgresql.enable;
58 message = "bar requires PostgreSQL";
59 }
60 ];
61
62 users.users."${cfg.user}" = {
63 group = cfg.group;
64 description = "User for the Bar Inventory System";
65 isSystemUser = true;
66 home = cfg.stateDir;
67 createHome = true;
68 };
69
70 users.groups."${cfg.group}" = {};
71
72 nixpkgs.overlays = [(self: super: {
73 bar = self.callPackage ./bar { inherit (self) haskellPackages; };
74 })];
75
76 systemd.services."bar" = {
77 environment = {
78 PORT = cfg.port;
79 HOST = cfg.host;
80 APPROOT = cfg.approot;
81 IP_FROM_HEADER = cfg.ipFromHeader;
82 TPRINT_BASEURL = mkIf (cfg.thermoprintBaseURL != null) cfg.thermoprintBaseURL;
83 };
84
85 bindsTo = [ "postgresql.service" ];
86 after = [ "postgresql.service" ];
87 wantedBy = [ "default.target" ];
88
89 serviceConfig = {
90 Type = "notify";
91 User = cfg.user;
92 Group = cfg.group;
93 WorkingDirectory = cfg.stateDir;
94
95 ExecStart = with pkgs; "${bar}/bin/bar";
96 };
97 };
98 };
99}
diff --git a/custom/bar/default.nix b/custom/bar/default.nix
new file mode 100644
index 00000000..98b36901
--- /dev/null
+++ b/custom/bar/default.nix
@@ -0,0 +1,47 @@
1{ haskellPackages
2, stdenv
3, fetchFromGitHub
4, fetchurl
5, haskell
6}:
7
8let
9 pkg = haskellPackages.callPackage ./generated.nix {};
10 webshim = stdenv.mkDerivation rec {
11 name = "webshim-${version}";
12 version = "1.16.0";
13 src = fetchFromGitHub {
14 owner = "aFarkas";
15 repo = "webshim";
16 rev = "1.16.0";
17 sha256 = "14pk7hljqipzp0n7vpgcfxr3w4bla57cwyd7bmwmmxrm2zn62cyh";
18 };
19
20 installPhase = ''
21 mkdir -p $out/js
22 cp -r $src/js-webshim/dev/* $out/js/
23 '';
24 };
25 jquery = stdenv.mkDerivation rec {
26 name = "jquery-${version}";
27 version = "3.3.1";
28 src = fetchurl {
29 url = "https://github.com/jquery/jquery/archive/${version}.tar.gz";
30 sha256 = "1d1pilrwiz0yjx27cd7gbn8qar6hw5zgwjhpsyaijcg52z82wi5q";
31 };
32
33 installPhase = ''
34 mkdir -p $out/js
35 cp -r dist/jquery.js $out/js/
36 '';
37 };
38in stdenv.lib.overrideDerivation pkg (drv: {
39 postUnpack = ''
40 (
41 cd bar-*/static
42 rm -rf jquery.js webshim
43 ln -vs ${jquery}/js/jquery.js .
44 ln -vs ${webshim}/js webshim
45 )
46 '';
47})
diff --git a/custom/bar/generated.nix b/custom/bar/generated.nix
new file mode 100644
index 00000000..966924ad
--- /dev/null
+++ b/custom/bar/generated.nix
@@ -0,0 +1,35 @@
1{ mkDerivation, aeson, base, bytestring, case-insensitive
2, classy-prelude, classy-prelude-conduit, classy-prelude-yesod
3, conduit, containers, data-default, directory, fast-logger
4, fetchgit, file-embed, hashids, hjsmin, http-conduit, lens
5, monad-control, monad-logger, mtl, persistent
6, persistent-postgresql, persistent-template, safe, shakespeare
7, stdenv, systemd, template-haskell, text, thermoprint-client, time
8, unordered-containers, vector, wai, wai-extra, wai-logger, warp
9, yaml, yesod, yesod-auth, yesod-core, yesod-form, yesod-static
10}:
11mkDerivation {
12 pname = "bar";
13 version = "0.6.6";
14 src = fetchgit {
15 url = "git://git.yggdrasil.li/gkleen/pub/bar";
16 sha256 = "1nhvmqnsfcj2afbxsqgvdrq97rq7xls7w9w280dg6vyba8gipiwp";
17 rev = "76fe2bc3bf14fb3f4cbd892e680f61183ff6db83";
18 };
19 isLibrary = true;
20 isExecutable = true;
21 libraryHaskellDepends = [
22 aeson base bytestring case-insensitive classy-prelude
23 classy-prelude-conduit classy-prelude-yesod conduit containers
24 data-default directory fast-logger file-embed hashids hjsmin
25 http-conduit lens monad-control monad-logger mtl persistent
26 persistent-postgresql persistent-template safe shakespeare systemd
27 template-haskell text thermoprint-client time unordered-containers
28 vector wai wai-extra wai-logger warp yaml yesod yesod-auth
29 yesod-core yesod-form yesod-static
30 ];
31 executableHaskellDepends = [ base ];
32 doHaddock = false;
33 license = stdenv.lib.licenses.unfree;
34 hydraPlatforms = stdenv.lib.platforms.none;
35}
diff --git a/custom/bar/generated.nix.gup b/custom/bar/generated.nix.gup
new file mode 100644
index 00000000..eeb13ad2
--- /dev/null
+++ b/custom/bar/generated.nix.gup
@@ -0,0 +1,5 @@
1#!/usr/bin/env zsh
2
3gup -u ${2:r}.cabal
4cd ${2:h}
5cabal2nix --no-haddock "git://git.yggdrasil.li/gkleen/pub/bar" >! ${1}
diff --git a/custom/trivmix-service.nix b/custom/trivmix-service.nix
index fc69d93e..f278c7eb 100644
--- a/custom/trivmix-service.nix
+++ b/custom/trivmix-service.nix
@@ -5,8 +5,6 @@ with lib;
5let 5let
6 cfg = config.services.trivmix; 6 cfg = config.services.trivmix;
7 7
8 trivmix = pkgs.haskellPackages.callPackage ./trivmix {};
9
10 mixerModule = { 8 mixerModule = {
11 options = { 9 options = {
12 connectIn = mkOption { 10 connectIn = mkOption {
@@ -117,7 +115,11 @@ in {
117 }; 115 };
118 116
119 config = mkIf (cfg.mixers != {}) { 117 config = mkIf (cfg.mixers != {}) {
120 environment.systemPackages = [ trivmix ]; 118 nixpkgs.overlays = [(self: super: {
119 trivmix = self.haskellPackages.callPackage ./trivmix {};
120 })];
121
122 environment.systemPackages = with pkgs; [ trivmix ];
121 123
122 systemd.services = mapAttrs service cfg.mixers; 124 systemd.services = mapAttrs service cfg.mixers;
123 }; 125 };