Skip to content

Instantly share code, notes, and snippets.

@samueldr
Last active July 11, 2018 04:43
Show Gist options
  • Save samueldr/64da1cedcf0f2678a118f5f402858148 to your computer and use it in GitHub Desktop.
Save samueldr/64da1cedcf0f2678a118f5f402858148 to your computer and use it in GitHub Desktop.
let
hostPkgs = import <nixpkgs> {};
# Look here for information about how to generate `nixpkgs-version.json`.
# → https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs
pinnedVersion = hostPkgs.lib.importJSON ./nixpkgs-version.json;
pinnedPkgs = hostPkgs.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs-channels";
inherit (pinnedVersion) rev sha256;
};
in
# This allows overriding nixpkgs by passing `--arg nixpkgs ...`
{ nixpkgs ? import pinnedPkgs {} }:
with nixpkgs;
stdenv.mkDerivation {
name = "WORK-env";
buildInputs = [
ruby
];
}
@samueldr
Copy link
Author

Here's how you'd override nixpkgs for one session...

~/tmp/ruby-shell $ nix-shell
[nix-shell:~/tmp/ruby-shell]$ which ruby
/nix/store/f3svdpbdciz3c91nc8bj8qi0adc6p5zl-ruby-2.4.4/bin/ruby
[nix-shell:~/tmp/ruby-shell]$ exit

~/tmp/ruby-shell $ nix-shell --arg nixpkgs 'import <nixpkgs> {}'
[nix-shell:~/tmp/ruby-shell]$ which ruby
/nix/store/x932mdkafx2c4dzqznj7cwa6974lywr0-ruby-2.4.4/bin/ruby
[nix-shell:~/tmp/ruby-shell]$ exit

@kalbasit
Copy link

@samueldr consider the following shell.nix. What are the pros/cons of using shell.nix with mkShell compared to what you have?

cat shell.nix                                                                                                                                                                                           ~/.private
let
  hostPkgs = import <nixpkgs> {};
  # Look here for information about how to generate `nixpkgs-version.json`.
  #  → https://nixos.wiki/wiki/FAQ/Pinning_Nixpkgs
  pinnedVersion = hostPkgs.lib.importJSON ./nixpkgs-version.json;
  pinnedPkgs = hostPkgs.fetchFromGitHub {
    owner = "NixOS";
    repo = "nixpkgs-channels";
    inherit (pinnedVersion) rev sha256;
  };
in

# This allows overriding nixpkgs by passing `--arg nixpkgs ...`
{ nixpkgs ? import pinnedPkgs {} }:

nixpkgs.mkShell {
  buildInputs = with nixpkgs; [
    ruby
    rake
  ];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment