Add support for building natter via nix.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
/result
|
||||
|
||||
@@ -48,7 +48,7 @@ default = ["tracing"]
|
||||
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
||||
|
||||
# Optimized build for any sort of release.
|
||||
[profile.release-lto]
|
||||
[profile.lto]
|
||||
inherits = "release"
|
||||
lto = true
|
||||
strip = "symbols"
|
||||
|
||||
48
flake.lock
generated
Normal file
48
flake.lock
generated
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1780749050,
|
||||
"narHash": "sha256-3av0pIjlOWQ6rDbNOmpUSvbNnJkGORQKKjb4LtCZsIY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "a799d3e3886da994fa307f817a6bc705ae538eeb",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"rust-overlay": "rust-overlay"
|
||||
}
|
||||
},
|
||||
"rust-overlay": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1781407245,
|
||||
"narHash": "sha256-VzJq4MmD0uyNDAceudSe1hHqcQMe9Tau0U4S+5iRGh0=",
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"rev": "d5f483210eb016d66102eef22baa128b3b3233fc",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "oxalica",
|
||||
"repo": "rust-overlay",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
86
flake.nix
Normal file
86
flake.nix
Normal file
@@ -0,0 +1,86 @@
|
||||
{
|
||||
description = "Natter static site generator";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
rust-overlay = {
|
||||
url = "github:oxalica/rust-overlay";
|
||||
inputs = {
|
||||
nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
rust-overlay,
|
||||
}:
|
||||
let
|
||||
forAllSystems =
|
||||
func:
|
||||
builtins.listToAttrs (
|
||||
map (system: {
|
||||
name = system;
|
||||
value = func system;
|
||||
}) nixpkgs.lib.systems.flakeExposed
|
||||
);
|
||||
in
|
||||
{
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml);
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
nativeBuildInputs = [
|
||||
rustToolchain
|
||||
];
|
||||
buildInputs = with pkgs; [
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
packages = forAllSystems (
|
||||
system:
|
||||
let
|
||||
overlays = [ (import rust-overlay) ];
|
||||
pkgs = import nixpkgs {
|
||||
inherit system overlays;
|
||||
};
|
||||
appliedOverlay = self.overlays.default pkgs pkgs;
|
||||
in
|
||||
rec {
|
||||
default = release;
|
||||
inherit (appliedOverlay.natter)
|
||||
release
|
||||
;
|
||||
docker_env = pkgs.buildEnv {
|
||||
name = "natter";
|
||||
paths = with pkgs; [
|
||||
appliedOverlay.natter.release
|
||||
bash
|
||||
uutils-coreutils-noprefix
|
||||
# toybox # Smaller than uutils-coreutils?
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
overlays.default = final: prev: {
|
||||
natter = final.lib.makeScope final.newScope (natterScope: {
|
||||
release = (
|
||||
natterScope.callPackage ./nix/package.nix {
|
||||
inherit rust-overlay;
|
||||
buildType = "lto";
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
};
|
||||
}
|
||||
82
nix/package.nix
Normal file
82
nix/package.nix
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
hello,
|
||||
lib,
|
||||
pkgs,
|
||||
rust-overlay,
|
||||
|
||||
targetBins ? [ ],
|
||||
features ? [ ],
|
||||
cargoBuildTarget ? null,
|
||||
buildType ? null,
|
||||
buildLib ? false,
|
||||
}:
|
||||
let
|
||||
cargoToml = (lib.importTOML ../Cargo.toml);
|
||||
rustPlatformFor =
|
||||
pkgs:
|
||||
let
|
||||
rust-bin = rust-overlay.lib.mkRustBin { } pkgs;
|
||||
rustToolchain = (rust-bin.fromRustupToolchainFile ../rust-toolchain.toml).override (
|
||||
if cargoBuildTarget != null then
|
||||
{
|
||||
targets = [ cargoBuildTarget ];
|
||||
}
|
||||
else
|
||||
{ }
|
||||
);
|
||||
baseRustPlatform = (
|
||||
pkgs.makeRustPlatform {
|
||||
cargo = rustToolchain;
|
||||
rustc = rustToolchain;
|
||||
}
|
||||
);
|
||||
rustPlatform =
|
||||
if cargoBuildTarget != null then
|
||||
baseRustPlatform.overrideScope (
|
||||
final: prev: {
|
||||
cargoBuildHook = prev.cargoBuildHook.overrideDerivation (_: {
|
||||
rustcTargetSpec = cargoBuildTarget;
|
||||
});
|
||||
cargoInstallHook = hello;
|
||||
}
|
||||
)
|
||||
else
|
||||
baseRustPlatform;
|
||||
in
|
||||
rustPlatform;
|
||||
in
|
||||
(rustPlatformFor pkgs).buildRustPackage (
|
||||
# rustPlatform.buildRustPackage (
|
||||
{
|
||||
pname = "natter";
|
||||
version = cargoToml.package.version;
|
||||
src = lib.cleanSource ../.;
|
||||
|
||||
cargoLock.lockFile = ../Cargo.lock;
|
||||
|
||||
cargoBuildFlags = builtins.concatLists [
|
||||
(builtins.concatMap (targetBin: [
|
||||
"--bin"
|
||||
targetBin
|
||||
]) targetBins)
|
||||
(if buildLib then [ "--lib" ] else [ ])
|
||||
(
|
||||
if features != [ ] then
|
||||
[
|
||||
"--features"
|
||||
(builtins.concatStringsSep " " features)
|
||||
]
|
||||
else
|
||||
[ ]
|
||||
)
|
||||
];
|
||||
}
|
||||
// (
|
||||
if buildType != null then
|
||||
{
|
||||
buildType = buildType;
|
||||
}
|
||||
else
|
||||
{ }
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user