Configuring the System Environment to match a Nix-Shell

Hey so this might be a silly question, but I came across a really useful nix-shell, structures as a flake.

I was wanting to have try use the same environment just for the entire system, ideally without messing around with the flake too much. My knowledge about how nix-shells works is very limited (ontop of being very fresh to nix), so whilst I tried to just replicate the environment using the flake as a template, I did not get that far or get it to work.

The flake in question was this one. The usecase is tinkering with an SeL4 project.

I get this probably isn’t the best idea (like this is a very good usecase for nix shells), but I still would like to try.

I’m not sure if there’s any good way to extract all the important details from a shell and reapply them to your system, but you can easily extract attributes from a shell. Here’s some examples:

~/nixpkgs $ nix repl .
nix-repl> (mkShell { packages = [ hello ]; MY_ENVVAR = 1; }).nativeBuildInputs
[ «derivation /nix/store/af3rc6phyv80h7aq4y3d08awnq2ja8fp-hello-2.12.1.drv» ]

nix-repl> (mkShell { packages = [ hello ]; MY_ENVVAR = 1; }).MY_ENVVAR
1

# REPL equivalent of referring to a flake input
nix-repl> sel4 = builtins.getFlake "github:sledgehammervampire/sel4-nix-shells"

# This one might take a while
nix-repl> sel4.devShells.x86_64-linux.sel4.buildInputs
[ «derivation /nix/store/z2czs67105cbgqk2m7bh2sjzy745gwaj-astyle-3.1.drv» «derivation /nix/store/cwzxdd3zyjrzc55pawh63w0cimxzs2s6-bash-interactive-5.1-p16.drv» .... ]

nix-repl> sel4.devShells.x86_64-linux.sel4.stdenv
«derivation /nix/store/wn9xc6dn2n9v9kdyd099jlxx9rfwpw5a-stdenv-linux.drv»

You might be able to just add the buildInputs list to the list of your environment.systemPackages if you’d like. Or extract any environment vars you need and set them equally in environment.sessionVariables.

I think you’re right about your hunch for nix-shell usecases though, I wouldn’t really recommend this setup.