nixfiles/flake.nix

151 lines
4.6 KiB
Nix
Raw Normal View History

2022-02-06 00:06:26 +00:00
{
description = "System configs";
inputs = {
flake-utils.url = "github:numtide/flake-utils";
devshell.url = "github:numtide/devshell";
devshell.inputs.nixpkgs.follows = "nixpkgs-unstable";
nixpkgs-master.url = "nixpkgs";
2022-02-06 00:06:26 +00:00
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
nixpkgs-stable.url = "nixpkgs/nixos-21.11";
2022-02-16 01:40:03 +00:00
nixpkgs-mine.url = "github:devplayer0/nixpkgs";
home-manager-unstable.url = "home-manager";
home-manager-unstable.inputs.nixpkgs.follows = "nixpkgs-unstable";
home-manager-stable.url = "home-manager/release-21.11";
home-manager-stable.inputs.nixpkgs.follows = "nixpkgs-stable";
2022-02-06 00:06:26 +00:00
# Stuff used by the flake for build / deployment
2022-02-06 00:06:26 +00:00
agenix.url = "github:ryantm/agenix";
agenix.inputs.nixpkgs.follows = "nixpkgs-unstable";
deploy-rs.url = "github:serokell/deploy-rs";
deploy-rs.inputs.nixpkgs.follows = "nixpkgs-unstable";
# Stuff used by systems
#impermanence.url = "github:nix-community/impermanence";
impermanence.url = "github:devplayer0/impermanence/qemu-vm-dirs";
2022-02-06 00:06:26 +00:00
};
outputs =
inputs@{
self,
flake-utils,
2022-02-16 01:40:03 +00:00
nixpkgs-master, nixpkgs-unstable, nixpkgs-stable, nixpkgs-mine,
home-manager-unstable, home-manager-stable,
2022-02-06 00:06:26 +00:00
...
}:
let
inherit (builtins) mapAttrs;
inherit (lib) recurseIntoAttrs filterAttrs evalModules;
2022-02-17 20:50:53 +00:00
inherit (lib.flake) flattenTree eachDefaultSystem;
inherit (lib.my) mkDefaultSystemsPkgs flakePackageOverlay;
2022-02-06 00:06:26 +00:00
# Extend a lib with extras that _must not_ internally reference private nixpkgs. flake-utils doesn't, but many
# other flakes (e.g. home-manager) probably do internally.
libOverlay = final: prev: {
2022-02-15 20:58:03 +00:00
my = import ./lib.nix { lib = final; };
2022-02-06 00:06:26 +00:00
flake = flake-utils.lib;
};
pkgsLibOverlay = final: prev: { lib = prev.lib.extend libOverlay; };
2022-02-06 00:06:26 +00:00
# Override the flake-level lib since we're going to use it for non-config specific stuff
pkgsFlakes = mapAttrs (_: pkgsFlake: pkgsFlake // { lib = pkgsFlake.lib.extend libOverlay; }) {
master = nixpkgs-master;
2022-02-06 00:06:26 +00:00
unstable = nixpkgs-unstable;
stable = nixpkgs-stable;
2022-02-16 01:40:03 +00:00
mine = nixpkgs-mine;
2022-02-06 00:06:26 +00:00
};
hmFlakes = {
unstable = home-manager-unstable;
stable = home-manager-stable;
};
2022-02-06 00:06:26 +00:00
# Should only be used for platform-independent flake stuff! This should never leak into a NixOS or home-manager
# config - they'll get their own.
2022-02-06 00:06:26 +00:00
lib = pkgsFlakes.unstable.lib;
# pkgs for dev shell etc
2022-02-13 14:28:49 +00:00
pkgs' = mapAttrs
2022-02-13 23:06:31 +00:00
(_: path: mkDefaultSystemsPkgs path (system: {
2022-02-13 14:28:49 +00:00
overlays = [
pkgsLibOverlay
inputs.devshell.overlay
2022-02-13 14:28:49 +00:00
inputs.agenix.overlay
inputs.deploy-rs.overlay
(flakePackageOverlay inputs.home-manager-unstable system)
2022-02-13 14:28:49 +00:00
];
2022-02-13 23:06:31 +00:00
}))
pkgsFlakes;
# Easiest to build the basic pkgs here (with our lib overlay too)
configPkgs' = mapAttrs
2022-02-13 23:06:31 +00:00
(_: path: mkDefaultSystemsPkgs path (_: {
overlays = [
pkgsLibOverlay
2022-02-13 23:06:31 +00:00
];
}))
2022-02-13 14:28:49 +00:00
pkgsFlakes;
2022-02-13 17:44:14 +00:00
configs = [
# Systems
nixos/boxes/colony.nix
nixos/installer.nix
# Homes
home-manager/configs/castle.nix
];
nixfiles = evalModules {
modules = [
{
_module.args = {
inherit lib pkgsFlakes hmFlakes inputs;
pkgs' = configPkgs';
};
}
./nixos
./home-manager
] ++ configs;
2022-02-13 23:06:31 +00:00
};
2022-02-13 13:10:21 +00:00
in
2022-02-13 14:28:49 +00:00
# Platform independent stuff
2022-02-13 13:10:21 +00:00
{
2022-02-13 14:28:49 +00:00
lib = lib.my;
2022-02-13 17:44:14 +00:00
nixpkgs = pkgs';
inherit nixfiles;
2022-02-06 00:06:26 +00:00
nixosModules = nixfiles.config.nixos.modules;
homeModules = nixfiles.config.home-manager.modules;
2022-02-13 23:06:31 +00:00
nixosConfigurations = mapAttrs (_: s: s.configuration) nixfiles.config.nixos.systems;
homeConfigurations = mapAttrs (_: s: s.configuration) nixfiles.config.home-manager.homes;
2022-02-19 22:55:53 +00:00
deploy = {
nodes = filterAttrs (_: n: n != null)
(mapAttrs (_: system: system.config.my.deploy.rendered) self.nixosConfigurations);
autoRollback = true;
magicRollback = true;
};
2022-02-13 14:28:49 +00:00
} //
(eachDefaultSystem (system:
let
pkgs = pkgs'.unstable.${system};
lib = pkgs.lib;
in
# Stuff for each platform
{
2022-02-17 20:50:53 +00:00
checks = flattenTree {
homeConfigurations = recurseIntoAttrs (mapAttrs (_: h: h.activationPackage) self.homeConfigurations);
2022-02-19 22:55:53 +00:00
deploy = recurseIntoAttrs (pkgs.deploy-rs.lib.deployChecks self.deploy);
2022-02-17 20:50:53 +00:00
};
2022-02-19 23:34:41 +00:00
devShell = pkgs.devshell.mkShell ./devshell;
2022-02-13 14:28:49 +00:00
}));
2022-02-06 00:06:26 +00:00
}