2022-05-21 00:07:49 +00:00
|
|
|
# docs:
|
2022-08-25 02:46:10 +00:00
|
|
|
# - <https://nixos.wiki/wiki/Flakes>
|
|
|
|
# - <https://serokell.io/blog/practical-nix-flakes>
|
2022-05-21 00:07:49 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
inputs = {
|
2022-12-14 22:32:41 +00:00
|
|
|
nixpkgs-stable.url = "nixpkgs/nixos-22.11";
|
2023-01-10 17:00:43 +00:00
|
|
|
nixpkgs-unpatched.url = "nixpkgs/nixos-unstable";
|
|
|
|
nixpkgs = {
|
2023-01-10 17:44:58 +00:00
|
|
|
url = "path:nixpatches";
|
2023-01-10 17:00:43 +00:00
|
|
|
inputs.nixpkgs.follows = "nixpkgs-unpatched";
|
|
|
|
};
|
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-10-11 00:19:57 +00:00
|
|
|
sops-nix = {
|
|
|
|
url = "github:Mic92/sops-nix";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2023-01-11 08:45:41 +00:00
|
|
|
uninsane-dot-org = {
|
2022-10-11 10:22:40 +00:00
|
|
|
url = "git+https://git.uninsane.org/colin/uninsane";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
|
|
|
};
|
2022-05-21 00:07:49 +00:00
|
|
|
};
|
2022-05-21 07:30:29 +00:00
|
|
|
|
2022-10-27 10:20:29 +00:00
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
nixpkgs-stable,
|
2023-01-10 17:00:43 +00:00
|
|
|
nixpkgs-unpatched,
|
2022-10-27 10:20:29 +00:00
|
|
|
mobile-nixos,
|
|
|
|
home-manager,
|
|
|
|
sops-nix,
|
2023-01-11 08:45:41 +00:00
|
|
|
uninsane-dot-org
|
2023-01-11 05:58:07 +00:00
|
|
|
}:
|
2022-06-23 22:57:20 +00:00
|
|
|
let
|
2023-01-11 05:58:07 +00:00
|
|
|
nixpkgsCompiledBy = local: nixpkgs.legacyPackages."${local}";
|
2022-12-14 12:27:24 +00:00
|
|
|
|
2023-01-11 09:31:05 +00:00
|
|
|
evalHost = { name, local, target }:
|
2023-01-11 05:58:07 +00:00
|
|
|
let
|
|
|
|
# XXX: we'd prefer to use `nixosSystem = (nixpkgsCompiledBy local).nixos`
|
|
|
|
# but it doesn't propagate config to the underlying pkgs, meaning it doesn't let you use
|
|
|
|
# non-free packages even after setting nixpkgs.allowUnfree.
|
|
|
|
nixosSystem = import ((nixpkgsCompiledBy local).path + "/nixos/lib/eval-config.nix");
|
|
|
|
in
|
|
|
|
(nixosSystem {
|
|
|
|
# we use pkgs built for and *by* the target, i.e. emulation, by default.
|
|
|
|
# cross compilation only happens on explicit access to `pkgs.cross`
|
|
|
|
system = target;
|
|
|
|
modules = [
|
2023-01-11 08:56:06 +00:00
|
|
|
(import ./hosts/instantiate.nix { localSystem = local; hostName = name; })
|
2023-01-11 08:45:41 +00:00
|
|
|
self.nixosModules.default
|
|
|
|
self.nixosModules.passthru
|
2023-01-11 05:58:07 +00:00
|
|
|
{
|
|
|
|
nixpkgs.overlays = [
|
2023-01-11 08:45:41 +00:00
|
|
|
self.overlays.default
|
|
|
|
self.overlays.passthru
|
|
|
|
];
|
2023-01-11 05:58:07 +00:00
|
|
|
}
|
|
|
|
];
|
|
|
|
});
|
2023-01-11 09:24:24 +00:00
|
|
|
in {
|
|
|
|
nixosConfigurations = {
|
2023-01-11 09:31:05 +00:00
|
|
|
servo = evalHost { name = "servo"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
|
|
|
desko = evalHost { name = "desko"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
|
|
|
lappy = evalHost { name = "lappy"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
|
|
|
moby = evalHost { name = "moby"; local = "aarch64-linux"; target = "aarch64-linux"; };
|
2023-01-11 05:58:07 +00:00
|
|
|
# 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 foo-cross and then foo incurs some rebuilding.
|
2023-01-11 09:31:05 +00:00
|
|
|
moby-cross = evalHost { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; };
|
|
|
|
rescue = evalHost { name = "rescue"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
2022-10-11 10:22:40 +00:00
|
|
|
};
|
2023-01-11 08:56:06 +00:00
|
|
|
|
|
|
|
# unofficial output
|
2023-01-11 09:24:24 +00:00
|
|
|
# this produces a EFI-bootable .img file (GPT with a /boot partition and a system (/ or /nix) partition).
|
|
|
|
# after building this:
|
|
|
|
# - flash it to a bootable medium (SD card, flash drive, HDD)
|
|
|
|
# - resize the root partition (use cfdisk)
|
|
|
|
# - mount the part
|
|
|
|
# - 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)
|
|
|
|
# - boot
|
|
|
|
# - if fs wasn't resized automatically, then `sudo btrfs filesystem resize max /`
|
|
|
|
# - checkout this flake into /etc/nixos AND UPDATE THE FS UUIDS.
|
|
|
|
# - `nixos-rebuild --flake './#<host>' switch`
|
2023-01-11 09:29:49 +00:00
|
|
|
imgs = builtins.mapAttrs (_: host-dfn: host-dfn.config.system.build.img) self.nixosConfigurations;
|
2023-01-11 05:58:07 +00:00
|
|
|
|
2023-01-11 07:22:21 +00:00
|
|
|
overlays = rec {
|
2023-01-11 08:45:41 +00:00
|
|
|
default = pkgs;
|
|
|
|
pkgs = import ./pkgs/overlay.nix;
|
2023-01-11 09:08:46 +00:00
|
|
|
passthru =
|
2023-01-11 08:45:41 +00:00
|
|
|
let
|
2023-01-11 09:08:46 +00:00
|
|
|
stable = next: prev: {
|
|
|
|
stable = nixpkgs-stable.legacyPackages."${prev.stdenv.hostPlatform}";
|
|
|
|
};
|
2023-01-11 08:45:41 +00:00
|
|
|
mobile = (import "${mobile-nixos}/overlay/overlay.nix");
|
|
|
|
uninsane = uninsane-dot-org.overlay;
|
|
|
|
in
|
2023-01-11 09:33:59 +00:00
|
|
|
next: prev:
|
|
|
|
(stable next prev) // (mobile next prev) // (uninsane next prev);
|
2023-01-11 08:45:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nixosModules = rec {
|
|
|
|
default = sane;
|
|
|
|
sane = import ./modules;
|
|
|
|
passthru = { ... }: {
|
|
|
|
imports = [
|
|
|
|
home-manager.nixosModule
|
|
|
|
sops-nix.nixosModules.sops
|
|
|
|
];
|
|
|
|
};
|
2023-01-11 07:22:21 +00:00
|
|
|
};
|
|
|
|
|
2023-01-11 09:21:09 +00:00
|
|
|
# this includes both our native packages and all the nixpkgs packages.
|
|
|
|
legacyPackages =
|
2023-01-11 05:58:07 +00:00
|
|
|
let
|
2023-01-11 09:21:09 +00:00
|
|
|
allPkgsFor = sys: (nixpkgsCompiledBy sys).appendOverlays [
|
|
|
|
self.overlays.passthru self.overlays.pkgs
|
|
|
|
];
|
2023-01-11 05:58:07 +00:00
|
|
|
in {
|
|
|
|
x86_64-linux = allPkgsFor "x86_64-linux";
|
|
|
|
aarch64-linux = allPkgsFor "aarch64-linux";
|
|
|
|
};
|
|
|
|
|
2023-01-11 09:29:49 +00:00
|
|
|
# extract only our own packages from the full set
|
|
|
|
packages = builtins.mapAttrs
|
|
|
|
(_: full: full.sane // { inherit (full) sane uninsane-dot-org; })
|
|
|
|
self.legacyPackages;
|
2023-01-11 09:21:09 +00:00
|
|
|
|
2023-01-11 10:22:25 +00:00
|
|
|
apps."x86_64-linux" = {
|
|
|
|
update-feeds = {
|
|
|
|
type = "app";
|
|
|
|
program =
|
|
|
|
let
|
|
|
|
pkgs = self.legacyPackages."x86_64-linux";
|
2023-01-11 10:31:00 +00:00
|
|
|
script = pkgs.feeds.passthru.updateScript;
|
2023-01-11 10:22:25 +00:00
|
|
|
in "${script}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-01-11 05:58:07 +00:00
|
|
|
templates = {
|
|
|
|
python-data = {
|
|
|
|
# initialize with:
|
|
|
|
# - `nix flake init -t '/home/colin/dev/nixos/#python-data'`
|
|
|
|
# then enter with:
|
|
|
|
# - `nix develop`
|
|
|
|
path = ./templates/python-data;
|
|
|
|
description = "python environment for data processing";
|
|
|
|
};
|
2022-11-30 00:48:27 +00:00
|
|
|
};
|
|
|
|
};
|
2022-05-21 00:07:49 +00:00
|
|
|
}
|
|
|
|
|