Comments (8)
Try this
nix shell nixpkgs#<package name>
from nixos-config.
Nix is so damn confusing 😆
When you see any Nix command with a - in it, like nix-env
, nix-shell,
that's "legacy" and using Nix channels.
Anything with a space, like nix shell
, is the "new" way and uses flakes.
https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-shell
I dropped all usage of channels in this project, so it's flakes only.
from nixos-config.
That works, but only for the shell in which it's run. I use tmux a lot and am constantly spawning/killing shell sessions as part of the same workflow. Is there no way to install an ad-hoc package to a profile?
from nixos-config.
I kind of skipped the whole Nix profile feature in this project, as I felt it was somewhat overkill. Here's my workflow:
- Use
nix shell
for things I want to try out quickly - If I like it and want to use it, just add the package to my configuration if it's something I want to stick around. Then
nix run .#build-switch
.
Most of my packages end up in shared:
https://github.com/dustinlyons/nixos-config/blob/main/modules/shared/packages.nix
But for Darwin specific, I put them here:
https://github.com/dustinlyons/nixos-config/blob/main/modules/darwin/packages.nix
It's really easy to add and remove them without any consequence. From my understanding, profiles just give you the ability to rotate between different sets of packages in your environment, which I don't really use.
As long as you don't update your flake.lock file, and just add a package to your configuration, it's very fast to install it (~same speed as profile or nix shell). It's only when you run nix flake update
that it takes a while (as it's rebuilding all new updates).
from nixos-config.
Hi @tlindsay, curious if the above workflow is sufficient for your use case. I'd just install tmux as part of your configuration if you use it all the time (it's what I do).
from nixos-config.
tmux is installed as part of my configuration, that's not really the issue. The issue is that I lose access to whatever command I need from $ nix shell ...
as soon as I drop into a new shell (which I do frequently using tmux).
It would be nice to be able to install something and have it persist until I generate a new generation from my flake. That lets me try things out, but have them automatically garbage collected whenever I rebuild my flake. If I need something past that point, it tells me something about how useful that tool actually is, and whether it deserves to become a permanent addition.
(Also, sorry for the long delay between responses. I need to tame my Github notification settings 😅)
from nixos-config.
Okay, I understand now.
When nix shell nixpkgs#hello
runs, all it's doing is looking up if you have hello
in the Nix store, then if you don't, building it, then dropping you in a shell and adding a path like this to your PATH
variable:
/nix/store/h92a9jd0lhhniv2q417hpwszd4jhys7q-hello-2.12.1/bin
So nothing is ever really installed, it's just sitting in the Nix Store. Your PATH
is the only thing that is mutated.
You may want to look at nix-direnv
, or for more complex projects nix-direnv
+ devenv
. It doesn't exactly meet your use case (installing temporary packages with nix shell
and having them available everywhere), but it automatically makes packages available to you when you drop into a particular directory. So, if you're trying project-specific stuff, you could edit that file and not touch your main configuration. I do this for most projects I'm working on.
Otherwise, you're looking at a script that exports your PATH
from within the Nix shell and imports it back in your regular shell.
You could do something like this:
Add to your .bashrc/.zshrc:
function export_nix_path_and_exit() {
if [ -n "$IN_NIX_SHELL" ]; then
echo $PATH > /tmp/nix_path_export
fi
exit
}
trap export_nix_path_and_exit EXIT
function check_nix_shell_exit() {
if [ -n "$IN_NIX_SHELL" ]; then
# Inside Nix shell, do nothing
return
fi
if [ -f /tmp/nix_path_export ]; then
export PATH=$(cat /tmp/nix_path_export)
fi
}
PROMPT_COMMAND="check_nix_shell_exit; $PROMPT_COMMAND" (for `bash`)
precmd_functions+=(check_nix_shell_exit) (for `zsh`)
This says:
- on shell exit, check if I'm in a
nix shell
, and if I am, export myPATH
- on entering any shell, check if I've exported a
nix shell
PATH
, and if I have, override my currentPATH
To reset/clear it, you can just delete the /tmp/nix_path_export
file. This could be something you do on every rebuild with a script.
from nixos-config.
Hi @tlindsay, I'm spending some time cleaning up Github Issues. I hope the answer above helps in some way. Let me know here (on this Issue) if you have any more questions.
from nixos-config.
Related Issues (20)
- Define user context in `flake.nix` and refactor install scripts
- MacOS M2 - install issue HOT 11
- Fix chmod command in README
- aarch64-darwin/create-keys: cannot execute: No such file or directory (MacBook Pro M3 Max chip) HOT 15
- Question [Help] HOT 11
- Issue with Adding Homebrew Tap HOT 5
- dustinlyons/nix-secrets.git dependency HOT 6
- NixOS install `./bin/apply: No such file or directory` HOT 8
- Installation issue on NixOS with xvda boot disk HOT 3
- Installed new NixOS install using this repo, no GUI on reboot HOT 13
- error: selector 'bash' matches no derivations HOT 21
- Purpose of mail and name? HOT 2
- Networking wireless device fails to start HOT 3
- How to upgrade everything installed (Mac OSX Sonoma)? HOT 6
- Add -b backup to `home-manager switch` HOT 2
- error: experimental Nix feature 'nix-command' is disabled HOT 8
- starter config appears to expect secrets repo HOT 3
- Couple of issues found with the latest instructions/code HOT 4
- Homebrew not found HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nixos-config.