From b2e2ef2b24fcf9be47694709867b54e6c8b4b318 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 4 Jul 2026 20:36:25 -0400 Subject: [PATCH] Set up nix building. --- .gitignore | 1 + Cargo.toml | 2 +- flake.nix | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 71 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 73077c5..1c89574 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /work /example_logs TODO.org +/result diff --git a/Cargo.toml b/Cargo.toml index 9bca627..bf1e57d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ url = { version = "2.5.8", default-features = false, features = ["std"] } primal = { version = "0.3.3", default-features = false, features = [] } # Optimized build for any sort of release. -[profile.release-lto] +[profile.lto] inherits = "release" lto = true strip = "symbols" diff --git a/flake.nix b/flake.nix index 3d47dae..cfd31d1 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - description = "nix_builder development environment"; + description = "nix_builder nix package builder"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; @@ -33,9 +33,10 @@ system: let overlays = [ (import rust-overlay) ]; - pkgs = import nixpkgs { - inherit system overlays; - }; + pkgs = + (import nixpkgs { + inherit system overlays; + }).pkgsStatic; rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; in { @@ -62,5 +63,69 @@ }; } ); + packages = forAllSystems ( + system: + let + overlays = [ (import rust-overlay) ]; + pkgs = + (import nixpkgs { + inherit system overlays; + }).pkgsStatic; + cargoToml = (pkgs.lib.importTOML ./Cargo.toml); + rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rustPlatform = pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + in + rec { + app = rustPlatform.buildRustPackage { + pname = "nix_builder"; + version = cargoToml.package.version; + src = pkgs.lib.cleanSource ./.; + + cargoLock.lockFile = ./Cargo.lock; + + buildType = "lto"; + # RUSTFLAGS = "-C target-cpu=x86-64-v3"; + + meta = with pkgs.lib; { + description = "A builder of nix configs for a build server."; + homepage = "https://code.fizz.buzz/talexander/nix_builder"; + license = licenses.bsd0; + maintainers = [ ]; + }; + + nativeBuildInputs = [ pkgs.makeWrapper ]; + + postInstall = '' + wrapProgram $out/bin/nix-builder --prefix PATH : ${ + pkgs.lib.makeBinPath [ + pkgs.git + pkgs.nix + pkgs.nixos-rebuild + ] + } + ''; + + # nativeBuildInputs = [ + # pkgs.pkg-config + # ]; + # buildInputs = [ + # pkgs.openssl + # ]; + }; + docker_env = pkgs.buildEnv { + name = "nix_builder"; + paths = with pkgs; [ + app + # bash + # uutils-coreutils-noprefix + # toybox # Smaller than uutils-coreutils? + ]; + }; + default = app; + } + ); }; }