-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathflake.nix
89 lines (73 loc) · 2.56 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
{
description = "Amp: A complete text editor for your terminal";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11";
};
outputs = { self, nixpkgs }:
let
supportedSystems = [ "x86_64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
in {
# Define packages for all supported systems
packages = forAllSystems (system: {
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";
# Extract version from Cargo.toml
version = builtins.head
(
builtins.match ".*name = \"amp\"\nversion = \"([^\"]+)\".*"
(builtins.readFile ./Cargo.toml)
);
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=${
if self ? shortRev then self.shortRev 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";
};
};
}