141 lines
4.1 KiB
Nix
141 lines
4.1 KiB
Nix
{
|
|
description = "Noisebell - door monitor system";
|
|
|
|
inputs = {
|
|
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
|
agenix = {
|
|
url = "github:ryantm/agenix";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
crane.url = "github:ipetkov/crane";
|
|
rust-overlay = {
|
|
url = "github:oxalica/rust-overlay";
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
};
|
|
};
|
|
|
|
outputs = { self, nixpkgs, agenix, crane, rust-overlay }:
|
|
let
|
|
system = "x86_64-linux";
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
overlays = [ rust-overlay.overlays.default ];
|
|
};
|
|
|
|
# --- Remote services (x86_64-linux) ---
|
|
|
|
rustToolchain = pkgs.rust-bin.stable.latest.default;
|
|
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
|
|
|
src = pkgs.lib.cleanSourceWith {
|
|
src = ./.;
|
|
filter = path: type:
|
|
(builtins.match ".*\.png$" path != null) || (craneLib.filterCargoSources path type);
|
|
};
|
|
|
|
remoteArgs = {
|
|
inherit src;
|
|
pname = "noisebell";
|
|
version = "0.1.0";
|
|
strictDeps = true;
|
|
doCheck = false;
|
|
};
|
|
|
|
remoteArtifacts = craneLib.buildDepsOnly remoteArgs;
|
|
|
|
buildRemoteMember = name: craneLib.buildPackage (remoteArgs // {
|
|
cargoArtifacts = remoteArtifacts;
|
|
cargoExtraArgs = "-p ${name}";
|
|
});
|
|
|
|
noisebell-cache = buildRemoteMember "noisebell-cache";
|
|
noisebell-discord = buildRemoteMember "noisebell-discord";
|
|
noisebell-rss = buildRemoteMember "noisebell-rss";
|
|
|
|
# --- Pi service (cross-compiled to aarch64-linux) ---
|
|
|
|
crossPkgs = import nixpkgs {
|
|
inherit system;
|
|
crossSystem.config = "aarch64-unknown-linux-gnu";
|
|
overlays = [ rust-overlay.overlays.default ];
|
|
};
|
|
|
|
piRustToolchain = pkgs.rust-bin.stable.latest.default.override {
|
|
targets = [ "aarch64-unknown-linux-gnu" ];
|
|
};
|
|
|
|
piCraneLib = (crane.mkLib pkgs).overrideToolchain piRustToolchain;
|
|
|
|
piArgs = {
|
|
inherit src;
|
|
pname = "noisebell-pi";
|
|
version = "0.1.0";
|
|
strictDeps = true;
|
|
doCheck = false;
|
|
|
|
CARGO_BUILD_TARGET = "aarch64-unknown-linux-gnu";
|
|
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER =
|
|
"${crossPkgs.stdenv.cc.targetPrefix}cc";
|
|
TARGET_CC = "${crossPkgs.stdenv.cc.targetPrefix}cc";
|
|
CC_aarch64_unknown_linux_gnu = "${crossPkgs.stdenv.cc.targetPrefix}cc";
|
|
HOST_CC = "${pkgs.stdenv.cc.nativePrefix}cc";
|
|
|
|
depsBuildBuild = [ crossPkgs.stdenv.cc ];
|
|
cargoExtraArgs = "-p noisebell";
|
|
};
|
|
|
|
piArtifacts = piCraneLib.buildDepsOnly piArgs;
|
|
|
|
noisebell-pi = piCraneLib.buildPackage (piArgs // {
|
|
cargoArtifacts = piArtifacts;
|
|
});
|
|
|
|
in
|
|
{
|
|
packages.${system} = {
|
|
inherit noisebell-cache noisebell-discord noisebell-rss;
|
|
default = noisebell-cache;
|
|
};
|
|
|
|
packages.aarch64-linux = {
|
|
noisebell = noisebell-pi;
|
|
default = noisebell-pi;
|
|
};
|
|
|
|
nixosModules = {
|
|
cache = import ./remote/cache-service/module.nix noisebell-cache;
|
|
discord = import ./remote/discord-bot/module.nix noisebell-discord;
|
|
rss = import ./remote/rss-service/module.nix noisebell-rss;
|
|
default = { imports = [
|
|
(import ./remote/cache-service/module.nix noisebell-cache)
|
|
(import ./remote/discord-bot/module.nix noisebell-discord)
|
|
(import ./remote/rss-service/module.nix noisebell-rss)
|
|
]; };
|
|
};
|
|
|
|
nixosConfigurations.pi = nixpkgs.lib.nixosSystem {
|
|
system = "aarch64-linux";
|
|
modules = [
|
|
agenix.nixosModules.default
|
|
(import ./pi/module.nix {
|
|
pkg = noisebell-pi;
|
|
rev = self.shortRev or "dirty";
|
|
})
|
|
./pi/configuration.nix
|
|
./pi/hardware-configuration.nix
|
|
];
|
|
};
|
|
|
|
nixosConfigurations.bootstrap = nixpkgs.lib.nixosSystem {
|
|
system = "aarch64-linux";
|
|
modules = [ ./pi/bootstrap.nix ];
|
|
};
|
|
|
|
devShells.${system}.default = craneLib.devShell {
|
|
packages = [
|
|
pkgs.rust-analyzer
|
|
agenix.packages.${system}.default
|
|
];
|
|
};
|
|
};
|
|
}
|