Skip to content

nix-env -> nix-shell #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
84 changes: 73 additions & 11 deletions default.nix
Original file line number Diff line number Diff line change
@@ -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 ];
};
}
43 changes: 30 additions & 13 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

119 changes: 30 additions & 89 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
44 changes: 44 additions & 0 deletions package.nix
Original file line number Diff line number Diff line change
@@ -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 ];
};
}
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(import ./. { }).app-shell