From c88ee737b8c44162c640a4c865336c5a843029ea Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 8 Sep 2018 14:37:34 +0200 Subject: Simplify bragi, move bar to odin --- custom/bar-service.nix | 99 ++++++++++++++++++++++++++++++++++++++++++++ custom/bar/default.nix | 47 +++++++++++++++++++++ custom/bar/generated.nix | 35 ++++++++++++++++ custom/bar/generated.nix.gup | 5 +++ custom/trivmix-service.nix | 8 ++-- 5 files changed, 191 insertions(+), 3 deletions(-) create mode 100644 custom/bar-service.nix create mode 100644 custom/bar/default.nix create mode 100644 custom/bar/generated.nix create mode 100644 custom/bar/generated.nix.gup (limited to 'custom') 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 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.bar; +in { + options.services.bar = { + enable = mkEnableOption "the Bar Inventory System"; + + user = mkOption { + type = types.str; + default = "bar"; + description = "User to execute the daemon under"; + }; + + group = mkOption { + type = types.str; + default = "bar"; + description = "Group to execute the daemon under"; + }; + + stateDir = mkOption { + type = types.path; + default = "/var/lib/bar"; + description = "Directory for the daemon to store semi-transient state (encryption keys etc.)"; + }; + + port = mkOption { + type = types.int; + default = 8080; + description = "Port for the daemon to listen on"; + }; + + host = mkOption { + type = types.str; + default = "localhost"; + description = "Host to bind to"; + }; + + approot = mkOption { + type = types.str; + default = "/"; + description = "Subdirectory of the daemon-managed site relative to HTTP /; only useful when using a reverse proxy"; + }; + + thermoprintBaseURL = mkOption { + type = with types; nullOr types.str; + default = null; + example = "http://localhost:80/thermoprint/api"; + description = "Thermoprint base url"; + }; + }; + + config = mkIf cfg.enable { + assertions = [ + { assertion = config.services.postgresql.enable; + message = "bar requires PostgreSQL"; + } + ]; + + users.users."${cfg.user}" = { + group = cfg.group; + description = "User for the Bar Inventory System"; + isSystemUser = true; + home = cfg.stateDir; + createHome = true; + }; + + users.groups."${cfg.group}" = {}; + + nixpkgs.overlays = [(self: super: { + bar = self.callPackage ./bar { inherit (self) haskellPackages; }; + })]; + + systemd.services."bar" = { + environment = { + PORT = cfg.port; + HOST = cfg.host; + APPROOT = cfg.approot; + IP_FROM_HEADER = cfg.ipFromHeader; + TPRINT_BASEURL = mkIf (cfg.thermoprintBaseURL != null) cfg.thermoprintBaseURL; + }; + + bindsTo = [ "postgresql.service" ]; + after = [ "postgresql.service" ]; + wantedBy = [ "default.target" ]; + + serviceConfig = { + Type = "notify"; + User = cfg.user; + Group = cfg.group; + WorkingDirectory = cfg.stateDir; + + ExecStart = with pkgs; "${bar}/bin/bar"; + }; + }; + }; +} 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 @@ +{ haskellPackages +, stdenv +, fetchFromGitHub +, fetchurl +, haskell +}: + +let + pkg = haskellPackages.callPackage ./generated.nix {}; + webshim = stdenv.mkDerivation rec { + name = "webshim-${version}"; + version = "1.16.0"; + src = fetchFromGitHub { + owner = "aFarkas"; + repo = "webshim"; + rev = "1.16.0"; + sha256 = "14pk7hljqipzp0n7vpgcfxr3w4bla57cwyd7bmwmmxrm2zn62cyh"; + }; + + installPhase = '' + mkdir -p $out/js + cp -r $src/js-webshim/dev/* $out/js/ + ''; + }; + jquery = stdenv.mkDerivation rec { + name = "jquery-${version}"; + version = "3.3.1"; + src = fetchurl { + url = "https://github.com/jquery/jquery/archive/${version}.tar.gz"; + sha256 = "1d1pilrwiz0yjx27cd7gbn8qar6hw5zgwjhpsyaijcg52z82wi5q"; + }; + + installPhase = '' + mkdir -p $out/js + cp -r dist/jquery.js $out/js/ + ''; + }; +in stdenv.lib.overrideDerivation pkg (drv: { + postUnpack = '' + ( + cd bar-*/static + rm -rf jquery.js webshim + ln -vs ${jquery}/js/jquery.js . + ln -vs ${webshim}/js webshim + ) + ''; +}) 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 @@ +{ mkDerivation, aeson, base, bytestring, case-insensitive +, classy-prelude, classy-prelude-conduit, classy-prelude-yesod +, conduit, containers, data-default, directory, fast-logger +, fetchgit, file-embed, hashids, hjsmin, http-conduit, lens +, monad-control, monad-logger, mtl, persistent +, persistent-postgresql, persistent-template, safe, shakespeare +, stdenv, systemd, template-haskell, text, thermoprint-client, time +, unordered-containers, vector, wai, wai-extra, wai-logger, warp +, yaml, yesod, yesod-auth, yesod-core, yesod-form, yesod-static +}: +mkDerivation { + pname = "bar"; + version = "0.6.6"; + src = fetchgit { + url = "git://git.yggdrasil.li/gkleen/pub/bar"; + sha256 = "1nhvmqnsfcj2afbxsqgvdrq97rq7xls7w9w280dg6vyba8gipiwp"; + rev = "76fe2bc3bf14fb3f4cbd892e680f61183ff6db83"; + }; + isLibrary = true; + isExecutable = true; + libraryHaskellDepends = [ + aeson base bytestring case-insensitive classy-prelude + classy-prelude-conduit classy-prelude-yesod conduit containers + data-default directory fast-logger file-embed hashids hjsmin + http-conduit lens monad-control monad-logger mtl persistent + persistent-postgresql persistent-template safe shakespeare systemd + template-haskell text thermoprint-client time unordered-containers + vector wai wai-extra wai-logger warp yaml yesod yesod-auth + yesod-core yesod-form yesod-static + ]; + executableHaskellDepends = [ base ]; + doHaddock = false; + license = stdenv.lib.licenses.unfree; + hydraPlatforms = stdenv.lib.platforms.none; +} 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 @@ +#!/usr/bin/env zsh + +gup -u ${2:r}.cabal +cd ${2:h} +cabal2nix --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; let cfg = config.services.trivmix; - trivmix = pkgs.haskellPackages.callPackage ./trivmix {}; - mixerModule = { options = { connectIn = mkOption { @@ -117,7 +115,11 @@ in { }; config = mkIf (cfg.mixers != {}) { - environment.systemPackages = [ trivmix ]; + nixpkgs.overlays = [(self: super: { + trivmix = self.haskellPackages.callPackage ./trivmix {}; + })]; + + environment.systemPackages = with pkgs; [ trivmix ]; systemd.services = mapAttrs service cfg.mixers; }; -- cgit v1.2.3