aboutsummaryrefslogtreecommitdiff
path: root/flake
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2025-07-21 07:31:45 -0700
committerFranck Cuny <franck@fcuny.net>2025-07-21 08:13:11 -0700
commit23f8df7396d35744069a4bda0d1d38a55ff64b79 (patch)
tree772b5e72355e9ee5b3ae31aef37fe1d4508e8f30 /flake
parentadd docker helpers and clean up some dependencies (diff)
downloadinfra-23f8df7396d35744069a4bda0d1d38a55ff64b79.tar.gz
refactoring to use flake-parts and automatic imports of hosts
This is the first step in a large refactoring to use flake-parts, and to automatically imports hosts based on paths.
Diffstat (limited to '')
-rw-r--r--flake.lock21
-rw-r--r--flake.nix202
2 files changed, 37 insertions, 186 deletions
diff --git a/flake.lock b/flake.lock
index 9022dc8..ca57c93 100644
--- a/flake.lock
+++ b/flake.lock
@@ -123,6 +123,26 @@
"type": "github"
}
},
+ "flake-parts": {
+ "inputs": {
+ "nixpkgs-lib": [
+ "nixpkgs"
+ ]
+ },
+ "locked": {
+ "lastModified": 1751413152,
+ "narHash": "sha256-Tyw1RjYEsp5scoigs1384gIg6e0GoBVjms4aXFfRssQ=",
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "rev": "77826244401ea9de6e3bac47c2db46005e1f30b5",
+ "type": "github"
+ },
+ "original": {
+ "owner": "hercules-ci",
+ "repo": "flake-parts",
+ "type": "github"
+ }
+ },
"gitignore": {
"inputs": {
"nixpkgs": [
@@ -262,6 +282,7 @@
"darwin": "darwin_2",
"disko": "disko",
"emacs-overlay": "emacs-overlay",
+ "flake-parts": "flake-parts",
"home-manager": "home-manager_2",
"nixpkgs": "nixpkgs",
"nixpkgsUnstable": "nixpkgsUnstable",
diff --git a/flake.nix b/flake.nix
index 557e550..110064b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -40,199 +40,29 @@
url = "github:nix-community/emacs-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
+
+ flake-parts = {
+ url = "github:hercules-ci/flake-parts";
+ inputs.nixpkgs-lib.follows = "nixpkgs";
+ };
};
- # Output config, or config for NixOS system
outputs =
- {
- self,
- nixpkgs,
- nixpkgsUnstable,
- darwin,
- treefmt-nix,
- pre-commit-hooks,
- emacs-overlay,
- agenix,
- ...
- }@inputs:
- let
- supportedSystems = [
+ inputs@{ flake-parts, ... }:
+ flake-parts.lib.mkFlake { inherit inputs; } {
+ systems = [
"aarch64-darwin"
"x86_64-linux"
];
- # Function to generate attributes for each system
- forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
-
- # Function to get pkgs for a specific system
- getPkgs =
- system:
- import nixpkgs {
- inherit system;
- config.allowUnfree = true;
- overlays = overlays;
- };
-
- getPkgsUnstable =
- system:
- import nixpkgsUnstable {
- inherit system;
- };
-
- # Define overlays here
- overlays = [
- emacs-overlay.overlay
- (final: _prev: {
- # Load all packages from the pkgs directory
- customPackages = builtins.mapAttrs (
- name: _:
- final.callPackage (./pkgs + "/${name}") {
- pkgsUnstable = getPkgsUnstable final.system;
- }
- ) (builtins.readDir ./pkgs);
- })
+ imports = [
+ ./nix/flake/apps.nix
+ ./nix/flake/checks.nix
+ ./nix/flake/devshells.nix
+ ./nix/flake/formatter.nix
+ ./nix/flake/hosts.nix
+ ./nix/flake/overlays.nix
+ ./nix/flake/packages.nix
];
-
- mkSystem = import ./nix/lib/mkSystem.nix {
- inherit
- self
- nixpkgs
- inputs
- overlays
- ;
- };
-
- mkFcunyNet =
- system:
- let
- pkgs = getPkgs system;
- in
- import ./src/fcuny.net { inherit pkgs; };
-
- # Create a treefmt-nix evaluation for a system
- mkTreefmtEval =
- system:
- let
- pkgs = getPkgs system;
- in
- treefmt-nix.lib.evalModule pkgs {
- projectRootFile = "flake.nix";
- programs = {
- nixfmt.enable = true;
- deadnix.enable = true;
- };
- };
-
- # Create pre-commit hooks for a system and source
- mkPreCommitHooks =
- system: src:
- let
- treefmtEval = mkTreefmtEval system;
- in
- inputs.pre-commit-hooks.lib.${system}.run {
- inherit src;
- hooks = {
- check-merge-conflicts.enable = true;
- deadnix.enable = true;
- detect-private-keys.enable = true;
- end-of-file-fixer.enable = true;
- mixed-line-endings.enable = true;
- shellcheck = {
- enable = true;
- excludes = [ "\\.envrc$" ];
- };
- flake-checker.enable = true;
- treefmt = {
- enable = true;
- entry = "${treefmtEval.config.build.wrapper}/bin/treefmt --ci";
- };
- trim-trailing-whitespace.enable = true;
- };
- };
- in
- {
- nixosModules = import ./nix/modules;
-
- packages = forAllSystems (
- system:
- let
- fcunyNet = mkFcunyNet system;
- in
- {
- "fcuny_net" = fcunyNet.site;
- }
- );
-
- apps = forAllSystems (
- system:
- let
- fcunyNet = mkFcunyNet system;
- in
- {
- "fcuny_net-serve" = {
- type = "app";
- program = "${fcunyNet.serve}/bin/serve-fcuny-net";
- };
- }
- );
-
- # nix fmt
- formatter = forAllSystems (
- system:
- let
- treefmtEval = mkTreefmtEval system;
- in
- treefmtEval.config.build.wrapper
- );
-
- # nix flake check
- checks = forAllSystems (system: {
- pre-commit-check = mkPreCommitHooks system ./.;
- });
-
- # my VM running on the synology NAS
- nixosConfigurations.vm-synology = mkSystem "vm-synology" {
- system = "x86_64-linux";
- user = "fcuny";
- };
-
- # my personal MacBook Air
- darwinConfigurations.mba-m2 = mkSystem "mba-m2" {
- system = "aarch64-darwin";
- user = "fcuny";
- darwin = true;
- };
-
- # work laptop
- darwinConfigurations.HQ-KWNY2VH41P = mkSystem "hq-kwny2vh41p" {
- system = "aarch64-darwin";
- user = "fcuny";
- darwin = true;
- };
-
- # Dev shells for each system
- devShells = forAllSystems (
- system:
- let
- pkgs = getPkgs system;
- pre-commit-check = mkPreCommitHooks system ./.;
- scripts = import ./nix/scripts {
- inherit pkgs system inputs;
- };
- in
- {
- default = pkgs.mkShellNoCC {
- inherit (pre-commit-check) shellHook; # This is the key line
- packages =
- with pkgs;
- [
- nixos-rebuild
- git
- inputs.agenix.packages."${system}".default
- ]
- ++ scripts.all;
- };
- }
- );
};
}