feat(flake): use flake-parts
This commit is contained in:
parent
611584a0be
commit
e2a0172e2d
14 changed files with 576 additions and 489 deletions
251
flake.nix
251
flake.nix
|
|
@ -1,11 +1,6 @@
|
|||
{
|
||||
description = "My awesome system config";
|
||||
|
||||
/*
|
||||
╔══════════════════════════════════════════════════════════╗
|
||||
║ Inputs ║
|
||||
╚══════════════════════════════════════════════════════════╝
|
||||
*/
|
||||
inputs = {
|
||||
# Nix
|
||||
master.url = "github:nixos/nixpkgs";
|
||||
|
|
@ -13,6 +8,8 @@
|
|||
stable.url = "github:nixos/nixpkgs/nixos-23.05";
|
||||
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
devshell.url = "github:numtide/devshell";
|
||||
|
||||
agenix.inputs.nixpkgs.follows = "nixpkgs";
|
||||
agenix.url = "github:ryantm/agenix";
|
||||
|
|
@ -20,9 +17,11 @@
|
|||
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||
home-manager.url = "github:nix-community/home-manager";
|
||||
|
||||
nil.inputs.flake-utils.follows = "flake-utils";
|
||||
nil.inputs.nixpkgs.follows = "nixpkgs";
|
||||
nil.url = "github:oxalica/nil";
|
||||
nil = {
|
||||
inputs.flake-utils.follows = "flake-utils";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
url = "github:oxalica/nil";
|
||||
};
|
||||
|
||||
pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix";
|
||||
|
||||
|
|
@ -77,147 +76,141 @@
|
|||
timers.url = "git+https://gitea.moritzboeh.me/moritz/timers.git";
|
||||
};
|
||||
|
||||
/*
|
||||
╔══════════════════════════════════════════════════════════╗
|
||||
║ Outputs ║
|
||||
╚══════════════════════════════════════════════════════════╝
|
||||
*/
|
||||
outputs = inputs@{ self, nixpkgs, ... }:
|
||||
outputs = inputs@{ self, flake-parts, ... }:
|
||||
let
|
||||
systems = [ "x86_64-linux" "aarch64-linux" ];
|
||||
|
||||
forEachSystem = lib.genAttrs systems;
|
||||
|
||||
lib = nixpkgs.lib.extend
|
||||
(self: _: { my = import ./lib { lib = self; }; });
|
||||
|
||||
overlay = import ./overlays {
|
||||
inherit inputs;
|
||||
inherit (self) lib;
|
||||
};
|
||||
|
||||
config.allowUnfree = true;
|
||||
|
||||
overlays = [
|
||||
defaultOverlays = [
|
||||
inputs.hypr-contrib.overlays.default
|
||||
inputs.neovim-nightly-overlay.overlay
|
||||
overlay
|
||||
self.overlay
|
||||
];
|
||||
|
||||
pkgsFor = system: import nixpkgs {
|
||||
inherit system config;
|
||||
overlays = overlays ++ [
|
||||
finalOverlays =
|
||||
defaultOverlays ++ [
|
||||
(
|
||||
_: prev: {
|
||||
master = import inputs.master {
|
||||
inherit (prev) system;
|
||||
inherit overlays config;
|
||||
overlays = defaultOverlays;
|
||||
};
|
||||
stable = import inputs.stable {
|
||||
inherit (prev) system;
|
||||
inherit overlays config;
|
||||
overlays = defaultOverlays;
|
||||
};
|
||||
}
|
||||
)
|
||||
overlay
|
||||
];
|
||||
};
|
||||
|
||||
defaultModules = [
|
||||
{ nixpkgs = { inherit config; }; }
|
||||
./modules
|
||||
inputs.home-manager.nixosModule
|
||||
{
|
||||
home-manager = {
|
||||
useGlobalPkgs = true;
|
||||
useUserPackages = true;
|
||||
extraSpecialArgs = { inherit inputs self; };
|
||||
sharedModules = [ inputs.nix-lazy-nvim.homeManagerModules.default ];
|
||||
};
|
||||
}
|
||||
inputs.agenix.nixosModules.age
|
||||
inputs.disko.nixosModules.default
|
||||
inputs.impermanence.nixosModules.impermanence
|
||||
in
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
inputs.flake-parts.flakeModules.easyOverlay
|
||||
inputs.pre-commit-hooks.flakeModule
|
||||
inputs.devshell.flakeModule
|
||||
];
|
||||
|
||||
hosts = self.lib.my.mapModules
|
||||
(path:
|
||||
let
|
||||
system = import "${path}/system.nix";
|
||||
pkgs = pkgsFor system;
|
||||
in
|
||||
lib.nixosSystem {
|
||||
inherit pkgs system lib;
|
||||
specialArgs = {
|
||||
inherit inputs self;
|
||||
};
|
||||
modules = defaultModules ++ [ path ];
|
||||
})
|
||||
./hosts;
|
||||
systems = [ "x86_64-linux" ];
|
||||
perSystem = { config, self', inputs', pkgs, system, ... }: {
|
||||
_module.args.pkgs =
|
||||
import inputs.nixpkgs {
|
||||
inherit system;
|
||||
overlays = finalOverlays;
|
||||
};
|
||||
|
||||
pre-commit-check = system: inputs.pre-commit-hooks.lib."${system}".run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixpkgs-fmt.enable = true;
|
||||
statix.enable = true;
|
||||
shellcheck.enable = true;
|
||||
stylua.enable = true;
|
||||
};
|
||||
};
|
||||
in
|
||||
with lib; {
|
||||
inherit lib;
|
||||
|
||||
# ╔══════════════════════════════════════════════════════════╗
|
||||
# ║ NixOS Configurations ║
|
||||
# ╚══════════════════════════════════════════════════════════╝
|
||||
|
||||
nixosConfigurations = hosts;
|
||||
|
||||
# ╔══════════════════════════════════════════════════════════╗
|
||||
# ║ Other Outputs ║
|
||||
# ╚══════════════════════════════════════════════════════════╝
|
||||
|
||||
devShells = forEachSystem (system:
|
||||
let
|
||||
pkgs = pkgsFor system;
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell
|
||||
devshells.default = {
|
||||
devshell.startup.pre-commit-hook.text = config.pre-commit.installationScript;
|
||||
commands = [
|
||||
{
|
||||
inherit (pre-commit-check system) shellHook;
|
||||
name = "dotfiles";
|
||||
packages = with pkgs; [
|
||||
# Secrets
|
||||
agenix
|
||||
# cachix
|
||||
cachix
|
||||
];
|
||||
};
|
||||
});
|
||||
|
||||
checks = forEachSystem (system: {
|
||||
pre-commit-check = pre-commit-check system;
|
||||
});
|
||||
|
||||
legacyPackages = forEachSystem pkgsFor;
|
||||
|
||||
packages = forEachSystem (system:
|
||||
let
|
||||
pkgs = pkgsFor system;
|
||||
in
|
||||
filterAttrs (_: isDerivation)
|
||||
(overlay pkgs pkgs)
|
||||
);
|
||||
|
||||
overlays =
|
||||
let
|
||||
overlayNames = attrNames (overlay null null);
|
||||
mkOverlay = name: final: prev: (overlay final prev).${name};
|
||||
in
|
||||
(genAttrs overlayNames mkOverlay) // {
|
||||
default = overlay;
|
||||
name = "agenix";
|
||||
help = "wrapper around agenix";
|
||||
command = ''
|
||||
sudo EDITOR="${pkgs.lib.getExe pkgs.vim}" ${pkgs.lib.getExe' inputs'.agenix.packages.default "agenix"} --identity /etc/ssh/ssh_host_ed25519_key "$@"
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "nixos-build";
|
||||
help = "use nom to build system";
|
||||
command =
|
||||
''
|
||||
nom build --no-link ".#nixosConfigurations.$(hostname).config.system.build.toplevel" $@
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "nixos-switch";
|
||||
help = "wrapper for nixos-rebuild switch";
|
||||
command = "sudo nixos-rebuild switch --flake . $@";
|
||||
}
|
||||
{
|
||||
name = "nixos-test";
|
||||
help = "wrapper for nixos-rebuild switch";
|
||||
command = "sudo nixos-rebuild test --flake . $@";
|
||||
}
|
||||
{
|
||||
name = "nixos-boot";
|
||||
help = "wrapper for nixos-rebuild switch";
|
||||
command = "sudo nixos-rebuild boot --flake . $@";
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
pre-commit = {
|
||||
check.enable = true;
|
||||
settings = {
|
||||
hooks = {
|
||||
nixpkgs-fmt.enable = true;
|
||||
statix.enable = true;
|
||||
shellcheck.enable = true;
|
||||
stylua.enable = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
legacyPackages = pkgs;
|
||||
|
||||
packages =
|
||||
self.lib.filterAttrs (_: self.lib.isDerivation)
|
||||
(self.overlay pkgs pkgs);
|
||||
};
|
||||
|
||||
flake = {
|
||||
lib = inputs.nixpkgs.lib.extend
|
||||
(self: _: { my = import ./lib { lib = self; }; });
|
||||
|
||||
overlay = import ./overlays {
|
||||
inherit inputs;
|
||||
inherit (self) lib;
|
||||
};
|
||||
|
||||
nixosConfigurations = self.lib.my.mapModules
|
||||
(path:
|
||||
self.lib.nixosSystem {
|
||||
inherit (self) lib;
|
||||
specialArgs = {
|
||||
inherit inputs self;
|
||||
};
|
||||
modules =
|
||||
[
|
||||
./modules
|
||||
{
|
||||
nixpkgs = {
|
||||
overlays = finalOverlays;
|
||||
config.allowUnfree = true;
|
||||
};
|
||||
}
|
||||
inputs.home-manager.nixosModule
|
||||
{
|
||||
home-manager = {
|
||||
useGlobalPkgs = true;
|
||||
useUserPackages = true;
|
||||
extraSpecialArgs = { inherit inputs self; };
|
||||
sharedModules = [ inputs.nix-lazy-nvim.homeManagerModules.default ];
|
||||
};
|
||||
}
|
||||
inputs.agenix.nixosModules.age
|
||||
inputs.disko.nixosModules.default
|
||||
inputs.impermanence.nixosModules.impermanence
|
||||
]
|
||||
++ [ path ];
|
||||
})
|
||||
./hosts;
|
||||
};
|
||||
};
|
||||
|
||||
nixConfig = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue