Skip to content

Instantly share code, notes, and snippets.

@jahkeup
Created April 21, 2018 22:17
Show Gist options
  • Select an option

  • Save jahkeup/14c0f35383bf949fdd92fbfa20184b4f to your computer and use it in GitHub Desktop.

Select an option

Save jahkeup/14c0f35383bf949fdd92fbfa20184b4f to your computer and use it in GitHub Desktop.
NixOS qcow2 build
{ hostName, pkgs, ... }:
{
imports = [
./hardware.nix
];
networking.hostName = hostName;
time.timeZone = "America/Los_Angeles";
system.copySystemConfiguration = true;
nix = {
maxJobs = 2;
useSandbox = true;
};
environment.systemPackages = with pkgs; [
nix-index
vim
emacs25-nox
fping
jq
ripgrep
htop
sysstat
strace
tcpdump
traceroute
iputils
curlFull
openssl
gitAndTools.git
go
ruby
python3
];
services.ntp = {
enable = true;
servers = [ "time.google.com" ];
};
services.openssh = {
enable = true;
passwordAuthentication = false;
};
services.fail2ban.enable = true;
programs.mosh.enable = true;
programs.bash.enableCompletion = true;
security.sudo = {
enable = true;
wheelNeedsPassword = false;
};
# Make console use the X colemak keyboard configuration.
i18n.consoleUseXkbConfig = true;
services.xserver = {
xkbVariant = "colemak";
xkbOptions = "ctrl:nocaps";
};
users.users.jake = {
isNormalUser = true;
initialPassword = "";
extraGroups = [ "wheel" ];
openssh.authorizedKeys.keyFiles = [ ./machine_rsa.pub ];
};
}
# If you're not running this from a host running nixos (ie: you're
# just using nix) you'll want to provide a path for nixos-config as
# ./configuration.nix:
#
# NIX_PATH=$NIX_PATH:nixos-config=./configuration.nix nix-build
#
# Running this will yield 2 'result' directories, one with a wrapper
# to run a qemu test vm to try out the configurtion and the other
# containing a sanitary qcow2 image.
#
{ pkgs ? import <nixpkgs> { }
, system ? builtins.currentSystem
}:
let
lib = pkgs.lib;
nixos = <nixpkgs/nixos>;
hostName = "hostname.vcastle.net";
configuration = import ./configuration.nix { inherit hostName pkgs; };
# Image config
config = (import nixos { inherit system configuration; });
make-disk-image = import <nixpkgs/nixos/lib/make-disk-image.nix>;
in
rec {
runner = config.vm;
image = make-disk-image {
inherit pkgs lib;
config = config.config;
name = "${hostName}-image";
format = "qcow2";
diskSize = 8 * 1024; # megabytes
postVM = ''
mv $diskImage ''${diskImage/nixos/${hostName}}
'';
};
}
{
# Virtual disk will suit these settings:
config = {
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
autoResize = true;
};
boot.growPartition = true;
boot.loader.grub.device = "/dev/sda";
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment