From cb6054298041490c1347c4dab357e1ee4970c53f Mon Sep 17 00:00:00 2001 From: Noah Masur <7386960+nmasur@users.noreply.github.com> Date: Sun, 26 Feb 2023 19:53:51 -0500 Subject: [PATCH] refactor apps and separate disko disks format-root app still not working --- apps/default.nix | 52 +++++---------------------- apps/format-root.nix | 39 ++++++++++++++++++++ apps/help.nix | 23 ++++++++++++ apps/neovim.nix | 13 +++++++ apps/rebuild.nix | 15 ++++++++ disks/root.nix | 2 +- flake.nix | 16 ++++++--- hosts/swan/default.nix | 7 +++- hosts/swan/hardware-configuration.nix | 18 +++++----- 9 files changed, 125 insertions(+), 60 deletions(-) create mode 100644 apps/format-root.nix create mode 100644 apps/help.nix create mode 100644 apps/neovim.nix create mode 100644 apps/rebuild.nix diff --git a/apps/default.nix b/apps/default.nix index 0d1f1d0..659628c 100644 --- a/apps/default.nix +++ b/apps/default.nix @@ -1,45 +1,19 @@ { pkgs, ... }: rec { - default = { - type = "app"; - program = builtins.toString (pkgs.writeShellScript "default" '' - ${pkgs.gum}/bin/gum style --margin "1 2" --padding "0 2" --foreground "15" --background "55" "Options" - ${pkgs.gum}/bin/gum format --type=template -- ' {{ Italic "Run with" }} {{ Color "15" "69" " nix run github:nmasur/dotfiles#" }}{{ Color "15" "62" "someoption" }}{{ Color "15" "69" " " }}.' - echo "" - echo "" - ${pkgs.gum}/bin/gum format --type=template -- \ - ' • {{ Color "15" "57" " readme " }} {{ Italic "Documentation for this repository." }}' \ - ' • {{ Color "15" "57" " rebuild " }} {{ Italic "Switch to this configuration." }}' \ - ' • {{ Color "15" "57" " installer " }} {{ Italic "Format and install from nothing." }}' \ - ' • {{ Color "15" "57" " neovim " }} {{ Italic "Test out the Neovim package." }}' \ - ' • {{ Color "15" "57" " loadkey " }} {{ Italic "Load an ssh key for this machine using melt." }}' \ - ' • {{ Color "15" "57" " encrypt-secret " }} {{ Italic "Encrypt a secret for all machines." }}' \ - ' • {{ Color "15" "57" " reencrypt-secrets " }} {{ Italic "Reencrypt all secrets when new machine is added." }}' \ - ' • {{ Color "15" "57" " netdata " }} {{ Italic "Connect a machine to Netdata cloud." }}' - echo "" - echo "" - ''); - }; + # Show quick helper + default = import ./help.nix { inherit pkgs; }; - # Format and install from nothing + # Format primary disk + format-root = import ./format-root.nix { inherit pkgs; }; + + # Format and install from nothing (deprecated) installer = import ./installer.nix { inherit pkgs; }; # Display the readme for this repository readme = import ./readme.nix { inherit pkgs; }; # Rebuild - rebuild = { - type = "app"; - program = builtins.toString (pkgs.writeShellScript "rebuild" '' - echo ${pkgs.system} - SYSTEM=${if pkgs.stdenv.isDarwin then "darwin" else "linux"} - if [ "$SYSTEM" == "darwin" ]; then - darwin-rebuild switch --flake github:nmasur/dotfiles#lookingglass - else - nixos-rebuild switch --flake github:nmasur/dotfiles - fi - ''); - }; + rebuild = import ./rebuild.nix { inherit pkgs; }; # Load the SSH key for this machine loadkey = import ./loadkey.nix { inherit pkgs; }; @@ -54,17 +28,7 @@ netdata = import ./netdata-cloud.nix { inherit pkgs; }; # Run neovim as an app - neovim = { - type = "app"; - program = "${ - (import ../modules/common/neovim/package { - inherit pkgs; - colors = - import ../colorscheme/gruvbox/neovim-gruvbox.nix { inherit pkgs; }; - }) - }/bin/nvim"; - }; - + neovim = import ./neovim.nix { inherit pkgs; }; nvim = neovim; } diff --git a/apps/format-root.nix b/apps/format-root.nix new file mode 100644 index 0000000..53200c5 --- /dev/null +++ b/apps/format-root.nix @@ -0,0 +1,39 @@ +{ pkgs, ... }: { + + # This script will partition and format drives; use at your own risk! + + type = "app"; + + program = builtins.toString (pkgs.writeShellScript "format-root" '' + set -e + + DISK=$1 + + if [ -z "''${DISK}" ]; then + ${pkgs.gum}/bin/gum style --width 50 --margin "1 2" --padding "2 4" \ + --foreground "#fb4934" \ + "Missing required parameter." \ + "Usage: format-root -- " \ + "Flake example: nix run github:nmasur/dotfiles#format-root -- nvme0n1" + echo "(exiting)" + exit 1 + fi + + ${pkgs.disko-packaged}/bin/disko \ + --mode create \ + --dry-run \ + --flake "path:$(pwd)#root" \ + --arg disks '[ "/dev/$DISK" ]' + + ${pkgs.gum}/bin/gum confirm \ + "This will ERASE ALL DATA on the disk /dev/''${DISK}. Are you sure you want to continue?" \ + --default=false + + ${pkgs.disko-packaged}/bin/disko \ + --mode create \ + --flake "path:$(pwd)#root" \ + --arg disks '[ '"/dev/$DISK"' ]' + + ''); + +} diff --git a/apps/help.nix b/apps/help.nix new file mode 100644 index 0000000..cb31b37 --- /dev/null +++ b/apps/help.nix @@ -0,0 +1,23 @@ +{ pkgs, ... }: { + + type = "app"; + + program = builtins.toString (pkgs.writeShellScript "default" '' + ${pkgs.gum}/bin/gum style --margin "1 2" --padding "0 2" --foreground "15" --background "55" "Options" + ${pkgs.gum}/bin/gum format --type=template -- ' {{ Italic "Run with" }} {{ Color "15" "69" " nix run github:nmasur/dotfiles#" }}{{ Color "15" "62" "someoption" }}{{ Color "15" "69" " " }}.' + echo "" + echo "" + ${pkgs.gum}/bin/gum format --type=template -- \ + ' • {{ Color "15" "57" " readme " }} {{ Italic "Documentation for this repository." }}' \ + ' • {{ Color "15" "57" " rebuild " }} {{ Italic "Switch to this configuration." }}' \ + ' • {{ Color "15" "57" " installer " }} {{ Italic "Format and install from nothing." }}' \ + ' • {{ Color "15" "57" " neovim " }} {{ Italic "Test out the Neovim package." }}' \ + ' • {{ Color "15" "57" " loadkey " }} {{ Italic "Load an ssh key for this machine using melt." }}' \ + ' • {{ Color "15" "57" " encrypt-secret " }} {{ Italic "Encrypt a secret for all machines." }}' \ + ' • {{ Color "15" "57" " reencrypt-secrets " }} {{ Italic "Reencrypt all secrets when new machine is added." }}' \ + ' • {{ Color "15" "57" " netdata " }} {{ Italic "Connect a machine to Netdata cloud." }}' + echo "" + echo "" + ''); + +} diff --git a/apps/neovim.nix b/apps/neovim.nix new file mode 100644 index 0000000..60fd389 --- /dev/null +++ b/apps/neovim.nix @@ -0,0 +1,13 @@ +{ pkgs, ... }: { + + type = "app"; + + program = "${ + (import ../modules/common/neovim/package { + inherit pkgs; + colors = + import ../colorscheme/gruvbox/neovim-gruvbox.nix { inherit pkgs; }; + }) + }/bin/nvim"; + +} diff --git a/apps/rebuild.nix b/apps/rebuild.nix new file mode 100644 index 0000000..9d04bdb --- /dev/null +++ b/apps/rebuild.nix @@ -0,0 +1,15 @@ +{ pkgs, ... }: { + + type = "app"; + + program = builtins.toString (pkgs.writeShellScript "rebuild" '' + echo ${pkgs.system} + SYSTEM=${if pkgs.stdenv.isDarwin then "darwin" else "linux"} + if [ "$SYSTEM" == "darwin" ]; then + darwin-rebuild switch --flake github:nmasur/dotfiles#lookingglass + else + nixos-rebuild switch --flake github:nmasur/dotfiles + fi + ''); + +} diff --git a/disks/root.nix b/disks/root.nix index 75c70f3..b64df37 100644 --- a/disks/root.nix +++ b/disks/root.nix @@ -1,4 +1,4 @@ -{ disks, ... }: { +{ disks ? [ ], ... }: { disk = { boot = { type = "disk"; diff --git a/flake.nix b/flake.nix index 7f851c3..93035b8 100644 --- a/flake.nix +++ b/flake.nix @@ -152,10 +152,8 @@ darwinConfigurations.lookingglass.config.home-manager.users."Noah.Masur".home; }; - diskoConfigurations = { - root = import ./disks/root.nix; - swan = { ... }: (import ./hosts/swan/disks.nix { }).disko.devices; - }; + # Disk formatting + diskoConfigurations = { root = import ./disks/root.nix; }; # Package servers into images with a generator packages = forAllSystems (system: { @@ -181,7 +179,15 @@ }); apps = forAllSystems (system: - let pkgs = import nixpkgs { inherit system overlays; }; + let + pkgs = import nixpkgs { + inherit system; + overlays = overlays ++ [ + (final: prev: { + disko-packaged = inputs.disko.packages.${system}.disko; + }) + ]; + }; in import ./apps { inherit pkgs; }); devShells = forAllSystems (system: diff --git a/hosts/swan/default.nix b/hosts/swan/default.nix index 4a983c9..fe1e67f 100644 --- a/hosts/swan/default.nix +++ b/hosts/swan/default.nix @@ -10,7 +10,6 @@ nixpkgs.lib.nixosSystem { specialArgs = { }; modules = [ ./hardware-configuration.nix - ./disks.nix ../../modules/common ../../modules/nixos (removeAttrs globals [ "mail.server" ]) @@ -21,6 +20,12 @@ nixpkgs.lib.nixosSystem { server = true; zfs.enable = true; + disko = { + enableConfig = true; + devices.disks = + import ../../disks/root.nix { disks = [ "/dev/nvme0n1" ]; }; + }; + # head -c 8 /etc/machine-id networking.hostId = "600279f4"; # Random ID required for ZFS diff --git a/hosts/swan/hardware-configuration.nix b/hosts/swan/hardware-configuration.nix index f8d211c..63b8a61 100644 --- a/hosts/swan/hardware-configuration.nix +++ b/hosts/swan/hardware-configuration.nix @@ -12,15 +12,15 @@ boot.kernelModules = [ "kvm-intel" ]; boot.extraModulePackages = [ ]; - fileSystems."/" = { - device = "/dev/disk/by-label/nixos"; - fsType = "ext4"; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-label/boot"; - fsType = "vfat"; - }; + # fileSystems."/" = { + # device = "/dev/disk/by-label/nixos"; + # fsType = "ext4"; + # }; + # + # fileSystems."/boot" = { + # device = "/dev/disk/by-label/boot"; + # fsType = "vfat"; + # }; swapDevices = [ ];