Skip to content

Commit 511352d

Browse files
committed
Add an overlay
1 parent 694311b commit 511352d

File tree

3 files changed

+66
-55
lines changed

3 files changed

+66
-55
lines changed

README.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,7 @@ This starts a shell within your shell which has `npc` available on the `PATH`.
5353

5454
### Home Manager
5555

56-
If you use [Home Manager](https://github.com/nix-community/home-manager) and would like to do a more global installation, you can add `npc` to your `home.nix` like this:
57-
58-
```nix
59-
{ pkgs, npc, ... }:
60-
{
61-
home = {
62-
stateVersion = "25.05";
63-
username = "username";
64-
homeDirectory = "/home/username";
65-
packages = [
66-
npc.packages.${pkgs.stdenv.hostPlatform.system}.default
67-
];
68-
};
69-
}
70-
```
71-
72-
This is assuming you configure Home Manager via a flake, in which case you'd pass `npc` to `home.nix` via `extraSpecialArgs`:
73-
74-
<details>
75-
<summary><code>flake.nix</code></summary>
56+
If you use [Home Manager](https://github.com/nix-community/home-manager) and would like to do a more global installation, the easiest way is via the overlay provided by this flake; for instance, your `flake.nix` might look like this:
7657

7758
```nix
7859
{
@@ -83,10 +64,7 @@ This is assuming you configure Home Manager via a flake, in which case you'd pas
8364
url = "github:nix-community/home-manager";
8465
inputs.nixpkgs.follows = "nixpkgs";
8566
};
86-
npc = {
87-
url = "github:samestep/npc";
88-
inputs.nixpkgs.follows = "nixpkgs";
89-
};
67+
npc.url = "github:samestep/npc";
9068
};
9169
outputs =
9270
{
@@ -99,16 +77,32 @@ This is assuming you configure Home Manager via a flake, in which case you'd pas
9977
flake-utils.lib.eachDefaultSystem (system: {
10078
homeConfigurations = {
10179
"username" = home-manager.lib.homeManagerConfiguration {
102-
pkgs = import nixpkgs { inherit system; };
80+
pkgs = import nixpkgs {
81+
inherit system;
82+
overlays = [ npc.overlays.default ];
83+
};
10384
modules = [ ./home.nix ];
104-
extraSpecialArgs = { inherit npc; };
10585
};
10686
};
10787
});
10888
}
10989
```
11090

111-
</details>
91+
Then you can add `npc` to your `home.nix` like this:
92+
93+
```nix
94+
{ pkgs, ... }:
95+
{
96+
home = {
97+
stateVersion = "25.05";
98+
username = "username";
99+
homeDirectory = "/home/username";
100+
packages = [
101+
pkgs.npc
102+
];
103+
};
104+
}
105+
```
112106

113107
## Usage
114108

flake.lock

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

flake.nix

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
url = "github:oxalica/rust-overlay";
88
inputs.nixpkgs.follows = "nixpkgs";
99
};
10-
# This is the last `nixpkgs-unstable` commit with a Git version earlier than
11-
# v2.48.0, which introduced a bug that sometimes causes `git fetch` to fail
12-
# on partial clones like the one `npc` uses.
13-
nixpkgs-git-2-47-2.url = "github:NixOS/nixpkgs/dad564433178067be1fbdfcce23b546254b6d641";
10+
# This is the last stable release with a Git version earlier than v2.48.0,
11+
# which introduced a bug that sometimes causes `git fetch` to fail on
12+
# partial clones like the one `npc` uses.
13+
nixpkgs-git.url = "github:NixOS/nixpkgs/nixos-24.11";
1414
};
1515
outputs =
1616
{
@@ -19,36 +19,53 @@
1919
flake-utils,
2020
crane,
2121
rust-overlay,
22-
nixpkgs-git-2-47-2,
22+
nixpkgs-git,
2323
}:
24-
flake-utils.lib.eachDefaultSystem (
24+
let
25+
env = pkgs: {
26+
GIT_BIN = "${(import nixpkgs-git { system = pkgs.stdenv.hostPlatform.system; }).git}/bin/git";
27+
NIX_BIN = "${pkgs.nix}/bin/nix";
28+
};
29+
overlay =
30+
final: prev:
31+
let
32+
craneLib = crane.mkLib final;
33+
commonArgs = {
34+
src = ./.;
35+
strictDeps = true;
36+
};
37+
in
38+
{
39+
npc = craneLib.buildPackage (
40+
commonArgs
41+
// {
42+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
43+
inherit (env final) GIT_BIN NIX_BIN;
44+
}
45+
);
46+
};
47+
in
48+
{
49+
overlays.default = overlay;
50+
}
51+
// flake-utils.lib.eachDefaultSystem (
2552
system:
2653
let
2754
pkgs = import nixpkgs {
2855
inherit system;
29-
overlays = [ (import rust-overlay) ];
30-
};
31-
craneLib = crane.mkLib pkgs;
32-
commonArgs = {
33-
src = ./.;
34-
strictDeps = true;
56+
overlays = [
57+
(import rust-overlay)
58+
overlay
59+
];
3560
};
36-
GIT_BIN = "${(import nixpkgs-git-2-47-2 { inherit system; }).git}/bin/git";
37-
NIX_BIN = "${pkgs.nix}/bin/nix";
3861
in
3962
{
40-
packages.default = craneLib.buildPackage (
41-
commonArgs
42-
// {
43-
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
44-
inherit GIT_BIN NIX_BIN;
45-
}
46-
);
63+
packages.default = pkgs.npc;
4764
devShells.default = pkgs.mkShell {
4865
buildInputs = [
4966
pkgs.rust-bin.stable.latest.default
5067
];
51-
inherit GIT_BIN NIX_BIN;
68+
inherit (env pkgs) GIT_BIN NIX_BIN;
5269
};
5370
}
5471
);

0 commit comments

Comments
 (0)