diff --git a/Justfile b/Justfile index 18b7c37..e26cd24 100755 --- a/Justfile +++ b/Justfile @@ -6,9 +6,14 @@ _device action dir +moreargs="": set -ex sudo $(set -x; nix-build --no-link --show-trace $(dirname {{dir}})/default.nix -A {{action}} --argstr dir {{dir}} {{moreargs}}) -_rebuild-device dir rebuildarg="dry-activate" +moreargs="": +_render_templates: #!/usr/bin/env bash + set -ex nix/scripts/pre-eval-fixed.sh nix/home-manager/profiles/dotfiles/vcsh{.tmpl,}.nix + +_rebuild-device dir rebuildarg="dry-activate" +moreargs="": _render_templates + #!/usr/bin/env bash + set -ex just -v _device rebuild {{dir}} --argstr rebuildarg {{rebuildarg}} {{moreargs}} # Rebulid this device's NixOS @@ -73,29 +78,9 @@ hm-iterate-qtile: wait $! kill ${XEPHYR_PID} -# Sorry, this is a manual step for now. Please see nix/os/modules/encryptedDisk.nix for the layout -disk-prepare: - echo NOT IMPLEMENTED - # GPT partition table - # part1: size: 1MiB type: 4 BIOS BOOT - # part2: size: 512MiB label: 2-DISKID (36 char limit?) - # part3: size: * label: 3-DISKID (36 char limit?) - # cryptsetup format part3 - # vgcreate DISKID part3 - # lvcreate DISKID -L 8G -n swap - # lvcreate DISKID -l 100%FREE -n root - # sudo mkfs.vfat -F32 part2 - # sudo mkfs.btrfs /dev/DISKID/root - # sudo mkswap /dev/DISKID/swap - # sudo mount /dev/DISKID/root /mnt - # sudo btrfs subvolume create nixos - # sudo btrfs subvolume create home - # sudo mount /dev/disk/by-partlabel/3-DISKID /mnt/DISKID-root - # pushd /dev/disk/by-partlabel/3-DISKID /mnt/DISKID-root - # sudo btrfs subvolume create nixos - # sudo mkdir nixos/{boot,home} - # sudo btrfs subvolume create home - # +# !!! DANGERIOUS !!! This wipes the disk which is configured for the given device. +disk-prepare dir: + just -v _device diskPrepare {{dir}} --argstr rebuildarg "dummy" # Mount the target disk specified by device configuration directory. The 'dir' argument points to a device configuration, e.g. 'nix/os/devices/steveej-live-mmc-SL32G_0x259093f6' disk-mount dir: @@ -105,6 +90,6 @@ disk-mount dir: disk-umount dir: just -v _device diskUmount {{dir}} --argstr rebuildarg "dummy" -# Perform an offline installation on the mounted the target disk, specified by device configuration directory -disk-install dir: +# Perform an offline installation on the mounted target disk, specified by device configuration directory +disk-install dir: _render_templates just -v _device diskInstall {{dir}} --argstr rebuildarg "dummy" diff --git a/README.md b/README.md index 69a5680..0e2c277 100644 --- a/README.md +++ b/README.md @@ -9,34 +9,32 @@ In the unlikely case that you actually read this and have any questions please d - All graphical systems (incl. install media) must have - [x] Full-disk encryption by default - [x] Yubikey support with SSH auth -- [ ] Migrate all devices to new structure +- [x] Migrate all devices to new structure - [x] Encrypted Install media - [x] steveej-laptop - - [ ] steveej-laptop-work + - [x] steveej-laptop-work - [ ] Migrate home environment to new structure - [x] home-manager - [x] pkgs-configuration - [ ] development environments - [ ] (Semi-) automatic synchronization of important repositories - - [ ] Modification strategy - - [ ] dotfiles + - [x] Modification strategy + - [x] dotfiles - [ ] password-store - [ ] this repo -- [ ] Toplevel Justfile for simple actions +- [x] Toplevel Justfile for simple actions - [x] mount/umount disks - [x] install to mounted disk - [x] rebuild running system - [x] update running system - [x] annotate recipes with some documentation - [x] declare shell.nix with runtime deps - - [ ] partition/encrypt/format disks + - [x] partition/encrypt/format disks - [ ] Document bootstrap process - [ ] a new machine - [ ] an install media - [ ] Design disaster recovery -- [ ] Automatic backups - - [ ] tracked dotfiles - - [ ] detect new and untracked dotfiles? +- [ ] Automatic synchronization of other state files - see https://gitlab.com/steveeJ/nix-expressions/issues/2 - [ ] Recycle *\_archived* - [ ] Maybe make this a nix-overlay diff --git a/nix/home-manager/configuration/graphical-fullblown.nix b/nix/home-manager/configuration/graphical-fullblown.nix index 701971c..967d92b 100644 --- a/nix/home-manager/configuration/graphical-fullblown.nix +++ b/nix/home-manager/configuration/graphical-fullblown.nix @@ -196,6 +196,7 @@ in { wireshark # Code Editors + unstablepkgs.atom xclip xsel unstablepkgs.vscode @@ -214,8 +215,6 @@ in { # ]; # }) - unstablepkgs.atom - # Image/Graphic/Design Tools gnome3.eog gimp diff --git a/nix/home-manager/configuration/graphical-removable.nix b/nix/home-manager/configuration/graphical-removable.nix index 2396faa..aade69f 100644 --- a/nix/home-manager/configuration/graphical-removable.nix +++ b/nix/home-manager/configuration/graphical-removable.nix @@ -124,7 +124,7 @@ in { cdrtools # Document Processing and Management - unstablepkgs.zathura + zathura # File Synchronzation rsync diff --git a/nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix b/nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix index fe99c8d..16a5d80 100644 --- a/nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix +++ b/nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix @@ -27,7 +27,7 @@ in pkgs.writeScript "activation-script" '' if ! test -d $HOME/.config/vcsh/repo.d/dotfiles.git; then echo Cloning dotfiles for $HOST... - ${pkgs.vcsh}/bin/vcsh clone -b $HOST ${repoBareLocal} + ${pkgs.vcsh}/bin/vcsh clone -b $HOST ${repoBareLocal} dotfiles set_remotes ${repoHttps} ${repoSsh} else set_remotes ${repoBareLocal} ${repoSsh} diff --git a/nix/os/devices/default.nix b/nix/os/devices/default.nix index 7c620af..aef8f58 100644 --- a/nix/os/devices/default.nix +++ b/nix/os/devices/default.nix @@ -1,21 +1,22 @@ { pkgs ? import {} +, ownLib ? import ../lib/default.nix { } , dir , rebuildarg , moreargs ? "" +, diskId ? (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.encryptedDisk.diskId +, gitRoot ? "$(git rev-parse --show-toplevel)" }: let - diskId = (import ((builtins.getEnv "PWD")+"/${dir}/hw.nix") {}).hardware.encryptedDisk.diskId; - GIT_ROOT=''''$(git rev-parse --show-toplevel)''; + mntRootVol="/mnt/${diskId}-root"; -in { +in rec { rebuild = pkgs.writeScript "script" '' #!/usr/bin/env bash set -xe - pushd ${GIT_ROOT}/${dir} + pushd ${gitRoot}/${dir} export NIXOS_CONFIG="$PWD"/configuration.nix - export INSTALL_ROOT="/mnt/$ID-root" [[ -e "''${NIXOS_CONFIG}" ]] @@ -28,39 +29,106 @@ in { diskMount = pkgs.writeScript "script" '' #!/usr/bin/env bash set -xe - ID=${diskId} - echo Mounting $ID - set -xe - cryptsetup luksOpen /dev/disk/by-id/$ID-part3 $ID-part3 - vgchange -ay $ID - mkdir -p /mnt/$ID-root - mount /dev/$ID/root /mnt/$ID-root -o subvol=nixos - mount /dev/$ID/root /mnt/$ID-root/home -o subvol=home - mount /dev/disk/by-id/$ID-part2 /mnt/$ID-root/boot + echo Mounting ${diskId} + cryptsetup luksOpen ${ownLib.disk.bootLuksDevice diskId} ${ownLib.disk.luksName diskId} + vgchange -ay ${ownLib.disk.volumeGroup diskId} + mkdir -p /mnt + mkdir ${mntRootVol} + mount ${ownLib.disk.rootFsDevice diskId} ${mntRootVol} + mount ${ownLib.disk.rootFsDevice diskId} ${mntRootVol}/nixos/home -o subvol=home + mount ${ownLib.disk.bootFsDevice diskId} ${mntRootVol}/nixos/boot ''; diskUmount = pkgs.writeScript "script" '' #!/usr/bin/env bash set -xe - ID=${diskId} - umount -R /mnt/$ID-root - rmdir /mnt/$ID-root - vgchange -an $ID - cryptsetup luksClose $ID-part3 + umount -R ${mntRootVol} + rmdir ${mntRootVol} + vgchange -an ${ownLib.disk.volumeGroup diskId} + cryptsetup luksClose ${ownLib.disk.luksName diskId} sync ''; diskInstall = pkgs.writeScript "script" '' #!/usr/bin/env bash set -xe - ID=${diskId} - pushd ${GIT_ROOT}/${dir} + pushd ${gitRoot}/${dir} export NIXOS_CONFIG="$PWD"/configuration.nix - export INSTALL_ROOT="/mnt/$ID-root" [[ -e "''${NIXOS_CONFIG}" ]] - [[ -e "''${INSTALL_ROOT}" ]] + [[ -e "${mntRootVol}/nixos" ]] - nixos-install --max-jobs 5 --cores 4 --no-channel-copy --no-root-passwd --root "''${INSTALL_ROOT}" + nixos-install --max-jobs 5 --cores 4 --no-root-passwd --root ${mntRootVol}/nixos + ''; + + diskPrepare = pkgs.writeScript "script" '' + #!/usr/bin/env bash + set -xe + + read -p "Continue to format ${ownLib.disk.bootGrubDevice diskId} (YES/n)?" choice + case "$choice" in + YES ) echo "Continuing in 3 seconds..."; sleep 3;; + n|N ) echo "Exiting..."; exit 0;; + * ) echo "Exiting..."; exit 1;; + esac + + # Partition + sync + { + fdisk -w always -W always ${ownLib.disk.bootGrubDevice diskId} < {}; +stdenv.mkDerivation { + name = "env"; + buildInputs = [ + zsh + go + go2nix + dep2nix + nix-prefetch-github + (callPackage ./default.nix {}) + ]; +}