My Nixos Bootstrap

Dec 30, 2024

Git repo: https://github.com/Evlos/my-nixos-bootstrap

For nix-install only since nix-anywhere does not accept optional substituter.

home.nix

The “stateVersion” should be replaced with the latest one.

{ config, pkgs, ... }:

{
  home.username = "evlos";
  home.homeDirectory = "/home/evlos";

  home.packages = with pkgs;[
  ];

  home.stateVersion = "23.05";

  programs.home-manager.enable = true;

}

Makefile

Use the domestic mirror to accelerate downloads. After installation, remember to change the password.

default:
	nixos-install -vvv --option substituters "https://mirrors.cernet.edu.cn/nix-channels/store"
	nixos-enter --root '/mnt'
	passwd evlos

flake.nix

The following configuration has been simplified as much as possible to allow you to apply your own configuration after installation.

The “disko” parts are optional.

{
  description = "Evlos' Flake";

  nixConfig = {
    experimental-features = [ "nix-command" "flakes" ];
    substituters = [
      "https://mirrors.ustc.edu.cn/nix-channels/store"
    ];

    extra-substituters = [
      "https://nix-community.cachix.org"
    ];
    extra-trusted-public-keys = [
      "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
    ];
  };

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    disko.url = "github:nix-community/disko";
    disko.inputs.nixpkgs.follows = "nixpkgs";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs@{ nixpkgs, home-manager, ... }: {
    nixosConfigurations = {
      dnscore = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          home-manager.nixosModules.home-manager
          {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.evlos = import ./home.nix;
          }
        ];

      };
    };
  };
}

configuration.nix

The “hostName”, ssh key, and time zone should all be replaced with your own corresponding values.

{ config, pkgs, lib, ... }:

{
  imports =
    [
      ./hardware-configuration.nix
    ];

  boot.loader.grub = {
    enable = true;
    efiSupport = false;
    device = "/dev/sda";
  };
  fileSystems."/".device = "/dev/disk/by-label/nixos";

  networking.hostName = ""; # TODO: fill in
  networking.networkmanager.enable = true;

  time.timeZone = "Asia/Shanghai";
  i18n.defaultLocale = "en_US.UTF-8";

  nix.settings.experimental-features = [
    "nix-command"
    "flakes"
  ];
  nix.settings.substituters = lib.mkForce [
    "https://mirrors.ustc.edu.cn/nix-channels/store"
  ];
  nix.settings.trusted-users = [ "evlos" ];

  users.users.evlos = {
    isNormalUser = true;
    extraGroups = [ "networkmanager" "wheel" "docker" ];
    openssh.authorizedKeys.keys = [
      "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIKQ8q1i5or0ARt3wqkEr3g7JW7jvQZ0IsXQOauSgMXAJ evlos@flamebook"
    ];
  };

  services.openssh = {
    enable = true;
    settings = {
      PermitRootLogin = "no";
      PasswordAuthentication = true;
    };
    openFirewall = true;
  };

  environment.systemPackages = with pkgs; [
    curl
    git
  ];

  system.stateVersion = "23.05";

}

[back]