From c2db5126234261fb434b2571671771d92f68300a Mon Sep 17 00:00:00 2001 From: Jordan MacDonald Date: Sat, 21 Sep 2024 12:16:06 -0400 Subject: [PATCH] Fully migrate Nix build to flakes --- .envrc | 2 +- default.nix | 38 ----------------------------- flake.nix | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++--- shell.nix | 14 ----------- 4 files changed, 68 insertions(+), 56 deletions(-) delete mode 100644 default.nix delete mode 100644 shell.nix diff --git a/.envrc b/.envrc index 1d953f4b..3550a30f 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use nix +use flake diff --git a/default.nix b/default.nix deleted file mode 100644 index 04d4da6c..00000000 --- a/default.nix +++ /dev/null @@ -1,38 +0,0 @@ -{ pkgs ? import {}, gitSha }: - pkgs.rustPlatform.buildRustPackage { - pname = "amp"; - version = "0.7.0"; - cargoLock.lockFile = ./Cargo.lock; - - # Use source files without version control noise - src = pkgs.lib.cleanSource ./.; - - # Packages needed at runtime - buildInputs = with pkgs; [ git xorg.libxcb openssl zlib ]; - - # Packages needed during the build - nativeBuildInputs = with pkgs; [ git ]; - - # Make the build/check/install commands explicit so we can - # provide the commit SHA for the splash screen - buildPhase = '' - export BUILD_REVISION=${builtins.substring 0 7 gitSha} - echo "BUILD_REVISION=$BUILD_REVISION" - - cargo build --release - ''; - - checkPhase = '' - cargo test - ''; - - installPhase = '' - mkdir -p $out/bin - cp target/release/amp $out/bin/ - ''; - - # Amp creates files and directories in $HOME/.config/amp when run. - # Since the checkPhase of the build process runs the test suite, we - # need a writable location to avoid permission error test failures. - HOME="$src"; - } diff --git a/flake.nix b/flake.nix index c8c659f6..4b17a1de 100644 --- a/flake.nix +++ b/flake.nix @@ -9,10 +9,74 @@ let supportedSystems = [ "x86_64-linux" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - pkgsFor = nixpkgs.legacyPackages; in { + # Define packages for all supported systems packages = forAllSystems (system: { - default = pkgsFor.${system}.callPackage ./. { gitSha = self.rev; }; + default = self.buildPackage { inherit system; }; }); - }; + + # Define dev shells for all supported systems + devShells = forAllSystems (system: { + default = self.buildShell { inherit system; }; + }); + + # Function to build a dev shell for a given system + buildShell = { system }: + let pkgs = import nixpkgs { inherit system; }; + in pkgs.mkShell { + buildInputs = with pkgs; [ + rustc + cargo + cargo-edit + rustfmt + rust-analyzer + clippy + ]; + + RUST_BACKTRACE = 1; + }; + + # Function to build the package for a given system + buildPackage = { system }: + let pkgs = import nixpkgs { inherit system; }; + in pkgs.rustPlatform.buildRustPackage { + pname = "amp"; + version = "0.7.0"; + cargoLock.lockFile = ./Cargo.lock; + + # Use source files without version control noise + src = pkgs.lib.cleanSource ./.; + + # Packages needed at runtime + buildInputs = with pkgs; [ git xorg.libxcb openssl zlib ]; + + # Packages needed during the build + nativeBuildInputs = with pkgs; [ git ]; + + # Make the build/check/install commands explicit so we can + # provide the commit SHA for the splash screen + buildPhase = '' + export BUILD_REVISION=${builtins.substring 0 7 ( + if self ? rev then self.rev else "" + )} + echo "BUILD_REVISION=$BUILD_REVISION" + + cargo build --release + ''; + + checkPhase = '' + cargo test + ''; + + installPhase = '' + mkdir -p $out/bin + cp target/release/amp $out/bin/ + ''; + + # Amp creates files and directories in $HOME/.config/amp when run. + # Since the checkPhase of the build process runs the test suite, we + # need a writable location to avoid permission error test failures. + HOME="$src"; + }; + }; } diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 38f41210..00000000 --- a/shell.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ pkgs ? import {}}: - -pkgs.mkShell { - buildInputs = with pkgs; [ - rustc - cargo - cargo-edit - rustfmt - rust-analyzer - clippy - ]; - - RUST_BACKTRACE = 1; -}