NixOS

!nixos

@infosec.pub
Create post
Need to run something and nix just isn't cutting it? No worries, distrobox will save the day!

Need to run something and nix just isn't cutting it? No worries, distrobox will save the day!

I made a post a while ago asking what you do when NixOS isn't cutting it. You need a package that isn't available as a flatpak/appimage or already in nixpkgs. You don't want to build from source, because it's either too difficult or too time consuming. One suggestion was containerization or virtual machines, but those seemed too cumbersome. Well, distrobox is the tool that fixes it.

Distrobox is a shell script that wraps over docker/podman to run a container of a distribution of your choice. But it does it behind a very high level API, and integrates the container environment seemlessly with your host environment. It is seriously as easy as this, if you need to install something with apt inside debian.

$ distrobox create -n my_debian --image debian:latest
$ distrobox enter my_debian

And bang, your in a debian container and it won't even feel like it. It automatically integrates your shell environment and maps your root directory inside the container (or something like that.) You seriously wouldn't know unless you neofetch. Best part is that since everything is in the nix store, every program in your environment should work, for the most part, inside this container. I've not noticed problems yet.

Tada! apt is available in this environment and you can install what you need. Then you can run it while inside the container. From the host machine, outside the container, you can run it directly too. Say you installed program X in debian:

$ distrobox enter my_debian -- X

And it will just run the command and send you back to the host machine.

In the case of docker, you can type docker ps and it will show you your debian image my_debian listed.

There's two more things I want to do to really polish this workflow. The first is to change my shell prompt so I know that I'm actually in debian without typing neofetch! Inside the box the variable CONTAINER_ID is set and the hostname is modified. I've adjusted my starship prompt to look like this when inside the box:

distrobox:my_debian ~ $

And lastly, I really want to blur the lines. If I install X in debian, I want to just call it directly from the host as X, not invoke my debian instance with distrobox enter.

When you type X and the program is missing, bash (and fish and zsh I'm sure) runs a hook that you can look at by typing

$ declare -p -f command_not_found_handle

By overriding this, you could first have it try the inside container if it can't find the application in the host container, like so.

command_not_found_handle () {
  distrobox enter my_debian -- $@
}

This is not a perfect solution, but I'm still experimenting with how to integrate this both seamlessly and also not accidentally run things inside debian and not realize it. If you have suggestions for how to improve handling calling commands from the outside environment, please share. Best case might just be adding aliases for programs explicitly. For example, `alias X=distrobox enter my_debian -- X.

Anyway, distrobox is the solution! This is one more barrier removed that was preventing me from moving my main computer over to NixOS. I'm so happy to have found this and wanted to share.

Any flutter devs got a build environment working?

Any flutter devs got a build environment working?

I was trying to use a flake with nix-pkg to set up a flutter dev environment but it just wouldn't stick, and a lot of the examples online are quite old and not documented well for a nix noob like myself.

Cheers folks!

Can someone explain NixOS to me like I'm absolutely clueless?

Can someone explain NixOS to me like I'm absolutely clueless?

I've been hearing a lot about it lately and I'm intrigued, but also utterly confused.

Is this a Linux distro I'd install on bare metal because it offers a new way of package management that addresses the issues other distros have?
Is it something I install in the distro I currently use?
How does it work and what does it do?

I've tried to read https://nixos.org/guides/how-nix-works but the first sentence is

"Nix is a purely functional package manager. This means that it treats packages like values in purely functional programming languages such as Haskell"

and that's where it lost me. Thanks for helping me understand!

Setting Up a NixOS 23.05 Development VM on Hetzner Cloud with nixos-anywhere

Setting Up a NixOS 23.05 Development VM on Hetzner Cloud with nixos-anywhere

Open link in next tab

Setting Up a NixOS 23.05 Development VM on Hetzner Cloud with nixos-anywhere!

https://www.youtube.com/watch?v=wr22CyoyRo4

https://www.youtube.com/playlist?list=PLllZnrEJu89Dl_YFJ-EIpG4a_9NFP0Awvhttps://github.com/LGUG2Z/nixos-hetzner-cloud-starterSponsor me on GitHub: https://gi...

A sane, batteries-included starter template for running NixOS on WSL

A sane, batteries-included starter template for running NixOS on WSL

Open link in next tab

Setting Up a LunarVim-Powered NixOS 23.05 Development VM on Windows 11 with WSL2

https://www.youtube.com/watch?v=UmRXXYxq8k4

https://github.com/LGUG2Z/nixos-wsl-starterSponsor me on GitHub: https://github.com/sponsors/LGUG2ZCheck out my website: https://LGUG2Z.comFollow me on Masto...

How to setup nixos with external encrypted raid

How to setup nixos with external encrypted raid

My server is currently running fedora and it has a encrypted raid attatched. Now i wanna move my server to nixos but i cant find anything on how to automount it. Any advice ? Thanks for your time and have a nice day!

Let NixOS or Home-Manager manage X, not both

Let NixOS or Home-Manager manage X, not both

I've been spending a couple weeks unable to modify my system, because using my window manager was ungodly slow (like 1fps.) Luckily NixOS lets you pick a previous generation to load so I could make changes, build a new generation, and try again.

It took me too long to find, but I realized I had both the x session managed by both nixos and home manager. Removing this fixed the problem. I assume this had 2 xsessions open and they were competing for resources or something. Be cautious! :)

How do I share my flakes for external projects?

How do I share my flakes for external projects?

Every now and then I see a program that doesn't have a default.nix or flake.nix in the source, doesn't have an entry in nixpkgs, and otherwise can't find a derivation for. So I write them myself.

What's the best way to share these? Should I contribute to nixpkgs? (does this count if I'm making flakes?) Do I maintain a single repo for each program? Or do I create a repo with a collection of flakes? Something else?

How is the situation of nix/nix-darwin/home-manager on macOS?

How is the situation of nix/nix-darwin/home-manager on macOS?

Used nix last year but dropped it after home-manager decided to unlink the apps from the Applications directory.

How is the current situation on usability of nix-Darwin + home-manager + brew?

Packages still fails to get indexed correctly in spotlight? I really like a fully repro environment but the fact that the usu ability was low bothered me a lot.

How do you manage the software on your personal workstation?

How do you manage the software on your personal workstation?

I recently wanted to try out (aider)[https://aider.chat], and ran into a problem that I continually run into: how do I install one-off, experimental software into my environment, without being a nix master, or spending an extreme amount of time on every new package.

In this case, it is a new python package available in pip. It isn't available in nixpkgs, and isn't nixified. pip2nix doesn't work on arm64 Macs (bug here)[https://github.com/nix-community/pip2nix/issues/88], so I can't use that to try and create a flake that works with this package. It isn't using poetry, so poetry2nix is out.

How are you dealing with this problem? Are you all experts in nix, and writing flakes for every piece of software that you want to play around with? Do you have a "dirty" part of your environment that you install this kind of stuff into? (I looked into using pipx to install this, however that (also has a bug)[https://github.com/NixOS/nixpkgs/issues/171429] in nixpkgs.)

Thoughts?