system/flake.nix

167 lines
5.5 KiB
Nix
Raw Normal View History

2022-08-29 23:46:02 +03:00
{
inputs = {
2022-10-09 14:56:08 +03:00
flake-utils.url = "github:numtide/flake-utils";
2023-11-30 14:14:12 +03:00
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
2022-09-26 03:48:38 +03:00
hardware.url = "github:NixOS/nixos-hardware/master";
2022-10-10 11:59:05 +03:00
agenix = {
url = "github:ryantm/agenix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.darwin.follows = "";
2022-10-10 11:59:05 +03:00
};
2022-08-30 00:17:21 +03:00
home-manager = {
url = "github:nix-community/home-manager/release-23.11";
2022-08-30 00:17:21 +03:00
inputs.nixpkgs.follows = "nixpkgs";
};
2022-09-01 11:17:54 +03:00
2022-09-21 13:08:01 +03:00
wired = {
url = "github:Toqozz/wired-notify";
inputs.nixpkgs.follows = "nixpkgs";
};
2022-09-18 18:29:40 +03:00
# nix lsp
nil = {
2022-09-25 17:07:41 +03:00
url = "github:oxalica/nil";
2022-09-18 18:29:40 +03:00
inputs.nixpkgs.follows = "nixpkgs";
2022-10-09 14:56:08 +03:00
inputs.flake-utils.follows = "flake-utils";
2022-09-18 18:29:40 +03:00
};
# my neovim configuration
2022-12-13 10:13:15 +03:00
myneovim = {
url = "git+https://git.pleshevski.ru/mynix/neovim";
inputs.nixpkgs.follows = "nixpkgs-unstable";
2022-12-13 10:13:15 +03:00
inputs.flake-utils.follows = "flake-utils";
};
2022-09-18 18:29:40 +03:00
# tool to change .env faster
vnetod = {
2022-11-12 23:32:58 +03:00
url = "git+https://git.pleshevski.ru/pleshevskiy/vnetod";
2022-09-17 21:55:13 +03:00
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
2022-09-17 21:55:13 +03:00
};
2022-10-13 23:11:12 +03:00
yagpt_tg_bot = {
url = "git+https://git.pleshevski.ru/pleshevskiy/yandexgpt_tg_bot";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
2022-10-13 23:11:12 +03:00
mailserver = {
url = "gitlab:simple-nixos-mailserver/nixos-mailserver";
inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.follows = "flake-utils";
};
2022-08-30 00:17:21 +03:00
};
2022-08-29 23:46:02 +03:00
2022-11-18 14:22:59 +03:00
outputs = inputs @ { self, flake-utils, nixpkgs, ... }:
2022-10-09 14:56:08 +03:00
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib;
2022-10-15 13:09:33 +03:00
nixos-rebuild = pkgs.nixos-rebuild.override { nix = pkgs.nixVersions.stable; };
2022-10-13 07:47:31 +03:00
localMachines = lib.filterAttrs (h: m: m.config.deployment.targetHost == null) self.nixosConfigurations;
vpsMachines = lib.filterAttrs (h: m: m.config.deployment.targetHost != null) self.nixosConfigurations;
2022-10-09 14:56:08 +03:00
in
{
apps = lib.mapAttrs
(name: program: { type = "app"; program = toString program; })
2022-10-09 15:04:03 +03:00
(flake-utils.lib.flattenTree {
2022-10-13 07:47:31 +03:00
deploy = lib.recurseIntoAttrs (lib.mapAttrs
(hostname: machine: pkgs.writeShellScript "deploy-${hostname}" ''
${nixos-rebuild}/bin/nixos-rebuild switch \
--flake .#${hostname} \
2024-02-18 23:08:50 +03:00
--target-host root@${machine.config.deployment.targetHost} \
$@
2022-10-13 07:47:31 +03:00
'')
vpsMachines);
2023-03-18 16:47:02 +03:00
rollback = lib.recurseIntoAttrs (lib.mapAttrs
(hostname: machine: pkgs.writeShellScript "rollback-${hostname}" ''
${nixos-rebuild}/bin/nixos-rebuild switch --rollback
2023-03-18 16:47:02 +03:00
'')
self.nixosConfigurations);
2022-10-09 15:04:03 +03:00
switch = lib.recurseIntoAttrs (lib.mapAttrs
(hostname: machine: pkgs.writeShellScript "switch-${hostname}" ''
${nixos-rebuild}/bin/nixos-rebuild switch --flake .#${hostname} $@
2022-10-09 15:04:03 +03:00
'')
2022-10-13 07:47:31 +03:00
localMachines);
test = lib.recurseIntoAttrs (lib.mapAttrs
(hostname: machine: pkgs.writeShellScript "test-${hostname}" ''
${nixos-rebuild}/bin/nixos-rebuild test --flake .#${hostname} $@
'')
2022-10-13 07:47:31 +03:00
localMachines);
2023-03-18 16:47:02 +03:00
2022-10-09 15:04:03 +03:00
});
2022-10-09 14:56:08 +03:00
devShells = {
default = pkgs.mkShell {
2022-10-10 11:59:05 +03:00
packages = with pkgs; [
stylua # lua formatter
ormolu # haskell formatter
inputs.agenix.packages.${system}.agenix
];
# Path to the agenix configuration file
RULES = "./.agenix_config.nix";
2022-10-09 14:56:08 +03:00
};
2022-10-19 18:30:46 +03:00
tools = pkgs.mkShell {
2023-03-02 13:09:07 +03:00
packages = with pkgs; [
2023-03-03 14:40:42 +03:00
mkpasswd
2023-03-02 13:09:07 +03:00
gucharmap
wireguard-tools
];
2022-10-19 18:30:46 +03:00
};
2022-10-09 14:56:08 +03:00
};
})
// {
2022-10-08 22:45:35 +03:00
nixosConfigurations =
nixpkgs.lib.mapAttrs
(hostname: { system
, specialArgs ? { }
, extraModules ? [ ]
, extraHomeModule ? null
2022-10-13 07:47:31 +03:00
, targetHost ? null
2022-10-08 22:45:35 +03:00
, nixpkgs ? inputs.nixpkgs
}:
nixpkgs.lib.nixosSystem {
inherit system;
2022-08-30 00:17:21 +03:00
specialArgs = { inherit inputs extraHomeModule; } // specialArgs;
2022-10-08 22:45:35 +03:00
modules =
2022-10-10 11:59:05 +03:00
(with inputs; [
2023-02-20 20:49:06 +03:00
agenix.nixosModules.default
2022-10-10 11:59:05 +03:00
home-manager.nixosModule
])
2022-10-13 07:47:31 +03:00
++ extraModules
++ [
# deployment settings
({ lib, ... }: {
options.deployment = with lib; {
targetHost = mkOption {
type = types.nullOr types.str;
readOnly = true;
internal = true;
};
};
config.deployment = { inherit targetHost; };
})
2022-10-18 00:42:23 +03:00
# base home manager settings
({ ... }: {
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
})
2023-03-18 16:47:02 +03:00
]
++ [ ./nixos/hosts/${hostname} ];
2022-10-08 22:45:35 +03:00
})
2023-03-18 16:47:02 +03:00
(import ./nixos/hosts inputs);
2022-08-29 23:46:02 +03:00
};
}