Skip to content

Instantly share code, notes, and snippets.

@infinisil
Created July 28, 2017 16:40

Revisions

  1. infinisil created this gist Jul 28, 2017.
    43 changes: 43 additions & 0 deletions configuration.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,43 @@
    # Edit this configuration file to define what should be installed on
    # your system. Help is available in the configuration.nix(5) man page
    # and in the NixOS manual (accessible by running ‘nixos-help’).

    { config, pkgs, ... }:

    {
    imports =
    [ # Include the results of the hardware scan.
    ./hardware-configuration.nix
    ];

    boot = {
    loader = {
    efi = {
    canTouchEfiVariables = true;
    };
    grub = {
    device = "/dev/sdc";
    efiSupport = true;
    enable = true;
    zfsSupport = true;
    };
    };
    supportedFilesystems = [ "zfs" ];
    };

    nixpkgs.config.allowUnfree = true;

    networking.hostName = "stick";
    networking.hostId = "a7634783";

    i18n.consoleUseXkbConfig = true;

    services.xserver = {
    layout = "us";
    xkbVariant = "dvp";
    };

    # The NixOS release to be compatible with for stateful data such as databases.
    system.stateVersion = "17.09";

    }
    44 changes: 44 additions & 0 deletions default.nix
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    with import <nixpkgs> {};
    { pool ? "main"
    , disk
    , altroot ? "/mnt"
    }:
    let
    createFilesystem = ''
    set -x
    sudo sgdisk -Z -n 1::+200M -t 1:ef00 -n 2:: -g ${disk}
    zpool create -f -o ashift=12 -m legacy ${pool} ${disk}2
    mkdir -p ${altroot}
    mount -t zfs ${pool} ${altroot}
    cd ${altroot}
    mkdir boot home root var
    mkdir nix
    mkfs.vfat ${disk}1
    mount -t vfat ${disk}1 boot
    sudo zfs create -o compress=on ${pool}/nix
    mount -t zfs ${pool}/nix nix
    sudo zfs create -o compress=on -o snapdir=visible ${pool}/home
    mount -t zfs ${pool}/home home
    sudo zfs create -o compress=on -o snapdir=visible ${pool}/root
    mount -t zfs ${pool}/root root
    sudo zfs create -o snapdir=visible ${pool}/var
    mount -t zfs ${pool}/var var
    mkdir -p etc/nixos
    '';
    in writeScript "setup" ''
    ${createFilesystem}
    cp ${./configuration.nix} etc/nixos/configuration.nix
    nixos-generate-config --root ${altroot}
    nixos-install
    ''