Skip to content

Instantly share code, notes, and snippets.

@rgrunbla
Created July 22, 2020 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgrunbla/93a98164c6fd555b4e22d2a6e770b104 to your computer and use it in GitHub Desktop.
Save rgrunbla/93a98164c6fd555b4e22d2a6e770b104 to your computer and use it in GitHub Desktop.
{ config, pkgs, lib, ... }:
{
networking.hostName = "wiloma";
networking.domain = "wiloma.tech";
i18n.defaultLocale = "fr_FR.UTF-8";
i18n.supportedLocales = ["fr_FR.UTF-8/UTF-8"];
time.timeZone = "Europe/Paris";
services.openssh.enable = true;
services.openssh.permitRootLogin = "yes";
services.timesyncd.enable = lib.mkDefault true;
#security.polkit.enable = false;
environment.systemPackages = with pkgs; [
];
users.mutableUsers = false;
system.stateVersion = "20.03";
}
let
pkgs = import <nixpkgs> { };
lib = pkgs.lib;
toEval = modules:
import <nixpkgs/nixos/lib/eval-config.nix> {
system = pkgs.system;
modules = [ ./configuration.nix ] ++ modules;
};
modules = {
standalone = [{
config = {
fileSystems."/" = {
device = "/dev/disk/by-label/nixos";
fsType = "ext4";
autoResize = true;
};
boot = {
loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
};
};
}];
};
evals = {
standalone = let
eval = toEval modules.standalone;
name =
"nixos-${eval.config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}";
in import <nixpkgs/nixos/lib/make-disk-image.nix> {
inherit lib name pkgs;
config = eval.config;
contents = [ ];
partitionTableType = "efi";
diskSize = 5000;
format = "raw";
postVM = ''
extension=''${diskImage##*.}
friendlyName=$out/${name}.$extension
mv "$diskImage" "$friendlyName"
diskImage=$friendlyName
mkdir -p $out/nix-support
${pkgs.jq}/bin/jq -n \
--arg label ${lib.escapeShellArg eval.config.system.nixos.label} \
--arg system ${lib.escapeShellArg pkgs.stdenv.hostPlatform.system} \
--arg logical_bytes "$(${pkgs.qemu}/bin/qemu-img info --output json "$diskImage" | ${pkgs.jq}/bin/jq '."virtual-size"')" \
--arg file "$diskImage" \
'$ARGS.named' \
> $out/nix-support/image-info.json
'';
};
};
scripts = {
standalone = pkgs.writeScript "run" ''
#!${pkgs.stdenv.shell}
file=$(cat ${evals.standalone}/nix-support/image-info.json | jq -r .file)
cp $file ./nixos.qcow2
chmod u+w nixos.qcow2
#trap "rm -f nixos.qcow2" EXIT
#${pkgs.qemu}/bin/qemu-system-x86_64 -nographic --cpu host --enable-kvm -hda nixos.qcow2
'';
};
in lib.mapAttrs (name: v:
v // {
run = scripts.${name};
eval = evals.${name};
modules = modules.${name};
}) scripts
.PHONY: run
run:
$(shell nix-build images.nix --no-out-link)
.PHONY: build
build:
nix-build images.nix --no-out-link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment