Skip to content

Commit

Permalink
Migrate Nix build to flakes
Browse files Browse the repository at this point in the history
While we're in here, do some cleanup of dependencies and set the build revision
using Nix's flake revision attribute.
  • Loading branch information
jmacdonald committed Sep 21, 2024
1 parent a133c6c commit d28a9e3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use nix
use flake
20 changes: 0 additions & 20 deletions default.nix

This file was deleted.

1 change: 0 additions & 1 deletion documentation/pages/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ brew install amp

* `cmake`
* `rust`
* `python3` if building on Linux

### Building

Expand Down
70 changes: 67 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./. { };
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";
};
};
}
14 changes: 0 additions & 14 deletions shell.nix

This file was deleted.

0 comments on commit d28a9e3

Please sign in to comment.