Skip to content

Commit

Permalink
Fully migrate Nix build to flakes
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacdonald committed Sep 21, 2024
1 parent 980f142 commit c2db512
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use nix
use flake
38 changes: 0 additions & 38 deletions default.nix

This file was deleted.

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 ./. { 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";
};
};
}
14 changes: 0 additions & 14 deletions shell.nix

This file was deleted.

0 comments on commit c2db512

Please sign in to comment.