mirror of
https://github.com/nushell/nushell.git
synced 2026-10-28 17:05:03 +08:00
I saw #10945 and added some notes in the `scripts/nix/README.md` file on how to use it properly in the non-root directory. Closes #10352. --- Allows including in another flake using the `...?dir=scripts/nix` option on the flake url. Some common uses in the repo: ```console $ # Build nushell $ nix build ./scripts/nix $ # Enter the development shell (sadly it's bash, use .envrc for nu) $ nix develop ./scripts/nix $ # Enable direnv for this project $ "use flake ./scripts/nix" | save -a ./.envrc ``` Everything else should be nicely extracted from the `rust-toolchain.toml` and `Cargo.toml`s around the repo, making changes outside the nix directory require almost no intervention, unless dependencies change or a new plugin is added. --- <!-- Thank you for improving Nushell! Please, read our contributing guide: https://github.com/nushell/nushell/blob/main/CONTRIBUTING.md --> ## Release notes summary - What our users need to know <!-- This section will be included as part of our release notes. See the contributing guide for more details. Please include only details relevant for users here. Motivation and technical details can be added above or below this section. You may leave this section blank until your PR is finalized. Ask a core team member if you need help filling this section. --> ## Tasks after submitting <!-- Remove any tasks which aren't relevant for your PR, or add your own --> - [ ] Update the [documentation](https://github.com/nushell/nushell.github.io)
2.7 KiB
2.7 KiB
Nix Flake for Nushell
Placed in the scripts/nix directory to keep it nicely out of the root of the repo, but also allow
including and building with the latest sources. Due to it not being in the root most nix commands
will need to be told the location of the flake:
$ nix run ./scripts/nix
$ nix build ./scripts/nix
$ nix flake update --flake ./scripts/nix
Including in another flake
# flake.nix
{
inputs = {
nixpkgs.url = "...";
nushell = {
url = "github:nushell/nushell?dir=scripts/nix";
inputs.nixpkgs.follows = "nixpkgs"; # optional
};
};
outputs = inputs: {
# ...
# I would recommend using a `for-each-system` function of some kind here.
packages.x86_64-linux = {
nushell = inputs.nushell.packages.x86_64-linux.nushell;
};
}
}
Adding the hash to version
The inputs.nushell.rev variable can be used to get the commit hash in the
output of version:
{
# ...
nushell = inputs.nushell.packages.x86_64-linux.nushell.override {
NU_COMMIT_HASH = inputs.nushell.rev;
};
# ...
}
Using the Overlay
This flake also includes an overlay to allow using the new nushell and plugins
without modifying every instance of nushell in the configuration. This is a
more complex example than the one above, allowing multiple systems and showing
an example of a nixosConfiguration that uses the flakes nushell.
{
outputs = inputs:
let
systems = [
# List of systems to enable, for example:
"x86_64-linux"
"aarch64-darwin"
];
# And for packages or other system-specific inputs, use a function that
# overlays overlays set during the nixpkgs import:
forEachSystem =
f:
inputs.nixpkgs.lib.genAttrs systems (
system:
f {
pkgs = import inputs.nixpkgs {
inherit system;
overlays = [ inputs.nixpkgs.overlays.default ];
}
}
);
in
{
packages = forEachSystem ({pkgs, ...}: {inherit nushell;});
# For a nixos configuration, add it to the `nixpkgs.overlays`. If a nixos
# configuration is all that is required, this is the only part needed
nixosConfiguration.yourHost = inputs.nixpkgs.lib.nixosSystem {
system = "...";
modules = [
{
nixpkgs.overlays = [
inputs.nushell.overlays.default
];
}
./configuration.nix
# ... other modules
];
};
};
}
Using Without Flakes
The package can be built using the scripts/nix/default.nix file:
let
pkgs = import <nixpkgs> { };
in
{
nushell = pkgs.callPackage ./scripts/nix { };
}