Skip to content

Commit 42c5d6f

Browse files
committed
allow to nix run nixos-shells from flakes
now it's possible to do this: ```nix { imports = [ inputs.nixos-shell.nixosModules.nixos-shell ]; } For the pure version (doesn't set SHELL or mount /home): ``` nix run .#nixosConfigurations.installer.config.system.build.nixos-shell ``` Or for a version closer to `nixos-shell`: ``` nix run .#nixosConfigurations.myconfig.config.system.build.nixos-shell ```
1 parent 1fd965a commit 42c5d6f

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ If an attribute _name_ is given, `nixos-shell` tries the following flake output
6767
- `nixosConfigurations.<name>`
6868
- `nixosModules.<name>`
6969
70+
7071
## Terminating the virtual machine
7172
7273
Type `Ctrl-a x` to exit the virtual machine.
@@ -247,6 +248,40 @@ To avoid having to download a nix-channel every time the VM is reset, you can us
247248

248249
This will add the nixpkgs that is used for the VM in the NIX_PATH of login shell.
249250

251+
## Embedding nixos-shell in your own nixos-configuration
252+
253+
Instead of using the cli, it's also possible to include the `nixos-shell` NixOS module in your own NixOS configuration.
254+
255+
Add this to your `flake.nix`:
256+
257+
```nix
258+
{
259+
inputs.nixos-shell.url = "github:Mic92/nixos-shell";
260+
}
261+
```
262+
263+
And this to your nixos configuration defined in your flake:
264+
265+
```nix
266+
{
267+
imports = [ inputs.nixos-shell.nixosModules.nixos-shell ];
268+
}
269+
```
270+
271+
Afterwards you can start your nixos configuration with nixos-shell with one of the two following variants:
272+
273+
For the pure version (doesn't set SHELL or mount /home):
274+
275+
```
276+
nix run .#nixosConfigurations.<yourmachine>.config.system.build.nixos-shell
277+
```
278+
279+
Or for a version closer to `nixos-shell`:
280+
281+
```
282+
nix run .#nixosConfigurations.<yourmachine>.config.system.build.nixos-shell
283+
```
284+
250285
## More configuration
251286

252287
Have a look at the [virtualisation] options NixOS provides.

share/modules/nixos-shell.nix

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ lib, modulesPath, ... }:
1+
{ lib, modulesPath, pkgs, extendModules, ... }:
22

33
{
44
imports = [
@@ -59,4 +59,14 @@
5959
};
6060
};
6161
};
62+
63+
config = let
64+
vmSystem = extendModules {
65+
modules = [
66+
./nixos-shell-config.nix
67+
];
68+
};
69+
in {
70+
system.build.nixos-shell = vmSystem.config.system.build.vm;
71+
};
6272
}

0 commit comments

Comments
 (0)