Skip to content

Commit c351ada

Browse files
committed
feat: Added nix support
- Added nix derivation to package software - Lets you try the program without installing it via `nix run` - Allows NixOS users to install and run the program :] - Updated README with details on how to use it
1 parent 3d7b294 commit c351ada

5 files changed

Lines changed: 212 additions & 0 deletions

File tree

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/target
2+
/.direnv
3+
/result

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ curl -fsSL https://raw.githubusercontent.com/unhappychoice/steamfetch/main/insta
2424
brew install unhappychoice/tap/steamfetch
2525
```
2626

27+
### Nix
28+
29+
Try it without installing via Nix
30+
31+
```bash
32+
nix run github:unhappychoice/steamfetch
33+
```
34+
35+
To pass arguments, add `--` to the end of the `nix run` invocation
36+
37+
```bash
38+
nix run github:unhappychoice/steamfetch -- --demo # Everything after `--` is passed as an argument to steamfetch
39+
```
40+
2741
### Download Binary
2842

2943
Download the latest release from [GitHub Releases](https://github.com/unhappychoice/steamfetch/releases).

flake.lock

Lines changed: 98 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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
description = "of-the-star's custom rust development flake";
3+
4+
inputs = {
5+
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
6+
flake-utils.url = "github:numtide/flake-utils";
7+
crane.url = "github:ipetkov/crane";
8+
rust-overlay = {
9+
url = "github:oxalica/rust-overlay";
10+
inputs.nixpkgs.follows = "nixpkgs";
11+
};
12+
};
13+
14+
outputs =
15+
{
16+
self,
17+
nixpkgs,
18+
flake-utils,
19+
crane,
20+
rust-overlay,
21+
}:
22+
flake-utils.lib.eachDefaultSystem (
23+
system:
24+
let
25+
pkgs = import nixpkgs {
26+
inherit system;
27+
overlays = [ (import rust-overlay) ];
28+
};
29+
30+
# Builds the rust components from the toolchain file, or defaults back to the latest nightly build
31+
rust-toolchain =
32+
if builtins.pathExists ./rust-toolchain.toml then
33+
pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml
34+
else
35+
pkgs.rust-bin.selectLatestNightlyWith (
36+
toolchain:
37+
toolchain.default.override {
38+
# extensions = [ "rust-src" ];
39+
}
40+
);
41+
42+
# Instantiates custom craneLib using toolchain
43+
craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain;
44+
45+
src = craneLib.cleanCargoSource ./.;
46+
pname = craneLib.crateNameFromCargoToml { cargoToml = ./Cargo.toml; }.pname;
47+
48+
# Common arguments shared between buildPackage and buildDepsOnly
49+
commonArgs = {
50+
inherit src;
51+
strictDeps = true;
52+
53+
buildInputs = with pkgs; [
54+
openssl
55+
];
56+
57+
nativeBuildInputs = with pkgs; [
58+
pkg-config
59+
];
60+
};
61+
62+
cargoArtifacts = craneLib.buildDepsOnly (commonArgs);
63+
64+
crane-package = craneLib.buildPackage (
65+
commonArgs
66+
// {
67+
inherit cargoArtifacts;
68+
postInstall = ''
69+
mkdir -p $out/bin
70+
cp ./target/release/libsteam_api.* $out/bin/.
71+
'';
72+
}
73+
);
74+
in
75+
{
76+
devShells.default = pkgs.mkShell {
77+
# Inherits buildInputs from crane-package
78+
inputsFrom = [ crane-package ];
79+
80+
# Additional packages for the dev environment
81+
packages = with pkgs; [
82+
];
83+
84+
shellHook = "";
85+
86+
env = {
87+
# Needed for rust-analyzer
88+
RUST_SRC_PATH = "${rust-toolchain}/lib/rustlib/src/rust/library";
89+
};
90+
};
91+
92+
packages.default = crane-package;
93+
94+
formatter.${system} = nixpkgs.legacyPackages.${system}.nixfmt-tree;
95+
}
96+
);
97+
}

0 commit comments

Comments
 (0)