Hello community,
i have reached my pain tolerance, which is why I am turning to you with my first and quite broad question. Sorry.
My goals are:
- Have a central github repository with a flake that defines all nixos systems of my devices, starting with “laptop2” for now.
- Generate an installation ISO from that flake that installs the customized nixos according to
nixosConfiguration.laptop2
on target device. - This nixos system refers itself to
github:repo#laptop2
to fetch and build future updates.
Right now, I have not succeeded past point 2.
Building and installing an ISO from output.nixosConfiguration.laptop2
with a simple imported nix/common.nix
module is quite easy. Code below.
The problems I face:
-
nixos-install
andnixos-generate-config
ignore the configuration of the otherwise correct live-nixos, resulting in a blank nixos installation, nullifying the purpose of the flake. -
nixos-install –flake “github:repo#laptop2”
is redundant, because network access is required for the installation of stuff, that is already known at ISO build time. Furthermore, the resulting nixos is broken,/boot
is missing and besides/nix/store
, not a single*.nix
file exists in/mnt
after installation. - I have no clue where to start to get a self/remote referential
nixosConfiguration
. - All tutorials begin with a fresh nixos install and edit
/etc/nixos/{configuraion.nix,flake.nix}
, my starting point is a remote flake without manual changes.
Somewhere in the chain flake nixosConfiguration -> nixos live-installer -> target nixos
is a break.
I could continue to investigate why the last step, the nixos-install –flake
is incomplete but I have growing suspicion, that somewhere my workflow is fundamentally broken.
I am grateful for any new direction to try or examples to copy.
Thank you for your time.
My code (simplified and unpolished):
flake.nix
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
};
outputs = inputs@{ self, nixpkgs, ... }: {
nixosConfigurations = {
laptop2 = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
${nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal-new-kernel-no-zfs.nix"
# TODO reactivate hardened kernel and fix missing ext4 support in live-nixos
${nixpkgs}/nixos/modules/profiles/hardened.nix"
nix/common.nix
];
};
};
}
nix/common.nix
{ config, lib, pkgs, ... }:
{
nix.settings.system-features = [ "nix-command" "flakes" "big-parallel" "kvm" ];
nix.extraOptions = "experimental-features = nix-command flakes";
boot= {
supportedFilesystems = [ "ext4" ];
loader.grub.device = "/dev/sda";
};
environment.systemPackages = with pkgs; [
git
tmux
neovim
];
# not supported by flakes. will copy to /etc/nixos/configuration.nix
#system.copySystemConfiguration = true;
isoImage = {
edition = lib.mkForce "laptop2-nixos";
isoBaseName = "laptop2-nixos";
volumeID = "laptop2-nixos";
contents = [
{ source = pkgs.writeText "install.sh" ''
#!/usr/bin/bash
set -xeuo pipefail
# partitioning primary boot and swap on sda1 and sda2, mounting
# ...
# sudo nixos-generate-config --root /mnt
# sudo nixos-install
sudo nixos-install --flake "github:repo#laptop2" # finds this exact flake
'';
target = "install.sh";
}
];
};
}
gen-iso.sh
nixos-generate --show-trace --flake .#laptop2 --format iso --out-link result
ISO=results/.../file.iso
sudo dd if="$ISO" of=/dev/sda status=progress
sync