{ description = "Home Manager configuration"; inputs = { devshell.url = "github:numtide/devshell"; flake-parts = { url = "github:hercules-ci/flake-parts"; inputs.nixpkgs-lib.follows = "nixpkgs"; }; home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; lix-module = { url = "https://git.lix.systems/lix-project/nixos-module/archive/main.tar.gz"; inputs.nixpkgs.follows = "nixpkgs"; }; nixgl = { url = "github:nix-community/nixGL"; inputs.nixpkgs.follows = "nixpkgs"; }; nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; nur.url = "github:nix-community/NUR"; git-hooks-nix.url = "github:cachix/git-hooks.nix"; sops-nix = { url = "github:Mic92/sops-nix"; inputs.nixpkgs.follows = "nixpkgs"; }; treefmt-nix.url = "github:numtide/treefmt-nix"; }; outputs = inputs@{ flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } ( { withSystem, ... }: { systems = [ "aarch64-linux" ]; imports = [ inputs.devshell.flakeModule inputs.git-hooks-nix.flakeModule inputs.home-manager.flakeModules.home-manager inputs.treefmt-nix.flakeModule # ./home/flake-module.nix ]; flake = { # https://nix-community.github.io/home-manager/options.xhtml homeConfigurations = { asahi = withSystem "aarch64-linux" ( { pkgs, ... }: inputs.home-manager.lib.homeManagerConfiguration { inherit pkgs; extraSpecialArgs = { inherit inputs pkgs; }; modules = [ ./home/home.nix inputs.lix-module.nixosModules.default inputs.sops-nix.homeManagerModules.sops { nixpkgs.overlays = [ inputs.nur.overlays.default ]; } ]; } ); }; }; perSystem = { system, config, ... }: let excludes = [ ".vale/*" "home/vencord.nix" ]; deepMerge = lhs: rhs: lhs // rhs // (builtins.mapAttrs ( rName: rValue: let lValue = lhs.${rName} or null; in if builtins.isAttrs lValue && builtins.isAttrs rValue then deepMerge lValue rValue else if builtins.isList lValue && builtins.isList rValue then lValue ++ rValue else rValue ) rhs); pkgs = import inputs.nixpkgs { inherit system; overlays = [ inputs.nur.overlays.default inputs.nixgl.overlays.default ]; }; treefmt = config.treefmt.build.wrapper; langDir = ./languages; langFiles = builtins.attrNames (builtins.readDir langDir); nixFiles = builtins.filter (name: builtins.match ".*\\.nix" name != null) langFiles; configs = map (file: import (langDir + "/${file}") { inherit pkgs treefmt; }) nixFiles; helixLanguages = { language = map (cfg: cfg.helix.language) ( (builtins.filter (cfg: builtins.hasAttr "language" cfg.helix) ( builtins.filter (cfg: builtins.hasAttr "helix" cfg) configs )) ); language-server = builtins.foldl' (acc: cfg: acc // (cfg.helix.language-server or { })) { } configs; }; treefmtPrograms = builtins.foldl' ( acc: cfg: deepMerge acc (cfg.treefmt.programs or { }) ) { } configs; preCommitHooks = builtins.foldl' (acc: cfg: acc // (cfg.pre-commit or { })) { } configs; devshellConfigs = { commands = builtins.concatMap (cfg: cfg.devshell.commands) ( (builtins.filter (cfg: builtins.hasAttr "commands" cfg.devshell) ( builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs )) ); packages = builtins.concatMap (cfg: cfg.devshell.packages) ( (builtins.filter (cfg: builtins.hasAttr "packages" cfg.devshell) ( builtins.filter (cfg: builtins.hasAttr "devshell" cfg) configs )) ); devshellStartup = builtins.foldl' ( acc: cfg: acc // (cfg.devshell.devshellStartup or { }) ) { } configs; }; helixLanguagesFormat = pkgs.formats.toml { }; helixLanguagesFile = helixLanguagesFormat.generate "languages.toml" helixLanguages; in { _module.args.pkgs = pkgs; # https://flake.parts/options/devshell.html devshells.default = { commands = [ { help = "`home-manager switch` for asahi"; name = "switch-asahi"; command = "${pkgs.home-manager}/bin/home-manager switch --flake .#asahi"; } { help = "`home-manager switch` for asahi with backup"; name = "switch-asahi-backup"; command = "${pkgs.home-manager}/bin/home-manager switch --flake .#asahi -b backup"; } { help = "update dependencies"; name = "update"; command = "${pkgs.lix}/bin/nix flake update"; } { help = "show home-manager documentation"; name = "man-home"; command = "${pkgs.man}/bin/man home-configuration.nix"; } { help = "generate Helix grammars"; name = "_helix-grammars"; command = "${pkgs.helix}/bin/hx --grammar fetch && hx --grammar build"; } { help = "generate age key"; name = "_age-generate-key"; command = "${pkgs.uutils-coreutils-noprefix}/bin/mkdir -p ~/.config/sops/age && ${pkgs.age}/bin/age-keygen -o ~/.config/sops/age/keys.txt && ${pkgs.uutils-coreutils-noprefix}/bin/cat ~/.config/sops/age/keys.txt"; } { help = "edit secrets.yaml"; name = "sops-edit"; command = "${pkgs.sops}/bin/sops edit ./home/secrets/secrets.yaml"; } ] ++ devshellConfigs.commands; packages = [ pkgs.age pkgs.forgejo-cli pkgs.git pkgs.helix pkgs.home-manager pkgs.jujutsu pkgs.lix pkgs.man pkgs.sops pkgs.uutils-coreutils-noprefix ] ++ devshellConfigs.packages; devshell = { motd = '' {202}🔨 Nix Laptop Configuration{reset} $(type -p menu &>/dev/null && menu) ''; name = "Laptop Configuration"; startup = devshellConfigs.devshellStartup // { # https://github.com/helix-editor/helix/blob/master/languages.toml # https://helix-editor.vercel.app/reference/formatters # https://docs.helix-editor.com/lang-support.html helix_config = { text = '' mkdir -p .helix ${pkgs.uutils-coreutils-noprefix}/bin/ln -fs ${helixLanguagesFile} ./.helix/languages.toml ''; }; pre-commit.text = '' ${config.pre-commit.installationScript} ''; }; }; }; # https://flake.parts/options/git-hooks-nix.html pre-commit.settings = { hooks = preCommitHooks // { treefmt = { enable = true; package = treefmt; }; check-merge-conflicts.enable = true; check-symlinks.enable = true; flake-checker.enable = true; }; excludes = excludes; }; # https://flake.parts/options/treefmt-nix.html treefmt = { projectRootFile = "flake.nix"; programs = treefmtPrograms; settings.global.excludes = excludes; }; }; } ); }