diff --git a/.envrc b/.envrc index 1d953f4..8392d15 100644 --- a/.envrc +++ b/.envrc @@ -1 +1 @@ -use nix +use flake \ No newline at end of file diff --git a/default.nix b/default.nix index 1950006..f01ab85 100644 --- a/default.nix +++ b/default.nix @@ -9,28 +9,26 @@ let inherit (pkgs) lib; inherit (lib.filesystem) listFilesRecursive; inherit (lib.strings) hasSuffix; - inherit (lib.attrsets) genAttrs; - nixosSystem = import (sources.nixpkgs + "/nixos/lib/eval-config.nix"); mkSystem = hostname: - nixosSystem { - system = null; + import (src.nixpkgs + "/nixos/lib/eval-config.nix") { specialArgs = { inherit sources; self = ./.; }; modules = [ + # This is used to pre-emptively set the hostPlatform for nixpkgs. + # Also, we set the system hostname here. { networking.hostName = hostname; } + ./hosts/common.nix ./hosts/${hostname} ] ++ ((listFilesRecursive ./modules) |> filter (hasSuffix ".mod.nix")); }; - - hosts = [ - "temperance" - "hermit" - "tower" - ]; in -genAttrs hosts mkSystem +{ + temperance = mkSystem "temperance"; + hermit = mkSystem "hermit"; + tower = mkSystem "tower"; +} diff --git a/docs/dualboot.md b/docs/dualboot.md new file mode 100644 index 0000000..e1571e5 --- /dev/null +++ b/docs/dualboot.md @@ -0,0 +1,55 @@ +# Dualbooting NixOS and FreeBSD + +Out of curiosity, I decided to dual-boot NixOS and FreeBSD on my laptop, sharing +one disk. I document the process here for future reference: + +## Linux install + +First, flash a stick with NixOS, then boot into it, wipe your disk, create two +partitions, one being boot, the other your main NixOS partition. Then, follow +these commands: + +```bash +sudo su + +cryptsetup luksFormat /dev/diskname/partition + +cryptsetup open /dev/diskname/partition crypt + +mkfs.btrfs -L nixos /dev/mapper/crypt + +mount /dev/mapper/crypt /mnt + +btrfs create subvolume /mnt/nix +btrfs create subvolume /mnt/home +btrfs create subvolume /mnt/persist + +mkdir /mnt/boot +mount /dev/partition # boot partition +``` + +Then, copy [my nixos flake](https://github.com/bloxx12/nichts) to `/mnt`, you +can remove it from there later on. + +```bash +git clone https://github.com/bloxx12/nichts /mnt +``` + +In there, change the file system uuids to the correct ones, you can see them +using + +```bash +sudo blkid +``` + +Then, install NixOS itself: + +```bash +nixos-install --impure --flake /mnt/nichts# -j 1 --cores 2 +``` + +Wait for that to finish, then reboot. + +If your system works, great! if not, redo from the beginning. + +After that, set up FreeBSD the following way: diff --git a/hosts/common.nix b/hosts/common.nix new file mode 100644 index 0000000..0405615 --- /dev/null +++ b/hosts/common.nix @@ -0,0 +1,50 @@ +# This is for packages I want in all systems. +# Keeping this list as small as possible is important, +# since these also get installed to server, +# which should have a small attack surface. +{ + lib, + pkgs, + ... +}: +let + inherit (lib.meta) hiPrioSet; +in +{ + environment.systemPackages = + builtins.attrValues { + inherit (pkgs) + cachix + calc + delta + difftastic + eza + gcc + git + httpie + inetutils + jujutsu + just + lazygit + linuxHeaders + neofetch + microfetch + mprocs + nmap + ripgrep + smartmontools + television + trash-cli + util-linux + w3m + wireguard-tools + zip + zoxide + ; + } + ++ builtins.attrValues (hiPrioSet { + }) + ++ [ (lib.hiPrio pkgs.uutils-coreutils-noprefix) ]; + # helix as the only editor, a reasonable choice. + environment.variables.EDITOR = "hx"; +} diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 0000000..12ee7fd --- /dev/null +++ b/hosts/default.nix @@ -0,0 +1,70 @@ +{ + sources, + nixpkgs, + self, + ... +}: +let + inherit (builtins) filter map toString; + inherit (nixpkgs) lib; + inherit (lib.attrsets) recursiveUpdate; + inherit (lib.filesystem) listFilesRecursive; + inherit (lib.lists) concatLists flatten singleton; + inherit (lib.strings) hasSuffix; + inherit (lib) nixosSystem; + # NOTE: This was inspired by raf, and I find this + # to be quite a sane way of managing all modules in my flake. + + mkSystem = + { + system, + hostname, + ... + }@args: + nixosSystem { + specialArgs = recursiveUpdate { + inherit lib; + inputs = sources; + inherit self; + } args.specialArgs or { }; + modules = concatLists [ + # This is used to pre-emptively set the hostPlatform for nixpkgs. + # Also, we set the system hostname here. + (singleton { + networking.hostName = hostname; + nixpkgs.hostPlatform = system; + }) + ( + concatLists [ + # configuration for the host, passed as an argument. + (singleton ./${hostname}/default.nix) + # common configuration, which all hosts share. + (singleton ./common.nix) + # Import all files called module.nix from my modules directory. + (map toString (listFilesRecursive ../modules) |> filter (hasSuffix "module.nix")) + (map toString (listFilesRecursive ../modules) |> filter (hasSuffix ".mod.nix")) + ] + |> flatten + ) + ]; + }; +in +{ + temperance = mkSystem { + system = "x86_64-linux"; + hostname = "temperance"; + }; + + hermit = mkSystem { + system = "x86_64-linux"; + hostname = "hermit"; + }; + tower = mkSystem { + system = "aarch64-linux"; + hostname = "tower"; + }; + # world = mkSystem { + # system = "x86_64-linux"; + # hostname = "world"; + # }; +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 505408b..0000000 --- a/shell.nix +++ /dev/null @@ -1,12 +0,0 @@ -{ - pkgs ? import { }, - sources ? import ./npins, -}: -pkgs.mkShellNoCC { - - packages = [ - (pkgs.callPackage (sources.npins + "/npins.nix") { }) - pkgs.nil - pkgs.nixfmt - ]; -}