2023-01-14 23:20:38 +00:00
|
|
|
# FLAKE FEEDBACK:
|
2023-01-15 04:10:10 +00:00
|
|
|
# - if flake inputs are meant to be human-readable, a human should be able to easily track them down given the URL.
|
|
|
|
# - this is not the case with registry URLs, like `nixpkgs/nixos-22.11`.
|
|
|
|
# - this is marginally the case with schemes like `github:nixos/nixpkgs`.
|
|
|
|
# - given the *existing* `git+https://` scheme, i propose expressing github URLs similarly:
|
|
|
|
# - `github+https://github.com/nixos/nixpkgs/tree/nixos-22.11`
|
2023-09-24 08:16:19 +00:00
|
|
|
# - this would allow for the same optimizations as today's `github:nixos/nixpkgs`, but without obscuring the source.
|
|
|
|
# a code reader could view the source being referenced simply by clicking the https:// portion of that URI.
|
2023-01-15 04:10:10 +00:00
|
|
|
# - need some way to apply local patches to inputs.
|
2023-01-14 23:20:38 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# DEVELOPMENT DOCS:
|
2023-01-15 04:10:10 +00:00
|
|
|
# - Flake docs: <https://nixos.wiki/wiki/Flakes>
|
|
|
|
# - Flake RFC: <https://github.com/tweag/rfcs/blob/flakes/rfcs/0049-flakes.md>
|
|
|
|
# - Discussion: <https://github.com/NixOS/rfcs/pull/49>
|
2022-08-25 02:46:10 +00:00
|
|
|
# - <https://serokell.io/blog/practical-nix-flakes>
|
2023-03-29 12:04:43 +00:00
|
|
|
#
|
|
|
|
#
|
|
|
|
# COMMON OPERATIONS:
|
|
|
|
# - update a specific flake input:
|
|
|
|
# - `nix flake lock --update-input nixpkgs`
|
2022-05-21 00:07:49 +00:00
|
|
|
|
|
|
|
{
|
2022-10-27 10:20:29 +00:00
|
|
|
outputs = {
|
|
|
|
self,
|
2023-01-31 04:09:49 +00:00
|
|
|
}@inputs:
|
2022-06-23 22:57:20 +00:00
|
|
|
let
|
2023-03-11 10:01:25 +00:00
|
|
|
inherit (builtins) attrNames elem listToAttrs map mapAttrs;
|
2023-09-24 15:30:12 +00:00
|
|
|
# redefine some nixpkgs `lib` functions to avoid the infinite recursion
|
|
|
|
# of if we tried to use patched `nixpkgs.lib` as part of the patching process.
|
2023-12-11 22:12:42 +00:00
|
|
|
mapAttrs' = f: set:
|
|
|
|
listToAttrs (map (attr: f attr set.${attr}) (attrNames set));
|
2023-09-24 15:30:12 +00:00
|
|
|
optionalAttrs = cond: attrs: if cond then attrs else {};
|
2023-03-01 23:33:32 +00:00
|
|
|
# mapAttrs but without the `name` argument
|
|
|
|
mapAttrValues = f: mapAttrs (_: f);
|
2023-09-24 15:30:12 +00:00
|
|
|
|
2024-06-08 01:20:18 +00:00
|
|
|
nixpkgs' = import ./pkgs/additional/nixpkgs;
|
|
|
|
nixpkgsUnpatched = nixpkgs' { doPatch = false; localSystem = "x86_64-linux"; };
|
2024-06-07 07:34:35 +00:00
|
|
|
nixpkgsCompiledBy = { system, variant ? "master" }:
|
2024-06-08 01:20:18 +00:00
|
|
|
(nixpkgs' { inherit variant system; }).legacyPackages."${system}";
|
2022-12-14 12:27:24 +00:00
|
|
|
|
2024-06-08 01:20:18 +00:00
|
|
|
evalHost = { name, local, target, variant ? null, nixpkgs ? nixpkgs' { localSystem = local; system = target;} }: nixpkgs.nixos (
|
|
|
|
[
|
2024-04-09 20:20:36 +00:00
|
|
|
(optionalAttrs (variant == "light") {
|
2024-05-13 19:45:34 +00:00
|
|
|
sane.maxBuildCost = 2;
|
2024-04-09 20:20:36 +00:00
|
|
|
})
|
|
|
|
(optionalAttrs (variant == "min") {
|
|
|
|
sane.maxBuildCost = 0;
|
2023-11-18 22:06:08 +00:00
|
|
|
})
|
2023-08-05 09:32:50 +00:00
|
|
|
(import ./hosts/instantiate.nix { hostName = name; })
|
2024-06-08 01:20:18 +00:00
|
|
|
(import ./modules)
|
|
|
|
(nixpkgs.appendOverlays [ self.overlays.pkgs ]).sops-nix.nixosModules.sops
|
2023-05-15 09:59:18 +00:00
|
|
|
{
|
|
|
|
nixpkgs.overlays = [
|
2023-05-24 03:57:35 +00:00
|
|
|
self.overlays.sane-all
|
2023-01-11 05:58:07 +00:00
|
|
|
];
|
2023-05-15 09:59:18 +00:00
|
|
|
}
|
2024-06-08 01:20:18 +00:00
|
|
|
]
|
|
|
|
);
|
2023-01-11 09:24:24 +00:00
|
|
|
in {
|
2023-12-11 21:07:17 +00:00
|
|
|
nixosConfigurations = let
|
|
|
|
hosts = {
|
|
|
|
servo = { name = "servo"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
|
|
|
desko = { name = "desko"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
2024-04-09 20:20:36 +00:00
|
|
|
desko-light = { name = "desko"; local = "x86_64-linux"; target = "x86_64-linux"; variant = "light"; };
|
2023-12-11 21:07:17 +00:00
|
|
|
lappy = { name = "lappy"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
2024-04-09 20:20:36 +00:00
|
|
|
lappy-light = { name = "lappy"; local = "x86_64-linux"; target = "x86_64-linux"; variant = "light"; };
|
2024-06-07 07:34:35 +00:00
|
|
|
lappy-min = { name = "lappy"; local = "x86_64-linux"; target = "x86_64-linux"; variant = "min"; };
|
2023-12-11 21:07:17 +00:00
|
|
|
moby = { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; };
|
2024-04-09 20:20:36 +00:00
|
|
|
moby-light = { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; variant = "light"; };
|
2024-06-07 07:34:35 +00:00
|
|
|
moby-min = { name = "moby"; local = "x86_64-linux"; target = "aarch64-linux"; variant = "min"; };
|
2024-06-07 08:04:57 +00:00
|
|
|
# crappy is technically armv7a, and armv7l uses only a _subset_ of the available ISA.
|
2024-06-08 01:20:18 +00:00
|
|
|
# but it's not as widely cached.
|
2024-06-07 08:04:57 +00:00
|
|
|
crappy = { name = "crappy"; local = "x86_64-linux"; target = "armv7l-linux"; };
|
|
|
|
crappy-min = { name = "crappy"; local = "x86_64-linux"; target = "armv7l-linux"; variant = "min"; };
|
2024-06-08 01:20:18 +00:00
|
|
|
crappy-7a = { name = "crappy"; local = "x86_64-linux"; target = "armv7a-linux"; variant = "min"; };
|
2023-12-11 21:07:17 +00:00
|
|
|
rescue = { name = "rescue"; local = "x86_64-linux"; target = "x86_64-linux"; };
|
|
|
|
};
|
2023-12-11 22:33:38 +00:00
|
|
|
hostsNext = mapAttrs' (h: v: {
|
|
|
|
name = "${h}-next";
|
2024-06-08 01:20:18 +00:00
|
|
|
value = v // {
|
|
|
|
nixpkgs = nixpkgs' {
|
|
|
|
localSystem = v.local;
|
|
|
|
system = v.target;
|
|
|
|
variant = "staging-next";
|
|
|
|
};
|
|
|
|
};
|
2024-06-07 07:34:35 +00:00
|
|
|
}) hosts;
|
|
|
|
hostsStaging = mapAttrs' (h: v: {
|
|
|
|
name = "${h}-staging";
|
2024-06-08 01:20:18 +00:00
|
|
|
value = v // {
|
|
|
|
nixpkgs = nixpkgs' {
|
|
|
|
localSystem = v.local;
|
|
|
|
system = v.target;
|
|
|
|
variant = "staging";
|
|
|
|
};
|
|
|
|
};
|
2023-12-11 22:12:42 +00:00
|
|
|
}) hosts;
|
|
|
|
in mapAttrValues evalHost (
|
2024-06-07 07:34:35 +00:00
|
|
|
hosts // hostsNext // hostsStaging
|
2023-12-11 22:12:42 +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-03-01 23:33:32 +00:00
|
|
|
imgs = mapAttrValues (host: host.config.system.build.img) self.nixosConfigurations;
|
2023-01-11 05:58:07 +00:00
|
|
|
|
2023-03-01 23:33:32 +00:00
|
|
|
# unofficial output
|
2023-11-20 06:29:51 +00:00
|
|
|
hostConfigs = mapAttrValues (host: host.config) self.nixosConfigurations;
|
2023-12-09 14:11:37 +00:00
|
|
|
hostSystems = mapAttrValues (host: host.config.system.build.toplevel) self.nixosConfigurations;
|
2023-10-24 12:25:39 +00:00
|
|
|
hostPkgs = mapAttrValues (host: host.config.system.build.pkgs) self.nixosConfigurations;
|
|
|
|
hostPrograms = mapAttrValues (host: mapAttrValues (p: p.package) host.config.sane.programs) self.nixosConfigurations;
|
2023-02-05 19:34:32 +00:00
|
|
|
|
2023-03-11 10:01:25 +00:00
|
|
|
overlays = {
|
|
|
|
# N.B.: `nix flake check` requires every overlay to take `final: prev:` at defn site,
|
|
|
|
# hence the weird redundancy.
|
|
|
|
default = final: prev: self.overlays.pkgs final prev;
|
2023-05-24 03:57:35 +00:00
|
|
|
sane-all = final: prev: import ./overlays/all.nix final prev;
|
2023-03-11 10:01:25 +00:00
|
|
|
pkgs = final: prev: import ./overlays/pkgs.nix final prev;
|
2023-08-02 06:38:46 +00:00
|
|
|
preferences = final: prev: import ./overlays/preferences.nix final prev;
|
2023-01-11 08:45:41 +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
|
2024-06-07 07:34:35 +00:00
|
|
|
allPkgsFor = variant: additionalOverlays: system:
|
2024-06-08 01:20:18 +00:00
|
|
|
(nixpkgs' { inherit system variant; localSystem = "x86_64-linux"; })
|
2024-06-07 07:34:35 +00:00
|
|
|
.appendOverlays (
|
|
|
|
[
|
|
|
|
self.overlays.pkgs
|
|
|
|
] ++ additionalOverlays
|
|
|
|
);
|
|
|
|
allPkgsFor' = system: allPkgsFor
|
|
|
|
"master"
|
|
|
|
[(self: super: {
|
|
|
|
# build `pkgsNext.FOO` to build the package FOO from nixpkgs staging-next branch
|
|
|
|
pkgsNext = allPkgsFor "staging-next" [] system;
|
|
|
|
pkgsStaging = allPkgsFor "staging" [] system;
|
|
|
|
})]
|
|
|
|
system
|
|
|
|
;
|
2023-01-11 05:58:07 +00:00
|
|
|
in {
|
2024-06-07 07:34:35 +00:00
|
|
|
x86_64-linux = allPkgsFor' "x86_64-linux";
|
|
|
|
aarch64-linux = allPkgsFor' "aarch64-linux";
|
2023-01-11 05:58:07 +00:00
|
|
|
};
|
|
|
|
|
2023-03-11 10:01:25 +00:00
|
|
|
# extract only our own packages from the full set.
|
|
|
|
# because of `nix flake check`, we flatten the package set and only surface x86_64-linux packages.
|
|
|
|
packages = mapAttrs
|
2024-01-10 11:48:20 +00:00
|
|
|
(system: passthruPkgs: passthruPkgs.lib.filterAttrs
|
|
|
|
(name: pkg:
|
2023-03-11 10:01:25 +00:00
|
|
|
# keep only packages which will pass `nix flake check`, i.e. keep only:
|
|
|
|
# - derivations (not package sets)
|
|
|
|
# - packages that build for the given platform
|
|
|
|
(! elem name [ "feeds" "pythonPackagesExtensions" ])
|
2024-01-10 11:48:20 +00:00
|
|
|
&& (passthruPkgs.lib.meta.availableOn passthruPkgs.stdenv.hostPlatform pkg)
|
2023-03-11 10:01:25 +00:00
|
|
|
)
|
2023-05-03 05:59:48 +00:00
|
|
|
(
|
2024-06-07 22:52:07 +00:00
|
|
|
import ./pkgs { pkgs = passthruPkgs; }
|
2023-05-03 05:59:48 +00:00
|
|
|
)
|
2023-03-11 10:01:25 +00:00
|
|
|
)
|
|
|
|
# self.legacyPackages;
|
2024-01-10 11:48:20 +00:00
|
|
|
{
|
2024-06-08 01:20:18 +00:00
|
|
|
x86_64-linux = nixpkgs' { localSystem = "x86_64-linux"; };
|
2024-01-10 11:48:20 +00:00
|
|
|
}
|
2023-03-11 10:01:25 +00:00
|
|
|
;
|
2023-01-11 09:21:09 +00:00
|
|
|
|
2023-01-11 10:41:39 +00:00
|
|
|
apps."x86_64-linux" =
|
|
|
|
let
|
|
|
|
pkgs = self.legacyPackages."x86_64-linux";
|
2023-09-24 10:27:32 +00:00
|
|
|
sanePkgs = import ./pkgs { inherit pkgs; };
|
2023-07-30 11:23:02 +00:00
|
|
|
deployScript = host: addr: action: pkgs.writeShellScript "deploy-${host}" ''
|
2024-02-28 17:34:45 +00:00
|
|
|
set -e
|
|
|
|
|
2024-02-14 13:45:15 +00:00
|
|
|
host="${host}"
|
|
|
|
addr="${addr}"
|
2024-02-18 01:24:05 +00:00
|
|
|
action="${if action != null then action else ""}"
|
2024-02-14 13:45:15 +00:00
|
|
|
runOnTarget() {
|
|
|
|
# run the command ($@) on the machine we're deploying to.
|
|
|
|
# if that's a remote machine, then do it via ssh, else local shell.
|
|
|
|
if [ -n "$addr" ]; then
|
|
|
|
ssh "$addr" "$@"
|
|
|
|
else
|
|
|
|
"$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-03-04 23:47:31 +00:00
|
|
|
nix build ".#nixosConfigurations.$host.config.system.build.toplevel" --out-link "./build/result-$host" "$@"
|
|
|
|
storePath="$(readlink ./build/result-$host)"
|
2024-02-03 01:42:54 +00:00
|
|
|
|
2024-02-14 13:45:15 +00:00
|
|
|
# mimic `nixos-rebuild --target-host`, in effect:
|
2024-02-03 01:42:54 +00:00
|
|
|
# - nix-copy-closure ...
|
|
|
|
# - nix-env --set ...
|
|
|
|
# - switch-to-configuration <boot|dry-activate|switch|test|>
|
2024-02-14 13:45:15 +00:00
|
|
|
# avoid the actual `nixos-rebuild` for a few reasons:
|
|
|
|
# - fewer nix evals
|
|
|
|
# - more introspectability and debuggability
|
|
|
|
# - sandbox friendliness (especially: `git` doesn't have to be run as root)
|
|
|
|
|
|
|
|
if [ -n "$addr" ]; then
|
2024-05-16 02:48:16 +00:00
|
|
|
sudo nix store sign -r -k /run/secrets/nix_signing_key "$storePath"
|
2024-02-14 13:45:15 +00:00
|
|
|
# add more `-v` for more verbosity (up to 5).
|
2024-02-26 15:00:07 +00:00
|
|
|
# builders-use-substitutes false: optimizes so that the remote machine doesn't try to get paths from its substituters.
|
|
|
|
# we already have all paths here, and the remote substitution is slow to check and SERIOUSLY flaky on moby in particular.
|
|
|
|
nix copy -vv --option builders-use-substitutes false --to "ssh-ng://$addr" "$storePath"
|
2024-02-14 13:45:15 +00:00
|
|
|
fi
|
2023-07-18 09:10:25 +00:00
|
|
|
|
2024-02-14 13:45:15 +00:00
|
|
|
if [ -n "$action" ]; then
|
|
|
|
runOnTarget sudo nix-env -p /nix/var/nix/profiles/system --set "$storePath"
|
|
|
|
runOnTarget sudo "$storePath/bin/switch-to-configuration" "$action"
|
|
|
|
fi
|
2023-03-02 07:49:29 +00:00
|
|
|
'';
|
2023-11-19 02:53:38 +00:00
|
|
|
deployApp = host: addr: action: {
|
|
|
|
type = "app";
|
|
|
|
program = ''${deployScript host addr action}'';
|
|
|
|
};
|
2023-09-24 12:11:28 +00:00
|
|
|
|
|
|
|
# pkg updating.
|
|
|
|
# a cleaner alternative lives here: <https://discourse.nixos.org/t/how-can-i-run-the-updatescript-of-personal-packages/25274/2>
|
2023-11-26 02:16:25 +00:00
|
|
|
# mkUpdater :: [ String ] -> { type = "app"; program = path; }
|
2023-09-24 08:16:19 +00:00
|
|
|
mkUpdater = attrPath: {
|
|
|
|
type = "app";
|
|
|
|
program = let
|
2023-09-24 10:27:32 +00:00
|
|
|
pkg = pkgs.lib.getAttrFromPath attrPath sanePkgs;
|
2023-09-24 08:16:19 +00:00
|
|
|
strAttrPath = pkgs.lib.concatStringsSep "." attrPath;
|
2023-09-27 19:09:29 +00:00
|
|
|
commandArgv = pkg.updateScript.command or pkg.updateScript;
|
|
|
|
command = pkgs.lib.escapeShellArgs commandArgv;
|
2023-09-24 12:11:28 +00:00
|
|
|
in builtins.toString (pkgs.writeShellScript "update-${strAttrPath}" ''
|
2024-05-27 07:16:42 +00:00
|
|
|
set -x
|
|
|
|
env UPDATE_NIX_NAME=${pkg.name} UPDATE_NIX_PNAME=${pkg.pname} UPDATE_NIX_OLD_VERSION=${pkg.version} UPDATE_NIX_ATTR_PATH=${strAttrPath} ${command}
|
2023-09-24 08:16:19 +00:00
|
|
|
'');
|
|
|
|
};
|
2023-09-24 12:35:39 +00:00
|
|
|
mkUpdatersNoAliases = opts: basePath: pkgs.lib.concatMapAttrs
|
2023-09-24 10:27:32 +00:00
|
|
|
(name: pkg:
|
|
|
|
if pkg.recurseForDerivations or false then {
|
2023-09-24 12:35:39 +00:00
|
|
|
"${name}" = mkUpdaters opts (basePath ++ [ name ]);
|
2023-09-24 10:27:32 +00:00
|
|
|
} else if pkg.updateScript or null != null then {
|
|
|
|
"${name}" = mkUpdater (basePath ++ [ name ]);
|
|
|
|
} else {}
|
|
|
|
)
|
|
|
|
(pkgs.lib.getAttrFromPath basePath sanePkgs);
|
2023-11-26 02:16:25 +00:00
|
|
|
mkUpdaters = { ignore ? [], flakePrefix ? [] }@opts: basePath:
|
2023-09-24 10:50:02 +00:00
|
|
|
let
|
2023-09-24 12:35:39 +00:00
|
|
|
updaters = mkUpdatersNoAliases opts basePath;
|
2023-09-24 10:50:02 +00:00
|
|
|
invokeUpdater = name: pkg:
|
|
|
|
let
|
2023-09-24 12:35:39 +00:00
|
|
|
fullPath = basePath ++ [ name ];
|
|
|
|
doUpdateByDefault = !builtins.elem fullPath ignore;
|
|
|
|
|
2023-09-24 12:11:28 +00:00
|
|
|
# in case `name` has a `.` in it, we have to quote it
|
2023-09-24 12:35:39 +00:00
|
|
|
escapedPath = builtins.map (p: ''"${p}"'') fullPath;
|
2023-11-26 02:16:25 +00:00
|
|
|
updatePath = builtins.concatStringsSep "." (flakePrefix ++ escapedPath);
|
2023-09-24 12:35:39 +00:00
|
|
|
in pkgs.lib.optionalString doUpdateByDefault (
|
|
|
|
pkgs.lib.escapeShellArgs [
|
|
|
|
"nix" "run" ".#${updatePath}"
|
|
|
|
]
|
2023-09-24 10:50:02 +00:00
|
|
|
);
|
2023-09-24 12:35:39 +00:00
|
|
|
in {
|
|
|
|
type = "app";
|
2023-11-26 02:16:25 +00:00
|
|
|
# top-level app just invokes the updater of everything one layer below it
|
2023-09-24 12:35:39 +00:00
|
|
|
program = builtins.toString (pkgs.writeShellScript
|
2023-11-26 02:16:25 +00:00
|
|
|
(builtins.concatStringsSep "-" (flakePrefix ++ basePath))
|
2023-09-24 12:35:39 +00:00
|
|
|
(builtins.concatStringsSep
|
|
|
|
"\n"
|
|
|
|
(pkgs.lib.mapAttrsToList invokeUpdater updaters)
|
|
|
|
)
|
|
|
|
);
|
2023-09-24 10:50:02 +00:00
|
|
|
} // updaters;
|
2023-01-11 10:41:39 +00:00
|
|
|
in {
|
2023-07-28 00:49:44 +00:00
|
|
|
help = {
|
|
|
|
type = "app";
|
|
|
|
program = let
|
|
|
|
helpMsg = builtins.toFile "nixos-config-help-message" ''
|
|
|
|
commands:
|
|
|
|
- `nix run '.#help'`
|
|
|
|
- show this message
|
2023-09-24 12:11:28 +00:00
|
|
|
- `nix run '.#update.pkgs'`
|
|
|
|
- updates every package
|
2023-09-24 12:35:39 +00:00
|
|
|
- `nix run '.#update.feeds'`
|
2023-07-28 00:49:44 +00:00
|
|
|
- updates metadata for all feeds
|
|
|
|
- `nix run '.#init-feed' <url>`
|
2024-02-03 02:01:17 +00:00
|
|
|
- `nix run '.#deploy.{desko,lappy,moby,servo}[-light|-test]' [nix args ...]`
|
|
|
|
- build and deploy the host
|
|
|
|
- `nix run '.#preDeploy.{desko,lappy,moby,servo}[-light]' [nix args ...]`
|
|
|
|
- copy closures to a host, but don't activate it
|
|
|
|
- or `nix run '.#preDeploy'` to target all hosts
|
2023-09-25 13:09:02 +00:00
|
|
|
- `nix run '.#check'`
|
|
|
|
- make sure all systems build; NUR evaluates
|
2024-02-28 15:10:45 +00:00
|
|
|
- `nix run '.#bench'`
|
|
|
|
- benchmark the eval time of common targets this flake provides
|
2023-11-08 11:35:32 +00:00
|
|
|
|
|
|
|
specific build targets of interest:
|
|
|
|
- `nix build '.#imgs.rescue'`
|
2023-07-28 00:49:44 +00:00
|
|
|
'';
|
|
|
|
in builtins.toString (pkgs.writeShellScript "nixos-config-help" ''
|
|
|
|
cat ${helpMsg}
|
2023-09-27 18:38:06 +00:00
|
|
|
echo ""
|
|
|
|
echo "complete flake structure:"
|
|
|
|
nix flake show --option allow-import-from-derivation true
|
2023-07-28 00:49:44 +00:00
|
|
|
'');
|
|
|
|
};
|
2023-11-26 02:16:25 +00:00
|
|
|
# wrangle some names to get package updaters which refer back into the flake, but also conditionally ignore certain paths (e.g. sane.feeds).
|
|
|
|
# TODO: better design
|
|
|
|
update = rec {
|
|
|
|
_impl.pkgs.sane = mkUpdaters { flakePrefix = [ "update" "_impl" "pkgs" ]; ignore = [ [ "sane" "feeds" ] ]; } [ "sane" ];
|
|
|
|
pkgs = _impl.pkgs.sane;
|
|
|
|
_impl.feeds.sane.feeds = mkUpdaters { flakePrefix = [ "update" "_impl" "feeds" ]; } [ "sane" "feeds" ];
|
|
|
|
feeds = _impl.feeds.sane.feeds;
|
|
|
|
};
|
2023-09-22 10:11:44 +00:00
|
|
|
|
2023-01-11 10:41:39 +00:00
|
|
|
init-feed = {
|
|
|
|
type = "app";
|
2023-09-24 12:11:28 +00:00
|
|
|
program = "${pkgs.feeds.init-feed}";
|
2023-01-11 10:41:39 +00:00
|
|
|
};
|
2023-03-02 07:49:29 +00:00
|
|
|
|
2023-11-19 02:53:38 +00:00
|
|
|
deploy = {
|
2024-02-03 02:54:39 +00:00
|
|
|
desko = deployApp "desko" "desko" "switch";
|
|
|
|
desko-light = deployApp "desko-light" "desko" "switch";
|
2023-11-19 02:53:38 +00:00
|
|
|
lappy = deployApp "lappy" "lappy" "switch";
|
|
|
|
lappy-light = deployApp "lappy-light" "lappy" "switch";
|
2024-04-09 20:20:36 +00:00
|
|
|
lappy-min = deployApp "lappy-min" "lappy" "switch";
|
2023-11-19 02:53:38 +00:00
|
|
|
moby = deployApp "moby" "moby" "switch";
|
|
|
|
moby-light = deployApp "moby-light" "moby" "switch";
|
2024-04-09 20:20:36 +00:00
|
|
|
moby-min = deployApp "moby-min" "moby" "switch";
|
2023-11-19 02:53:38 +00:00
|
|
|
moby-test = deployApp "moby" "moby" "test";
|
|
|
|
servo = deployApp "servo" "servo" "switch";
|
2024-02-14 13:45:15 +00:00
|
|
|
|
|
|
|
# like `nixos-rebuild --flake . switch`
|
2024-04-09 20:20:36 +00:00
|
|
|
self = deployApp "$(hostname)" "" "switch";
|
|
|
|
self-light = deployApp "$(hostname)-light" "" "switch";
|
|
|
|
self-min = deployApp "$(hostname)-min" "" "switch";
|
2024-02-14 13:45:15 +00:00
|
|
|
|
2024-02-03 02:54:39 +00:00
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "deploy-all" ''
|
|
|
|
nix run '.#deploy.lappy'
|
|
|
|
nix run '.#deploy.moby'
|
|
|
|
nix run '.#deploy.desko'
|
|
|
|
nix run '.#deploy.servo'
|
|
|
|
'');
|
2023-11-19 02:53:38 +00:00
|
|
|
};
|
2024-02-03 02:01:17 +00:00
|
|
|
preDeploy = {
|
|
|
|
# build the host and copy the runtime closure to that host, but don't activate it.
|
2024-02-03 02:54:39 +00:00
|
|
|
desko = deployApp "desko" "desko" null;
|
|
|
|
desko-light = deployApp "desko-light" "desko" null;
|
2024-02-03 02:01:17 +00:00
|
|
|
lappy = deployApp "lappy" "lappy" null;
|
|
|
|
lappy-light = deployApp "lappy-light" "lappy" null;
|
2024-04-09 20:20:36 +00:00
|
|
|
lappy-min = deployApp "lappy-min" "lappy" null;
|
2024-02-03 02:01:17 +00:00
|
|
|
moby = deployApp "moby" "moby" null;
|
|
|
|
moby-light = deployApp "moby-light" "moby" null;
|
2024-04-09 20:20:36 +00:00
|
|
|
moby-min = deployApp "moby-min" "moby" null;
|
2024-02-03 02:01:17 +00:00
|
|
|
servo = deployApp "servo" "servo" null;
|
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "predeploy-all" ''
|
2024-04-09 20:20:36 +00:00
|
|
|
# copy the -min/-light variants first; this might be run while waiting on a full build. or the full build failed.
|
|
|
|
nix run '.#preDeploy.moby-min' -- "$@"
|
|
|
|
nix run '.#preDeploy.lappy-min' -- "$@"
|
2024-02-03 02:01:17 +00:00
|
|
|
nix run '.#preDeploy.moby-light' -- "$@"
|
|
|
|
nix run '.#preDeploy.lappy-light' -- "$@"
|
2024-02-03 02:54:39 +00:00
|
|
|
nix run '.#preDeploy.desko-light' -- "$@"
|
2024-02-03 02:01:17 +00:00
|
|
|
nix run '.#preDeploy.lappy' -- "$@"
|
|
|
|
nix run '.#preDeploy.servo' -- "$@"
|
|
|
|
nix run '.#preDeploy.moby' -- "$@"
|
2024-02-03 02:54:39 +00:00
|
|
|
nix run '.#preDeploy.desko' -- "$@"
|
2024-02-03 02:01:17 +00:00
|
|
|
'');
|
|
|
|
};
|
2023-06-26 01:26:13 +00:00
|
|
|
|
2023-12-08 10:25:01 +00:00
|
|
|
sync = {
|
2023-08-14 08:20:06 +00:00
|
|
|
type = "app";
|
2023-12-08 10:25:01 +00:00
|
|
|
program = builtins.toString (pkgs.writeShellScript "sync-all" ''
|
2023-12-12 02:15:53 +00:00
|
|
|
RC_lappy=$(nix run '.#sync.lappy' -- "$@")
|
|
|
|
RC_moby=$(nix run '.#sync.moby' -- "$@")
|
|
|
|
RC_desko=$(nix run '.#sync.desko' -- "$@")
|
2023-12-08 10:25:01 +00:00
|
|
|
|
|
|
|
echo "lappy: $RC_lappy"
|
|
|
|
echo "moby: $RC_moby"
|
|
|
|
echo "desko: $RC_desko"
|
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
|
|
|
sync.desko = {
|
|
|
|
# copy music from servo to desko
|
|
|
|
# can run this from any device that has ssh access to desko and servo
|
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "sync-to-desko" ''
|
2024-02-06 05:48:11 +00:00
|
|
|
sudo mount /mnt/desko/home
|
|
|
|
${pkgs.sane-scripts.sync-music}/bin/sane-sync-music --compat /mnt/servo/media/Music /mnt/desko/home/Music "$@"
|
2023-08-14 08:20:06 +00:00
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
2023-12-08 10:25:01 +00:00
|
|
|
sync.lappy = {
|
2023-08-20 07:46:55 +00:00
|
|
|
# copy music from servo to lappy
|
2023-12-08 10:25:01 +00:00
|
|
|
# can run this from any device that has ssh access to lappy and servo
|
2023-08-20 07:46:55 +00:00
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "sync-to-lappy" ''
|
2024-02-06 05:48:11 +00:00
|
|
|
sudo mount /mnt/lappy/home
|
|
|
|
${pkgs.sane-scripts.sync-music}/bin/sane-sync-music --compress --compat /mnt/servo/media/Music /mnt/lappy/home/Music "$@"
|
2023-12-08 10:25:01 +00:00
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
|
|
|
sync.moby = {
|
|
|
|
# copy music from servo to moby
|
|
|
|
# can run this from any device that has ssh access to moby and servo
|
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "sync-to-moby" ''
|
2024-02-06 05:48:11 +00:00
|
|
|
sudo mount /mnt/moby/home
|
|
|
|
sudo mount /mnt/desko/home
|
2024-06-04 10:05:20 +00:00
|
|
|
sudo mount /mnt/servo/media/Books
|
|
|
|
# copy photos/screenshots from moby to desko:
|
2024-02-06 05:48:11 +00:00
|
|
|
${pkgs.rsync}/bin/rsync -arv --exclude servo-macros /mnt/moby/home/Pictures/ /mnt/desko/home/Pictures/moby/
|
2024-06-04 10:05:20 +00:00
|
|
|
# copy books from servo to moby; delete old/untracked ones, but keep KOreader state files (sdr)
|
|
|
|
${pkgs.rsync}/bin/rsync -arv --delete --exclude unprocessed --exclude '*.sdr' /mnt/servo/media/Books/ /mnt/moby/home/Books/local/servo/
|
2023-12-08 14:52:11 +00:00
|
|
|
# N.B.: limited by network/disk -> reduce job count to improve pause/resume behavior
|
2024-02-06 05:48:11 +00:00
|
|
|
${pkgs.sane-scripts.sync-music}/bin/sane-sync-music --compress --compat --jobs 4 /mnt/servo/media/Music /mnt/moby/home/Music "$@"
|
2023-08-20 07:46:55 +00:00
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
2023-09-25 13:09:02 +00:00
|
|
|
check = {
|
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "check-all" ''
|
|
|
|
nix run '.#check.nur'
|
|
|
|
RC0=$?
|
2023-11-30 01:40:50 +00:00
|
|
|
nix run '.#check.hostConfigs'
|
2023-09-25 13:09:02 +00:00
|
|
|
RC1=$?
|
2023-11-08 11:39:45 +00:00
|
|
|
nix run '.#check.rescue'
|
|
|
|
RC2=$?
|
2023-09-25 13:09:02 +00:00
|
|
|
echo "nur: $RC0"
|
2023-11-30 01:40:50 +00:00
|
|
|
echo "hostConfigs: $RC1"
|
2023-11-08 11:39:45 +00:00
|
|
|
echo "rescue: $RC2"
|
|
|
|
exit $(($RC0 | $RC1 | $RC2))
|
2023-09-25 13:09:02 +00:00
|
|
|
'');
|
|
|
|
};
|
|
|
|
|
|
|
|
check.nur = {
|
2023-06-26 01:26:13 +00:00
|
|
|
# `nix run '.#check-nur'`
|
|
|
|
# validates that my repo can be included in the Nix User Repository
|
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "check-nur" ''
|
|
|
|
cd ${./.}/integrations/nur
|
|
|
|
NIX_PATH= NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM=1 nix-env -f . -qa \* --meta --xml \
|
|
|
|
--allowed-uris https://static.rust-lang.org \
|
|
|
|
--option restrict-eval true \
|
|
|
|
--option allow-import-from-derivation true \
|
|
|
|
--drv-path --show-trace \
|
2024-06-08 01:20:18 +00:00
|
|
|
-I nixpkgs=${nixpkgsUnpatched} \
|
2024-02-28 13:47:51 +00:00
|
|
|
-I nixpkgs-overlays=${./.}/hosts/common/nix/overlay \
|
2023-09-25 13:09:02 +00:00
|
|
|
-I ../../ \
|
|
|
|
| tee # tee to prevent interactive mode
|
2023-06-26 01:26:13 +00:00
|
|
|
'');
|
|
|
|
};
|
2023-09-02 01:25:20 +00:00
|
|
|
|
2023-12-11 22:51:58 +00:00
|
|
|
check.hostConfigs = {
|
|
|
|
type = "app";
|
|
|
|
program = let
|
|
|
|
checkHost = host: let
|
|
|
|
shellHost = pkgs.lib.replaceStrings [ "-" ] [ "_" ] host;
|
|
|
|
in ''
|
2024-03-04 23:47:31 +00:00
|
|
|
nix build -v '.#nixosConfigurations.${host}.config.system.build.toplevel' --out-link ./build/result-${host} -j2 "$@"
|
2023-12-11 22:51:58 +00:00
|
|
|
RC_${shellHost}=$?
|
|
|
|
'';
|
|
|
|
in builtins.toString (pkgs.writeShellScript
|
|
|
|
"check-host-configs"
|
|
|
|
''
|
|
|
|
# build minimally-usable hosts first, then their full image.
|
|
|
|
# this gives me a minimal image i can deploy or copy over, early.
|
2024-04-09 20:20:36 +00:00
|
|
|
${checkHost "lappy-min"}
|
|
|
|
${checkHost "moby-min"}
|
|
|
|
|
2023-12-11 22:51:58 +00:00
|
|
|
${checkHost "desko-light"}
|
|
|
|
${checkHost "moby-light"}
|
|
|
|
${checkHost "lappy-light"}
|
|
|
|
|
|
|
|
${checkHost "desko"}
|
|
|
|
${checkHost "lappy"}
|
|
|
|
${checkHost "servo"}
|
|
|
|
${checkHost "moby"}
|
|
|
|
${checkHost "rescue"}
|
|
|
|
|
2023-12-11 23:00:15 +00:00
|
|
|
# still want to build the -light variants first so as to avoid multiple simultaneous webkitgtk builds
|
|
|
|
${checkHost "desko-light-next"}
|
|
|
|
${checkHost "moby-light-next"}
|
|
|
|
|
2023-12-11 22:51:58 +00:00
|
|
|
${checkHost "desko-next"}
|
|
|
|
${checkHost "lappy-next"}
|
|
|
|
${checkHost "servo-next"}
|
|
|
|
${checkHost "moby-next"}
|
|
|
|
${checkHost "rescue-next"}
|
|
|
|
|
|
|
|
echo "desko: $RC_desko"
|
|
|
|
echo "lappy: $RC_lappy"
|
|
|
|
echo "servo: $RC_servo"
|
|
|
|
echo "moby: $RC_moby"
|
|
|
|
echo "rescue: $RC_rescue"
|
|
|
|
|
|
|
|
echo "desko-next: $RC_desko_next"
|
|
|
|
echo "lappy-next: $RC_lappy_next"
|
|
|
|
echo "servo-next: $RC_servo_next"
|
|
|
|
echo "moby-next: $RC_moby_next"
|
|
|
|
echo "rescue-next: $RC_rescue_next"
|
|
|
|
|
|
|
|
# i don't really care if the -next hosts fail. i build them mostly to keep the cache fresh/ready
|
|
|
|
exit $(($RC_desko | $RC_lappy | $RC_servo | $RC_moby | $RC_rescue))
|
|
|
|
''
|
|
|
|
);
|
|
|
|
};
|
2023-11-08 11:39:45 +00:00
|
|
|
|
|
|
|
check.rescue = {
|
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "check-rescue" ''
|
2024-03-04 23:47:31 +00:00
|
|
|
nix build -v '.#imgs.rescue' --out-link ./build/result-rescue-img -j2
|
2023-11-08 11:39:45 +00:00
|
|
|
'');
|
|
|
|
};
|
2024-02-28 15:10:45 +00:00
|
|
|
|
|
|
|
bench = {
|
|
|
|
type = "app";
|
|
|
|
program = builtins.toString (pkgs.writeShellScript "bench" ''
|
|
|
|
doBench() {
|
|
|
|
attrPath="$1"
|
|
|
|
shift
|
|
|
|
echo -n "benchmarking eval of '$attrPath'... "
|
|
|
|
/run/current-system/sw/bin/time -f "%e sec" -o /dev/stdout \
|
|
|
|
nix eval --no-eval-cache --quiet --raw ".#$attrPath" --apply 'result: if result != null then "" else "unexpected null"' $@ 2> /dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
doBench "$@"
|
|
|
|
else
|
|
|
|
doBench hostConfigs
|
|
|
|
doBench hostConfigs.lappy
|
|
|
|
doBench hostConfigs.lappy.sane.programs
|
|
|
|
doBench hostConfigs.lappy.sane.users.colin
|
|
|
|
doBench hostConfigs.lappy.sane.fs
|
|
|
|
doBench hostConfigs.lappy.environment.systemPackages
|
|
|
|
fi
|
|
|
|
'');
|
|
|
|
};
|
2023-01-11 10:22:25 +00:00
|
|
|
};
|
|
|
|
|
2023-01-11 05:58:07 +00:00
|
|
|
templates = {
|
2023-04-26 07:35:04 +00:00
|
|
|
env.python-data = {
|
2023-01-11 05:58:07 +00:00
|
|
|
# initialize with:
|
2023-04-26 07:35:04 +00:00
|
|
|
# - `nix flake init -t '/home/colin/dev/nixos/#env.python-data'`
|
2023-01-11 05:58:07 +00:00
|
|
|
# then enter with:
|
|
|
|
# - `nix develop`
|
2023-04-26 07:35:04 +00:00
|
|
|
path = ./templates/env/python-data;
|
2023-01-11 05:58:07 +00:00
|
|
|
description = "python environment for data processing";
|
|
|
|
};
|
2024-06-07 07:23:35 +00:00
|
|
|
|
|
|
|
pkgs.make = {
|
|
|
|
# initialize with:
|
|
|
|
# - `nix flake init -t '/home/colin/dev/nixos/#pkgs.make'`
|
|
|
|
path = ./templates/pkgs/make;
|
|
|
|
description = "default Makefile-based derivation";
|
|
|
|
};
|
|
|
|
pkgs.python = {
|
|
|
|
# initialize with:
|
|
|
|
# - `nix flake init -t '/home/colin/dev/nixos/#pkgs.python'`
|
|
|
|
path = ./templates/pkgs/python;
|
|
|
|
description = "python package";
|
|
|
|
};
|
2023-04-26 07:35:04 +00:00
|
|
|
pkgs.rust-inline = {
|
2023-04-26 07:20:02 +00:00
|
|
|
# initialize with:
|
2023-04-26 07:35:04 +00:00
|
|
|
# - `nix flake init -t '/home/colin/dev/nixos/#pkgs.rust-inline'`
|
|
|
|
path = ./templates/pkgs/rust-inline;
|
2023-04-26 07:41:08 +00:00
|
|
|
description = "rust package and development environment (inline rust sources)";
|
|
|
|
};
|
|
|
|
pkgs.rust = {
|
|
|
|
# initialize with:
|
|
|
|
# - `nix flake init -t '/home/colin/dev/nixos/#pkgs.rust'`
|
|
|
|
path = ./templates/pkgs/rust;
|
|
|
|
description = "rust package fit to ship in nixpkgs";
|
2023-04-26 07:20:02 +00:00
|
|
|
};
|
2022-11-30 00:48:27 +00:00
|
|
|
};
|
|
|
|
};
|
2022-05-21 00:07:49 +00:00
|
|
|
}
|
|
|
|
|