Repository navigation
Expand file tree
/
Copy pathflake.nix
More file actions
136 lines (121 loc) · 4.18 KB
/
Copy pathflake.nix
File metadata and controls
136 lines (121 loc) · 4.18 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
{
description = "bonk - NixOS workflow multitool";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
# Pin nh to master for --build-host fix (PR #497).
# nixpkgs still ships 4.2.0 which silently ignores --build-host.
nh = {
url = "github:nix-community/nh";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
nh,
}:
# System-agnostic outputs
{
# NixOS module (curried: takes self to access packages)
nixosModules = {
bonk = import ./nix/default.nix self;
default = self.nixosModules.bonk;
};
# Home Manager module (curried: takes self to access packages)
homeManagerModules = {
bonk = import ./nix/home.nix self;
default = self.homeManagerModules.bonk;
};
# Overlay for adding bonk-nix to pkgs
# Named bonk-nix to avoid conflict with nixpkgs bonk package
overlays.default = final: prev: {
bonk-nix = self.packages.${final.system}.default;
};
}
//
# System-specific outputs
flake-utils.lib.eachDefaultSystem (
system:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit system overlays;
};
# Use stable Rust toolchain
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = [
"rust-src"
"rust-analyzer"
"clippy"
];
};
# Native build inputs
nativeBuildInputs = with pkgs; [
pkg-config
rustToolchain
installShellFiles # For installing shell completions
];
in
{
# Development shell
devShells.default = pkgs.mkShell {
inherit nativeBuildInputs;
shellHook = ''
echo "bonk development shell"
echo "Rust: $(rustc --version)"
echo ""
echo "Available commands:"
echo " cargo build - Build the project"
echo " cargo build -r - Build release binary"
echo " cargo clippy - Run linter"
echo " cargo fmt - Format code"
echo " cargo test - Run tests"
echo ""
'';
};
# Package definition
packages.default = pkgs.rustPlatform.buildRustPackage {
pname = "bonk";
version = "0.1.0";
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
inherit nativeBuildInputs;
# Install shell completions generated at build time by build.rs.
# build.rs writes completions to $OUT_DIR/completions/ and records
# the path in completions_dir.txt for reliable discovery.
postInstall = ''
# Read the completions directory path from the file created by build.rs
completions_path_file=$(find target -name "completions_dir.txt" -type f | head -n1)
if [ -f "$completions_path_file" ]; then
completions_dir=$(cat "$completions_path_file")
if [ -d "$completions_dir" ]; then
installShellCompletion --fish "$completions_dir/bonk.fish"
installShellCompletion --bash "$completions_dir/bonk.bash"
installShellCompletion --zsh "$completions_dir/_bonk"
fi
fi
'';
meta = with pkgs.lib; {
description = "NixOS workflow multitool - wraps nh, nix, and nix-store";
homepage = "https://github.com/tophc7/bonk";
license = licenses.gpl3;
maintainers = [ "tophc7" ];
platforms = platforms.linux;
mainProgram = "bonk";
};
};
# Convenient alias
packages.bonk = self.packages.${system}.default;
}
);
}