naerskify

This commit is contained in:
Astro 2022-06-04 02:33:45 +02:00
parent a8d23455bd
commit 56b8c193ad
4 changed files with 143 additions and 64 deletions

View File

@ -1,41 +0,0 @@
{ pkgs ? import <nixpkgs> {},
}:
let
src = builtins.filterSource (path: type:
!builtins.elem (baseNameOf path) [
"target"
"default.nix"
"shell.nix"
"nixos-module.nix"
]
) ./.;
build = { pname, cargoSha256 }: pkgs.rustPlatform.buildRustPackage {
inherit pname cargoSha256 src;
version = "0.1.0";
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [
openssl
postgresql.lib
];
preBuild = "pushd ${pname}";
postBuild = "popd";
};
in {
ticker-update = build {
pname = "ticker-update";
cargoSha256 = "0hgxxlvpq8mywjmdhyaxfcp117yryfyb4j5m35ahrnmphlqk5lks";
};
ticker-serve = (build {
pname = "ticker-serve";
cargoSha256 = "1zsk3lpjq1czn7hq4lzi04w0wzwrwpj1avq3p9jk76ypwm6i42ck";
}).overrideAttrs (oa: {
postBuild = ''
${oa.postBuild}
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/
'';
});
}

View File

@ -1,5 +1,46 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1654237591,
"narHash": "sha256-+uOzx9fuo3CBHO7aGI+SKxDXpf/7NTOXi0g4UxOdk9k=",
"owner": "nix-community",
"repo": "fenix",
"rev": "8dccfbe51a8adea643ec29a4ec516499a5a081c6",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"naersk": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1653413650,
"narHash": "sha256-wojDHjb+eU80MPH+3HQaK0liUy8EgR95rvmCl24i58Y=",
"owner": "nmattia",
"repo": "naersk",
"rev": "69daaceebe12c070cd5ae69ba38f277bbf033695",
"type": "github"
},
"original": {
"owner": "nmattia",
"repo": "naersk",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1654126564,
@ -16,7 +57,42 @@
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"fenix": "fenix",
"naersk": "naersk",
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1654178556,
"narHash": "sha256-LG8J9E/wMBolkWS3VstuvhgQ4jOp3Nk328EXlCYY24U=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "88024c7ec2d44a8be8bf05a6580409200cf726fc",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"utils": {
"locked": {
"lastModified": 1653893745,
"narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
}
},

View File

@ -1,28 +1,72 @@
{
description = "Ticker calendar aggregator";
inputs = {
utils.url = "github:numtide/flake-utils";
naersk.url = "github:nmattia/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs }:
let
systems = [ "x86_64-linux" "i686-linux" "aarch64-linux" ];
forSystems = nixpkgs.lib.genAttrs systems;
in rec {
packages = forSystems (system:
import ./default.nix {
pkgs = nixpkgs.legacyPackages.${system};
}
);
outputs = { self, nixpkgs, utils, fenix, naersk }:
utils.lib.eachSystem (with utils.lib.system; [ x86_64-linux aarch64-linux ]) (system: let
pkgs = nixpkgs.legacyPackages."${system}";
defaultPackage = forSystems (system:
self.packages.${system}.ticker-serve
);
rust = fenix.packages.${system}.stable.withComponents [
"cargo"
"rustc"
"rust-src" # just for rust-analyzer
"clippy"
];
hydraJobs =
packages.${builtins.head systems};
devShell = import ./shell.nix {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
# Override the version used in naersk
naersk-lib = naersk.lib."${system}".override {
cargo = rust;
rustc = rust;
};
nixosModule = import ./nixos-module.nix;
buildRustPackage = args: naersk-lib.buildPackage ({
src = ./.;
targets = [ args.pname ];
cargoBuildOptions = opts: opts ++ [ "-p" args.pname ];
nativeBuildInputs = with pkgs; [ pkg-config ];
buildInputs = with pkgs; [ openssl postgresql.lib ];
} // args);
in rec {
# `nix build`
packages.ticker-update = buildRustPackage {
pname = "ticker-update";
};
packages.ticker-serve = buildRustPackage {
pname = "ticker-serve";
overrideMain = x: {
installPhase = ''
${x.installPhase}
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/
'';
};
};
checks = packages;
# `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;
};
nixosModules = rec {
ticker = import ./nixos-module.nix self;
default = ticker;
};
};
}

View File

@ -1,8 +1,8 @@
self:
{ pkgs, config, lib, ... }:
with import ./. { inherit pkgs; };
let
inherit (self.packages.${pkgs.system}) ticker-update ticker-serve;
inherit (pkgs.lib) mkOption types;
cfg = config.services.ticker;
defaultTickerConfig = {