Skip to content

Commit 1d7be1e

Browse files
author
es-sai-fi
committed
feat(nix): add devshell, package derivation, flake, and non-flake entrypoint
- Initialize development shell - Add package derivation - Add flake entrypoint - Add non-flake entrypoint - Document Nix installation and development setup in README
1 parent 217a3f9 commit 1d7be1e

File tree

8 files changed

+255
-0
lines changed

8 files changed

+255
-0
lines changed

.envrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
watch_file flake.lock
2+
watch_file flake.nix
3+
watch_file shell.nix
4+
5+
use flake

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
/target
22
/*.log
33
/*.gif
4+
5+
# Nix
6+
.direnv
7+
result

README.md

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,131 @@ cd gitv
5252
cargo install --path .
5353
```
5454

55+
#### NixOS
56+
57+
<details>
58+
<summary>Flake</summary>
59+
60+
First add the repository to your inputs.
61+
62+
Point to main branch:
63+
64+
```nix
65+
inputs = {
66+
...
67+
gitv.url = "github:JayanAXHF/gitv";
68+
...
69+
};
70+
```
71+
72+
Point to a rev in main branch:
73+
74+
```nix
75+
inputs = {
76+
...
77+
gitv.url = "github:JayanAXHF/gitv/d70273b05c5e80b05446e4aa0847758e54435d62";
78+
...
79+
};
80+
```
81+
82+
Point to a tag:
83+
84+
```nix
85+
inputs = {
86+
...
87+
gitv.url = "github:JayanAXHF/gitv/refs/tags/gitv-tui-v0.3.2";
88+
...
89+
};
90+
```
91+
92+
Then your outputs should look something like this:
93+
94+
```nix
95+
outputs = {...} @ inputs: {
96+
# Don't forget to add nixpkgs to your inputs
97+
nixosConfigurations."nixos" = inputs.nixpkgs.lib.nixosSystem {
98+
...
99+
specialArgs = {inherit inputs;};
100+
modules = [
101+
./configuration.nix
102+
...
103+
];
104+
};
105+
};
106+
```
107+
108+
And finally, somewhere in your `configuration.nix`:
109+
110+
```nix
111+
{inputs, pkgs, ...}: {
112+
...
113+
environment.systemPackages = [
114+
inputs.gitv.packages.${pkgs.stdenv.hostPlatform.system}.default
115+
];
116+
...
117+
}
118+
```
119+
</details>
120+
121+
<details>
122+
<summary>Non-Flake</summary>
123+
124+
##### Pinning Tool
125+
126+
First add the pin using your pinning tool.
127+
128+
We are going to show examples using npins.
129+
130+
Point to a branch:
131+
132+
```bash
133+
npins add github JayanAXHF gitv -b main
134+
```
135+
136+
Point to a rev in main branch:
137+
138+
```bash
139+
npins add github JayanAXHF gitv -b main --at d70273b05c5e80b05446e4aa0847758e54435d62
140+
```
141+
142+
Point to a tag:
143+
144+
```bash
145+
npins add github JayanAXHF gitv --at gitv-tui-v0.3.2
146+
```
147+
148+
Or point to latest release:
149+
150+
```bash
151+
npins add github JayanAXHF gitv
152+
```
153+
154+
Then add the package to your `systemPackages`:
155+
156+
```nix
157+
let
158+
sources = import ./npins;
159+
in {
160+
environment.systemPackages = [
161+
(import sources.gitv)
162+
];
163+
}
164+
```
165+
166+
##### No Pinning Tool
167+
168+
```nix
169+
let
170+
rev = "d70273b05c5e80b05446e4aa0847758e54435d62";
171+
gitv = import (fetchTarball "https://github.com/JayanAXHF/gitv/archive/${rev}.tar.gz") {};
172+
in {
173+
environment.systemPackages = [
174+
gitv
175+
];
176+
}
177+
```
178+
</details>
179+
55180
### Usage
56181

57182
```
@@ -111,6 +236,9 @@ Contributions to `gitv` are welcome! If you have an idea for a new feature or ha
111236
> [!TIP]
112237
> Run the `init.py` initialization script to set up your development environment. It installs a pre-push hook that runs `typos` and `clippy` to help maintain code quality and consistency. Ensure that you have the `typos-cli` installed and available in your PATH for the pre-push hook to work correctly. You can install it using `cargo install typos-cli`.
113238
239+
> [!TIP]
240+
> If you're using nix then you can use the provided devshell to get your development environment up and running, it also includes the pre-push hook provided. You can do so by executing `direnv allow` or `nix develop`.
241+
114242
### License
115243

116244
`gitv` is dual-licensed under the MIT License and the Unlicense, at your option. See the [MIT](./LICENSE-MIT) and [Unlicense](./UNLICENSE) for more information.

default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{pkgs ? import <nixpkgs> {}}:
2+
pkgs.callPackage ./package.nix {}

flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
inputs = {
3+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
4+
};
5+
6+
outputs = {nixpkgs, ...}: let
7+
supportedSystems = [
8+
"x86_64-linux"
9+
"aarch64-linux"
10+
"x86_64-darwin"
11+
"aarch64-darwin"
12+
];
13+
14+
forAllSystems = function:
15+
nixpkgs.lib.genAttrs
16+
supportedSystems
17+
(system: function nixpkgs.legacyPackages.${system});
18+
in {
19+
packages = forAllSystems (
20+
pkgs: let
21+
default = pkgs.callPackage ./package.nix {};
22+
in {
23+
inherit default;
24+
25+
debug = default.overrideAttrs (finalAttrs: _: {
26+
cargoBuildType = "debug";
27+
cargoCheckType = finalAttrs.cargoBuildType;
28+
});
29+
}
30+
);
31+
32+
devShells = forAllSystems (
33+
pkgs: {
34+
default = import ./shell.nix {inherit pkgs;};
35+
}
36+
);
37+
};
38+
}

package.nix

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
lib,
3+
rustPlatform,
4+
}:
5+
rustPlatform.buildRustPackage (finalAttrs: {
6+
name = "gitv";
7+
8+
src = ./.;
9+
cargoLock = {
10+
lockFile = ./Cargo.lock;
11+
allowBuiltinFetchGit = true;
12+
};
13+
14+
meta = with lib; {
15+
description = "Terminal-based viewer for GitHub issues";
16+
homepage = "https://github.com/JayanAXHF/gitv";
17+
license = with lib.licenses; [mit unlicense];
18+
};
19+
})

shell.nix

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{pkgs ? import <nixpkgs> {}}:
2+
with pkgs;
3+
mkShell {
4+
packages = [
5+
nil
6+
alejandra
7+
8+
rustc
9+
cargo
10+
clippy
11+
rustfmt
12+
rust-analyzer
13+
14+
typos
15+
];
16+
17+
env = {
18+
RUST_BACKTRACE = "full";
19+
};
20+
21+
shellHook = ''
22+
echo "Setting up pre-push hook..."
23+
24+
HOOK=".git/hooks/pre-push"
25+
26+
if [ ! -f "$HOOK" ]; then
27+
cp ./etc/pre-push.sh "$HOOK"
28+
chmod 755 "$HOOK"
29+
echo "Pre-push hook installed."
30+
fi
31+
'';
32+
}

0 commit comments

Comments
 (0)