aboutsummaryrefslogtreecommitdiff
path: root/nix/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 /nix/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 'nix/flake')
-rw-r--r--nix/flake/apps.nix16
-rw-r--r--nix/flake/checks.nix42
-rw-r--r--nix/flake/devshells.nix57
-rw-r--r--nix/flake/formatter.nix17
-rw-r--r--nix/flake/hosts.nix184
-rw-r--r--nix/flake/overlays.nix21
-rw-r--r--nix/flake/packages.nix13
7 files changed, 350 insertions, 0 deletions
diff --git a/nix/flake/apps.nix b/nix/flake/apps.nix
new file mode 100644
index 0000000..ef764eb
--- /dev/null
+++ b/nix/flake/apps.nix
@@ -0,0 +1,16 @@
+{ ... }:
+{
+ perSystem =
+ { pkgs, ... }:
+ let
+ mkFcunyNet = import ../../src/fcuny.net { inherit pkgs; };
+ in
+ {
+ apps = {
+ "fcuny_net-serve" = {
+ type = "app";
+ program = "${mkFcunyNet.serve}/bin/serve-fcuny-net";
+ };
+ };
+ };
+}
diff --git a/nix/flake/checks.nix b/nix/flake/checks.nix
new file mode 100644
index 0000000..87d4a7f
--- /dev/null
+++ b/nix/flake/checks.nix
@@ -0,0 +1,42 @@
+{ inputs, ... }:
+{
+ perSystem =
+ { system, pkgs, ... }:
+ let
+ treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs {
+ projectRootFile = "flake.nix";
+ programs = {
+ nixfmt.enable = true;
+ deadnix.enable = true;
+ };
+ };
+
+ mkPreCommitHooks =
+ src:
+ 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
+ {
+ checks = {
+ pre-commit-check = mkPreCommitHooks ./.;
+ };
+ };
+}
diff --git a/nix/flake/devshells.nix b/nix/flake/devshells.nix
new file mode 100644
index 0000000..339a8f4
--- /dev/null
+++ b/nix/flake/devshells.nix
@@ -0,0 +1,57 @@
+{ inputs, ... }:
+{
+ perSystem =
+ { system, pkgs, ... }:
+ let
+ treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs {
+ projectRootFile = "flake.nix";
+ programs = {
+ nixfmt.enable = true;
+ deadnix.enable = true;
+ };
+ };
+
+ mkPreCommitHooks =
+ src:
+ 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;
+ };
+ };
+
+ pre-commit-check = mkPreCommitHooks ./.;
+ scripts = import ../../nix/scripts {
+ inherit pkgs system inputs;
+ };
+ in
+ {
+ devShells = {
+ default = pkgs.mkShellNoCC {
+ inherit (pre-commit-check) shellHook;
+ packages =
+ with pkgs;
+ [
+ nixos-rebuild
+ git
+ inputs.agenix.packages."${system}".default
+ ]
+ ++ scripts.all;
+ };
+ };
+ };
+}
diff --git a/nix/flake/formatter.nix b/nix/flake/formatter.nix
new file mode 100644
index 0000000..44c0190
--- /dev/null
+++ b/nix/flake/formatter.nix
@@ -0,0 +1,17 @@
+{ inputs, ... }:
+{
+ perSystem =
+ { pkgs, ... }:
+ let
+ treefmtEval = inputs.treefmt-nix.lib.evalModule pkgs {
+ projectRootFile = "flake.nix";
+ programs = {
+ nixfmt.enable = true;
+ deadnix.enable = true;
+ };
+ };
+ in
+ {
+ formatter = treefmtEval.config.build.wrapper;
+ };
+}
diff --git a/nix/flake/hosts.nix b/nix/flake/hosts.nix
new file mode 100644
index 0000000..3ce8c6b
--- /dev/null
+++ b/nix/flake/hosts.nix
@@ -0,0 +1,184 @@
+{
+ inputs,
+ self,
+ withSystem,
+ ...
+}:
+let
+ inherit (inputs.nixpkgs.lib // builtins)
+ filterAttrs
+ foldl'
+ makeOverridable
+ mapAttrs'
+ mapAttrsToList
+ mkForce
+ mkIf
+ nixosSystem
+ readDir
+ replaceStrings
+ substring
+ ;
+
+ inherit (inputs.darwin.lib) darwinSystem;
+
+ nixSettings = {
+ nix.registry.nixpkgs = {
+ flake = inputs.nixpkgs;
+ };
+ };
+
+ mapSystems =
+ dir: mapAttrsToList (name: _: name) (filterAttrs (_: type: type == "directory") (readDir dir));
+
+ mapHosts = foldl' (
+ hosts: system:
+ hosts
+ // (mapAttrs' (
+ filename: _:
+ let
+ name = replaceStrings [ ".nix" ] [ "" ] filename;
+ in
+ {
+ inherit name;
+ value = {
+ inherit system;
+ hostconf = ../machines/nixos + "/${system}/${filename}";
+ };
+ }
+ ) (builtins.readDir ../machines/nixos/${system}))
+ ) { };
+
+ mapMacs = foldl' (
+ hosts: system:
+ hosts
+ // (mapAttrs' (
+ filename: _:
+ let
+ name = replaceStrings [ ".nix" ] [ "" ] filename;
+ in
+ {
+ inherit name;
+ value = {
+ inherit system;
+ hostconf = ../machines/darwin + "/${system}/${filename}";
+ };
+ }
+ ) (builtins.readDir ../machines/darwin/${system}))
+ ) { };
+
+ defaultModules = [
+ nixSettings
+ inputs.agenix.nixosModules.age
+ inputs.disko.nixosModules.disko
+ inputs.home-manager.nixosModules.home-manager
+ ../modules/default.nix
+ ];
+
+ darwinDefaultModules = [
+ nixSettings
+ inputs.agenix.darwinModules.age
+ inputs.home-manager.darwinModules.home-manager
+ ../modules/default-darwin.nix
+ ];
+
+ darwinConfigurations = mapAttrs' (
+ name: conf:
+ let
+ inherit (conf) system hostconf;
+ adminUser = {
+ name = "fcuny";
+ userinfo = {
+ email = "franck@fcuny.net";
+ fullName = "Franck Cuny";
+ };
+ };
+ in
+ {
+ inherit name;
+ value = withSystem system (
+ { pkgs, ... }:
+ makeOverridable darwinSystem {
+ inherit system;
+ specialArgs = {
+ hostName = name;
+ inherit adminUser;
+ inherit self;
+ inherit inputs;
+ };
+ modules =
+ [
+ { inherit adminUser; }
+ {
+ nixpkgs.pkgs = pkgs;
+ nixpkgs.hostPlatform = system;
+ system.stateVersion = 5;
+ environment.systemPackages = [
+ pkgs.git
+ ];
+ }
+ ]
+ ++ darwinDefaultModules
+ ++ [
+ hostconf
+ ];
+ }
+ );
+ }
+ ) (mapMacs (mapSystems ../machines/darwin));
+
+ nixosConfigurations = mapAttrs' (
+ name: conf:
+ let
+ inherit (conf) system hostconf;
+ adminUser = {
+ name = "fcuny";
+ userinfo = {
+ email = "franck@fcuny.net";
+ fullName = "Franck Cuny";
+ };
+ };
+ in
+ {
+ inherit name;
+ value = withSystem system (
+ { pkgs, ... }:
+ makeOverridable nixosSystem {
+ inherit system;
+ specialArgs = {
+ hostName = name;
+ inherit adminUser;
+ inherit self;
+ hostConfigurations = mapAttrs' (name: conf: {
+ inherit name;
+ value = conf.config;
+ }) nixosConfigurations;
+ inherit inputs;
+ };
+ modules =
+ [
+ {
+ inherit adminUser;
+ }
+ {
+ system.configurationRevision = mkIf (self ? rev) self.rev;
+ system.nixos.versionSuffix = mkForce "git.${substring 0 11 inputs.nixpkgs.rev}";
+ nixpkgs.pkgs = pkgs;
+ environment.systemPackages = [
+ pkgs.git
+ ];
+ }
+ ]
+ ++ defaultModules
+ ++ [
+ hostconf
+ ];
+ }
+ );
+ }
+ ) (mapHosts (mapSystems ../machines/nixos));
+in
+{
+ flake = {
+ inherit nixosConfigurations darwinConfigurations;
+ };
+}
diff --git a/nix/flake/overlays.nix b/nix/flake/overlays.nix
new file mode 100644
index 0000000..83eadd0
--- /dev/null
+++ b/nix/flake/overlays.nix
@@ -0,0 +1,21 @@
+{ inputs, self, ... }:
+{
+
+ flake.overlays.default = _final: prev: {
+ llmPython = prev.callPackage "${self}/pkgs/llmPython/" { };
+ };
+
+ perSystem =
+ { system, ... }:
+ {
+ _module.args.pkgs = import inputs.nixpkgs {
+ inherit system;
+ config.allowUnfree = true;
+ overlays = [
+ inputs.agenix.overlays.default
+ inputs.emacs-overlay.overlay
+ self.overlays.default
+ ];
+ };
+ };
+}
diff --git a/nix/flake/packages.nix b/nix/flake/packages.nix
new file mode 100644
index 0000000..a166803
--- /dev/null
+++ b/nix/flake/packages.nix
@@ -0,0 +1,13 @@
+{ ... }:
+{
+ perSystem =
+ { pkgs, ... }:
+ let
+ mkFcunyNet = import ../../src/fcuny.net { inherit pkgs; };
+ in
+ {
+ packages = {
+ "fcuny_net" = mkFcunyNet.site;
+ };
+ };
+}