module works
This commit is contained in:
parent
10cf66ae53
commit
6bb712db98
2 changed files with 65 additions and 65 deletions
33
flake.nix
33
flake.nix
|
|
@ -7,21 +7,20 @@
|
||||||
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
|
inputs.gomod2nix.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils";
|
inputs.gomod2nix.inputs.flake-utils.follows = "flake-utils";
|
||||||
|
|
||||||
outputs = inputs @ { self, nixpkgs, flake-utils, gomod2nix }:
|
outputs = inputs@{ self, nixpkgs, flake-utils, gomod2nix }:
|
||||||
(flake-utils.lib.eachDefaultSystem
|
(flake-utils.lib.eachDefaultSystem (system:
|
||||||
(system:
|
let
|
||||||
let
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
callPackage =
|
||||||
callPackage = pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
|
pkgs.darwin.apple_sdk_11_0.callPackage or pkgs.callPackage;
|
||||||
in
|
in {
|
||||||
{
|
packages.default = callPackage ./. {
|
||||||
packages.default = callPackage ./. {
|
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
|
||||||
inherit (gomod2nix.legacyPackages.${system}) buildGoApplication;
|
};
|
||||||
};
|
devShells.default = callPackage ./shell.nix {
|
||||||
devShells.default = callPackage ./shell.nix {
|
inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix;
|
||||||
inherit (gomod2nix.legacyPackages.${system}) mkGoEnv gomod2nix;
|
};
|
||||||
};
|
})) // {
|
||||||
nixosModules.default = import ./module.nix inputs;
|
nixosModules.default = import ./module.nix inputs;
|
||||||
})
|
};
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
97
module.nix
97
module.nix
|
|
@ -4,61 +4,62 @@ let
|
||||||
inherit (pkgs.stdenv.hostPlatform) system;
|
inherit (pkgs.stdenv.hostPlatform) system;
|
||||||
cfg = config.services.birdtown-visit-counter;
|
cfg = config.services.birdtown-visit-counter;
|
||||||
inherit (lib) types mkOption mkIf;
|
inherit (lib) types mkOption mkIf;
|
||||||
package = inputs.self.packages."${system}".birdtown-visit-counter;
|
package = inputs.self.packages."${system}".default;
|
||||||
in {
|
in {
|
||||||
options.services.birdtown-visit-counter = {
|
options.services.birdtown-visit-counter = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = false;
|
default = false;
|
||||||
};
|
};
|
||||||
listenPort = mkOption {
|
listenPort = mkOption {
|
||||||
type = types.int;
|
type = types.int;
|
||||||
default = 11567;
|
default = 11568;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
users.users.birdtown-visit-counter = {
|
||||||
|
group = "birdtown-visit-counter";
|
||||||
|
home = "/var/lib/birdtown-visit-counter";
|
||||||
|
isSystemUser = true;
|
||||||
|
createHome = true;
|
||||||
|
};
|
||||||
|
users.groups.birdtown-visit-counter = { };
|
||||||
|
|
||||||
|
systemd.services.birdtown-visit-counter = {
|
||||||
|
after = [ "network.target" ];
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
serviceConfig = {
|
||||||
|
ExecStart =
|
||||||
|
"${package}/bin/birdtown-visit-counter -addr :${toString cfg.listenPort} -file visits.json";
|
||||||
|
User = "birdtown-visit-counter";
|
||||||
|
Group = "birdtown-visit-counter";
|
||||||
|
WorkingDirectory = "/var/lib/birdtown-visit-counter";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
|
||||||
users.users.birdtown-visit-counter = {
|
|
||||||
group = "birdtown-visit-counter";
|
|
||||||
home = "/var/lib/birdtown-visit-counter";
|
|
||||||
isSystemUser = true;
|
|
||||||
createHome = true;
|
|
||||||
};
|
|
||||||
users.groups.birdtown-visit-counter = { };
|
|
||||||
|
|
||||||
systemd.services.birdtown-visit-counter = {
|
systemd.timers.birdtown-visits-saver = {
|
||||||
after = [ "network.target" ];
|
wantedBy = [ "timers.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
timerConfig = {
|
||||||
serviceConfig = {
|
OnBootSec = "10m";
|
||||||
ExecStart = "${package}/bin/birdtown-visit-counter -addr :${cfg.listenPort} -file visits.json";
|
OnUnitActiveSec = "10m";
|
||||||
User = "birdtown-visit-counter";
|
Unit = "birdtown-visits-saver.service";
|
||||||
Group = "birdtown-visit-counter";
|
|
||||||
WorkingDirectory = "/var/lib/birdtown-visit-counter";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
systemd.timers.birdtown-visits-saver = {
|
systemd.services.birdtown-visits-saver = {
|
||||||
wantedBy = [ "timers.target" ];
|
script = ''
|
||||||
timerConfig = {
|
set -eu
|
||||||
OnBootSec = "10m";
|
if ${pkgs.curl}/bin/curl http://localhost:${toString cfg.listenPort}/visits > visits-new.json; then
|
||||||
OnUnitActiveSec = "10m";
|
cp visits-new.json "$(date +"%Y-%m-%d-%H-%M").json"
|
||||||
Unit = "birdtown-visits-saver.service";
|
mv visits-new.json visits.json
|
||||||
};
|
fi
|
||||||
};
|
'';
|
||||||
|
serviceConfig = {
|
||||||
systemd.services.birdtown-visits-saver = {
|
Type = "oneshot";
|
||||||
script = ''
|
User = "birdtown-visit-counter";
|
||||||
set -eu
|
Group = "birdtown-visit-counter";
|
||||||
if ${pkgs.curl}/bin/curl http://localhost:${cfg.listenPort}/visits > visits-new.json; then
|
WorkingDirectory = "/var/lib/birdtown-visit-counter";
|
||||||
cp visits-new.json "$(date +"%Y-%m-%d-%H-%M").json"
|
|
||||||
mv visits-new.json visits.json
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "oneshot";
|
|
||||||
User = "birdtown-visit-counter";
|
|
||||||
Group = "birdtown-visit-counter";
|
|
||||||
WorkingDirectory = "/var/lib/birdtown-visit-counter";
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue