nixfiles/flake.nix

136 lines
3.8 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";
# Used by most systems
nixpkgs-unstable.url = "nixpkgs/nixos-unstable";
# For extra-stable systems
nixpkgs-stable.url = "nixpkgs/nixos-21.11";
# 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";
2022-02-13 23:06:31 +00:00
home-manager.url = "home-manager";
2022-02-06 00:06:26 +00:00
home-manager.inputs.nixpkgs.follows = "nixpkgs-unstable";
# Stuff used by systems
nix.url = "nix/latest-release";
#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,
nixpkgs-unstable, nixpkgs-stable,
...
}:
let
2022-02-13 17:44:14 +00:00
inherit (builtins) mapAttrs attrValues;
inherit (lib.flake) eachDefaultSystem;
2022-02-13 23:06:31 +00:00
inherit (lib.my) mkApp mkShellApp inlineModules mkDefaultSystemsPkgs flakePackageOverlay;
2022-02-06 00:06:26 +00:00
extendLib = lib: lib.extend (final: prev: {
my = import ./util.nix { lib = final; };
flake = flake-utils.lib;
});
libOverlay = final: prev: { lib = extendLib prev.lib; };
pkgsFlakes = mapAttrs (_: pkgs: pkgs // { lib = extendLib pkgs.lib; }) {
unstable = nixpkgs-unstable;
stable = nixpkgs-stable;
};
lib = pkgsFlakes.unstable.lib;
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 = [
libOverlay
inputs.agenix.overlay
inputs.deploy-rs.overlay
inputs.nix.overlay
2022-02-13 23:06:31 +00:00
(flakePackageOverlay inputs.home-manager 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)
homePkgs' = mapAttrs
(_: path: mkDefaultSystemsPkgs path (_: {
overlays = [
libOverlay
];
}))
2022-02-13 14:28:49 +00:00
pkgsFlakes;
2022-02-13 17:44:14 +00:00
modules = mapAttrs (_: f: ./. + "/modules/${f}") {
common = "common.nix";
build = "build.nix";
dynamic-motd = "dynamic-motd.nix";
tmproot = "tmproot.nix";
firewall = "firewall.nix";
server = "server.nix";
};
2022-02-13 23:06:31 +00:00
homeModules = mapAttrs (_: f: ./. + "/home-modules/${f}") {
common = "common.nix";
};
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';
2022-02-06 00:06:26 +00:00
2022-02-13 23:06:31 +00:00
nixosModules = inlineModules modules;
homeModules = inlineModules homeModules;
2022-02-06 00:06:26 +00:00
2022-02-13 23:06:31 +00:00
nixosConfigurations = import ./systems.nix {
inherit lib pkgsFlakes inputs;
modules = attrValues modules;
homeModules = attrValues homeModules;
};
systems = mapAttrs (_: system: system.config.system.build.toplevel) self.nixosConfigurations;
2022-02-13 14:28:49 +00:00
vms = mapAttrs (_: system: system.config.my.build.devVM) self.nixosConfigurations;
2022-02-13 23:06:31 +00:00
homeConfigurations = import ./homes.nix {
inherit lib inputs;
pkgs' = homePkgs';
modules = attrValues homeModules;
};
homes = mapAttrs(_: home: home.activationPackage) self.homeConfigurations;
2022-02-13 14:28:49 +00:00
} //
(eachDefaultSystem (system:
let
pkgs = pkgs'.unstable.${system};
lib = pkgs.lib;
in
# Stuff for each platform
{
apps = {
fmt = mkShellApp pkgs "fmt" ''exec "${pkgs.nixpkgs-fmt}/bin/nixpkgs-fmt" "$@" .'';
};
2022-02-06 00:06:26 +00:00
2022-02-13 14:28:49 +00:00
devShell = pkgs.mkShell {
2022-02-13 23:06:31 +00:00
NIX_USER_CONF_FILES = pkgs.writeText "nix.conf"
2022-02-13 18:47:35 +00:00
''
experimental-features = nix-command flakes ca-derivations
'';
2022-02-13 14:28:49 +00:00
packages = with pkgs; [
nix
agenix
deploy-rs.deploy-rs
nixpkgs-fmt
2022-02-13 23:06:31 +00:00
home-manager
2022-02-13 14:28:49 +00:00
];
};
}));
2022-02-06 00:06:26 +00:00
}