From 5b8d09f2d7ebb7a1670c695af5761353d5b76d7e Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Sun, 7 Sep 2025 20:48:46 -0700 Subject: [PATCH] create drive abstractions and entry points for disko --- config/nix.org | 256 +++++++++++++++------------- nix/disko/drive-bios.nix | 35 ++++ nix/disko/drive-simple.nix | 42 +++++ nix/disko/nvme-simple.nix | 35 ---- nix/disko/sda-simple.nix | 35 ---- nix/disko/vda-simple.nix | 28 --- nix/flake.lock | 30 ++-- nix/flake.nix | 15 +- nix/modules/home/default.nix | 6 +- nix/modules/home/user.nix | 9 +- nix/modules/home/zsh.nix | 2 +- nix/modules/vars.nix | 12 ++ nix/systems/affinity/default.nix | 6 +- nix/systems/continuity/default.nix | 9 +- nix/systems/includes.nix | 7 + nix/systems/installer/commits.nix | 2 +- nix/systems/installer/default.nix | 41 ++--- nix/systems/spontaneity/default.nix | 6 +- 18 files changed, 307 insertions(+), 269 deletions(-) create mode 100644 nix/disko/drive-bios.nix create mode 100644 nix/disko/drive-simple.nix delete mode 100644 nix/disko/nvme-simple.nix delete mode 100644 nix/disko/sda-simple.nix delete mode 100644 nix/disko/vda-simple.nix create mode 100644 nix/systems/includes.nix diff --git a/config/nix.org b/config/nix.org index f999701..f9247e9 100644 --- a/config/nix.org +++ b/config/nix.org @@ -5,7 +5,7 @@ * Introduction This is my NixOS configuration. It is a part of my monorepo, and this file automatically tangles -to all the under the nix/ directory in my monorepo [[https://git.nullring.xyz/monorepo.git][git repository]]. My monorepo also stores my +to all the under the nix/ directory in my monorepo [[https://ret2pop.net/gitweb/monorepo.git][git repository]]. My monorepo also stores my website, as my website stores my [[file:elfeed.org][elfeed]] and [[file:emacs.org][emacs]] configurations. Additionally, I want to track my emacs configuration with my Nix configuration. Having them in one repository means that my emacs configuration is pinned to my flake. @@ -62,13 +62,19 @@ so that adding new configurations that add modifications is made simple. "spontaneity" # add hostnames here ]; + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + generate = nixos-dns.utils.generate nixpkgs.legacyPackages."${system}"; + dnsConfig = { inherit (self) nixosConfigurations; extraConfig = import ./dns/default.nix; }; + + # function that generates all systems from hostnames mkConfigs = map (hostname: {name = "${hostname}"; value = nixpkgs.lib.nixosSystem { inherit system; @@ -98,10 +104,17 @@ so that adding new configurations that add modifications is made simple. ]; }; }); + + mkDiskoFiles = map (hostname: { + name = "${hostname}"; + value = self.nixosConfigurations."${hostname}".config.monorepo.vars.myDiskoSpec; + }); + in { - # add new systems here nixosConfigurations = builtins.listToAttrs (mkConfigs hostnames); + evalDisko = builtins.listToAttrs (mkDiskoFiles (builtins.filter (x: x != "installer") hostnames)); + topology."${system}" = import nix-topology { pkgs = import nixpkgs { inherit system; @@ -239,6 +252,18 @@ largely self-documenting. { lib, ... }: { options.monorepo.vars = { + device = lib.mkOption { + type = lib.types.str; + default = "/dev/sda"; + example = "/dev/nvme0n1"; + description = "device that NixOS is installed to"; + }; + + myDiskoSpec = lib.mkOption { + type = lib.types.attrs; + description = "retains a copy of the disko spec for reflection"; + }; + userName = lib.mkOption { type = lib.types.str; default = "preston"; @@ -1242,34 +1267,39 @@ because they enhance security. This is the disko configuration for my continuity system. It features a boot and ext4 partition, on disk /dev/sda. All my SATA disks have this location by default, but if you want to use nvme, you will have to import that configuration in your ~systems/xxx/default.nix~. -#+begin_src nix :tangle ../nix/disko/sda-simple.nix - { - disko.devices = { - disk = { - my-disk = { - device = "/dev/sda"; - type = "disk"; - content = { - type = "gpt"; - partitions = { - ESP = { - type = "EF00"; - size = "500M"; - priority = 1; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - mountOptions = [ "umask=0077" ]; +*** NVME +For my nvme drives. +#+begin_src nix :tangle ../nix/disko/drive-simple.nix + { lib, config, ... }: + let + spec = { + disko.devices = { + disk = { + my-disk = { + device = config.monorepo.vars.device; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + type = "EF00"; + size = "500M"; + priority = 1; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; }; - }; - root = { - size = "100%"; - priority = 2; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; + root = { + size = "100%"; + priority = 2; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; }; }; }; @@ -1277,70 +1307,38 @@ you will have to import that configuration in your ~systems/xxx/default.nix~. }; }; }; + in + { + monorepo.vars.myDiskoSpec = spec; + disko.devices = spec.disko.devices; } #+end_src -*** NVME -For my nvme drives. -#+begin_src nix :tangle ../nix/disko/nvme-simple.nix -{ - disko.devices = { - disk = { - my-disk = { - device = "/dev/nvme0n1"; - type = "disk"; - content = { - type = "gpt"; - partitions = { - ESP = { - type = "EF00"; - size = "500M"; - priority = 1; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - mountOptions = [ "umask=0077" ]; - }; - }; - root = { - size = "100%"; - priority = 2; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - }; - }; - }; - }; - }; - }; - }; -} -#+end_src *** VDA For my virtual machines. -#+begin_src nix :tangle ../nix/disko/vda-simple.nix - { - disko.devices = { - disk = { - main = { - device = "/dev/vda"; - type = "disk"; - content = { - type = "gpt"; - partitions = { - boot = { - size = "1M"; - type = "EF02"; - }; - root = { - label = "disk-main-root"; - size = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; +#+begin_src nix :tangle ../nix/disko/drive-bios.nix + { config, lib, ... }: + let + spec = { + disko.devices = { + disk = { + main = { + device = config.monorepo.vars.device; + type = "disk"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + }; + root = { + label = "disk-main-root"; + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; }; }; }; @@ -1348,6 +1346,10 @@ For my virtual machines. }; }; }; + in + { + monorepo.vars.myDiskoSpec = spec; + disko.devices = spec.disko.devices; } #+end_src ** Home @@ -1502,7 +1504,7 @@ I have many imports that we'll go through next. ++ (if config.monorepo.profiles.art.enable then (with pkgs; [ inkscape - krita + # krita ]) else []) ++ (if config.monorepo.profiles.music.enable then (with pkgs; [ @@ -1515,7 +1517,7 @@ I have many imports that we'll go through next. alsa-scarlett-gui ardour audacity - blender + # blender foxdot fluidsynth qjackctl @@ -1525,7 +1527,7 @@ I have many imports that we'll go through next. supercollider inkscape kdePackages.kdenlive - kicad + # kicad murmur silver-searcher ]) else []); @@ -2922,7 +2924,7 @@ standard. g = "git"; v = "vim"; py = "python3"; - rb = "sudo nixos-rebuild switch --flake .#${systemHostName}"; + rb = "sudo nixos-rebuild switch --flake $HOME/monorepo/nix#${systemHostName}"; nfu = "cd ~/monorepo/nix && git add . && git commit -m \"new flake lock\" && nix flake update"; usync = "rsync -azvP --chmod=\"Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r\" ~/website_html/ root@${config.monorepo.vars.remoteHost}:/var/www/ret2pop-website/"; usite @@ -2992,7 +2994,7 @@ for these configurations. packages = with pkgs; (if config.monorepo.profiles.graphics.enable then [ # wikipedia - kiwix kiwix-tools + # kiwix kiwix-tools # passwords age sops @@ -3004,7 +3006,7 @@ for these configurations. graphviz jq # Apps - octaveFull + # octaveFull vesktop grim swww vim telegram-desktop # Sound/media @@ -3032,14 +3034,13 @@ for these configurations. (writeShellScriptBin "remote-build" '' #!/bin/bash - cd ~/monorepo/nix - nixos-rebuild --use-remote-sudo --target-host "$1" switch --flake .#spontaneity + nixos-rebuild --sudo --ask-sudo-password --target-host "$1" switch --flake $HOME/monorepo/nix#spontaneity '' ) (writeShellScriptBin "install-vps" '' #!/bin/bash - nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-generate-config ./systems/spontaneity/hardware-configuration.nix --flake .#spontaneity --target-host "$1" + nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-generate-config $HOME/monorepo/nix/systems/spontaneity/hardware-configuration.nix --flake $HOME/monorepo/nix#spontaneity --target-host "$1" '') ] else [ pfetch @@ -3090,16 +3091,30 @@ the path. }; } #+end_src +** Includes +These are the common includes for my systems. +#+begin_src nix :tangle ../nix/systems/includes.nix + { config, lib, ... }: + { + imports = [ + ./home.nix + ../modules/default.nix + ]; + } +#+end_src ** Continuity This is pretty understandable, if you understand all the above. #+begin_src nix :tangle ../nix/systems/continuity/default.nix { ... }: { imports = [ - ../../modules/default.nix - ../../disko/sda-simple.nix - ../home.nix + ../../disko/drive-simple.nix + ../includes.nix ]; + config = { + # drive to install to + monorepo.vars.device = "/dev/sda"; + }; } #+end_src *** Home @@ -3121,12 +3136,12 @@ as several other useful services. { config, lib, home-manager, ... }: { imports = [ - ../../modules/default.nix - ../../disko/nvme-simple.nix - ../home.nix + ../includes.nix + ../../disko/drive-simple.nix ]; config = { monorepo = { + vars.device = "/dev/nvme0n1"; profiles = { server.enable = false; cuda.enable = true; @@ -3154,14 +3169,14 @@ Spontaneity is my VPS instance. { config, lib, ... }: { imports = [ + ../includes.nix # nixos-anywhere generates this file ./hardware-configuration.nix - ../../disko/vda-simple.nix - ../../modules/default.nix - ../home.nix + ../../disko/drive-bios.nix ]; config = { monorepo = { + vars.device = "/dev/vda"; profiles = { server.enable = true; ttyonly.enable = true; @@ -3289,6 +3304,10 @@ This contains the installation script I use to install my systems. exit 1 fi + cd "$HOME" + + ping -q -c1 google.com &>/dev/null && echo "online! Proceeding with the installation..." || nmtui + gum style --border normal --margin "1" --padding "1 2" "Choose a system to install or select `new` in order to create a new system." SYSTEM="$(gum choose $(find "$HOME/monorepo/nix/systems" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | grep -v -E 'installer'; printf "New"))" @@ -3302,15 +3321,10 @@ This contains the installation script I use to install my systems. if [[ "$DRIVE" == "New" ]]; then gum style --border normal --margin "1" --padding "1 2" "Choose a name to call your drive file." - DRIVE="$(gum input --placeholder "drive file name (ex: my_sda.nix)")" + DRIVE="$(gum input --placeholder "drive file name (ex: partition_scheme.nix)")" fi fi - - ping -q -c1 google.com &>/dev/null && echo "online! Proceeding with the installation..." || nmtui - - cd "$HOME" - if [ ! -d "$HOME/monorepo/" ]; then git clone ${commits.monorepoUrl} cd "$HOME/monorepo" @@ -3326,10 +3340,11 @@ This contains the installation script I use to install my systems. { ... }: { imports = [ - ../../modules/default.nix + ../includes.nix ../../disko/$DRIVE - ../home.nix ]; + # CHANGEME + config.monorepo.vars.drive = "/dev/sda"; } EOF @@ -3337,10 +3352,14 @@ This contains the installation script I use to install my systems. gum input --placeholder "Press Enter to continue" >/dev/null vim "$HOME/monorepo/nix/systems/$SYSTEM/default.nix" + gum style --border normal --margin "1" --padding "1 2" "Edit the home default.nix with options." + gum input --placeholder "Press Enter to continue" >/dev/null + vim "$HOME/monorepo/nix/systems/$SYSTEM/home.nix" + sed -i "/hostnames = \[/,/];/ { /];/i \ \"your-hostname-$SYSTEM\" }" "$HOME/monorepo/nix/flake.nix" if [ ! -f "$HOME/monorepo/nix/disko/$DRIVE" ]; then - cp "$HOME/monorepo/nix/disko/sda-simple.nix" "$HOME/monorepo/nix/disko/$DRIVE" + cp "$HOME/monorepo/nix/disko/drive-simple.nix" "$HOME/monorepo/nix/disko/$DRIVE" gum style --border normal --margin "1" --padding "1 2" "Edit the drive file with your preferred partitioning scheme." gum input --placeholder "Press Enter to continue" >/dev/null vim "$HOME/monorepo/nix/disko/$DRIVE" @@ -3348,6 +3367,8 @@ This contains the installation script I use to install my systems. cd "$HOME/monorepo" && git add . && cd "$HOME" fi + nix --extra-experimental-features 'nix-command flakes' eval "$HOME/monorepo/nix#evalDisko.$SYSTEM" > "$HOME/drive.nix" + gum style --border normal --margin "1" --padding "1 2" "Formatting the drive is destructive!" if gum confirm "Are you sure you want to continue?"; then echo "Proceeding..." @@ -3356,7 +3377,8 @@ This contains the installation script I use to install my systems. exit 1 fi - sudo nix --experimental-features "nix-command flakes" run "github:nix-community/disko/${commits.diskoCommitHash}" -- --mode destroy,format,mount "$HOME/monorepo/nix/disko/$DRIVE" + sudo nix --experimental-features "nix-command flakes" run "github:nix-community/disko/${commits.diskoCommitHash}" -- --mode destroy,format,mount "$HOME/drive.nix" + cd /mnt sudo nixos-install --flake "$HOME/monorepo/nix#$SYSTEM" diff --git a/nix/disko/drive-bios.nix b/nix/disko/drive-bios.nix new file mode 100644 index 0000000..cf0aeba --- /dev/null +++ b/nix/disko/drive-bios.nix @@ -0,0 +1,35 @@ +{ config, lib, ... }: +let + spec = { + disko.devices = { + disk = { + main = { + device = config.monorepo.vars.device; + type = "disk"; + content = { + type = "gpt"; + partitions = { + boot = { + size = "1M"; + type = "EF02"; + }; + root = { + label = "disk-main-root"; + size = "100%"; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; + }; + }; +in +{ + monorepo.vars.myDiskoSpec = spec; + disko.devices = spec.disko.devices; +} diff --git a/nix/disko/drive-simple.nix b/nix/disko/drive-simple.nix new file mode 100644 index 0000000..4d229bf --- /dev/null +++ b/nix/disko/drive-simple.nix @@ -0,0 +1,42 @@ +{ lib, config, ... }: +let + spec = { + disko.devices = { + disk = { + my-disk = { + device = config.monorepo.vars.device; + type = "disk"; + content = { + type = "gpt"; + partitions = { + ESP = { + type = "EF00"; + size = "500M"; + priority = 1; + content = { + type = "filesystem"; + format = "vfat"; + mountpoint = "/boot"; + mountOptions = [ "umask=0077" ]; + }; + }; + root = { + size = "100%"; + priority = 2; + content = { + type = "filesystem"; + format = "ext4"; + mountpoint = "/"; + }; + }; + }; + }; + }; + }; + }; + }; +in +{ + monorepo.vars.myDiskoSpec = spec; + disko.devices = spec.disko.devices; +} diff --git a/nix/disko/nvme-simple.nix b/nix/disko/nvme-simple.nix deleted file mode 100644 index 665c17e..0000000 --- a/nix/disko/nvme-simple.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ - disko.devices = { - disk = { - my-disk = { - device = "/dev/nvme0n1"; - type = "disk"; - content = { - type = "gpt"; - partitions = { - ESP = { - type = "EF00"; - size = "500M"; - priority = 1; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - mountOptions = [ "umask=0077" ]; - }; - }; - root = { - size = "100%"; - priority = 2; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/nix/disko/sda-simple.nix b/nix/disko/sda-simple.nix deleted file mode 100644 index fdf6556..0000000 --- a/nix/disko/sda-simple.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ - disko.devices = { - disk = { - my-disk = { - device = "/dev/sda"; - type = "disk"; - content = { - type = "gpt"; - partitions = { - ESP = { - type = "EF00"; - size = "500M"; - priority = 1; - content = { - type = "filesystem"; - format = "vfat"; - mountpoint = "/boot"; - mountOptions = [ "umask=0077" ]; - }; - }; - root = { - size = "100%"; - priority = 2; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/nix/disko/vda-simple.nix b/nix/disko/vda-simple.nix deleted file mode 100644 index 3ae1d34..0000000 --- a/nix/disko/vda-simple.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ - disko.devices = { - disk = { - main = { - device = "/dev/vda"; - type = "disk"; - content = { - type = "gpt"; - partitions = { - boot = { - size = "1M"; - type = "EF02"; - }; - root = { - label = "disk-main-root"; - size = "100%"; - content = { - type = "filesystem"; - format = "ext4"; - mountpoint = "/"; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/nix/flake.lock b/nix/flake.lock index 393915b..0be049f 100644 --- a/nix/flake.lock +++ b/nix/flake.lock @@ -67,11 +67,11 @@ ] }, "locked": { - "lastModified": 1755519972, - "narHash": "sha256-bU4nqi3IpsUZJeyS8Jk85ytlX61i4b0KCxXX9YcOgVc=", + "lastModified": 1756733629, + "narHash": "sha256-dwWGlDhcO5SMIvMSTB4mjQ5Pvo2vtxvpIknhVnSz2I8=", "owner": "nix-community", "repo": "disko", - "rev": "4073ff2f481f9ef3501678ff479ed81402caae6d", + "rev": "a5c4f2ab72e3d1ab43e3e65aa421c6f2bd2e12a1", "type": "github" }, "original": { @@ -257,11 +257,11 @@ ] }, "locked": { - "lastModified": 1753592768, - "narHash": "sha256-oV695RvbAE4+R9pcsT9shmp6zE/+IZe6evHWX63f2Qg=", + "lastModified": 1756679287, + "narHash": "sha256-Xd1vOeY9ccDf5VtVK12yM0FS6qqvfUop8UQlxEB+gTQ=", "owner": "nix-community", "repo": "home-manager", - "rev": "fc3add429f21450359369af74c2375cb34a2d204", + "rev": "07fc025fe10487dd80f2ec694f1cd790e752d0e8", "type": "github" }, "original": { @@ -378,11 +378,11 @@ }, "nixpkgs_2": { "locked": { - "lastModified": 1755186698, - "narHash": "sha256-wNO3+Ks2jZJ4nTHMuks+cxAiVBGNuEBXsT29Bz6HASo=", + "lastModified": 1757068644, + "narHash": "sha256-NOrUtIhTkIIumj1E/Rsv1J37Yi3xGStISEo8tZm3KW4=", "owner": "nixos", "repo": "nixpkgs", - "rev": "fbcf476f790d8a217c3eab4e12033dc4a0f6d23c", + "rev": "8eb28adfa3dc4de28e792e3bf49fcf9007ca8ac9", "type": "github" }, "original": { @@ -394,11 +394,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1755186698, - "narHash": "sha256-wNO3+Ks2jZJ4nTHMuks+cxAiVBGNuEBXsT29Bz6HASo=", + "lastModified": 1757068644, + "narHash": "sha256-NOrUtIhTkIIumj1E/Rsv1J37Yi3xGStISEo8tZm3KW4=", "owner": "nixos", "repo": "nixpkgs", - "rev": "fbcf476f790d8a217c3eab4e12033dc4a0f6d23c", + "rev": "8eb28adfa3dc4de28e792e3bf49fcf9007ca8ac9", "type": "github" }, "original": { @@ -430,11 +430,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1755566258, - "narHash": "sha256-bLDKNtjyDjMOK6w2dsRRRPKr2GzcKOdIjsiJd2FbZuA=", + "lastModified": 1757237279, + "narHash": "sha256-u0cJc2Thq0QF8fzTSy3617E83aAPsGKjnIKgaZBXW+I=", "owner": "nix-community", "repo": "NUR", - "rev": "b54ab372b6c2831be68f7302142bdfae08204756", + "rev": "4dcb0b2bddd4456fc10d7f29862a1f1b1fd304e9", "type": "github" }, "original": { diff --git a/nix/flake.nix b/nix/flake.nix index 021bcce..cffec96 100644 --- a/nix/flake.nix +++ b/nix/flake.nix @@ -42,13 +42,19 @@ "spontaneity" # add hostnames here ]; + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; }; + generate = nixos-dns.utils.generate nixpkgs.legacyPackages."${system}"; + dnsConfig = { inherit (self) nixosConfigurations; extraConfig = import ./dns/default.nix; }; + + # function that generates all systems from hostnames mkConfigs = map (hostname: {name = "${hostname}"; value = nixpkgs.lib.nixosSystem { inherit system; @@ -78,10 +84,17 @@ ]; }; }); + + mkDiskoFiles = map (hostname: { + name = "${hostname}"; + value = self.nixosConfigurations."${hostname}".config.monorepo.vars.myDiskoSpec; + }); + in { - # add new systems here nixosConfigurations = builtins.listToAttrs (mkConfigs hostnames); + evalDisko = builtins.listToAttrs (mkDiskoFiles (builtins.filter (x: x != "installer") hostnames)); + topology."${system}" = import nix-topology { pkgs = import nixpkgs { inherit system; diff --git a/nix/modules/home/default.nix b/nix/modules/home/default.nix index 52174a9..7bfee42 100644 --- a/nix/modules/home/default.nix +++ b/nix/modules/home/default.nix @@ -145,7 +145,7 @@ ++ (if config.monorepo.profiles.art.enable then (with pkgs; [ inkscape - krita + # krita ]) else []) ++ (if config.monorepo.profiles.music.enable then (with pkgs; [ @@ -158,7 +158,7 @@ alsa-scarlett-gui ardour audacity - blender + # blender foxdot fluidsynth qjackctl @@ -168,7 +168,7 @@ supercollider inkscape kdePackages.kdenlive - kicad + # kicad murmur silver-searcher ]) else []); diff --git a/nix/modules/home/user.nix b/nix/modules/home/user.nix index 1e88b75..12bba2e 100644 --- a/nix/modules/home/user.nix +++ b/nix/modules/home/user.nix @@ -25,7 +25,7 @@ packages = with pkgs; (if config.monorepo.profiles.graphics.enable then [ # wikipedia - kiwix kiwix-tools + # kiwix kiwix-tools # passwords age sops @@ -37,7 +37,7 @@ graphviz jq # Apps - octaveFull + # octaveFull vesktop grim swww vim telegram-desktop # Sound/media @@ -65,14 +65,13 @@ (writeShellScriptBin "remote-build" '' #!/bin/bash -cd ~/monorepo/nix -nixos-rebuild --use-remote-sudo --target-host "$1" switch --flake .#spontaneity +nixos-rebuild --sudo --ask-sudo-password --target-host "$1" switch --flake $HOME/monorepo/nix#spontaneity '' ) (writeShellScriptBin "install-vps" '' #!/bin/bash -nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-generate-config ./systems/spontaneity/hardware-configuration.nix --flake .#spontaneity --target-host "$1" +nix run github:nix-community/nixos-anywhere -- --generate-hardware-config nixos-generate-config $HOME/monorepo/nix/systems/spontaneity/hardware-configuration.nix --flake $HOME/monorepo/nix#spontaneity --target-host "$1" '') ] else [ pfetch diff --git a/nix/modules/home/zsh.nix b/nix/modules/home/zsh.nix index 9f848bc..e12a2d8 100644 --- a/nix/modules/home/zsh.nix +++ b/nix/modules/home/zsh.nix @@ -25,7 +25,7 @@ g = "git"; v = "vim"; py = "python3"; - rb = "sudo nixos-rebuild switch --flake .#${systemHostName}"; + rb = "sudo nixos-rebuild switch --flake $HOME/monorepo/nix#${systemHostName}"; nfu = "cd ~/monorepo/nix && git add . && git commit -m \"new flake lock\" && nix flake update"; usync = "rsync -azvP --chmod=\"Du=rwx,Dg=rx,Do=rx,Fu=rw,Fg=r,Fo=r\" ~/website_html/ root@${config.monorepo.vars.remoteHost}:/var/www/ret2pop-website/"; usite diff --git a/nix/modules/vars.nix b/nix/modules/vars.nix index 6ee1cc0..48da971 100644 --- a/nix/modules/vars.nix +++ b/nix/modules/vars.nix @@ -1,6 +1,18 @@ { lib, ... }: { options.monorepo.vars = { + device = lib.mkOption { + type = lib.types.str; + default = "/dev/sda"; + example = "/dev/nvme0n1"; + description = "device that NixOS is installed to"; + }; + + myDiskoSpec = lib.mkOption { + type = lib.types.attrs; + description = "retains a copy of the disko spec for reflection"; + }; + userName = lib.mkOption { type = lib.types.str; default = "preston"; diff --git a/nix/systems/affinity/default.nix b/nix/systems/affinity/default.nix index 7f1f29d..17f140a 100644 --- a/nix/systems/affinity/default.nix +++ b/nix/systems/affinity/default.nix @@ -1,12 +1,12 @@ { config, lib, home-manager, ... }: { imports = [ - ../../modules/default.nix - ../../disko/nvme-simple.nix - ../home.nix + ../includes.nix + ../../disko/drive-simple.nix ]; config = { monorepo = { + vars.device = "/dev/nvme0n1"; profiles = { server.enable = false; cuda.enable = true; diff --git a/nix/systems/continuity/default.nix b/nix/systems/continuity/default.nix index 4899804..5bd6517 100644 --- a/nix/systems/continuity/default.nix +++ b/nix/systems/continuity/default.nix @@ -1,8 +1,11 @@ { ... }: { imports = [ - ../../modules/default.nix - ../../disko/sda-simple.nix - ../home.nix + ../../disko/drive-simple.nix + ../includes.nix ]; + config = { + # drive to install to + monorepo.vars.device = "/dev/sda"; + }; } diff --git a/nix/systems/includes.nix b/nix/systems/includes.nix new file mode 100644 index 0000000..5122fb2 --- /dev/null +++ b/nix/systems/includes.nix @@ -0,0 +1,7 @@ +{ config, lib, ... }: +{ + imports = [ + ./home.nix + ../modules/default.nix + ]; +} diff --git a/nix/systems/installer/commits.nix b/nix/systems/installer/commits.nix index bf865a3..cce0b46 100644 --- a/nix/systems/installer/commits.nix +++ b/nix/systems/installer/commits.nix @@ -1,5 +1,5 @@ { diskoCommitHash = "a5c4f2ab72e3d1ab43e3e65aa421c6f2bd2e12a1"; - monorepoCommitHash = "af3c15c43c65fd77aab441f4c657aeaa74cc67d5"; + monorepoCommitHash = "8f4f46e59ad0b7c5662a417d10f3074f17c962c3"; monorepoUrl = "https://github.com/ret2pop/monorepo"; } diff --git a/nix/systems/installer/default.nix b/nix/systems/installer/default.nix index 75f0b81..a22b126 100644 --- a/nix/systems/installer/default.nix +++ b/nix/systems/installer/default.nix @@ -50,27 +50,27 @@ if [ "$(id -u)" -eq 0 ]; then exit 1 fi +cd "$HOME" + +ping -q -c1 google.com &>/dev/null && echo "online! Proceeding with the installation..." || nmtui + gum style --border normal --margin "1" --padding "1 2" "Choose a system to install or select `new` in order to create a new system." -SYSTEM="$(gum choose "$(find "$HOME/monorepo/nix/systems" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | grep -v -E 'installer'; printf "New")")" +SYSTEM="$(gum choose $(find "$HOME/monorepo/nix/systems" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | grep -v -E 'installer'; printf "New"))" if [[ "$SYSTEM" == "New" ]]; then gum style --border normal --margin "1" --padding "1 2" "Choose a system name" SYSTEM="$(gum input --placeholder "system name")" -fi -gum style --border normal --margin "1" --padding "1 2" "Select a drive file or create a new drive file." -DRIVE="$(gum choose "$(find "$HOME/monorepo/nix/disko" -mindepth 1 -maxdepth 1 -type d -printf "%f\n" | printf "New")")" + gum style --border normal --margin "1" --padding "1 2" "Select a drive file or create a new drive file." + DRIVE="$(gum choose $(find "$HOME/monorepo/nix/disko" -mindepth 1 -maxdepth 1 -type f -printf "%f\n"; printf "New"))" -if [[ "$DRIVE" == "New" ]]; then - gum style --border normal --margin "1" --padding "1 2" "Choose a name to call your drive file." - SYSTEM="$(gum input --placeholder "drive file name (ex: my_sda.nix)")" + if [[ "$DRIVE" == "New" ]]; then + gum style --border normal --margin "1" --padding "1 2" "Choose a name to call your drive file." + DRIVE="$(gum input --placeholder "drive file name (ex: partition_scheme.nix)")" + fi fi -ping -q -c1 google.com &>/dev/null && echo "online! Proceeding with the installation..." || nmtui - -cd "$HOME" - if [ ! -d "$HOME/monorepo/" ]; then git clone ${commits.monorepoUrl} cd "$HOME/monorepo" @@ -86,10 +86,11 @@ if [ ! -d "$HOME/monorepo/nix/systems/$SYSTEM" ]; then { ... }: { imports = [ - ../../modules/default.nix + ../includes.nix ../../disko/$DRIVE - ../home.nix ]; + # CHANGEME + config.monorepo.vars.drive = "/dev/sda"; } EOF @@ -97,10 +98,14 @@ EOF gum input --placeholder "Press Enter to continue" >/dev/null vim "$HOME/monorepo/nix/systems/$SYSTEM/default.nix" + gum style --border normal --margin "1" --padding "1 2" "Edit the home default.nix with options." + gum input --placeholder "Press Enter to continue" >/dev/null + vim "$HOME/monorepo/nix/systems/$SYSTEM/home.nix" + sed -i "/hostnames = \[/,/];/ { /];/i \ \"your-hostname-$SYSTEM\" }" "$HOME/monorepo/nix/flake.nix" if [ ! -f "$HOME/monorepo/nix/disko/$DRIVE" ]; then - cp "$HOME/monorepo/nix/disko/sda-simple.nix" "$HOME/monorepo/nix/disko/$DRIVE" + cp "$HOME/monorepo/nix/disko/drive-simple.nix" "$HOME/monorepo/nix/disko/$DRIVE" gum style --border normal --margin "1" --padding "1 2" "Edit the drive file with your preferred partitioning scheme." gum input --placeholder "Press Enter to continue" >/dev/null vim "$HOME/monorepo/nix/disko/$DRIVE" @@ -108,10 +113,7 @@ EOF cd "$HOME/monorepo" && git add . && cd "$HOME" fi -if [ ! -f "$HOME/monorepo/nix/disko/$DRIVE" ]; then - echo "error: you should create a new system if you use a drive file that is not in the repo." - exit 1 -fi +nix --extra-experimental-features 'nix-command flakes' eval "$HOME/monorepo/nix#evalDisko.$SYSTEM" > "$HOME/drive.nix" gum style --border normal --margin "1" --padding "1 2" "Formatting the drive is destructive!" if gum confirm "Are you sure you want to continue?"; then @@ -121,7 +123,8 @@ else exit 1 fi -sudo nix --experimental-features "nix-command flakes" run "github:nix-community/disko/${commits.diskoCommitHash}" -- --mode destroy,format,mount "$HOME/monorepo/nix/disko/$DRIVE" +sudo nix --experimental-features "nix-command flakes" run "github:nix-community/disko/${commits.diskoCommitHash}" -- --mode destroy,format,mount "$HOME/drive.nix" + cd /mnt sudo nixos-install --flake "$HOME/monorepo/nix#$SYSTEM" diff --git a/nix/systems/spontaneity/default.nix b/nix/systems/spontaneity/default.nix index 3aa0a39..5460428 100644 --- a/nix/systems/spontaneity/default.nix +++ b/nix/systems/spontaneity/default.nix @@ -1,14 +1,14 @@ { config, lib, ... }: { imports = [ + ../includes.nix # nixos-anywhere generates this file ./hardware-configuration.nix - ../../disko/vda-simple.nix - ../../modules/default.nix - ../home.nix + ../../disko/drive-bios.nix ]; config = { monorepo = { + vars.device = "/dev/vda"; profiles = { server.enable = true; ttyonly.enable = true; -- 2.50.1