summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--flake.lock21
-rw-r--r--flake.nix7
-rw-r--r--nix/deployment/default.nix (renamed from nix/deployment.nix)23
-rw-r--r--nix/deployment/module.nix (renamed from nix/module.nix)0
-rw-r--r--nix/deployment/static.nix50
-rw-r--r--nix/derivation.nix14
-rw-r--r--nix/packages.nix12
-rw-r--r--nix/static.nix38
8 files changed, 66 insertions, 99 deletions
diff --git a/flake.lock b/flake.lock
index 4ccaa56..bd8068d 100644
--- a/flake.lock
+++ b/flake.lock
@@ -80,26 +80,6 @@
"type": "github"
}
},
- "naersk": {
- "inputs": {
- "nixpkgs": [
- "nixpkgs"
- ]
- },
- "locked": {
- "lastModified": 1698420672,
- "narHash": "sha256-/TdeHMPRjjdJub7p7+w55vyABrsJlt5QkznPYy55vKA=",
- "owner": "nix-community",
- "repo": "naersk",
- "rev": "aeb58d5e8faead8980a807c840232697982d47b9",
- "type": "github"
- },
- "original": {
- "owner": "nix-community",
- "repo": "naersk",
- "type": "github"
- }
- },
"nixpkgs": {
"locked": {
"lastModified": 1710503106,
@@ -166,7 +146,6 @@
"inputs": {
"fenix": "fenix",
"flake-parts": "flake-parts",
- "naersk": "naersk",
"nixpkgs": "nixpkgs",
"pre-commit-hooks-nix": "pre-commit-hooks-nix",
"procfile-nix": "procfile-nix",
diff --git a/flake.nix b/flake.nix
index 618eb5a..28c35a6 100644
--- a/flake.nix
+++ b/flake.nix
@@ -19,11 +19,6 @@
inputs.nixpkgs.follows = "nixpkgs";
};
- naersk = {
- url = "github:nix-community/naersk";
- inputs.nixpkgs.follows = "nixpkgs";
- };
-
pre-commit-hooks-nix = {
url = "github:cachix/pre-commit-hooks.nix";
inputs = {
@@ -52,7 +47,7 @@
inputs.treefmt-nix.flakeModule
./nix/ci.nix
- ./nix/deployment.nix
+ ./nix/deployment
./nix/dev.nix
./nix/packages.nix
];
diff --git a/nix/deployment.nix b/nix/deployment/default.nix
index 514b307..7fd379f 100644
--- a/nix/deployment.nix
+++ b/nix/deployment/default.nix
@@ -1,9 +1,10 @@
{
- inputs,
flake-parts-lib,
withSystem,
...
}: {
+ imports = [./static.nix];
+
flake.nixosModules.default = flake-parts-lib.importApply ./module.nix {
inherit withSystem;
};
@@ -11,25 +12,9 @@
perSystem = {
lib,
pkgs,
- system,
- config,
- inputs',
self',
...
}: let
- crossPkgs = with pkgs.pkgsCross; {
- x86_64 = musl64;
- aarch64 = aarch64-multiplatform.pkgsStatic;
- };
-
- teawieFor = arch:
- pkgs.callPackage ./static.nix {
- inherit (self'.packages) teawiebot;
- pkgsStatic = crossPkgs.${arch};
- fenix = inputs'.fenix.packages;
- naersk = inputs.naersk.lib.${system};
- };
-
containerFor = arch:
pkgs.dockerTools.buildLayeredImage {
name = "teawiebot";
@@ -39,12 +24,10 @@
(lib.getExe self'.packages."teawiebot-static-${arch}")
];
- architecture = crossPkgs.${arch}.go.GOARCH;
+ architecture = withSystem "${arch}-linux" ({pkgs, ...}: pkgs.pkgsStatic.go.GOARCH);
};
in {
packages = {
- teawiebot-static-x86_64 = teawieFor "x86_64";
- teawiebot-static-aarch64 = teawieFor "aarch64";
container-x86_64 = containerFor "x86_64";
container-aarch64 = containerFor "aarch64";
};
diff --git a/nix/module.nix b/nix/deployment/module.nix
index 09999f1..09999f1 100644
--- a/nix/module.nix
+++ b/nix/deployment/module.nix
diff --git a/nix/deployment/static.nix b/nix/deployment/static.nix
new file mode 100644
index 0000000..dcdf0f3
--- /dev/null
+++ b/nix/deployment/static.nix
@@ -0,0 +1,50 @@
+{
+ perSystem = {
+ lib,
+ pkgs,
+ inputs',
+ self',
+ ...
+ }: let
+ targets = with pkgs.pkgsCross; {
+ x86_64 = musl64.pkgsStatic;
+ aarch64 = aarch64-multiplatform.pkgsStatic;
+ };
+
+ toolchain = let
+ fenix = inputs'.fenix.packages;
+ in
+ with fenix;
+ combine (
+ [minimal.cargo minimal.rustc]
+ ++ map (
+ pkgs:
+ fenix.targets.${pkgs.stdenv.hostPlatform.config}.latest.rust-std
+ ) (lib.attrValues targets)
+ );
+
+ rustPlatforms =
+ lib.mapAttrs (
+ lib.const (pkgs:
+ pkgs.makeRustPlatform (
+ lib.genAttrs ["cargo" "rustc"] (lib.const toolchain)
+ ))
+ )
+ targets;
+
+ buildTeawieWith = rustPlatform:
+ self'.packages.teawiebot.override {
+ inherit rustPlatform;
+ lto = true;
+ optimizeSize = true;
+ };
+ in {
+ packages = lib.optionalAttrs pkgs.stdenv.isLinux (
+ lib.mapAttrs' (
+ target: rustPlatform:
+ lib.nameValuePair "teawiebot-static-${target}" (buildTeawieWith rustPlatform)
+ )
+ rustPlatforms
+ );
+ };
+}
diff --git a/nix/derivation.nix b/nix/derivation.nix
index 3456e6c..bb60706 100644
--- a/nix/derivation.nix
+++ b/nix/derivation.nix
@@ -1,17 +1,19 @@
{
lib,
stdenv,
- naersk,
+ rustPlatform,
darwin,
self,
lto ? false,
optimizeSize ? false,
}:
-naersk.buildPackage {
+rustPlatform.buildRustPackage {
pname = "teawiebot";
version =
- toString (lib.importTOML ../Cargo.toml).package.version
- + "-${self.shortRev or self.dirtyShortRev or "dirty"}";
+ (lib.importTOML ../Cargo.toml).package.version
+ + "-${self.shortRev or self.dirtyShortRev or "unknown-dirty"}";
+
+ __structuredAttrs = true;
src = lib.fileset.toSource {
root = ../.;
@@ -23,6 +25,10 @@ naersk.buildPackage {
];
};
+ cargoLock = {
+ lockFile = ../Cargo.lock;
+ };
+
buildInputs = lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
CoreFoundation
Security
diff --git a/nix/packages.nix b/nix/packages.nix
index ba6dc6e..764301c 100644
--- a/nix/packages.nix
+++ b/nix/packages.nix
@@ -1,8 +1,4 @@
-{
- self,
- inputs,
- ...
-}: {
+{self, ...}: {
perSystem = {
pkgs,
system,
@@ -10,11 +6,7 @@
...
}: {
packages = {
- teawiebot = pkgs.callPackage ./derivation.nix {
- inherit self;
- naersk = inputs.naersk.lib.${system};
- };
-
+ teawiebot = pkgs.callPackage ./derivation.nix {inherit self;};
default = self'.packages.teawiebot;
};
};
diff --git a/nix/static.nix b/nix/static.nix
deleted file mode 100644
index 22fbad6..0000000
--- a/nix/static.nix
+++ /dev/null
@@ -1,38 +0,0 @@
-{
- lib,
- pkgsStatic,
- fenix,
- naersk,
- teawiebot,
-}: let
- inherit (pkgsStatic.stdenv) cc;
-
- target = pkgsStatic.stdenv.hostPlatform.config;
- target' = builtins.replaceStrings ["-"] ["_"] target;
- targetUpper = lib.toUpper target';
-
- toolchain = with fenix;
- combine [
- minimal.cargo
- minimal.rustc
- targets.${target}.latest.rust-std
- ];
-
- naersk' = naersk.override {
- cargo = toolchain;
- rustc = toolchain;
- };
-in
- (teawiebot.override {
- naersk = naersk';
- lto = true;
- optimizeSize = true;
- })
- .overrideAttrs (new: old: {
- env = {
- "CC_${target'}" = "${cc}/bin/${cc.targetPrefix}cc";
- CARGO_BUILD_TARGET = target;
- CARGO_BUILD_RUSTFLAGS = old.env.CARGO_BUILD_RUSTFLAGS + " -C target-feature=+crt-static";
- "CARGO_TARGET_${targetUpper}_LINKER" = new.env."CC_${target'}";
- };
- })