ticker/flake.nix

80 lines
2.4 KiB
Nix
Raw Permalink Normal View History

2021-03-08 23:11:40 +01:00
{
2022-06-04 02:33:45 +02:00
inputs = {
utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
2022-06-04 02:33:45 +02:00
naersk.inputs.nixpkgs.follows = "nixpkgs";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
2021-03-08 23:11:40 +01:00
2022-06-04 02:33:45 +02:00
outputs = { self, nixpkgs, utils, fenix, naersk }:
utils.lib.eachSystem (with utils.lib.system; [ x86_64-linux aarch64-linux ]) (system: let
pkgs = nixpkgs.legacyPackages."${system}";
rust = fenix.packages.${system}.stable.withComponents [
"cargo"
"rustc"
"rust-src" # just for rust-analyzer
"clippy"
];
# Override the version used in naersk
naersk-lib = naersk.lib."${system}".override {
cargo = rust;
rustc = rust;
};
buildRustPackage = args: naersk-lib.buildPackage ({
version =
let
inherit (self) lastModifiedDate;
year = builtins.substring 0 4 lastModifiedDate;
month = builtins.substring 4 2 lastModifiedDate;
day = builtins.substring 6 2 lastModifiedDate;
in "0.1.0-${year}-${month}-${day}";
2022-06-04 02:33:45 +02:00
src = ./.;
targets = [ args.pname ];
cargoBuildOptions = opts: opts ++ [ "-p" args.pname ];
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl postgresql.lib ];
} // args);
2021-03-13 03:44:39 +01:00
in rec {
2022-06-04 02:33:45 +02:00
# `nix build`
packages.ticker-update = buildRustPackage {
pname = "ticker-update";
};
packages.ticker-serve = buildRustPackage {
pname = "ticker-serve";
overrideMain = x: {
installPhase = ''
${x.installPhase}
2021-03-08 23:11:40 +01:00
2022-06-04 02:33:45 +02:00
mkdir -p $out/shared/libticker $out/shared/ticker-serve
cp -ar ticker-serve/static $out/shared/ticker-serve/
cp -ar schema.sql $out/shared/libticker/
'';
};
};
2021-03-08 23:11:40 +01:00
2022-06-04 02:33:45 +02:00
checks = packages;
2021-03-13 03:44:39 +01:00
2022-06-04 02:33:45 +02:00
# `nix develop`
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
fenix.packages.${system}.rust-analyzer
] ++ (with packages.ticker-serve;
nativeBuildInputs ++ buildInputs
);
};
}) // rec {
overlays.default = final: prev: {
inherit (self.packages.${prev.system}) ticker-update ticker-serve;
2021-03-08 23:11:40 +01:00
};
2022-06-04 02:33:45 +02:00
nixosModules = rec {
ticker = import ./nixos-module.nix self;
default = ticker;
};
2021-03-08 23:11:40 +01:00
};
}