diff --git a/flake.nix b/flake.nix index 50ad429..3dc6cb9 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,37 @@ { description = "A simple NixOS flakes"; + outputs = { + nixpkgs, + flake-parts, + flake-utils, + home-manager, + treefmt-nix, + ... + } @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = flake-utils.lib.defaultSystems; + imports = [ + home-manager.flakeModules.home-manager + treefmt-nix.flakeModule + + ./flake + ]; + flake = { + nix.settings = { + # substituters shared in home-manager and nixos configuration + substituters = let + cachix = x: "https://${x}.cachix.org"; + in + nixpkgs.lib.flatten [ + (cachix "nix-community") + "https://cache.nixos.org" + (cachix "cosmic") + ]; + }; + }; + }; + inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small"; @@ -140,130 +171,4 @@ repo = "treefmt-nix"; }; }; - outputs = { - self, - nixpkgs, - flake-parts, - flake-utils, - ... - } @ inputs: - flake-parts.lib.mkFlake {inherit inputs;} ({flake-parts-lib, ...}: let - inherit (self) outputs; - inherit (flake-parts-lib) importApply; - rootPath = ./.; - nixos = importApply ./flake/nixos.nix {inherit rootPath outputs;}; - home = importApply ./flake/home.nix {inherit rootPath outputs;}; - deploy = importApply ./flake/deploy.nix {inherit outputs;}; - templates = importApply ./flake/templates.nix {inherit rootPath;}; - in { - systems = flake-utils.lib.defaultSystems; - imports = [ - inputs.home-manager.flakeModules.home-manager - inputs.treefmt-nix.flakeModule - nixos - home - deploy - templates - ]; - perSystem = { - pkgs, - system, - ... - } @ args: { - _module.args.pkgs = import inputs.nixpkgs { - inherit system; - config = { - allowUnfree = true; - }; - }; - packages = import ./pkgs ( - args - // { - inherit inputs rootPath; - } - ); - devShells.default = pkgs.mkShell { - packages = with pkgs; [ - nixd - typos - typos-lsp - just - nvfetcher - ]; - }; - treefmt = { - programs = { - alejandra = { - enable = true; - excludes = ["pkgs/_sources/*.nix"]; - }; - biome = { - enable = true; - includes = ["*.json"]; - excludes = ["pkgs/_sources/*.json"]; - settings = { - javascript.formatter.enabled = false; - css.formatter.enabled = false; - }; - }; - dprint = { - enable = true; - includes = ["*.md" "*.toml" "*.yaml"]; - excludes = ["secrets/*.yaml"]; - settings = { - plugins = pkgs.dprint-plugins.getPluginList (plugins: - with plugins; [ - dprint-plugin-toml - dprint-plugin-markdown - g-plane-pretty_yaml - ]); - }; - }; - just = { - enable = true; - includes = [".justfile"]; - }; - typos = let - config = ./.typos.toml |> builtins.readFile |> builtins.fromTOML; - in { - enable = true; - includes = ["*"]; - excludes = ["assets/*"] ++ config.files.extend-exclude; - configFile = "${toString ./.typos.toml}"; - # Disable all extra option in treefmt module. - # Use config file. - sort = false; - isolated = false; - hidden = false; - noIgnore = false; - noIgnoreDot = false; - noIgnoreGlobal = false; - noIgnoreParent = false; - noIgnoreVCS = false; - binary = false; - noCheckFilenames = false; - noCheckFiles = false; - noUnicode = false; - }; - }; - }; - }; - flake = { - overlays = { - modifications = import ./overlays/modifications {inherit inputs outputs;}; - additions = import ./overlays/additions {inherit inputs outputs;}; - }; - nix.settings = { - # substituters shared in home-manager and nixos configuration - substituters = let - cachix = x: "https://${x}.cachix.org"; - in - nixpkgs.lib.flatten [ - (cachix "nix-community") - "https://cache.nixos.org" - (cachix "cosmic") - ]; - }; - }; - }); } diff --git a/flake/default.nix b/flake/default.nix new file mode 100644 index 0000000..b2c10cc --- /dev/null +++ b/flake/default.nix @@ -0,0 +1,10 @@ +{ + imports = [ + ./nixos.nix + ./home.nix + ./templates.nix + ./perSystem.nix + ./deploy.nix + ./overlays.nix + ]; +} diff --git a/flake/deploy.nix b/flake/deploy.nix index 5741f9b..3f86808 100644 --- a/flake/deploy.nix +++ b/flake/deploy.nix @@ -1,9 +1,12 @@ -{outputs}: { +{ lib, inputs, flake-parts-lib, + self, ... }: let + inherit (self) outputs; + inherit (inputs) deploy-rs; mkDeployNode = { hostName, unixName ? "deploy", @@ -18,7 +21,7 @@ system = { user = "root"; path = - inputs.deploy-rs.lib."${system}".activate.nixos + deploy-rs.lib."${system}".activate.nixos outputs.nixosConfigurations."${hostName}"; }; }; diff --git a/flake/home.nix b/flake/home.nix index a80b0c2..a4a5aff 100644 --- a/flake/home.nix +++ b/flake/home.nix @@ -1,17 +1,13 @@ { - outputs, - rootPath, -}: { lib, inputs, + self, ... }: let + rootPath = ./..; + inherit (self) outputs; homeModules = - { - default = import "${toString rootPath}/home/modules"; - extra = import "${toString rootPath}/home/extra"; - } - // ( + ( (rootPath + "/home") |> builtins.readDir |> lib.filterAttrs (key: value: value == "directory") @@ -23,13 +19,13 @@ ] ) |> builtins.attrNames - |> map (name: { - name = name; - value = import "${toString rootPath}/home/${name}/modules"; - }) - |> builtins.listToAttrs - ); - mkHomeConfig = { + |> (with lib; flip genAttrs (name: import (rootPath + "/home/${name}/modules"))) + ) + // { + default = import "${toString rootPath}/home/modules"; + extra = import "${toString rootPath}/home/extra"; + }; + makeHomeConfiguration = { hostName, unixName ? "david", system ? "x86_64-linux", @@ -37,10 +33,12 @@ home-manager ? inputs.home-manager, }: { "${unixName}@${hostName}" = home-manager.lib.homeManagerConfiguration { - pkgs = nixpkgs.legacyPackages."${system}"; + pkgs = import nixpkgs { + inherit system; + }; modules = [ - "${toString rootPath}/home/${unixName}/configurations/${hostName}" + (rootPath + "/home/${unixName}/configurations/${hostName}") ] ++ (with homeModules; [ default @@ -67,7 +65,7 @@ in { [ # Hostname ] - |> map (hostName: mkHomeConfig {inherit hostName;}) + |> map (hostName: makeHomeConfiguration {inherit hostName;}) ); inherit homeModules; }; diff --git a/flake/nixos.nix b/flake/nixos.nix index 519cab5..10cd557 100644 --- a/flake/nixos.nix +++ b/flake/nixos.nix @@ -1,42 +1,37 @@ { - rootPath, - outputs, -}: {inputs, ...}: let + inputs, + lib, + self, + ... +}: let + rootPath = ./..; + inherit (self) outputs; + inherit (inputs) nixpkgs; defaultNixosModule = import (rootPath + "/nixos/modules"); - inherit (inputs.nixpkgs) lib; in { flake = { nixosModules.default = defaultNixosModule; nixosConfigurations = let - nixosConfigDir = rootPath + "/nixos/configurations"; makeNixConfiguration = hostName: - lib.nixosSystem { + nixpkgs.lib.nixosSystem { modules = [defaultNixosModule] ++ [ - ( - let - dirPath = nixosConfigDir + "/${hostName}"; - filePath = nixosConfigDir + "/${hostName}.nix"; - in - if builtins.pathExists dirPath - then dirPath - else filePath - ) + (rootPath + "/nixos/configurations/${hostName}") ]; specialArgs = { inherit inputs outputs rootPath; }; }; in - nixosConfigDir - |> builtins.readDir - |> builtins.attrNames - |> map (f: lib.removeSuffix ".nix" f) - |> map (name: { - inherit name; - value = makeNixConfiguration name; - }) - |> builtins.listToAttrs; + [ + "Tytonidae" + "Cape" + "Akun" + ] + |> ( + with lib; + flip genAttrs makeNixConfiguration + ); }; } diff --git a/flake/overlays.nix b/flake/overlays.nix new file mode 100644 index 0000000..05cedf1 --- /dev/null +++ b/flake/overlays.nix @@ -0,0 +1,17 @@ +{ + self, + inputs, + lib, + ... +}: let + rootPath = ./..; + inherit (self) outputs; + importWithArgs = lib.flip import {inherit inputs outputs;}; +in { + flake.overlays = + [ + "modifications" + "additions" + ] + |> (with lib; flip genAttrs (name: importWithArgs (rootPath + "/overlays/${name}"))); +} diff --git a/flake/perSystem.nix b/flake/perSystem.nix new file mode 100644 index 0000000..b13a179 --- /dev/null +++ b/flake/perSystem.nix @@ -0,0 +1,35 @@ +{inputs, ...}: let + rootPath = ./..; +in { + imports = [ + (rootPath + "/treefmt.nix") + ]; + perSystem = { + pkgs, + system, + lib, + self', + ... + }: let + inherit (inputs) nixpkgs; + callPackages = lib.callPackagesWith (pkgs // {inherit callPackages inputs rootPath;}); + in { + _module.args.pkgs = import nixpkgs { + inherit system; + config = { + allowUnfree = true; + }; + }; + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + nixd + typos + typos-lsp + just + nvfetcher + ]; + }; + packages = callPackages (rootPath + "/pkgs") {}; + checks = self'.packages; + }; +} diff --git a/flake/templates.nix b/flake/templates.nix index 7f71168..a1396f9 100644 --- a/flake/templates.nix +++ b/flake/templates.nix @@ -1,8 +1,10 @@ -{rootPath, ...}: { +{ flake-parts-lib, lib, ... -}: { +}: let + rootPath = ./..; +in { options = { flake = flake-parts-lib.mkSubmoduleOptions { templates = lib.mkOption { diff --git a/pkgs/default.nix b/pkgs/default.nix index 4e4be55..f27dedf 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,11 +1,13 @@ { - pkgs, inputs, rootPath, + callPackages, + lib, + pkgs, ... }: let - srcs = pkgs.callPackage ./_sources/generated.nix {}; - callPackage = pkgs.lib.callPackageWith (pkgs // {inherit inputs srcs callPackage rootPath;}); + srcs = callPackages ./_sources/generated.nix {}; + callPackage = lib.callPackageWith (pkgs // {inherit inputs srcs callPackage rootPath;}); in { pinentry-selector = callPackage ./pinentry-selector.nix {}; @@ -28,5 +30,5 @@ in let firefox-addons = callPackage "${inputs.nur-rycee}/pkgs/firefox-addons/default.nix" {}; in - pkgs.lib.genAttrs ["immersive-translate" "tridactyl"] (name: firefox-addons."${name}") + lib.genAttrs ["immersive-translate" "tridactyl"] (name: firefox-addons."${name}") ) diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..11f1026 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,60 @@ +{ + perSystem = {pkgs, ...}: { + treefmt = { + programs = { + alejandra = { + enable = true; + excludes = ["pkgs/_sources/*.nix"]; + }; + biome = { + enable = true; + includes = ["*.json"]; + excludes = ["pkgs/_sources/*.json"]; + settings = { + javascript.formatter.enabled = false; + css.formatter.enabled = false; + }; + }; + dprint = { + enable = true; + includes = ["*.md" "*.toml" "*.yaml"]; + excludes = ["secrets/*.yaml"]; + settings = { + plugins = pkgs.dprint-plugins.getPluginList (plugins: + with plugins; [ + dprint-plugin-toml + dprint-plugin-markdown + g-plane-pretty_yaml + ]); + }; + }; + just = { + enable = true; + includes = [".justfile"]; + }; + typos = let + config = ./.typos.toml |> builtins.readFile |> builtins.fromTOML; + in { + enable = true; + includes = ["*"]; + excludes = ["assets/*"] ++ config.files.extend-exclude; + configFile = toString ./.typos.toml; + # Disable all extra option in treefmt module. + # Use config file. + sort = false; + isolated = false; + hidden = false; + noIgnore = false; + noIgnoreDot = false; + noIgnoreGlobal = false; + noIgnoreParent = false; + noIgnoreVCS = false; + binary = false; + noCheckFilenames = false; + noCheckFiles = false; + noUnicode = false; + }; + }; + }; + }; +}