GithubHelp home page GithubHelp logo

mitchellh / nixos-config Goto Github PK

View Code? Open in Web Editor NEW
1.8K 42.0 176.0 3.7 MB

My NixOS configurations.

Home Page: https://twitter.com/mitchellh/status/1346136404682625024

License: MIT License

Nix 84.73% Shell 8.54% Makefile 6.48% Scheme 0.25%

nixos-config's Introduction

NixOS System Configurations

This repository contains my NixOS system configurations. This repository isn't meant to be a turnkey solution to copying my setup or learning Nix, so I want to apologize to anyone trying to look for something "easy". I've tried to use very simple Nix practices wherever possible, but if you wish to copy from this, you'll have to learn the basics of Nix, NixOS, etc.

I don't claim to be an expert at Nix or NixOS, so there are certainly improvements that could be made! Feel free to suggest them, but please don't be offended if I don't integrate them, I value having my config work over having it be optimal.

How I Work

I like to use macOS as the host OS and NixOS within a VM as my primary development environment. I use the graphical applications on the host (browser, calendars, mail app, iMessage, etc.) but I do almost everything dev-related in the VM (editor, compilation, databases, etc.).

Inevitably I get asked why? I genuinely like the macOS application ecosystem, and I'm pretty "locked in" to their various products such as iMessage. I like the Apple hardware, and I particularly like that my hardware always Just Works with excellent performance, battery life, and service. However, I prefer the Linux environment for almost all my dev work. I find that modern computers are plenty fast enough for the best of both worlds.

Here is what it ends up looking like:

Screenshot

Note that I usually full screen the VM so there isn't actually a window, and I three-finger swipe or use other keyboard shortcuts to active that window.

Common Questions Related To This Workflow

How does web application development work? I use the VM's IP. Even though it isn't strictly static, it never changes since I rarely run other VMs. You just have to make sure software in the VM listens on 0.0.0.0 so that it isn't only binding to loopback.

Does copy/paste work? Yes.

Do you use shared folders? I set up a shared folder so I can access the home directory of my host OS user, but I very rarely use it. I primarily only use it to access browser downloads. You can see this setup in these Nix files.

Do you ever launch graphical applications in the VM? Sometimes, but rarely. I'll sometimes do OAuth flows and stuff using FireFox in the VM. Most of the time, I use the host OS browser.

Do you have graphical performance issues? For the types of graphical applications I run (GUIs, browsers, etc.), not really. VMware (and other hypervisors) support 3D acceleration on macOS and I get really smooth rendering because of it.

This can't actually work! This only works on a powerful workstation! I've been doing this since late 2020, and I've developed a lot of very real software. It works for me. I also use this VM on a MacBook Pro (to be fair, it is maxed out on specs), and I have no issues whatsoever.

Does this work with Apple Silicon Macs? Yes, I use VMware Fusion but my configurations also work for Parallels and UTM. Folder syncing, clipboards, and graphics acceleration all work. I've been using an Apple Silicon Mac full time since Nov 2021 with this setup.

Does this work on Windows? Yes, I've tested this setup with both Hyper-V and VMware Workstation Pro and it works great in either case.

Setup (VM)

Video: https://www.youtube.com/watch?v=ubDMLoWz76U

Note: This setup guide will cover VMware Fusion because that is the hypervisor I use day to day. The configurations in this repository also work with UTM (see vm-aarch64-utm) and Parallels (see vm-aarch64-prl) but I'm not using that full time so they may break from time to time. I've also successfully set up this environment on Windows with VMware Workstation and Hyper-V.

You can download the NixOS ISO from the official NixOS download page. There are ISOs for both x86_64 and aarch64 at the time of writing this.

Create a VMware Fusion VM with the following settings. My configurations are made for VMware Fusion exclusively currently and you will have issues on other virtualization solutions without minor changes.

  • ISO: NixOS 23.05 or later.
  • Disk: SATA 150 GB+
  • CPU/Memory: I give at least half my cores and half my RAM, as much as you can.
  • Graphics: Full acceleration, full resolution, maximum graphics RAM.
  • Network: Shared with my Mac.
  • Remove sound card, remove video camera, remove printer.
  • Profile: Disable almost all keybindings
  • Boot Mode: UEFI

Boot the VM, and using the graphical console, change the root password to "root":

$ sudo su
$ passwd
# change to root

At this point, verify /dev/sda exists. This is the expected block device where the Makefile will install the OS. If you setup your VM to use SATA, this should exist. If /dev/nvme or /dev/vda exists instead, you didn't configure the disk properly. Note, these other block device types work fine, but you'll have to modify the bootstrap0 Makefile task to use the proper block device paths.

Also at this point, I recommend making a snapshot in case anything goes wrong. I usually call this snapshot "prebootstrap0". This is entirely optional, but it'll make it super easy to go back and retry if things go wrong.

Run ifconfig and get the IP address of the first device. It is probably 192.168.58.XXX, but it can be anything. In a terminal with this repository set this to the NIXADDR env var:

$ export NIXADDR=<VM ip address>

The Makefile assumes an Intel processor by default. If you are using an ARM-based processor (M1, etc.), you must change NIXNAME so that the ARM-based configuration is used:

$ export NIXNAME=vm-aarch64

Other Hypervisors: If you are using Parallels, use vm-aarch64-prl. If you are using UTM, use vm-aarch64-utm. Note that the environments aren't exactly equivalent between hypervisors but they're very close and they all work.

Perform the initial bootstrap. This will install NixOS on the VM disk image but will not setup any other configurations yet. This prepares the VM for any NixOS customization:

$ make vm/bootstrap0

After the VM reboots, run the full bootstrap, this will finalize the NixOS customization using this configuration:

$ make vm/bootstrap

You should have a graphical functioning dev VM.

At this point, I never use Mac terminals ever again. I clone this repository in my VM and I use the other Make tasks such as make test, make switch, etc. to make changes my VM.

Setup (macOS/Darwin)

THIS IS OPTIONAL AND UNRELATED TO THE VM WORK. I recommend you ignore this unless you're interested in using Nix to manage your Mac too.

I share some of my Nix configurations with my Mac host and use Nix to manage some aspects of my macOS installation, too. This uses the nix-darwin project. I don't manage everything with Nix, for example I don't manage apps, some of my system settings, Homebrew, etc. I plan to migrate some of those in time.

To utilize the Mac setup, first install Nix using some Nix installer. There are two great installers right now: nix-installer by Determinate Systems and Flox. The point of both for my configs is just to get the nix CLI with flake support installed.

Once installed, clone this repo and run make. If there are any errors, follow the error message (some folders may need permissions changed, some files may need to be deleted). That's it.

WARNING: Don't do this without reading the source. This repository is and always has been my configurations. If you blindly run this, your system may be changed in ways that you don't want. Read my source!

Setup (WSL)

THIS IS OPTIONAL AND UNRELATED TO THE VM WORK. I recommend you ignore this unless you're interested in using Nix to manage your WSL (Windows Subsystem for Linux) environment, too.

I use Nix to build a WSL root tarball for Windows. I then have my entire Nix environment on Windows in WSL too, which I use to for example run Neovim amongst other things. My general workflow is that I only modify my WSL environment outside of WSL, rebuild my root filesystem, and recreate the WSL distribution each time there are system changes. My system changes are rare enough that this is not annoying at all.

To create a WSL root tarball, you must be running on a Linux machine that is able to build x86_64 binaries (either directly or cross-compiling). My aarch64 VMs are all properly configured to cross-compile to x86_64 so if you're using my NixOS configurations you're already good to go.

Run make wsl. This will take some time but will ultimately output a tarball in ./result/tarball. Copy that to your Windows machine. Once it is copied over, run the following steps on Windows:

$ wsl --import nixos .\nixos .\path\to\tarball.tar.gz
...

$ wsl -d nixos
...

# Optionally, make it the default
$ wsl -s nixos

After the wsl -d command, you should be dropped into the Nix environment. Voila!

FAQ

Why do you still use niv?

I am still transitioning into a fully flaked setup. During this transition (which is indefinite, I'm in no rush), I'm using both.

nixos-config's People

Contributors

cor avatar fud avatar girishramnani avatar klivan avatar lucamaraschi avatar mitchellh avatar rnd avatar supermarin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nixos-config's Issues

make vm/switch failing on bootctl update

Hi @mitchellh, thank you so much for this repository. I realize you aren't a personal support line so no worries/rush/expectations are made when raising this issue.

I recently tried this with an Intel-based MacOS machine and VMware Fusion 12.

I followed the same VM settings. NixOS is version 21.11.

I commented out vm/secret, but other than that, the settings are the same. When running make vm/bootstrap, I receive the following error:

NIXUSER=root /Library/Developer/CommandLineTools/usr/bin/make vm/switch
ssh -o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p22 [email protected] " \
                sudo NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nixos-rebuild switch --flake \"/nix-config#vm-intel\" \
        "
Warning: Permanently added '192.168.189.132' (ED25519) to the list of known hosts.
Password:
building the system configuration...
Skipping "/boot/EFI/systemd/systemd-bootx64.efi", since a newer boot loader version exists already.
Skipping "/boot/EFI/BOOT/BOOTX64.EFI", since a newer boot loader version exists already.
updating systemd-boot from (249.7) to (249.5)
Traceback (most recent call last):
  File "/nix/store/jjmymx70npfmdl6fhjb71py9fhj9yrk3-systemd-boot", line 314, in <module>
    main()
  File "/nix/store/jjmymx70npfmdl6fhjb71py9fhj9yrk3-systemd-boot", line 267, in main
    subprocess.check_call(["/nix/store/q0881awy50g4srnnwasci37y2jk5sf99-systemd-249.5/bin/bootctl", "--path=/boot", "update"])
  File "/nix/store/5bh6rpya1ar6l49vrhx1rg58dsa42906-python3-3.9.6/lib/python3.9/subprocess.py", line 373, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['/nix/store/q0881awy50g4srnnwasci37y2jk5sf99-systemd-249.5/bin/bootctl', '--path=/boot', 'update']' returned non-zero exit status 1.
warning: error(s) occurred while switching to the new configuration
make[1]: *** [vm/switch] Error 1
make: *** [vm/bootstrap] Error 2

Curious if you or others have seen this, and if there's a particular setting that could be triggering it.

Missing `/dev/sda` in Nixos VM

Hello,

I managed to create a nixos ISO (on a M1) and run it, but when I try to bootstrap it complains that /dev/sda doesn't exist:

❯ make vm/bootstrap0
ssh -o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -p22 [email protected] " \
		parted /dev/sda -- mklabel gpt; \
		parted /dev/sda -- mkpart primary 512MiB -8GiB; \
		parted /dev/sda -- mkpart primary linux-swap -8GiB 100\%; \
		parted /dev/sda -- mkpart ESP fat32 1MiB 512MiB; \
		parted /dev/sda -- set 3 esp on; \
		mkfs.ext4 -L nixos /dev/sda1; \
		mkswap -L swap /dev/sda2; \
		mkfs.fat -F 32 -n boot /dev/sda3; \
		mount /dev/disk/by-label/nixos /mnt; \
		mkdir -p /mnt/boot; \
		mount /dev/disk/by-label/boot /mnt/boot; \
		nixos-generate-config --root /mnt; \
		sed --in-place '/system\.stateVersion = .*/a \
			nix.package = pkgs.nixUnstable;\n \
			nix.extraOptions = \"experimental-features = nix-command flakes\";\n \
  			services.openssh.enable = true;\n \
			services.openssh.passwordAuthentication = true;\n \
			services.openssh.permitRootLogin = \"yes\";\n \
			users.users.root.initialPassword = \"root\";\n \
		' /mnt/etc/nixos/configuration.nix; \
		nixos-install --no-root-passwd; \
		reboot; \
	"
Warning: Permanently added '192.168.136.130' (ED25519) to the list of known hosts.
([email protected]) Password:
Error: Could not stat device /dev/sda - No such file or directory.
Error: Could not stat device /dev/sda - No such file or directory.
Error: Could not stat device /dev/sda - No such file or directory.
Error: Could not stat device /dev/sda - No such file or directory.
Error: Could not stat device /dev/sda - No such file or directory.
mke2fs 1.46.4 (18-Aug-2021)
The file /dev/sda1 does not exist and no size was specified.
mkswap: cannot open /dev/sda2: No such file or directory
mkfs.fat 4.1 (2017-01-24)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
mkfs.fat: unable to open /dev/sda3: No such file or directory
mount: /mnt: special device /dev/disk/by-label/nixos does not exist.
mount: /mnt/boot: special device /dev/disk/by-label/boot does not exist.
writing /mnt/etc/nixos/hardware-configuration.nix...

Is there an obvious setting in VMware that I missed?

Run a Linux builder in the background

I recently added a module to my nix-darwin config (see here) that runs a Linux builder as a background process on my Apple M1. I was inspired by this comment on Discourse and the fantastic work of Gabriella Gonzalez. If you'd like, I'd be more than happy to add this capability to your configs here as an alternative to the Docker builder. I can now run nix build <flake>#packages.aarch64-linux.<package> without a second thought on macOS and it's been a real game changer for me.

Some notes for UTM/QEMU

Been working with trying to get bootstrapped off of this setup, thanks @mitchellh!

Couple of things I've noticed as I've been messing with this on UTM:

  • We need the userspace spice-vdagent (not vdagentd) running in the user's X session, e.g. launched out of .xprofile.
  • UTM prior to 4.4.0 does not handle accessibility resizing properly which might drive you wild trying to figure out what is going on when troubleshooting dynamic resolution while doing things like snapping to edges in Rectangle.
  • LIBGL_ALWAYS_SOFTWARE may be unnecessary now, unless I haven't stumbled on issues yet. 😉 I was building from scratch and didn't include this option, and things seemed to be working okay.

I'll add a PR once I get more settled in with my config!

I might also take a stab at adding some automation for dynamic resolution too so that I don't necessarily need to run xrandr-auto super quick after I resize. I noticed the note about udev rules, I'll see if I can find a way to get this tidy so that it's localized to the UTM setup!

running it on Windows

Hi Mitchell,
I can confirm that everything runs fine on Windows with VMware (pro) 16.x :-)
I used WSL2 for running the Makefile because, apart from make a few other tools are needed.
Checking out the repo from WS2 directly avoids some problems with end of line feeds.
I had some trouble at times with kernel going into emergency mode and complaining about being unable to mount host.
I believe this was caused by me not following closely how you configured the VM (3d Acceleration, sound off sharing enabled).
The Readme still says SATA where as you otherwise mentioned that with the Makefile as is, it only works with SCSI.

Otherwise thanks a lot for open sourcing this!
I am a huge fan of running reproducible Dev environments on Linux(VMs mostly) and I am also running nix on Windows WSL2 since a while. A few years ago (ok almost 8 years) I was creating and maintaining dev environments for a couple of hundred developers, which worked quite well. this was (well is, because it seems people are still using it) based on Chef scripts (yes 😢 ) and later Docker.

Stuck at restart dhcpd.service and sshd.service?

I'm tryng to default test this repo, but when i do make vm/bootstrap i got this errro:

building '/nix/store/gw61nhppdd7qwzjbng88mhccaphy7n2a-system-units.drv'...
building '/nix/store/4swkhlmpyxcbrkk373168h4gazc3sgld-etc.drv'...
building '/nix/store/4n4wh9xbhqnjgdi08z22dyrbw8yhmyyw-nixos-system-dev-23.05.20230728.48e82fe.drv'...
stopping the following units: -.mount, boot.mount, firewall.service, network-setup.service, systemd-modules-load.service, systemd-sysctl.service, systemd-udevd-control.socket, systemd-udevd-kernel.socket, systemd-udevd.service
Failed to stop -.mount: Job type stop is not applicable for unit -.mount.
NOT restarting the following changed units: systemd-fsck@dev-disk-by\x2duuid-7130\x2dF67C.service
activating the configuration...
setting up /etc...
reloading user units for root...
setting up tmpfiles
reloading the following units: dbus.service
restarting the following units: dhcpcd.service, sshd.service
client_loop: send disconnect: Broken pipe
make[1]: *** [Makefile:115: vm/switch] Error 255
make[1]: Leaving directory '/home/user/.nix/nixos-config'
make: *** [Makefile:83: vm/bootstrap] Error 2

the config is kept unchange while i'm doing the test. but this test is with kvm/qemu as vm on archliux, not a vm on macos.

i use host networking for vm, so vm get ip address directly from router.

then I have this change:
vi machines/vm-intel.nix

{ config, pkgs, ... }: {
  imports = [
    ./vm-shared.nix
  ];

  # virtualisation.vmware.guest.enable = true;

  # Interface is this on Intel Fusion
  # networking.interfaces.ens33.useDHCP = true;

  # Shared folder to host works on Intel
  # fileSystems."/host" = {
  #   fsType = "fuse./run/current-system/sw/bin/vmhgfs-fuse";
  #   device = ".host:/";
  #   options = [
  #     "umask=22"
  #     "uid=1000"
  #     "gid=1000"
  #     "allow_other"
  #     "auto_unmount"
  #     "defaults"
  #   ];
  # };
}

it stuck at:

building '/nix/store/szfnbji0y6dd3sgzjfvr5kqlyx6286if-etc.drv'...
building '/nix/store/9bb8qhrng6ba7w4776p4kqbyikrgwips-nixos-system-dev-23.05.20230728.48e82fe.drv'...
stopping the following units: -.mount, boot.mount, dhcpcd.service, firewall.service, systemd-modules-load.service, systemd-sysctl.service, systemd-udevd-control.socket, systemd-udevd-kernel.socket, systemd-udevd.service
Failed to stop -.mount: Job type stop is not applicable for unit -.mount.

ip ad under vm show no ip address that host can ping (the ip address from previou step that i export NIXADDR= gone)

bootstrap stalls and a restart login says root password is incorrect

[update: you may disregard this comment since the third comment has more reproducible detail]

I followed the instructions with a UTM setup on an M1 macbook. I can run git clone and ping google, so there doesn't seem to be network issues. ifconfig gave me an ip address which I used in the NIXADDR environment variable as instructed. After running make vm/bootstrap0 successfully and ensuring the project was ready again to run the second script, I ran make vm/bootstrap and it had an ssh error.
ssh: connect to host 192.164.64.4 port 22: Connection refused
rsync error: unexplained error (code 255) at io.c(228) [sender=3.2.5]
Note: I don't have clipboard sharing functioning so it's just retyped from what I see.
I rebooted the OS and it asks nixos login: If I enter root it asks Password: and root prompts a response Login incorrect I have attempted empty fields for login and password already.

konsole not starting

Hi Mitchell, thanks for sharing this, this is EXACTLY what I was looking for!

My "issue" is probably not really an issue with your setup, but I don't have the knowledge to debug and get beyond this, so your help is much appreciated:

I went through all your steps, learned a lot in going through your setup, but in the last step, after logging in from the VM window, I never got the terminal window! I am just stuck with the nixos logo background.

I am sure this must be a trivial problem. ssh into the virtual machine works just fine, rebuild/switch within the VM also no problem over ssh, but I don't know how to get the VM window to show the terminal prompt.

Any help with this is much appreciated -- I'm so close to the perfect setup now!

Thanks, LatB

Missing conditional

I started from latest NixOS 22.05.926.8b538fcb329. Seems like vmware-user-suid-wrapper is missing, which makes it bail out:

Checking that Nix store paths of all wrapped programs exist... FAIL
The path /nix/store/4nr8h0y47xn8vpb4llv7fj2nbjn0pwg8-open-vm-tools-12.0.0/bin/vmware-user-suid-wrapper does not exist!
Please, check the value of `security.wrappers."vmware-user-suid-wrapper".source`.
Adding hwdb files for package /nix/store/vb55ph7qmjj85lfaa709jlxllvfpfb6j-systemd-250.4
Adding rules for package /nix/store/4nr8h0y47xn8vpb4llv7fj2nbjn0pwg8-open-vm-tools-12.0.0

error: builder for '/nix/store/yhv7v1k132zrqqdzl7cz30p5zxrm1ffp-ensure-all-wrappers-paths-exist.drv' failed with exit code 1
error: 1 dependencies of derivation '/nix/store/g132qpgx4lr5bl5vfv6x6vm5rgx4qf5z-nixos-system-nixos-22.05.926.8b538fcb329.drv' failed to build

Indeed:

$ ls /nix/store/4nr8h0y47xn8vpb4llv7fj2nbjn0pwg8-open-vm-tools-12.0.0/bin/
vmhgfs-fuse  vmware-checkvm     vmware-namespace-cmd  vmware-toolbox-cmd   vmware-xferlogs
vmtoolsd     vmware-hgfsclient  vmware-rpctool        vmware-vmblock-fuse  vmwgfxctrl

In any case it feels like there's a missing mkIf (!cfg.headless) conditional since IIRC its only use is for X?

    security.wrappers.vmware-user-suid-wrapper = mkIf (!cfg.headless) {
      setuid = true;
      owner = "root";
      group = "root";
      source = "${open-vm-tools}/bin/vmware-user-suid-wrapper";
    };

And with that I was good to go with my headless setup.

Bootstrap on intel throws an error during vm/switch

From a fresh install on VMWare Fusion 12.2.0 (18760249) on an Intel machine, the following error is thrown during the bootstrap phase (make vm/bootstrap) using the latest main branch code without any change (impersonating mitchellh on the VM ;-))

building the system configuration...
error: anonymous function at /nix/store/z2kiwivn50v7ncd4p362g1gjwi2ng2vi-source/lib/mkvm.nix:3:7 called without required argument 'overlays'

       at /nix/store/z2kiwivn50v7ncd4p362g1gjwi2ng2vi-source/flake.nix:44:36:

           43|
           44|     nixosConfigurations.vm-intel = mkVM "vm-intel" rec {
             |                                    ^
           45|       inherit nixpkgs home-manager;
make[1]: *** [vm/switch] Error 1

As per the video, I applied the same settings.
The only change I made is in the makefile to disable the step vm/secrets during bootstrap.

Root account locked

i am getting the error "cannot open access to console, the root account is locked". I haven't seen any other issues reporting this.

Screenshot 2024-02-29 at 11 27 08

Running setup on vm-aarch64 throws error

I tried to run the latest codebase on VMWare Professional Version e.x.p (18656771) and using as iso the latest generated by make iso/nixos.iso however, the make vm/bootstrap throws in the terminal with:

building the system configuration...
trace: warning: literalExample is deprecated, use literalExpression instead, or use literalDocBook for a non-Nix description.
could not find any previously installed systemd-boot
stopping the following units: -.mount, audit.service, boot.mount, dbus.service, firewall.service, kmod-static-nodes.service, mount-pstore.service, network-local-commands.service, network-setup.service, nscd.service, resolvconf.service, systemd-journal-catalog-update.service, systemd-journald.service, systemd-modules-load.service, systemd-sysctl.service, systemd-timesyncd.service, systemd-tmpfiles-setup-dev.service, systemd-udev-trigger.service, systemd-udevd.service, systemd-update-done.service
Failed to stop -.mount: Job type stop is not applicable for unit -.mount.
Warning: Stopping dbus.service, but it can still be activated by:
  dbus.socket
Warning: Stopping systemd-journald.service, but it can still be activated by:
  systemd-journald-dev-log.socket
  systemd-journald-audit.socket
  systemd-journald.socket
Warning: Stopping systemd-udevd.service, but it can still be activated by:
  systemd-udevd-control.socket
  systemd-udevd-kernel.socket
activating the configuration...
setting up /etc...
removing obsolete symlink ‘/etc/ssl/trust-source’...
restarting systemd...
Failed to list users: Unit dbus-org.freedesktop.login1.service not found.
setting up tmpfiles
reloading the following units: dbus.service, dev-hugepages.mount, dev-mqueue.mount, reload-systemd-vconsole-setup.service, sys-fs-fuse-connections.mount, sys-kernel-config.mount, sys-kernel-debug.mount
restarting the following units: dbus.socket, dhcpcd.service, network-addresses-ens160.service, nix-daemon.socket, sshd.service, systemd-coredump.socket, systemd-journald-audit.socket, systemd-journald-dev-log.socket, systemd-journald.socket, systemd-rfkill.socket, systemd-tmpfiles-clean.timer, systemd-udevd-control.socket, systemd-udevd-kernel.socket
warning: some sockets failed to restart. Please check your journal (journalctl -eb) and act accordingly.
starting the following units: -.mount, audit.service, boot.mount, kmod-static-nodes.service, mount-pstore.service, network-local-commands.service, network-setup.service, nscd.service, resolvconf.service, systemd-journal-catalog-update.service, systemd-modules-load.service, systemd-sysctl.service, systemd-timesyncd.service, systemd-tmpfiles-setup-dev.service, systemd-udev-trigger.service, systemd-update-done.service
org.freedesktop.DBus.Error.Disconnected: Connection was disconnected before a reply was received
warning: error(s) occurred while switching to the new configuration
make[1]: *** [vm/switch] Error 1
make: *** [vm/bootstrap] Error 2

and in the VM with unknown ioctl 1976.

In order to set up NixOS, I changed the HDD to SATA in the VM configuration (instead of SCSI).

What obstacles did you encounter when using nix on macOS?

@mitchellh, first I want to thank you for sharing your nix config, that's what got me started in nix.

I remember read it somewhere that you decided to use nixos in a VM because nix on macOS caused enough trouble or something like that.

I'm a happy nixos-in-VM user, but couldn't help but wondering what a nix-on-macOS life would be like. So I'd be interested to hear what obstacles you encountered, if you still remember.

Multiple monitors

Thanks for sharing this awesome setup.

Has anyone tried using this with multiple monitors? When I follow these instructions I can get vmware fusion to mirror on 2 displays. When when I run xrandr inside the guest, I only see one display show up:

$ xrandr --query
Screen 0: minimum 320 x 200, current 3840 x 2160, maximum 8192 x 8192
Virtual-1 connected primary 3840x2160+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1024x768      60.00 +  60.00  
   3840x2400     59.97  
   3840x2160     59.97* 
   2880x1800     59.95  
   2560x1600     59.99  
   2560x1440     59.95  
   1920x1440     60.00  
   1856x1392     60.00  
   1792x1344     60.00  
   1920x1200     59.88  
   1920x1080     59.96  
   1600x1200     60.00  
   1680x1050     59.95  
   1400x1050     59.98  
   1280x1024     60.02  
   1440x900      59.89  
   1280x960      60.00  
   1360x768      60.02  
   1280x800      59.81  
   1152x864      75.00  
   1280x768      59.87  
   1280x720      59.86  
   800x600       60.32  
   640x480       59.94  

So to me it seems like linux doesn't know it is being mirrored on 2 monitors. So I'm stuck mirroring which doesn't help at all.

nix-shell FHS interop throws cryptic error

Interesting idea, thanks for sharing the configurations. Wondering if anyone else has experienced issues with running nix-shell for tools that expect FHS systems. Using nix-shell without build an FHS environment seems to work fine.

Host System

OSX 12.2.1 - Apple M1 Pro

Shell Configuration

# shell.nix
{ pkgs ? import <nixpkgs> {} }:
(pkgs.buildFHSUserEnv {
   name = "dev";
   targetPkgs = pkgs : [];
}).env

Error thrown

** (process:25978): ERROR **: 18:24:13.384: main: execvp(*argv, argv): No such file or directory      │
fish: Job 1, 'nix-shell' terminated by signal SIGTRAP (Trace or breakpoint trap)

Can't ssh into instance during bootstrap

There are a few issues.

  1. Since after make vm/bootstrap0 we are rebooting an instance, ssh key is getting regenerated. So when we run make vm/bootstrap I'm getting an error ED25519 host key for 172.16.X.X has changed and you have requested strict checking.
  2. If you have more than 5 SSH keys inside your ~/.ssh/ directory, by default ssh client will try offering those keys to login into an instance. Also, by default, after 5 unsuccessful logins, ssh will fail, so you won't be asked for a password for the root user.

Better resolution management

sessionCommands = ''
${pkgs.xlibs.xset}/bin/xset r rate 200 40
'' + (if currentSystem == "aarch64-linux" then ''
${pkgs.xorg.xrandr}/bin/xrandr -s '2880x1800'
'' else "");
};

I think services.xserver.resolutions = [{ x = 2880; y = 1800; }] would be a simpler way to achieve this, instead of using xrandr directly

[Mac M1] Getting an error on `make vm/bootstrap` step

$ make vm/bootstrap
NIXUSER=root /Applications/Xcode.app/Contents/Developer/usr/bin/make vm/copy
rsync -av -e 'ssh -p22' \
                --exclude='vendor/' \
                --exclude='.git/' \
                --exclude='.git-crypt/' \
                --rsync-path="sudo rsync" \
                /Users/ivan/Devloper/Personal/nixos-config/ [email protected]:/nix-config
Password:
building file list ... done

sent 1303 bytes  received 20 bytes  378.00 bytes/sec
total size is 813279865  speedup is 614724.01
NIXUSER=root /Applications/Xcode.app/Contents/Developer/usr/bin/make vm/switch
ssh -p22 [email protected] " \
                sudo NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nixos-rebuild switch --flake \"/nix-config#vm-aarch64\" \
        "
Password:
building the system configuration...
error: builder for '/nix/store/8xn781yhlkr9bj9dvx3x919wicscn5aa-linux-config-5.14.14.drv' failed with exit code 255;
       last 10 log lines:
       >
       > Error in reading or end of file.
       >
       > Error in reading or end of file.
       >
       > Error in reading or end of file.
       >
       > Error in reading or end of file.
       >
       > Error in reading or end of file.
       For full logs, run 'nix log /nix/store/8xn781yhlkr9bj9dvx3x919wicscn5aa-linux-config-5.14.14.drv'.
error: 1 dependencies of derivation '/nix/store/61jlx8ncjrhnfhyxxzi48ds5q5ca89lr-linux-5.14.14.drv' failed to build
error: 1 dependencies of derivation '/nix/store/cfwdvqmm4d9cw63d3ffgqj9rffcvd3ly-nixos-system-dev-21.05.20211024.3b17893.drv' failed to build
make[1]: *** [vm/switch] Error 100
make: *** [vm/bootstrap] Error 2

The only change I made in Makefile is I replaced vm-intel with vm-aarch64

Stuck trying to boot

I'm on an M1 MacBook and I followed all the instructions in the YouTube video & instructions in this repo. I ran make iso/nixos.iso to build an ISO. Tried with VMWare Fusion downloaded from here and brew install --cask vmware-fusion-tech-preview.

I get to this screen and select the top option

image

But I get stuck here

image

Any ideas how to fix this?

emergency mode

Hi. I tried to reproduce your environment over all steps (I also saw your video). The step vm/bootstrap0 is ok, but I got an error (check the screenshot) on next step vm/bootstrap.
The last log is

building the system configuration...
stopping the following units: -.mount, boot.mount, firewall.service, network-addresses-enp0s5.service, network-setup.service, nscd.service, systemd-modules-load.service, systemd-sysctl.service, systemd-udevd-control.socket, systemd-udevd-kernel.socket, systemd-udevd.service
Failed to stop -.mount: Job type stop is not applicable for unit -.mount.
NOT restarting the following changed units: systemd-fsck@dev-disk-by\x2duuid-D605\x2d8851.service
activating the configuration...
setting up /etc...
removing obsolete symlink ‘/etc/systemd/network/40-enp0s5.link’...
reloading user units for root...
setting up tmpfiles
reloading the following units: dbus.service, reload-systemd-vconsole-setup.service
restarting the following units: dhcpcd.service, sshd.service

Снимок экрана 2021-11-07 в 10 33 58

build-vm fails

Hi,

Wanted to play around with your configs in a vm to learn from them.
But it get build errors trying, am I missing something?

# nixos-rebuild build-vm --flake '.#'
building the system configuration...
error:
       … while calling the 'derivationStrict' builtin

         at /builtin/derivation.nix:9:12: (source not available)

       … while evaluating derivation 'nixos-vm'
         whose name attribute is located at /nix/store/cb1gs888vfqxawvc65q1dk6jzbayh3wz-source/pkgs/stdenv/generic/make-derivation.nix:331:7

       … while evaluating attribute 'buildCommand' of derivation 'nixos-vm'

         at /nix/store/cb1gs888vfqxawvc65q1dk6jzbayh3wz-source/pkgs/build-support/trivial-builders/default.nix:68:16:

           67|         enableParallelBuilding = true;
           68|         inherit buildCommand name;
             |                ^
           69|         passAsFile = [ "buildCommand" ]

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attempt to call something which is not a function but a set

       at /nix/store/4k7qs5lmijldgris651af5sis8pv56ck-source/modules/filesystem/encryption.nix:107:39:

          106|       availableKernelModules = mkIf cfg.ssh.enable cfg.ssh.networkModule;
          107|       luks.forceLuksSupportInInitrd = mkIf cfg.ssh.enable mkForce true;
             |                                       ^
          108|       luks.devices = {

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.