Skip to content

Commit 3e34b60

Browse files
committed
First attempt at NixOS build
These configurations were copied[1] and heavily modified. The general modification strategy was to remove as much as I could without breaking things. Later, I'll add customizations back go the nixos configurations. The VMware build comes from comments[2]. This commit tests if the vmware build works. I am editing from a Mac, so I am relying on Github actions to test the nixos and vmware artifact build. References: 1. https://github.com/mitchellh/nixos-config/tree/01fcaea3bdcd47540da39446d80e85d042a70cc1 2. mitchellh/nixos-config#1
1 parent af0579d commit 3e34b60

File tree

9 files changed

+551
-0
lines changed

9 files changed

+551
-0
lines changed

.github/workflows/nix.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Nix
2+
on:
3+
push:
4+
branches:
5+
- main
6+
pull_request:
7+
jobs:
8+
build:
9+
runs-on: ubuntu-22.04
10+
steps:
11+
- uses: actions/checkout@v2
12+
- run: nix flake check
13+
- run: nix build .#nixosConfigurations.vm-intel
14+
- uses: actions/upload-artifact@v2
15+
with:
16+
name: vmware
17+
path: ./result/*.vmdk

flake.nix

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Credit: https://github.com/mitchellh/nixos-config/blob/501f9aa0a669479c34d8d036f52a15b04002d259/flake.nix
2+
3+
{
4+
description = "NixOS systems and tools by jwieringa";
5+
6+
inputs = {
7+
# Pin our primary nixpkgs repository. This is the main nixpkgs repository
8+
# we'll use for our configurations. Be very careful changing this because
9+
# it'll impact your entire system.
10+
nixpkgs.url = "github:nixos/nixpkgs/release-22.11";
11+
12+
# I don't know if I need this yet, so I've disabled it.
13+
# We use the unstable nixpkgs repo for some packages.
14+
# nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
15+
16+
home-manager = {
17+
url = "github:nix-community/home-manager/release-22.11";
18+
19+
# We want home-manager to use the same set of nixpkgs as our system.
20+
inputs.nixpkgs.follows = "nixpkgs";
21+
};
22+
};
23+
24+
outputs = { self, nixpkgs, home-manager, ... }@inputs: let
25+
mkVM = import ./lib/mkvm.nix;
26+
27+
# Overlays is the list of overlays we want to apply from flake inputs.
28+
overlays = [];
29+
in {
30+
nixosConfigurations.vm-intel = mkVM "vm-intel" rec {
31+
inherit nixpkgs home-manager overlays;
32+
system = "x86_64-linux";
33+
user = "jason";
34+
};
35+
36+
# Use this to prepare a new VMWare image.
37+
#
38+
# $ nix build .#vmwareImage -L
39+
# $ open ./result/*.vmdk
40+
41+
# Enable for M1 build?
42+
# packages.aarch64-linux = {
43+
# vmwareImage =
44+
# self.nixosConfigurations.vm-aarch64.config.system.build.vmwareImage;
45+
# };
46+
47+
packages.x86_64-linux = {
48+
vmwareImage =
49+
self.nixosConfigurations.vm-intel.config.system.build.vmwareImage;
50+
};
51+
};
52+
}

hardware/vm-intel.nix

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# This file is normally automatically generated. Since we build a VM
2+
# and have full control over that hardware I can hardcode this into my
3+
# repository.
4+
{ config, lib, pkgs, modulesPath, ... }:
5+
6+
{
7+
imports = [ "${modulesPath}/virtualisation/vmware-image.nix" ];
8+
9+
boot.initrd.availableKernelModules = [
10+
"ata_piix" "mptspi" "uhci_hcd" "ehci_pci" "sd_mod" "sr_mod" ];
11+
boot.initrd.kernelModules = [ ];
12+
boot.kernelModules = [ ];
13+
boot.extraModulePackages = [ ];
14+
15+
swapDevices = [ ];
16+
}

lib/mkvm.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This function creates a NixOS system based on our VM setup for a
2+
# particular architecture.
3+
#
4+
# I am only building one architecture, so this function was modified
5+
# to handle only x86_64-linux.
6+
name: { nixpkgs, home-manager, system, user, overlays }:
7+
8+
nixpkgs.lib.nixosSystem rec {
9+
inherit system;
10+
11+
modules = [
12+
# Apply our overlays. Overlays are keyed by system type so we have
13+
# to go through and apply our system type. We do this first so
14+
# the overlays are available globally.
15+
{ nixpkgs.overlays = overlays; }
16+
17+
# For both hardware and machines, I have not yet taken the time
18+
# to understand what they do exactly. So I've copied them verbatim.
19+
# One difference, I've only copied for the VMs and arch that I
20+
# currently use.
21+
../hardware/${name}.nix
22+
../machines/${name}.nix
23+
home-manager.nixosModules.home-manager {
24+
home-manager.useGlobalPkgs = true;
25+
home-manager.useUserPackages = true;
26+
home-manager.users.${user} = import ../users/${user}/home-manager.nix;
27+
}
28+
29+
# We expose some extra arguments so that our modules can parameterize
30+
# better based on these values.
31+
{
32+
config._module.args = {
33+
currentSystemName = name;
34+
currentSystem = system;
35+
};
36+
}
37+
];
38+
}

machines/vm-intel.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{ config, pkgs, ... }: {
2+
imports = [
3+
./vm-shared.nix
4+
];
5+
6+
virtualisation.vmware.guest.enable = true;
7+
8+
# Interface is this on Intel Fusion
9+
networking.interfaces.ens33.useDHCP = true;
10+
11+
# Shared folder to host works on Intel
12+
fileSystems."/host" = {
13+
fsType = "fuse./run/current-system/sw/bin/vmhgfs-fuse";
14+
device = ".host:/";
15+
options = [
16+
"umask=22"
17+
"uid=1000"
18+
"gid=1000"
19+
"allow_other"
20+
"auto_unmount"
21+
"defaults"
22+
];
23+
};
24+
}

machines/vm-shared.nix

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{ config, pkgs, lib, currentSystem, currentSystemName,... }:
2+
3+
{
4+
# Be careful updating this.
5+
boot.kernelPackages = pkgs.linuxPackages_latest;
6+
7+
nix = {
8+
# use unstable nix so we can access flakes
9+
package = pkgs.nixUnstable;
10+
extraOptions = ''
11+
experimental-features = nix-command flakes
12+
keep-outputs = true
13+
keep-derivations = true
14+
'';
15+
16+
# TODO: Disabled - figure out caching later
17+
# public binary cache that I use for all my derivations. You can keep
18+
# this, use your own, or toss it. Its typically safe to use a binary cache
19+
# since the data inside is checksummed.
20+
# settings = {
21+
# substituters = ["https://mitchellh-nixos-config.cachix.org"];
22+
# trusted-public-keys = ["mitchellh-nixos-config.cachix.org-1:bjEbXJyLrL1HZZHBbO4QALnI5faYZppzkU4D2s0G8RQ="];
23+
# };
24+
};
25+
26+
# We expect to run the VM on hidpi machines.
27+
hardware.video.hidpi.enable = true;
28+
29+
# Use the systemd-boot EFI boot loader.
30+
boot.loader.systemd-boot.enable = true;
31+
boot.loader.efi.canTouchEfiVariables = true;
32+
33+
# VMware, Parallels both only support this being 0 otherwise you see
34+
# "error switching console mode" on boot.
35+
boot.loader.systemd-boot.consoleMode = "0";
36+
37+
# Define your hostname.
38+
networking.hostName = "dev";
39+
40+
# Set your time zone.
41+
time.timeZone = "US/Central";
42+
43+
# The global useDHCP flag is deprecated, therefore explicitly set to false here.
44+
# Per-interface useDHCP will be mandatory in the future, so this generated config
45+
# replicates the default behaviour.
46+
networking.useDHCP = false;
47+
48+
# Don't require password for sudo
49+
security.sudo.wheelNeedsPassword = false;
50+
51+
# Virtualization settings
52+
virtualisation.docker.enable = true;
53+
54+
# Select internationalisation properties.
55+
i18n.defaultLocale = "en_US.UTF-8";
56+
57+
# setup windowing environment
58+
services.xserver = {
59+
enable = true;
60+
layout = "us";
61+
dpi = 220;
62+
63+
desktopManager = {
64+
xterm.enable = false;
65+
wallpaper.mode = "fill";
66+
};
67+
68+
# TODO: Select a windows manager
69+
# displayManager = {
70+
# defaultSession = "none+i3";
71+
# lightdm.enable = true;
72+
73+
# # AARCH64: For now, on Apple Silicon, we must manually set the
74+
# # display resolution. This is a known issue with VMware Fusion.
75+
# sessionCommands = ''
76+
# ${pkgs.xorg.xset}/bin/xset r rate 200 40
77+
# '';
78+
# };
79+
80+
# windowManager = {
81+
# i3.enable = true;
82+
# };
83+
};
84+
85+
# Define a user account. Don't forget to set a password with ‘passwd’.
86+
users.mutableUsers = false;
87+
88+
# Enable the OpenSSH daemon.
89+
services.openssh.enable = true;
90+
services.openssh.passwordAuthentication = true;
91+
services.openssh.permitRootLogin = "no";
92+
93+
# Disable the firewall since we're in a VM and we want to make it
94+
# easy to visit stuff in here. We only use NAT networking anyways.
95+
networking.firewall.enable = false;
96+
97+
# This value determines the NixOS release from which the default
98+
# settings for stateful data, like file locations and database versions
99+
# on your system were taken. It‘s perfectly fine and recommended to leave
100+
# this value at the release version of the first install of this system.
101+
# Before changing this value read the documentation for this option
102+
# (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
103+
system.stateVersion = "22.11";
104+
}

0 commit comments

Comments
 (0)