-
-
Notifications
You must be signed in to change notification settings - Fork 124
/
flake.nix
107 lines (95 loc) · 3.15 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, ... }:
let
version = builtins.replaceStrings [ "\n" ] [ "" ]
(builtins.readFile ./.version + versionSuffix);
versionSuffix =
if officialRelease then
""
else
"pre${
nixpkgs.lib.substring 0 8 (self.lastModifiedDate or self.lastModified)
}_${self.shortRev or "dirty"}";
officialRelease = false;
systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" "x86_64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
# Memoize nixpkgs for different platforms for efficiency.
nixpkgsFor = forAllSystems (system:
import nixpkgs {
inherit system;
overlays = [ self.overlay ];
});
in
{
overlay = final: prev: {
ifconfigio = with final;
with pkgs;
(buildGoModule {
name = "ifconfig.io-${version}";
src = self;
vendorHash = "sha256-3PT/0sxn5LCx6nt0U3TFuBKCdSkKVrV5akotUfIvI04=";
tags = [ "jsoniter" ];
postInstall = ''
mkdir -p $out/usr/lib/ifconfig.io/
cp -r ./templates $out/usr/lib/ifconfig.io
'';
});
ifconfigio-docker = with final;
with pkgs;
(dockerTools.buildLayeredImage {
name = "ifconfig.io";
tag = version;
created = "now";
contents = [ ifconfigio busybox ];
config = {
Cmd = "/bin/ifconfig.io";
WorkingDir = "/usr/lib/ifconfig.io";
ExposedPorts = { "8080" = { }; };
Env = [ "HOSTNAME=ifconfig.io" "TLS=0" "TLSCERT=" "TLSKEY=" ];
};
});
};
packages = forAllSystems (system: {
inherit (nixpkgsFor.${system}) ifconfigio ifconfigio-docker;
});
defaultPackage =
forAllSystems (system: self.packages.${system}.ifconfigio);
nixosModules.ifconfigio = { pkgs, lib, ... }: {
nixpkgs.overlays = [ self.overlay ];
users.users.ifconfigio = {
description = "ifconfig.io daemon user";
group = "ifconfigio";
isSystemUser = true;
home = "/opt/ifconfig";
};
users.groups.ifconfigio = { };
systemd.services.ifconfigio = {
description = "ifconfig.io web service";
enable = true;
wantedBy = [ "multi-user.target" ];
environment = {
GIN_MODE = lib.mkDefault "release";
TLS = lib.mkDefault "0";
};
script = ''
# For some reason the systemd WorkingDir is not doing what we need
# so we `cd` to it explicitly.
cd "${pkgs.ifconfigio}/usr/lib/ifconfig.io"
exec "${pkgs.ifconfigio}/bin/ifconfig.io"
'';
serviceConfig = {
User = "ifconfigio";
WorkingDir = "${pkgs.ifconfigio}/usr/lib/ifconfig.io";
LimitNOFILE = 200000;
};
};
};
};
}