diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index ea8c4bf..fdf11bc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ /target +/.direnv +/result diff --git a/README.md b/README.md index 9d45eb7..c562e7d 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,20 @@ curl -fsSL https://raw.githubusercontent.com/unhappychoice/steamfetch/main/insta brew install unhappychoice/tap/steamfetch ``` +### Nix + +Try it without installing via Nix + +```bash +nix run github:unhappychoice/steamfetch +``` + +To pass arguments, add `--` to the end of the `nix run` invocation + +```bash +nix run github:unhappychoice/steamfetch -- --demo # Everything after `--` is passed as an argument to steamfetch +``` + ### Download Binary Download the latest release from [GitHub Releases](https://github.com/unhappychoice/steamfetch/releases). diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a8a0efe --- /dev/null +++ b/flake.lock @@ -0,0 +1,98 @@ +{ + "nodes": { + "crane": { + "locked": { + "lastModified": 1771438068, + "narHash": "sha256-nGBbXvEZVe/egCPVPFcu89RFtd8Rf6J+4RFoVCFec0A=", + "owner": "ipetkov", + "repo": "crane", + "rev": "b5090e53e9d68c523a4bb9ad42b4737ee6747597", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1771369470, + "narHash": "sha256-0NBlEBKkN3lufyvFegY4TYv5mCNHbi5OmBDrzihbBMQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0182a361324364ae3f436a63005877674cf45efb", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "crane": "crane", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1771556776, + "narHash": "sha256-zKprqMQDl3xVfhSSYvgru1IGXjFdxryWk+KqK0I20Xk=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8b3f46b8a6d17ab46e533a5e3d5b1cc2ff228860", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e4ab3ef --- /dev/null +++ b/flake.nix @@ -0,0 +1,100 @@ +{ + description = "Steamfetch nix flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + crane = { + url = "github:ipetkov/crane"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + crane, + rust-overlay, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ (import rust-overlay) ]; + }; + + # Builds the rust components from the toolchain file, or defaults back to the latest nightly build + rust-toolchain = + if builtins.pathExists ./rust-toolchain.toml then + pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml + else + pkgs.rust-bin.selectLatestNightlyWith ( + toolchain: + toolchain.default.override { + extensions = [ "rust-src" ]; + } + ); + + # Instantiates custom craneLib using toolchain + craneLib = (crane.mkLib pkgs).overrideToolchain rust-toolchain; + + src = craneLib.cleanCargoSource ./.; + pname = craneLib.crateNameFromCargoToml { cargoToml = ./Cargo.toml; }.pname; + + # Common arguments shared between buildPackage and buildDepsOnly + commonArgs = { + inherit src; + strictDeps = true; + + buildInputs = with pkgs; [ + openssl + ]; + + nativeBuildInputs = with pkgs; [ + pkg-config + ]; + }; + + cargoArtifacts = craneLib.buildDepsOnly (commonArgs); + + crane-package = craneLib.buildPackage ( + commonArgs + // { + inherit cargoArtifacts; + postInstall = '' + mkdir -p $out/bin + cp ./target/release/libsteam_api.* $out/bin/. + ''; + } + ); + in + { + devShells.default = pkgs.mkShell { + # Inherits buildInputs from crane-package + inputsFrom = [ crane-package ]; + + # Additional packages for the dev environment + packages = with pkgs; [ + ]; + + shellHook = ""; + + env = { + # Needed for rust-analyzer + RUST_SRC_PATH = "${rust-toolchain}/lib/rustlib/src/rust/library"; + }; + }; + + packages.default = crane-package; + + formatter = pkgs.nixfmt-tree; + } + ); +}