ifconfig.io/flake.nix

108 lines
3.2 KiB
Nix
Raw Permalink Normal View History

2020-11-16 02:05:14 +00:00
{
inputs = {
2020-11-17 17:36:21 +00:00
nixpkgs.url = "github:nixos/nixpkgs";
2020-11-16 02:05:14 +00:00
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = { self, nixpkgs, ... }:
let
version = builtins.replaceStrings [ "\n" ] [ "" ]
(builtins.readFile ./.version + versionSuffix);
2023-11-26 22:35:43 +00:00
versionSuffix =
if officialRelease then
""
else
"pre${
2020-11-16 02:05:14 +00:00
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 ];
});
2023-11-26 22:35:43 +00:00
in
{
2020-11-16 02:05:14 +00:00
overlay = final: prev: {
ifconfigio = with final;
with pkgs;
(buildGoModule {
name = "ifconfig.io-${version}";
src = self;
2024-12-29 15:30:13 +00:00
vendorHash = "sha256-a9ZKlkYtvet7w32wLb/iZ3vh1Rdx5QlFBuf53PlKUa4=";
2020-11-16 02:05:14 +00:00
2022-01-05 17:23:33 +00:00
tags = [ "jsoniter" ];
2020-11-16 02:05:14 +00:00
postInstall = ''
mkdir -p $out/usr/lib/ifconfig.io/
cp -r ./templates $out/usr/lib/ifconfig.io
'';
});
2020-11-17 02:42:21 +00:00
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=" ];
};
});
2020-11-16 02:05:14 +00:00
};
2020-11-17 02:42:21 +00:00
packages = forAllSystems (system: {
inherit (nixpkgsFor.${system}) ifconfigio ifconfigio-docker;
});
2020-11-16 02:05:14 +00:00
defaultPackage =
forAllSystems (system: self.packages.${system}.ifconfigio);
2023-11-26 22:35:43 +00:00
nixosModules.ifconfigio = { pkgs, lib, ... }: {
2020-11-16 02:05:14 +00:00
nixpkgs.overlays = [ self.overlay ];
users.users.ifconfigio = {
description = "ifconfig.io daemon user";
group = "ifconfigio";
isSystemUser = true;
2023-11-26 22:35:43 +00:00
home = "/opt/ifconfig";
2020-11-16 02:05:14 +00:00
};
users.groups.ifconfigio = { };
2023-11-26 22:35:43 +00:00
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;
};
};
2020-11-16 02:05:14 +00:00
};
};
}