diff --git a/README.md b/README.md index 6c55cd9..1b13e47 100644 --- a/README.md +++ b/README.md @@ -29,22 +29,36 @@ camlistore.out 7,938,952 x /nix/store/xn5ivjdyslx $ nix run github:nix-community/nix-index#nix-locate -- bin/hello ``` +### From Nixpkgs + +From your locally configured version Nixpkgs: + +``` +$ nix-shell -p nix-index +[nix-shell]$ nix-index +[nix-shell]$ nix-locate bin/hello +``` + +From the latest rolling release of Nixpkgs: + +``` +$ nix-shell -p nix-index -I nixpkgs=channel:nixpkgs-unstable +``` + ### Latest Git version -To install the latest development version of nix-index, simply clone the repo and run `nix-env -if.`: +To run the latest development version: ``` -$ git clone https://github.com/nix-community/nix-index -$ cd nix-index -$ nix-env -if. +$ nix-shell https://github.com/nix-community/nix-index/tarball/master ``` -### Stable +### Stable releases -For the stable version, you can either [checkout](https://git-scm.com/docs/git-checkout) the latest [tag](https://git-scm.com/docs/git-tag) (see the list [here](https://github.com/nix-community/nix-index/tags)) or use Nixpkgs' repositories' and install it with: +To get a specific stable release, use one of the [release tags](https://github.com/nix-community/nix-index/tags): ``` -$ nix-env -iA nixos.nix-index +$ nix-shell https://github.com/nix-community/nix-index/tarball/v0.1.8 ``` ## Usage diff --git a/default.nix b/default.nix index d87fd23..0c6d987 100644 --- a/default.nix +++ b/default.nix @@ -1,11 +1,73 @@ -# This file is the compt layer of flakes: https://github.com/edolstra/flake-compat -# See flake.nix for details -(import ( - let - lock = builtins.fromJSON (builtins.readFile ./flake.lock); - in fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; } -) { - src = ./.; -}).defaultNix +{ + system ? builtins.currentSystem, + inputs ? import (fetchTarball "https://github.com/fricklerhandwerk/flake-inputs/tarball/1.0") { + root = ./.; + }, + nixpkgs-config ? { + inherit system; + config = { }; + overlays = [ ]; + }, +}: +let + # avoid re-importing `nixpkgs` if it comes from `flake.nix` + pkgs = + if inputs.nixpkgs ? lib then + inputs.nixpkgs.legacyPackages.${system} + else + import inputs.nixpkgs nixpkgs-config; +in +rec { + packages = { + default = pkgs.callPackage ./package.nix { }; + }; + devShells = { + minimal = + with pkgs; + mkShell { + name = "nix-index"; + + nativeBuildInputs = [ + pkg-config + ]; + + buildInputs = + [ + openssl + sqlite + ] + ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Security + ]; + + env.LD_LIBRARY_PATH = lib.makeLibraryPath [ openssl ]; + }; + + default = + with pkgs; + mkShell { + name = "nix-index"; + + inputsFrom = [ devShells.minimal ]; + + nativeBuildInputs = [ + rustc + cargo + clippy + rustfmt + ]; + + env = { + LD_LIBRARY_PATH = lib.makeLibraryPath [ openssl ]; + RUST_SRC_PATH = rustPlatform.rustLibSrc; + }; + }; + + }; + app-shell = + with pkgs; + mkShellNoCC { + name = "nix-index"; + packages = [ packages.default ]; + }; +} diff --git a/flake.lock b/flake.lock index 58911fb..1662e29 100644 --- a/flake.lock +++ b/flake.lock @@ -1,28 +1,30 @@ { "nodes": { - "flake-compat": { - "flake": false, + "flake-utils": { + "inputs": { + "systems": "systems" + }, "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "owner": "edolstra", - "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", "type": "github" }, "original": { - "owner": "edolstra", - "repo": "flake-compat", + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, "nixpkgs": { "locked": { - "lastModified": 1713248628, - "narHash": "sha256-NLznXB5AOnniUtZsyy/aPWOk8ussTuePp2acb9U+ISA=", + "lastModified": 1746141548, + "narHash": "sha256-IgBWhX7A2oJmZFIrpRuMnw5RAufVnfvOgHWgIdds+hc=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "5672bc9dbf9d88246ddab5ac454e82318d094bb8", + "rev": "f02fddb8acef29a8b32f10a335d44828d7825b78", "type": "github" }, "original": { @@ -33,9 +35,24 @@ }, "root": { "inputs": { - "flake-compat": "flake-compat", + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } + }, + "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", diff --git a/flake.nix b/flake.nix index 668b6f0..4d0dec2 100644 --- a/flake.nix +++ b/flake.nix @@ -3,103 +3,44 @@ inputs = { nixpkgs.url = "nixpkgs/nixos-unstable"; - flake-compat = { - url = "github:edolstra/flake-compat"; - flake = false; - }; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-compat }: - let - inherit (nixpkgs) lib; - systems = [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" "aarch64-linux" ]; - forAllSystems = lib.genAttrs systems; - nixpkgsFor = nixpkgs.legacyPackages; - in + outputs = { - packages = forAllSystems (system: { - default = with nixpkgsFor.${system}; rustPlatform.buildRustPackage { - pname = "nix-index"; - inherit ((lib.importTOML ./Cargo.toml).package) version; - - src = lib.sourceByRegex self [ - "(examples|src)(/.*)?" - ''Cargo\.(toml|lock)'' - ''command-not-found\.sh'' - ]; - - cargoLock = { - lockFile = ./Cargo.lock; + self, + nixpkgs, + flake-utils, + ... + }@inputs: + flake-utils.lib.eachDefaultSystem ( + system: + let + inherit (nixpkgs) lib; + classic = import ./. { inherit system inputs; }; + in + { + + inherit (classic) packages devShells; + + apps = { + nix-index = { + type = "app"; + program = "${self.packages.${system}.default}/bin/nix-index"; }; - - nativeBuildInputs = [ pkg-config ]; - buildInputs = [ openssl curl sqlite ] - ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ]; - - postInstall = '' - substituteInPlace command-not-found.sh \ - --subst-var out - install -Dm555 command-not-found.sh -t $out/etc/profile.d - ''; - - meta = with lib; { - description = "A files database for nixpkgs"; - homepage = "https://github.com/nix-community/nix-index"; - license = with licenses; [ bsd3 ]; - maintainers = [ maintainers.bennofs ]; + nix-locate = { + type = "app"; + program = "${self.packages.${system}.default}/bin/nix-locate"; }; + default = self.apps.${system}.nix-locate; }; - }); - checks = forAllSystems (system: + checks = let packages = lib.mapAttrs' (n: lib.nameValuePair "package-${n}") self.packages.${system}; devShells = lib.mapAttrs' (n: lib.nameValuePair "devShell-${n}") self.devShells.${system}; - in packages // devShells - ); - - devShells = forAllSystems (system: { - minimal = with nixpkgsFor.${system}; mkShell { - name = "nix-index"; - - nativeBuildInputs = [ - pkg-config - ]; - - buildInputs = [ - openssl - sqlite - ] ++ lib.optionals stdenv.isDarwin [ - darwin.apple_sdk.frameworks.Security - ]; - - env.LD_LIBRARY_PATH = lib.makeLibraryPath [ openssl ]; - }; - - default = with nixpkgsFor.${system}; mkShell { - name = "nix-index"; - - inputsFrom = [ self.devShells.${system}.minimal ]; - - nativeBuildInputs = [ rustc cargo clippy rustfmt ]; - - env = { - LD_LIBRARY_PATH = lib.makeLibraryPath [ openssl ]; - RUST_SRC_PATH = rustPlatform.rustLibSrc; - }; - }; - }); - - apps = forAllSystems (system: { - nix-index = { - type = "app"; - program = "${self.packages.${system}.default}/bin/nix-index"; - }; - nix-locate = { - type = "app"; - program = "${self.packages.${system}.default}/bin/nix-locate"; - }; - default = self.apps.${system}.nix-locate; - }); - }; + in + packages // devShells; + } + ); } diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..255a65a --- /dev/null +++ b/package.nix @@ -0,0 +1,44 @@ +{ + lib, + curl, + darwin, + openssl, + pkg-config, + rustPlatform, + sqlite, + stdenv, +}: +rustPlatform.buildRustPackage { + pname = "nix-index"; + inherit ((lib.importTOML ./Cargo.toml).package) version; + + src = lib.sourceByRegex ./. [ + "(examples|src)(/.*)?" + ''Cargo\.(toml|lock)'' + ''command-not-found\.sh'' + ]; + + cargoLock = { + lockFile = ./Cargo.lock; + }; + + nativeBuildInputs = [ pkg-config ]; + buildInputs = [ + openssl + curl + sqlite + ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.Security ]; + + postInstall = '' + substituteInPlace command-not-found.sh \ + --subst-var out + install -Dm555 command-not-found.sh -t $out/etc/profile.d + ''; + + meta = with lib; { + description = "A files database for nixpkgs"; + homepage = "https://github.com/nix-community/nix-index"; + license = with licenses; [ bsd3 ]; + maintainers = [ maintainers.bennofs ]; + }; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..1d9a6e4 --- /dev/null +++ b/shell.nix @@ -0,0 +1 @@ +(import ./. { }).app-shell