From b538626c12e7a5c5e68ce91a64d1494aab4b06e3 Mon Sep 17 00:00:00 2001 From: Poby <87608318+smg1024@users.noreply.github.com> Date: Wed, 20 May 2026 23:04:42 +0900 Subject: [PATCH] initial install yggdrasil --- INSTALL.md | 30 +++---- flake.lock | 91 ++++++++++++++++++++++ flake.nix | 82 ++++++++++--------- hosts/midgard/default.nix | 6 ++ hosts/yggdrasil/default.nix | 20 ++--- hosts/yggdrasil/disko.nix | 6 +- hosts/yggdrasil/hardware-configuration.nix | 23 +++++- 7 files changed, 186 insertions(+), 72 deletions(-) create mode 100644 flake.lock diff --git a/INSTALL.md b/INSTALL.md index f000dbe..1d460f5 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,7 +1,7 @@ # NixOS Homelab Install Guide -이 문서는 `yggdrasil`, `midgard`를 NixOS installer USB에서 부팅한 뒤 -이 repo를 source of truth로 사용해 최초 설치하는 절차를 설명한다. +이 문서는 `yggdrasil`, `midgard`를 NixOS installer USB에서 부팅한 뒤 이 repo를 +source of truth로 사용해 최초 설치하는 절차를 설명한다. 기본 원칙: @@ -85,8 +85,8 @@ installer shell이 뜨면 대상 머신 콘솔에서 root 비밀번호를 임시 sudo passwd root ``` -이 비밀번호는 installer live environment에서만 쓰는 임시 비밀번호다. -설치 후 재부팅하면 최종 NixOS 설정이 적용되고 root SSH login은 비활성화된다. +이 비밀번호는 installer live environment에서만 쓰는 임시 비밀번호다. 설치 후 +재부팅하면 최종 NixOS 설정이 적용되고 root SSH login은 비활성화된다. SSH 서버를 시작한다. @@ -224,7 +224,8 @@ ssh root@ \ - `hardware-configuration.nix`는 대상 머신에서 생성한 값을 사용한다. - yggdrasil에서 생성한 파일을 midgard에 재사용하지 않는다. -- disko가 `/`와 `/boot` 파일시스템을 선언하므로 생성된 hardware config를 그대로 믿지 말고 검토한다. +- disko가 `/`와 `/boot` 파일시스템을 선언하므로 생성된 hardware config를 그대로 + 믿지 말고 검토한다. `hardware-configuration.nix`에는 보통 이런 내용이 남으면 된다. @@ -243,8 +244,8 @@ hardware.cpu.intel.updateMicrocode = ...; hardware.cpu.amd.updateMicrocode = ...; ``` -다음 항목은 `disko.nix`와 중복되거나 installer/live 환경의 값일 수 있으므로 -특히 확인한다. +다음 항목은 `disko.nix`와 중복되거나 installer/live 환경의 값일 수 있으므로 특히 +확인한다. ```nix fileSystems."/" @@ -252,9 +253,9 @@ fileSystems."/boot" swapDevices ``` -이 repo에서는 `/`와 `/boot`는 `disko.nix`가 담당한다. swap은 `modules/swap.nix`의 -zram swap이 담당한다. 따라서 hardware config에 위 항목이 들어 있다면 왜 필요한지 -확실할 때만 남긴다. +이 repo에서는 `/`와 `/boot`는 `disko.nix`가 담당한다. swap은 +`modules/swap.nix`의 zram swap이 담당한다. 따라서 hardware config에 위 항목이 +들어 있다면 왜 필요한지 확실할 때만 남긴다. ## 6. host default.nix imports 활성화 @@ -321,16 +322,18 @@ nix-instantiate --parse hosts/yggdrasil/hardware-configuration.nix >/dev/null ```bash nix run github:nix-community/nixos-anywhere -- \ --flake .#yggdrasil \ + --build-on-remote \ root@ ``` -워크스테이션의 Nix에서 flakes가 꺼져 있다는 에러가 나면 같은 명령에 -experimental features를 명시한다. +워크스테이션의 Nix에서 flakes가 꺼져 있다는 에러가 나면 같은 명령에 experimental +features를 명시한다. ```bash nix --extra-experimental-features "nix-command flakes" \ run github:nix-community/nixos-anywhere -- \ --flake .#yggdrasil \ + --build-on-remote \ root@ ``` @@ -583,7 +586,8 @@ ssh root@midgard ## 15. 롤백 기본 -NixOS 설정 변경 후 문제가 생기면 대상 머신에서 이전 generation으로 되돌릴 수 있다. +NixOS 설정 변경 후 문제가 생기면 대상 머신에서 이전 generation으로 되돌릴 수 +있다. ```bash sudo nixos-rebuild switch --rollback diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..34bcec8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,91 @@ +{ + "nodes": { + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1779226674, + "narHash": "sha256-wuOkjI6pRiN4sEn/EPBRnNW5cmcpvd7xtIM8y5LooAs=", + "owner": "nix-community", + "repo": "disko", + "rev": "65fb947964bd44fc0008faf77d1fcb7a9f40bb32", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, + "home-manager": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1778905220, + "narHash": "sha256-ox/5IHc8uwy6UTw6N7Shp6uCHIgu/S2PsWeuXsOHSo8=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "d1686dc7d36cbd1234cb226ad6ef97e882716acb", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "release-25.11", + "repo": "home-manager", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1779102034, + "narHash": "sha256-vZJZjLo513IeI8hjzHFc6TDezUd4uCE2Eq4SNO3DNNg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "687f05a9184cad4eaf905c48b63649e3a86f5433", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-25.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "disko": "disko", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs", + "sops-nix": "sops-nix" + } + }, + "sops-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1777944972, + "narHash": "sha256-VfGRo1qTBKOe3s2gOv8LSoA6Fk19PvBlwQ1ECN0Evn8=", + "owner": "Mic92", + "repo": "sops-nix", + "rev": "c591bf665727040c6cc5cb409079acb22dcce33c", + "type": "github" + }, + "original": { + "owner": "Mic92", + "repo": "sops-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 9e4ffc4..a00f130 100644 --- a/flake.nix +++ b/flake.nix @@ -20,51 +20,47 @@ }; }; - outputs = - inputs@{ - nixpkgs, - disko, - home-manager, - sops-nix, - ... - }: - let - system = "x86_64-linux"; + outputs = inputs @ { + nixpkgs, + disko, + home-manager, + sops-nix, + ... + }: let + system = "x86_64-linux"; - mkHost = - hostModule: - nixpkgs.lib.nixosSystem { - inherit system; - specialArgs = { - inherit inputs; - }; - - modules = [ - ./modules/base.nix - ./modules/gc.nix - ./modules/swap.nix - ./modules/users.nix - ./modules/ssh.nix - ./modules/tailscale.nix - - disko.nixosModules.disko - sops-nix.nixosModules.sops - home-manager.nixosModules.home-manager - - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; - home-manager.users.poby = import ./home/poby.nix; - } - - hostModule - ]; + mkHost = hostModule: + nixpkgs.lib.nixosSystem { + inherit system; + specialArgs = { + inherit inputs; }; - in - { - nixosConfigurations = { - yggdrasil = mkHost ./hosts/yggdrasil; - midgard = mkHost ./hosts/midgard; + + modules = [ + ./modules/base.nix + ./modules/gc.nix + ./modules/swap.nix + ./modules/users.nix + ./modules/ssh.nix + ./modules/tailscale.nix + + disko.nixosModules.disko + sops-nix.nixosModules.sops + home-manager.nixosModules.home-manager + + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.poby = import ./home/poby.nix; + } + + hostModule + ]; }; + in { + nixosConfigurations = { + yggdrasil = mkHost ./hosts/yggdrasil; + midgard = mkHost ./hosts/midgard; }; + }; } diff --git a/hosts/midgard/default.nix b/hosts/midgard/default.nix index 3aa40ac..3f119dd 100644 --- a/hosts/midgard/default.nix +++ b/hosts/midgard/default.nix @@ -10,5 +10,11 @@ networking.hostName = "midgard"; + services.logind.settings.Login = { + HandleLidSwitch = "ignore"; + HandleLidSwitchExternalPower = "ignore"; + HandleLidSwitchDocked = "ignore"; + }; + system.stateVersion = "25.11"; } diff --git a/hosts/yggdrasil/default.nix b/hosts/yggdrasil/default.nix index 9303c66..270ce67 100644 --- a/hosts/yggdrasil/default.nix +++ b/hosts/yggdrasil/default.nix @@ -1,14 +1,16 @@ -{ ... }: - -{ - # Enable these imports after collecting disk IDs and generated hardware config - # during the NixOS installer phase. - # imports = [ - # ./hardware-configuration.nix - # ./disko.nix - # ]; +{...}: { + imports = [ + ./hardware-configuration.nix + ./disko.nix + ]; networking.hostName = "yggdrasil"; + services.logind.settings.Login = { + HandleLidSwitch = "ignore"; + HandleLidSwitchExternalPower = "ignore"; + HandleLidSwitchDocked = "ignore"; + }; + system.stateVersion = "25.11"; } diff --git a/hosts/yggdrasil/disko.nix b/hosts/yggdrasil/disko.nix index f7ea73e..a91ae82 100644 --- a/hosts/yggdrasil/disko.nix +++ b/hosts/yggdrasil/disko.nix @@ -1,10 +1,8 @@ -{ ... }: - -{ +{...}: { disko.devices = { disk.main = { type = "disk"; - device = "/dev/disk/by-id/REPLACE_WITH_YGGDRASIL_DISK_ID"; + device = "/dev/disk/by-id/ata-SAMSUNG_MZNLN128HCGR-000_S200NYAG700346"; content = { type = "gpt"; diff --git a/hosts/yggdrasil/hardware-configuration.nix b/hosts/yggdrasil/hardware-configuration.nix index 09b0e4c..28ece0d 100644 --- a/hosts/yggdrasil/hardware-configuration.nix +++ b/hosts/yggdrasil/hardware-configuration.nix @@ -1,5 +1,22 @@ -{ ... }: - +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. { - # TODO: Replace with generated yggdrasil hardware configuration. + config, + lib, + pkgs, + modulesPath, + ... +}: { + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = ["ahci" "xhci_pci" "usb_storage" "sd_mod" "sdhci_pci" "rtsx_usb_sdmmc"]; + boot.initrd.kernelModules = ["dm-snapshot"]; + boot.kernelModules = ["kvm-intel"]; + boot.extraModulePackages = []; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; }