feat: reorganize to one flake one rust project
This commit is contained in:
parent
5183130427
commit
e8b60519e7
23 changed files with 792 additions and 2144 deletions
159
flake.nix
159
flake.nix
|
|
@ -7,36 +7,135 @@
|
|||
url = "github:ryantm/agenix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
pi-service.url = "path:./pi/pi-service";
|
||||
remote.url = "path:./remote";
|
||||
remote.inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, agenix, pi-service, remote }: {
|
||||
nixosModules = remote.nixosModules;
|
||||
|
||||
nixosConfigurations.pi = nixpkgs.lib.nixosSystem {
|
||||
system = "aarch64-linux";
|
||||
modules = [
|
||||
agenix.nixosModules.default
|
||||
(import ./pi/module.nix {
|
||||
pkg = pi-service.packages.aarch64-linux.default;
|
||||
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.x86_64-linux.default = let
|
||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||
in pkgs.mkShell {
|
||||
packages = [ agenix.packages.x86_64-linux.default ];
|
||||
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
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue