2022-05-21 00:07:49 +00:00
|
|
|
# docs:
|
|
|
|
# https://nixos.wiki/wiki/Flakes
|
|
|
|
# https://serokell.io/blog/practical-nix-flakes
|
|
|
|
|
|
|
|
{
|
|
|
|
inputs = {
|
2022-05-28 19:35:43 +00:00
|
|
|
nixpkgs.url = "nixpkgs/nixos-22.05";
|
2022-05-23 02:45:54 +00:00
|
|
|
mobile-nixos = {
|
2022-05-24 05:47:32 +00:00
|
|
|
url = "github:nixos/mobile-nixos";
|
|
|
|
flake = false;
|
2022-05-23 02:45:54 +00:00
|
|
|
};
|
2022-05-22 01:05:32 +00:00
|
|
|
home-manager = {
|
2022-06-03 08:39:34 +00:00
|
|
|
url = "github:nix-community/home-manager/release-22.05";
|
2022-05-22 01:05:32 +00:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2022-06-06 23:36:22 +00:00
|
|
|
sops-nix.url = "github:Mic92/sops-nix";
|
2022-06-20 10:28:01 +00:00
|
|
|
impermanence.url = "github:nix-community/impermanence";
|
2022-05-21 00:07:49 +00:00
|
|
|
};
|
2022-05-21 07:30:29 +00:00
|
|
|
|
2022-07-06 21:03:28 +00:00
|
|
|
outputs = { self, nixpkgs, mobile-nixos, home-manager, sops-nix, impermanence }:
|
2022-06-23 22:57:20 +00:00
|
|
|
let
|
2022-06-24 06:26:51 +00:00
|
|
|
patchedPkgs = system: nixpkgs.legacyPackages.${system}.applyPatches {
|
|
|
|
name = "nixpkgs-patched-uninsane";
|
|
|
|
src = nixpkgs;
|
|
|
|
patches = import ./nixpatches/list.nix nixpkgs.legacyPackages.${system}.fetchpatch;
|
|
|
|
};
|
|
|
|
# return something which behaves like `pkgs`, for the provided system
|
2022-08-12 00:02:41 +00:00
|
|
|
# `local` = architecture of builder. `target` = architecture of the system beying deployed to
|
|
|
|
nixpkgsFor = local: target: import (patchedPkgs target) { crossSystem = target; localSystem = local; };
|
2022-06-24 06:26:51 +00:00
|
|
|
# evaluate ONLY our overlay, for the provided system
|
2022-08-12 00:02:41 +00:00
|
|
|
customPackagesFor = local: target: import ./pkgs/overlay.nix (nixpkgsFor local target) (nixpkgsFor local target);
|
|
|
|
decl-machine = { name, local, target }:
|
2022-06-23 22:57:20 +00:00
|
|
|
let
|
2022-08-12 00:02:41 +00:00
|
|
|
nixosSystem = import ((patchedPkgs target) + "/nixos/lib/eval-config.nix");
|
2022-06-23 22:57:20 +00:00
|
|
|
in (nixosSystem {
|
2022-08-12 00:02:41 +00:00
|
|
|
# by default the local system is the same as the target, employing emulation when they differ
|
|
|
|
system = target;
|
2022-08-12 00:05:10 +00:00
|
|
|
specialArgs = { inherit mobile-nixos home-manager impermanence; };
|
2022-06-23 22:57:20 +00:00
|
|
|
modules = [
|
|
|
|
./modules
|
|
|
|
./machines/${name}
|
|
|
|
(import ./helpers/set-hostname.nix name)
|
2022-07-06 21:36:14 +00:00
|
|
|
home-manager.nixosModule
|
2022-07-06 21:17:29 +00:00
|
|
|
impermanence.nixosModule
|
2022-07-06 21:36:14 +00:00
|
|
|
sops-nix.nixosModules.sops
|
2022-06-23 22:57:20 +00:00
|
|
|
{
|
|
|
|
nixpkgs.config.allowUnfree = true;
|
|
|
|
nixpkgs.overlays = [
|
|
|
|
(import "${mobile-nixos}/overlay/overlay.nix")
|
|
|
|
(import ./pkgs/overlay.nix)
|
2022-08-12 00:02:41 +00:00
|
|
|
(next: prev: {
|
|
|
|
# non-emulated packages build *from* local *for* target.
|
|
|
|
# for large packages like the linux kernel which are expensive to build under emulation,
|
|
|
|
# the config can explicitly pull such packages from `pkgs.cross` to do more efficient cross-compilation.
|
|
|
|
cross = (nixpkgsFor local target) // (customPackagesFor local target);
|
|
|
|
})
|
2022-06-23 22:57:20 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
2022-05-21 07:40:56 +00:00
|
|
|
});
|
|
|
|
|
2022-08-12 00:02:41 +00:00
|
|
|
decl-bootable-machine = { name, local, target }: rec {
|
|
|
|
nixosConfiguration = decl-machine { inherit name local target; };
|
2022-06-23 22:53:35 +00:00
|
|
|
# this produces a EFI-bootable .img file (GPT with a /boot partition and a system (/ or /nix) partition).
|
|
|
|
# after building this:
|
2022-06-24 23:04:25 +00:00
|
|
|
# - flash it to a bootable medium (SD card, flash drive, HDD)
|
|
|
|
# - resize the root partition (use cfdisk)
|
|
|
|
# - mount the part
|
2022-08-03 00:10:32 +00:00
|
|
|
# - chown root:nixbld <part>/nix/store
|
|
|
|
# - chown root:root -R <part>/nix/store/*
|
|
|
|
# - chown root:root -R <part>/persist # if using impermanence
|
|
|
|
# - populate any important things (persist/, home/colin/.ssh, etc)
|
2022-06-23 22:53:35 +00:00
|
|
|
# - boot
|
2022-06-24 23:04:25 +00:00
|
|
|
# - if fs wasn't resized automatically, then `sudo btrfs filesystem resize max /`
|
2022-06-23 22:53:35 +00:00
|
|
|
# - checkout this flake into /etc/nixos AND UPDATE THE FS UUIDS.
|
|
|
|
# - `nixos-rebuild --flake './#<machine>' switch`
|
|
|
|
img = nixosConfiguration.config.system.build.img;
|
2022-05-24 00:15:38 +00:00
|
|
|
};
|
2022-08-12 00:02:41 +00:00
|
|
|
machines.servo = decl-bootable-machine { name = "servo"; local = "aarch64-linux"; target = "aarch64-linux"; };
|
|
|
|
machines.desko = decl-bootable-machine { name = "desko"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
|
|
|
machines.lappy = decl-bootable-machine { name = "lappy"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
|
|
|
machines.moby = decl-bootable-machine { name = "moby"; local = "aarch64-linux"; target = "aarch64-linux"; };
|
|
|
|
# special cross-compiled variant, to speed up deploys from an x86 box to the arm target
|
|
|
|
# note that these *do* produce different store paths, because the closure for the tools used to cross compile
|
|
|
|
# v.s. emulate differ.
|
|
|
|
# so deploying moby-cross and then moby incurs some rebuilding.
|
|
|
|
machines.moby-cross = decl-bootable-machine { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; };
|
|
|
|
machines.rescue = decl-bootable-machine { name = "rescue"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
2022-06-23 22:57:20 +00:00
|
|
|
in {
|
|
|
|
nixosConfigurations = builtins.mapAttrs (name: value: value.nixosConfiguration) machines;
|
|
|
|
imgs = builtins.mapAttrs (name: value: value.img) machines;
|
2022-08-12 00:02:41 +00:00
|
|
|
packages.x86_64-linux = customPackagesFor "x86_64-linux" "x86_64-linux";
|
|
|
|
packages.aarch64-linux = customPackagesFor "aarch64-linux" "aarch64-linux";
|
2022-05-21 00:07:49 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|