flake.nix: init

This commit is contained in:
Jeremy Baxter 2024-10-26 20:11:08 +13:00
parent 7fabc826c7
commit e7fe37458b
2 changed files with 124 additions and 0 deletions

27
flake.lock generated Normal file
View file

@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1729665710,
"narHash": "sha256-AlcmCXJZPIlO5dmFzV3V2XF6x/OpNWUV8Y/FMPGd8Z4=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2768c7d042a37de65bb1b5b3268fc987e534c49d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

97
flake.nix Normal file
View file

@ -0,0 +1,97 @@
{
description = "filesystem monitor";
inputs = {
nixpkgs.url = github:NixOS/nixpkgs/nixos-unstable;
};
outputs = { self, nixpkgs }:
let
plats = nixpkgs.lib.platforms.unix;
forAllSystems = fn:
nixpkgs.lib.genAttrs plats (system:
fn (import nixpkgs {
inherit system;
})
);
in
{
packages = forAllSystems (pkgs: {
default = pkgs.stdenv.mkDerivation (finalAttrs: {
name = "bluetop";
src = ./.;
# overridable attributes
fileSystems = ["/"];
indexPage = null;
nativeBuildInputs = with pkgs; [ ldc ];
postPatch =
let
mounts = toString (pkgs.lib.forEach finalAttrs.fileSystems (f: ''"${f}",''));
in
''
${if finalAttrs.indexPage != null
then "install -Dm644 ${finalAttrs.indexPage} static/index.html"
else ""}
sed -E 's:mountpoints = \[.+\];$:mountpoints = \[${mounts}\];:' buildconf.d | tee buildconf.d
'';
dontAddPrefix = true;
enableParallelBuilding = true;
installFlags = [
"DESTDIR=$(out)"
"PREFIX=/"
];
meta.mainProgram = "bluetopd";
});
});
nixosModule = { config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.bluetop;
in
{
options = {
services.bluetop = {
enable = mkEnableOption "bluetop, a status page displaying storage statistics";
package = mkPackageOption pkgs "bluetop" { };
openFirewall = mkOption {
type = types.bool;
default = false;
description = "Whether to open the bluetop port to the firewall.";
};
port = mkOption {
type = types.port;
default = 8089;
description = "Port for bluetop to bind to.";
};
};
};
config = mkIf cfg.enable {
users.groups.bluetop = {};
users.users.bluetop = {
description = "bluetop service user";
group = "bluetop";
isSystemUser = true;
};
systemd.services.bluetopd = {
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = ''
set -eu
${getExe cfg.package} --port ${toString cfg.port}
'';
};
networking.firewall = mkIf cfg.openFirewall {
allowedTCPPorts = [ cfg.port ];
};
};
};
};
}