https://github.com/tfc/nspawn-nixos
Accompanying Code for Nixcademy.com Blog Article
https://github.com/tfc/nspawn-nixos
container nixos nspawn systemd
Last synced: 5 months ago
JSON representation
Accompanying Code for Nixcademy.com Blog Article
- Host: GitHub
- URL: https://github.com/tfc/nspawn-nixos
- Owner: tfc
- Created: 2023-08-26T11:46:11.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-22T15:37:02.000Z (7 months ago)
- Last Synced: 2024-12-07T18:22:50.717Z (6 months ago)
- Topics: container, nixos, nspawn, systemd
- Language: Nix
- Homepage: https://nixcademy.com/2023/08/29/nixos-nspawn/
- Size: 7.81 KB
- Stars: 50
- Watchers: 3
- Forks: 7
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# nspawn-nixos
This repository contains nix recipes of NixOS images that can be run on any
GNU/Linux that has `systemd` using `machinectl`.## How to run this
You don't need `nix` or NixOS to fetch and run the image:
```sh
# x86_64-linux architecture
machinectl pull-tar https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-x86_64-linux.tar.xz nixos --verify=no# aarch64-linux architecture
machinectl pull-tar https://github.com/tfc/nspawn-nixos/releases/download/v1.0/nixos-system-aarch64-linux.tar.xz nixos --verify=nomachinectl start nixos
# Set root password
machinectl shell nixos /usr/bin/env passwd
machinectl login nixos
```You can also change the configuration in this repository first, and then import
a local build:```sh
machinectl import-tar $(nix build --print-out-paths)/tarball/* nixos
```If you want the container to use the host's network, create a configuration
file like this:```sh
printf "[Network]\nVirtualEthernet=no" > /etc/systemd/nspawn/nixos.nspawn
```The system configuration in `/etc/nixos/configuration.nix` can be adapted to
your needs.
`nixos-rebuild switch` activates a new configuration.If you would like to share mounts between host and container, create port
mappings, etc. please refer to the
[`systemd.nspawn` config file documentation](https://man7.org/linux/man-pages/man5/systemd.nspawn.5.html)
and/or the [archlinux wiki about `systemd-nspawn`](https://wiki.archlinux.org/title/systemd-nspawn)## Why not Docker images?
Docker puts the file system of any Linux distro around a single process, but it
essentially does not run a whole system.
Running NixOS (or any other distro) in `systemd-nspawn` is similar to running a
full VM, but with the same thin namespace isolation as in Docker, which leads to
less overhead.Changes that you do to your nspawn container remain persistent by default.