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
{
2023-01-15 04:10:10 +00:00
# XXX: use the `github:` scheme instead of the more readable git+https: because it's *way* more efficient
# preferably, i would rewrite the human-readable https URLs to nix-specific github: URLs with a helper,
# but `inputs` is required to be a strict attrset: not an expression.
2022-05-21 00:07:49 +00:00
inputs = {
2023-04-15 23:06:37 +00:00
# branch workflow:
# - daily:
# - nixos-unstable cut from master after enough packages have been built in caches.
# - every 6 hours:
2023-12-11 22:33:38 +00:00
# - master auto-merged into staging and staging-next
2023-04-15 23:06:37 +00:00
# - staging-next auto-merged into staging.
# - manually, approximately once per month:
# - staging-next is cut from staging.
# - staging-next merged into master.
#
# which branch to source from?
2023-11-21 23:44:28 +00:00
# - nixos-unstable: for everyday development; it provides good caching
# - master: temporarily if i'm otherwise cherry-picking lots of already-applied patches
# - staging-next: if testing stuff that's been PR'd into staging, i.e. base library updates.
# - staging: maybe if no staging-next -> master PR has been cut yet?
2023-04-15 23:06:37 +00:00
#
2023-01-15 04:10:10 +00:00
# <https://github.com/nixos/nixpkgs/tree/nixos-unstable>
2023-11-21 23:44:28 +00:00
# nixpkgs-unpatched.url = "github:nixos/nixpkgs?ref=nixos-unstable";
nixpkgs-unpatched . url = " g i t h u b : n i x o s / n i x p k g s ? r e f = m a s t e r " ;
2023-12-11 22:33:38 +00:00
# nixpkgs-unpatched.url = "github:nixos/nixpkgs?ref=nixos-staging";
# nixpkgs-unpatched.url = "github:nixos/nixpkgs?ref=nixos-staging-next";
nixpkgs-next-unpatched . url = " g i t h u b : n i x o s / n i x p k g s ? r e f = s t a g i n g - n e x t " ;
2023-03-01 13:01:41 +00:00
2022-05-23 02:45:54 +00:00
mobile-nixos = {
2023-01-15 04:10:10 +00:00
# <https://github.com/nixos/mobile-nixos>
2023-09-25 13:35:50 +00:00
# only used for building disk images, not relevant after deployment
2023-11-08 12:13:50 +00:00
# TODO: replace with something else. commit `0f3ac0bef1aea70254a3bae35e3cc2561623f4c1`
# replaces the imageBuilder with a "new implementation from celun" and wildly breaks my use.
# pinning to d25d3b... is equivalent to holding at 2023-09-15
url = " g i t h u b : n i x o s / m o b i l e - n i x o s ? r e f = d 2 5 d 3 b 8 7 e 7 f 3 0 0 d 8 0 6 6 e 3 1 d 7 9 2 3 3 7 d 9 c d 7 e c d 2 3 b " ;
2022-05-24 05:47:32 +00:00
flake = false ;
2022-05-23 02:45:54 +00:00
} ;
2022-10-11 00:19:57 +00:00
sops-nix = {
2023-01-15 04:10:10 +00:00
# <https://github.com/Mic92/sops-nix>
2023-09-25 13:35:50 +00:00
# used to distribute secrets to my hosts
2023-01-15 04:10:10 +00:00
url = " g i t h u b : M i c 9 2 / s o p s - n i x " ;
2023-03-01 13:01:41 +00:00
# inputs.nixpkgs.follows = "nixpkgs";
inputs . nixpkgs . follows = " n i x p k g s - u n p a t c h e d " ;
2022-10-11 00:19:57 +00:00
} ;
2023-01-11 08:45:41 +00:00
uninsane-dot-org = {
2023-09-25 13:35:50 +00:00
# provides the package to deploy <https://uninsane.org>, used only when building the servo host
2022-10-11 10:22:40 +00:00
url = " g i t + h t t p s : / / g i t . u n i n s a n e . o r g / c o l i n / u n i n s a n e " ;
2023-03-01 13:01:41 +00:00
# inputs.nixpkgs.follows = "nixpkgs";
inputs . nixpkgs . follows = " n i x p k g s - u n p a t c h e d " ;
2022-10-11 10:22:40 +00:00
} ;
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 ,
2023-01-10 17:00:43 +00:00
nixpkgs-unpatched ,
2023-12-11 22:33:38 +00:00
nixpkgs-next-unpatched ? nixpkgs-unpatched ,
2022-10-27 10:20:29 +00:00
mobile-nixos ,
sops-nix ,
2023-01-31 04:09:49 +00:00
uninsane-dot-org ,
. . .
} @ 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
2023-03-01 13:01:41 +00:00
# rather than apply our nixpkgs patches as a flake input, do that here instead.
# this (temporarily?) resolves the bad UX wherein a subflake residing in the same git
# repo as the main flake causes the main flake to have an unstable hash.
2023-12-11 22:12:42 +00:00
patchNixpkgs = variant : nixpkgs : ( import ./nixpatches/flake.nix ) . outputs {
inherit variant nixpkgs ;
self = patchNixpkgs variant nixpkgs ;
2023-09-24 15:30:12 +00:00
} // {
# provide values that nixpkgs ordinarily sources from the flake.lock file,
# inaccessible to it here because of the import-from-derivation.
# rev and shortRev seem to not always exist (e.g. if the working tree is dirty),
# so those are made conditional.
#
# these values impact the name of a produced nixos system. having date/rev in the
# `readlink /run/current-system` store path helps debuggability.
inherit ( self ) lastModifiedDate lastModified ;
} // optionalAttrs ( self ? rev ) {
inherit ( self ) rev ;
} // optionalAttrs ( self ? shortRev ) {
inherit ( self ) shortRev ;
2023-03-01 13:01:41 +00:00
} ;
2023-12-11 22:51:58 +00:00
nixpkgs' = patchNixpkgs " m a s t e r " nixpkgs-unpatched ;
nixpkgsCompiledBy = system : nixpkgs' . legacyPackages . " ${ system } " ;
2022-12-14 12:27:24 +00:00
2023-12-11 22:51:58 +00:00
evalHost = { name , local , target , light ? false , nixpkgs ? nixpkgs' }: nixpkgs . lib . nixosSystem {
2023-12-11 21:24:33 +00:00
system = target ;
2023-05-15 09:59:18 +00:00
modules = [
2023-08-05 09:32:50 +00:00
{
2023-12-11 21:07:17 +00:00
nixpkgs . buildPlatform . system = local ;
2023-08-05 09:32:50 +00:00
# nixpkgs.config.replaceStdenv = { pkgs }: pkgs.ccacheStdenv;
}
2023-12-11 21:24:33 +00:00
( optionalAttrs ( local != target ) {
# XXX(2023/12/11): cache.nixos.org uses `system = ...` instead of `hostPlatform.system`, and that choice impacts the closure of every package.
# so avoid specifying hostPlatform.system on non-cross builds, so i can use upstream caches.
nixpkgs . hostPlatform . system = target ;
} )
2023-11-18 22:06:08 +00:00
( optionalAttrs light {
sane . enableSlowPrograms = false ;
} )
2023-08-05 09:32:50 +00:00
( import ./hosts/instantiate.nix { hostName = name ; } )
2023-05-15 09:59:18 +00:00
self . nixosModules . default
self . nixosModules . passthru
{
nixpkgs . overlays = [
self . overlays . passthru
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
}
] ;
} ;
2023-01-11 09:24:24 +00:00
in {
2023-12-11 21:07:17 +00:00
nixosConfigurations = let
hosts = {
servo = { name = " s e r v o " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " x 8 6 _ 6 4 - l i n u x " ; } ;
desko = { name = " d e s k o " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " x 8 6 _ 6 4 - l i n u x " ; } ;
desko-light = { name = " d e s k o " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " x 8 6 _ 6 4 - l i n u x " ; light = true ; } ;
lappy = { name = " l a p p y " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " x 8 6 _ 6 4 - l i n u x " ; } ;
lappy-light = { name = " l a p p y " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " x 8 6 _ 6 4 - l i n u x " ; light = true ; } ;
moby = { name = " m o b y " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " a a r c h 6 4 - l i n u x " ; } ;
moby-light = { name = " m o b y " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " a a r c h 6 4 - l i n u x " ; light = true ; } ;
rescue = { name = " r e s c u e " ; local = " x 8 6 _ 6 4 - l i n u x " ; target = " x 8 6 _ 6 4 - l i n u x " ; } ;
} ;
2023-12-11 22:33:38 +00:00
hostsNext = mapAttrs' ( h : v : {
name = " ${ h } - n e x t " ;
value = v // { nixpkgs = patchNixpkgs " s t a g i n g - n e x t " nixpkgs-next-unpatched ; } ;
2023-12-11 22:12:42 +00:00
} ) hosts ;
in mapAttrValues evalHost (
2023-12-11 22:33:38 +00:00
hosts // hostsNext
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-12-12 09:19:10 +00:00
patched . nixpkgs = nixpkgs' ;
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-04-04 23:30:27 +00:00
disable-flakey-tests = final : prev : import ./overlays/disable-flakey-tests.nix final prev ;
2023-03-11 10:01:25 +00:00
pkgs = final : prev : import ./overlays/pkgs.nix final prev ;
pins = final : prev : import ./overlays/pins.nix final prev ;
2023-08-02 06:38:46 +00:00
preferences = final : prev : import ./overlays/preferences.nix final prev ;
2023-03-11 10:01:25 +00:00
optimizations = final : prev : import ./overlays/optimizations.nix final prev ;
passthru = final : prev :
2023-01-11 08:45:41 +00:00
let
mobile = ( import " ${ mobile-nixos } / o v e r l a y / o v e r l a y . n i x " ) ;
2023-12-19 16:44:22 +00:00
uninsane = uninsane-dot-org . overlays . default ;
2023-01-11 08:45:41 +00:00
in
2023-06-29 22:47:51 +00:00
( mobile final prev )
// ( uninsane final prev )
;
2023-01-11 08:45:41 +00:00
} ;
nixosModules = rec {
default = sane ;
sane = import ./modules ;
passthru = { . . . }: {
imports = [
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 " x 8 6 _ 6 4 - l i n u x " ;
aarch64-linux = allPkgsFor " a a r c h 6 4 - l i n u x " ;
} ;
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 [ " f e e d s " " p y t h o n P a c k a g e s E x t e n s i o n s " ] )
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
(
# expose sane packages and chosen inputs (uninsane.org)
2024-01-10 11:48:20 +00:00
( import ./pkgs { pkgs = passthruPkgs ; } ) // {
inherit ( passthruPkgs ) uninsane-dot-org ;
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
{
x86_64-linux = ( nixpkgsCompiledBy " x 8 6 _ 6 4 - l i n u x " ) . appendOverlays [
self . overlays . passthru
] ;
}
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 . " x 8 6 _ 6 4 - l i n u x " =
let
pkgs = self . legacyPackages . " x 8 6 _ 6 4 - l i n u x " ;
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 " d e p l o y - ${ host } " ''
2023-12-12 02:15:53 +00:00
nix build ' . #nixosConfigurations.${host}.config.system.build.toplevel' --out-link ./result-${host} "$@"
2024-02-03 01:42:54 +00:00
storePath = " $ ( r e a d l i n k . / r e s u l t - ${ host } ) "
sudo nix sign-paths - r - k /run/secrets/nix_serve_privkey " $ s t o r e P a t h "
# N.B.: `--fast` option here is critical to cross-compiled deployments: without it the build machine will try to invoke the host machine's `nix` binary.
2024-02-03 02:01:17 +00:00
# nixos-rebuild --flake '.#${host}' <action> --target-host colin@${addr} --use-remote-sudo "$@" --fast
2024-02-03 01:42:54 +00:00
# instead of `nixos-rebuild --target-host`, recreate its main parts in-line, below.
# the benefit is fewer nix evals, and more granularity for debugging/tweaking.
# `nixos-rebuild --target-host` effectively does:
# - nix-copy-closure ...
# - nix-env --set ...
# - switch-to-configuration <boot|dry-activate|switch|test|>
2023-07-18 09:10:25 +00:00
2024-02-02 00:50:25 +00:00
# add more `-v` for more verbosity (up to 5).
# i copy the closure here separately from the nixos-rebuild mostly for the sake of introspectability.
2024-02-03 02:10:42 +00:00
nix-copy-closure - v - - gzip - - to ' $ { addr } ' " $ s t o r e P a t h "
2024-02-03 02:01:17 +00:00
$ { pkgs . lib . optionalString ( action != null ) ''
2024-02-03 02:10:42 +00:00
ssh ' $ { addr } ' sudo nix-env - p /nix/var/nix/profiles/system - - set " $ s t o r e P a t h "
ssh ' $ { addr } ' sudo " $ s t o r e P a t h / b i n / s w i t c h - t o - c o n f i g u r a t i o n " ' $ { action } '
2024-02-03 02:01:17 +00:00
'' }
2023-03-02 07:49:29 +00:00
'' ;
2023-11-19 02:53:38 +00:00
deployApp = host : addr : action : {
type = " a p p " ;
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 = " a p p " ;
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 " u p d a t e - ${ strAttrPath } " ''
2023-09-24 08:16:19 +00:00
export UPDATE_NIX_NAME = $ { pkg . name }
export UPDATE_NIX_PNAME = $ { pkg . pname }
export UPDATE_NIX_OLD_VERSION = $ { pkg . version }
export UPDATE_NIX_ATTR_PATH = $ { strAttrPath }
2023-09-24 12:11:28 +00:00
$ { 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 [
" n i x " " r u n " " . # ${ updatePath } "
]
2023-09-24 10:50:02 +00:00
) ;
2023-09-24 12:35:39 +00:00
in {
type = " a p p " ;
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 = " a p p " ;
program = let
helpMsg = builtins . toFile " n i x o s - c o n f i g - h e l p - m e s s a g e " ''
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
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 " n i x o s - c o n f i g - h e l p " ''
cat $ { helpMsg }
2023-09-27 18:38:06 +00:00
echo " "
echo " c o m p l e t e f l a k e s t r u c t u r e : "
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 = [ " u p d a t e " " _ i m p l " " p k g s " ] ; ignore = [ [ " s a n e " " f e e d s " ] ] ; } [ " s a n e " ] ;
pkgs = _impl . pkgs . sane ;
_impl . feeds . sane . feeds = mkUpdaters { flakePrefix = [ " u p d a t e " " _ i m p l " " f e e d s " ] ; } [ " s a n e " " f e e d s " ] ;
feeds = _impl . feeds . sane . feeds ;
} ;
2023-09-22 10:11:44 +00:00
2023-01-11 10:41:39 +00:00
init-feed = {
type = " a p p " ;
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 = {
lappy = deployApp " l a p p y " " l a p p y " " s w i t c h " ;
lappy-light = deployApp " l a p p y - l i g h t " " l a p p y " " s w i t c h " ;
moby = deployApp " m o b y " " m o b y " " s w i t c h " ;
moby-light = deployApp " m o b y - l i g h t " " m o b y " " s w i t c h " ;
moby-test = deployApp " m o b y " " m o b y " " t e s t " ;
servo = deployApp " s e r v o " " s e r v o " " s w i t c h " ;
} ;
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.
lappy = deployApp " l a p p y " " l a p p y " null ;
lappy-light = deployApp " l a p p y - l i g h t " " l a p p y " null ;
moby = deployApp " m o b y " " m o b y " null ;
moby-light = deployApp " m o b y - l i g h t " " m o b y " null ;
servo = deployApp " s e r v o " " s e r v o " null ;
type = " a p p " ;
program = builtins . toString ( pkgs . writeShellScript " p r e d e p l o y - a l l " ''
# copy the -light variants first; this might be run while waiting on a full build. or the full build failed.
nix run ' . #preDeploy.moby-light' -- "$@"
nix run ' . #preDeploy.lappy-light' -- "$@"
nix run ' . #preDeploy.lappy' -- "$@"
nix run ' . #preDeploy.servo' -- "$@"
nix run ' . #preDeploy.moby' -- "$@"
'' ) ;
} ;
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 = " a p p " ;
2023-12-08 10:25:01 +00:00
program = builtins . toString ( pkgs . writeShellScript " s y n c - a l l " ''
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 " l a p p y : $ R C _ l a p p y "
echo " m o b y : $ R C _ m o b y "
echo " d e s k o : $ R C _ d e s k o "
'' ) ;
} ;
sync . desko = {
# copy music from servo to desko
# can run this from any device that has ssh access to desko and servo
type = " a p p " ;
program = builtins . toString ( pkgs . writeShellScript " s y n c - t o - d e s k o " ''
2023-12-08 12:24:00 +00:00
sudo mount /mnt/desko-home
2023-12-12 02:15:53 +00:00
$ { 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 = " a p p " ;
program = builtins . toString ( pkgs . writeShellScript " s y n c - t o - l a p p y " ''
sudo mount /mnt/lappy-home
2023-12-12 02:15:53 +00:00
$ { 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 = " a p p " ;
program = builtins . toString ( pkgs . writeShellScript " s y n c - t o - m o b y " ''
sudo mount /mnt/moby-home
2024-02-03 00:54:04 +00:00
sudo mount /mnt/desko-home
$ { pkgs . rsync } /bin/rsync - arv - - exclude servo-macros /mnt/moby-home/Pictures / /mnt/desko-home/Pictures/moby /
2023-12-08 14:52:11 +00:00
# N.B.: limited by network/disk -> reduce job count to improve pause/resume behavior
2023-12-12 02:15:53 +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 = " a p p " ;
program = builtins . toString ( pkgs . writeShellScript " c h e c k - a l l " ''
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 " n u r : $ R C 0 "
2023-11-30 01:40:50 +00:00
echo " h o s t C o n f i g s : $ R C 1 "
2023-11-08 11:39:45 +00:00
echo " r e s c u e : $ R C 2 "
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 = " a p p " ;
program = builtins . toString ( pkgs . writeShellScript " c h e c k - n u r " ''
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 \
2023-12-12 03:53:54 +00:00
- I nixpkgs = $ { nixpkgs-unpatched } \
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 = " a p p " ;
program = let
checkHost = host : let
shellHost = pkgs . lib . replaceStrings [ " - " ] [ " _ " ] host ;
in ''
2023-12-12 02:15:53 +00:00
nix build - v ' . #nixosConfigurations.${host}.config.system.build.toplevel' --out-link ./result-${host} -j2 "$@"
2023-12-11 22:51:58 +00:00
RC_ $ { shellHost } = $ ?
'' ;
in builtins . toString ( pkgs . writeShellScript
" c h e c k - h o s t - c o n f i g s "
''
# build minimally-usable hosts first, then their full image.
# this gives me a minimal image i can deploy or copy over, early.
$ { checkHost " d e s k o - l i g h t " }
$ { checkHost " m o b y - l i g h t " }
$ { checkHost " l a p p y - l i g h t " }
$ { checkHost " d e s k o " }
$ { checkHost " l a p p y " }
$ { checkHost " s e r v o " }
$ { checkHost " m o b y " }
$ { checkHost " r e s c u e " }
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 " d e s k o - l i g h t - n e x t " }
$ { checkHost " m o b y - l i g h t - n e x t " }
2023-12-11 22:51:58 +00:00
$ { checkHost " d e s k o - n e x t " }
$ { checkHost " l a p p y - n e x t " }
$ { checkHost " s e r v o - n e x t " }
$ { checkHost " m o b y - n e x t " }
$ { checkHost " r e s c u e - n e x t " }
echo " d e s k o : $ R C _ d e s k o "
echo " l a p p y : $ R C _ l a p p y "
echo " s e r v o : $ R C _ s e r v o "
echo " m o b y : $ R C _ m o b y "
echo " r e s c u e : $ R C _ r e s c u e "
echo " d e s k o - n e x t : $ R C _ d e s k o _ n e x t "
echo " l a p p y - n e x t : $ R C _ l a p p y _ n e x t "
echo " s e r v o - n e x t : $ R C _ s e r v o _ n e x t "
echo " m o b y - n e x t : $ R C _ m o b y _ n e x t "
echo " r e s c u e - n e x t : $ R C _ r e s c u e _ n e x t "
# 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 = " a p p " ;
program = builtins . toString ( pkgs . writeShellScript " c h e c k - r e s c u e " ''
nix build - v ' . #imgs.rescue' --out-link ./result-rescue-img -j2
'' ) ;
} ;
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 = " p y t h o n e n v i r o n m e n t f o r d a t a p r o c e s s i n g " ;
} ;
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 = " r u s t p a c k a g e a n d d e v e l o p m e n t e n v i r o n m e n t ( i n l i n e r u s t s o u r c e s ) " ;
} ;
pkgs . rust = {
# initialize with:
# - `nix flake init -t '/home/colin/dev/nixos/#pkgs.rust'`
path = ./templates/pkgs/rust ;
description = " r u s t p a c k a g e f i t t o s h i p i n n i x p k g s " ;
2023-04-26 07:20:02 +00:00
} ;
2023-05-18 01:31:06 +00:00
pkgs . make = {
# initialize with:
# - `nix flake init -t '/home/colin/dev/nixos/#pkgs.make'`
path = ./templates/pkgs/make ;
description = " d e f a u l t M a k e f i l e - b a s e d d e r i v a t i o n " ;
} ;
2022-11-30 00:48:27 +00:00
} ;
} ;
2022-05-21 00:07:49 +00:00
}