From dc31548f49995a8c2d36dfcad46fc9339fc12d32 Mon Sep 17 00:00:00 2001 From: uttarayan21 Date: Mon, 4 Nov 2024 18:48:40 +0530 Subject: [PATCH] feat: Added nixos-anywhere installer --- common/home.nix | 5 ++- flake.lock | 6 +-- server/cachix.nix | 6 --- server/configuration.nix | 30 +++++++++++++ server/default.nix | 5 --- server/disk-config.nix | 94 ++++++++++++++++++++++++++++++++++++++++ server/flake.lock | 64 +++++++++++++++++++++++++++ server/flake.nix | 41 ++++++++++++++++++ 8 files changed, 235 insertions(+), 16 deletions(-) delete mode 100644 server/cachix.nix create mode 100644 server/configuration.nix delete mode 100644 server/default.nix create mode 100644 server/disk-config.nix create mode 100644 server/flake.lock create mode 100644 server/flake.nix diff --git a/common/home.nix b/common/home.nix index b9c5dba6..101c827f 100644 --- a/common/home.nix +++ b/common/home.nix @@ -62,7 +62,6 @@ in { nodejs deploy-rs vcpkg-tool - gh just yarn clang @@ -139,12 +138,14 @@ in { extraConfig = lib.strings.optionalString pkgs.stdenv.isDarwin '' - IdentityAgent ~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock + IdentityAgent "~/Library/Group Containers/2BUA8C4S2C.com.1password/t/agent.sock" '' + lib.strings.optionalString pkgs.stdenv.isLinux '' IdentityAgent ~/.1password/agent.sock ''; }; + gh.enable = true; + gh-dash.enable = true; sketchybar.enable = device.isMac; atuin = { settings = { diff --git a/flake.lock b/flake.lock index 3b3c7a38..fd347982 100644 --- a/flake.lock +++ b/flake.lock @@ -1910,11 +1910,11 @@ ] }, "locked": { - "lastModified": 1727999297, - "narHash": "sha256-LTJuQPCsSItZ/8TieFeP30iY+uaLoD0mT0tAj1gLeyQ=", + "lastModified": 1730698801, + "narHash": "sha256-sq68bCmk4tCXSt5CoRNimfigIZSLJSpNi/gjFtNLjRE=", "owner": "LnL7", "repo": "nix-darwin", - "rev": "8c8388ade72e58efdeae71b4cbb79e872c23a56b", + "rev": "189d2d422c773fa065cc9c72e6806f007ebb9be0", "type": "github" }, "original": { diff --git a/server/cachix.nix b/server/cachix.nix deleted file mode 100644 index 5436a2bf..00000000 --- a/server/cachix.nix +++ /dev/null @@ -1,6 +0,0 @@ -{...}: { - services.cachix-agent = { - enable = true; - name = "mirai"; - }; -} diff --git a/server/configuration.nix b/server/configuration.nix new file mode 100644 index 00000000..d88fea84 --- /dev/null +++ b/server/configuration.nix @@ -0,0 +1,30 @@ +{ + modulesPath, + lib, + pkgs, + ... +}: { + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + (modulesPath + "/profiles/qemu-guest.nix") + ./disk-config.nix + ]; + boot.loader.grub = { + # no need to set devices, disko will add all devices that have a EF02 partition to the list already + # devices = [ ]; + efiSupport = true; + efiInstallAsRemovable = true; + }; + services.openssh.enable = true; + + environment.systemPackages = map lib.lowPrio [ + pkgs.curl + pkgs.gitMinimal + ]; + + users.users.root.openssh.authorizedKeys.keys = [ + "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDMh7ohX3cIB/euZwy9hk8iKywlu+koHrOiyaEG/ubr7Lfr+d92HV8arAIow52VMzv17sUBiP8Us/13FTtlLNKle7VXi5Eh+BBzNjOU/bpDKe4XZQtiEnnVd7LzLaAYfS+Gg9cD9hG3GGaxPYe8iN5bfpR1l15ccUTPHvBtefAoPax5bnMd89Z82stWvnpFs42YtP5VXLwMjk2nZhst1AspXMFxvsg/vkniMun+SuzyoQGkEo+ncTEmQzEQF5JpWEsfBdhmcOJnWoIWNcaWTAmVbF4Xkv5GqtdibXykVjlTUtrsVrBvvTL+BfQ99qiCafyWIhQgULDqXY2Ocq6mK9ZBohDzzsR0W/TXvRVIShfaRK6qmArcr4dSGQpd2H7/dJtpM9xHXSSyGhNHrlRFCTLBjHxjYrax9JzeRIWFSpNGOl3rUmI0P3FZJLBP9P6DJ9wJiksWD3kDRjaMQmr3gZhqAq6qYZIkSHiW1tLqcCncEFCdb/x5XJzkqEv3wPbKD1t4D0iBvSaFRaJTiTr611MlkS69T/5JCJW5RQoxE9qTV7X6WiQUToll/NqQ6Ox5mlQbj/zv4gFQq0CEHm/EgemHzHXatkMbV8ze/JHZFs3kxqaL6881yfVYWQIT8UbFZNdvJUd+VLWF5PpnXBWEH0+yPXttTyNSirztr1deTbZhDw==" + ]; + + system.stateVersion = "24.05"; +} diff --git a/server/default.nix b/server/default.nix deleted file mode 100644 index fbad3a00..00000000 --- a/server/default.nix +++ /dev/null @@ -1,5 +0,0 @@ -{...}: { - imports = [ - ./cachix.nix - ]; -} diff --git a/server/disk-config.nix b/server/disk-config.nix new file mode 100644 index 00000000..c7c45cb4 --- /dev/null +++ b/server/disk-config.nix @@ -0,0 +1,94 @@ +{lib, ...}: { + disko.devices = { + disk = { + one = { + type = "disk"; + device = "/dev/nvme0n1"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "512M"; + type = "EF00"; + content = { + type = "mdraid"; + name = "boot"; + }; + }; + primary = { + size = "100%"; + content = { + type = "lvm_pv"; + vg = "pool"; + }; + }; + }; + }; + }; + two = { + type = "disk"; + device = "/dev/nvme1n1"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "512M"; + type = "EF00"; + content = { + type = "mdraid"; + name = "boot"; + }; + }; + primary = { + size = "100%"; + content = { + type = "lvm_pv"; + vg = "pool"; + }; + }; + }; + }; + }; + }; + mdadm = { + boot = { + type = "mdadm"; + level = 1; + metadata = "1.0"; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + }; + }; + }; + lvm_vg = { + pool = { + type = "lvm_vg"; + lvs = { + root = { + size = "128G"; + lvm_type = "mirror"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + mountOptions = [ + "defaults" + ]; + }; + }; + home = { + size = "512G"; + lvm_type = "raid0"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/home"; + }; + }; + }; + }; + }; + }; +} diff --git a/server/flake.lock b/server/flake.lock new file mode 100644 index 00000000..b743cb59 --- /dev/null +++ b/server/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "disko": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1730675461, + "narHash": "sha256-Mhqz3p/HEiI/zxBJWO57LYQf6gGlJB0tci6fiVXLjd8=", + "owner": "nix-community", + "repo": "disko", + "rev": "380847d94ff0fedee8b50ee4baddb162c06678df", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "disko", + "type": "github" + } + }, + "nixos-facter-modules": { + "locked": { + "lastModified": 1730715598, + "narHash": "sha256-FPSbetOjBJp+pRadleiSVioAiHPerUDsYlTAWLCX+Tw=", + "owner": "numtide", + "repo": "nixos-facter-modules", + "rev": "5db1750d7663f96f0babb454320047af0866acf8", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "nixos-facter-modules", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1730272153, + "narHash": "sha256-B5WRZYsRlJgwVHIV6DvidFN7VX7Fg9uuwkRW9Ha8z+w=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "2d2a9ddbe3f2c00747398f3dc9b05f7f2ebb0f53", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "disko": "disko", + "nixos-facter-modules": "nixos-facter-modules", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/server/flake.nix b/server/flake.nix new file mode 100644 index 00000000..6a4b2bcb --- /dev/null +++ b/server/flake.nix @@ -0,0 +1,41 @@ +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.disko.url = "github:nix-community/disko"; + inputs.disko.inputs.nixpkgs.follows = "nixpkgs"; + inputs.nixos-facter-modules.url = "github:numtide/nixos-facter-modules"; + + outputs = { + nixpkgs, + disko, + nixos-facter-modules, + ... + }: { + # Use this for all other targets + # nix run github:nix-community/nixos-anywhere -- --flake .#generic --generate-hardware-config nixos-generate-config ./hardware-configuration.nix root@sh.darksailor.dev + nixosConfigurations.generic = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + disko.nixosModules.disko + ./configuration.nix + ./hardware-configuration.nix + ]; + }; + + # Slightly experimental: Like generic, but with nixos-facter (https://github.com/numtide/nixos-facter) + # nix run github:nix-community/nixos-anywhere -- --flake .#generic-nixos-facter --generate-hardware-config nixos-facter facter.json root@sh.darksailor.dev + nixosConfigurations.generic-nixos-facter = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + disko.nixosModules.disko + ./configuration.nix + nixos-facter-modules.nixosModules.facter + { + config.facter.reportPath = + if builtins.pathExists ./facter.json + then ./facter.json + else throw "Have you forgotten to run nixos-anywhere with `--generate-hardware-config nixos-facter ./facter.json`?"; + } + ]; + }; + }; +}