citadel

My dotfiles, scripts and nix configs
git clone git://jb55.com/citadel
Log | Files | Refs | README | LICENSE

default.nix (1862B)


      1 extra:
      2 { config, lib, pkgs, ... }:
      3 with lib;
      4 let private   = extra.private;
      5     foldAttr  = lib.lists.fold (a: b: a // b) {};
      6     foldMap   = fn: foldAttr (map fn private.pokemaps);
      7     mkName    = def: "pogom-${def.subdomain}";
      8     mkOptions = def: { "${mkName def}" = { enable = mkEnableOption "PokemonGO-Map, ${def.subdomain}";}; };
      9     mkService = def: mkIf config.services."${mkName def}".enable (services def);
     10     pythonEnv = import ./requirements.nix {};
     11     pokemonMap = pkgs.fetchFromGitHub {
     12       owner  = "jb55";
     13       repo   = "PokemonGo-Map";
     14       rev    = "a63721bfadc318b1f158f53e0cc532a4e16091ef";
     15       sha256 = "11m8h38glpbm2va4xxjfsvpigfmmjf531w1db2nqfccnkw872k75";
     16     };
     17     services = def: {
     18       "${mkName def}" = {
     19         description = "PokemonGO-Map, ${def.subdomain}";
     20 
     21         wantedBy = [ "multi-user.target" ];
     22 
     23         environment = {
     24           AUTH_SERVICE = def.service;
     25           USERNAME = def.user;
     26           PASSWORD = def.pass;
     27           LOCATION = def.location;
     28           GMAPS_KEY = def.mapkey;
     29           STEP_COUNT = "5";
     30           PORT = def.port;
     31         };
     32 
     33         serviceConfig.Type = "simple";
     34         serviceConfig.ExecStartPre = "${pkgs.coreutils}/bin/mkdir -p /var/db/pogom";
     35         serviceConfig.ExecStart = pkgs.writeScript "run-pogom" ''
     36           #!${pkgs.bash}/bin/bash
     37           ${pythonEnv.interpreter}/bin/python ${pokemonMap}/runserver.py \
     38             -a "$AUTH_SERVICE" \
     39             -u "$USERNAME" \
     40             -p "$PASSWORD" \
     41             -l "$LOCATION" \
     42             -st $STEP_COUNT \
     43             -D /var/db/pogom/pogom-${def.subdomain}.db \
     44             -wh "https://jb55.com/pogom" \
     45             -H 0.0.0.0 \
     46             -P $PORT \
     47             -k $GMAPS_KEY
     48         '';
     49       };
     50     };
     51 in { options.services        = foldMap mkOptions;
     52      config.systemd.services = foldMap mkService;
     53    }