Skip to content

Commit 2101479

Browse files
authored
Merge pull request #77 from Mic92/fix-flakes
Fix flakes
2 parents 44ce07e + 42c5d6f commit 2101479

File tree

4 files changed

+53
-12
lines changed

4 files changed

+53
-12
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.

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
removeAttrs configs.vm [ "extendModules" "override" ];
3838
};
3939

40-
nixosModules.nixos-shell = import ./share/modules/nixos-shell.nix;
40+
nixosModules.nixos-shell.imports = [ ./share/modules/nixos-shell.nix ];
4141
}
4242

4343
//

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
}

share/nixos-shell.nix

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
let
1010
lib = flake.inputs.nixpkgs.lib or (import nixpkgs { }).lib;
1111

12-
nixos-shell = import ./modules/nixos-shell.nix;
13-
nixos-shell-config = import ./modules/nixos-shell-config.nix;
14-
1512
defaultTo = default: e: if e == null then default else e;
1613

1714
getFlakeOutput = path: lib.attrByPath path null flake.outputs;
@@ -20,8 +17,8 @@ let
2017
inherit system;
2118
modules = [
2219
config
23-
nixos-shell
24-
nixos-shell-config
20+
./modules/nixos-shell.nix
21+
./modules/nixos-shell-config.nix
2522
];
2623
};
2724

@@ -33,11 +30,10 @@ let
3330

3431
flakeModule = getFlakeOutput [ "nixosModules" "${flakeAttr}" ];
3532

36-
nixosShellModules =
37-
if flakeSystem ? options.nixos-shell then
38-
[ nixos-shell-config ]
39-
else
40-
[ nixos-shell nixos-shell-config ];
33+
nixosShellModules = [
34+
./modules/nixos-shell.nix
35+
./modules/nixos-shell-config.nix
36+
];
4137
in
4238
if flakeUri != null then
4339
if flakeSystem != null then

0 commit comments

Comments
 (0)