aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2022-09-22 18:05:34 -0700
committerFranck Cuny <franck@fcuny.net>2022-09-22 18:05:34 -0700
commit4f1513dfa4fc22240ab7dcbe1c60c14f827645a7 (patch)
treeb81a45ae768dc2620d54e3b6a41b2c485d1f6aac /flake.nix
parentref(flake): move all the checks to external module (diff)
downloadinfra-4f1513dfa4fc22240ab7dcbe1c60c14f827645a7.tar.gz
ref(home-manager): don't use home-manager when building the host
When rebuilding the host (through `nixos-rebuild switch --flake`) I don't want to rebuild also my home-manager configuration. I want these to be two different steps. I rebuild the home-manager configuration more frequently and it's a waste of time and CPU to rebuild the world every time. This is a pretty large refactoring: - move checks back into the flake: if I modify a check, the configuration for `pre-commits` is not regenerated, as the file with the checks is not monitored with `direnv` (I could probably configure it for it, but not now) - remove `home.nix` from the host level configuration - introduce a `mkHomeManagerConfiguration` function to manage the different user@host - fix a warning with the rust overlay
Diffstat (limited to '')
-rw-r--r--flake.nix149
1 files changed, 107 insertions, 42 deletions
diff --git a/flake.nix b/flake.nix
index 125e214..f659025 100644
--- a/flake.nix
+++ b/flake.nix
@@ -2,14 +2,11 @@
description = "personal NixOS configurations";
inputs = {
- # Nixpkgs, NixOS's official repo
nixpkgs.url = "github:nixos/nixpkgs/release-22.05";
+ nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
futils.url = "github:numtide/flake-utils";
- # We use the unstable nixpkgs repo for some packages.
- nixpkgs-unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable";
-
emacs-overlay.url = "github:nix-community/emacs-overlay";
agenix = {
@@ -43,52 +40,120 @@
};
# Output config, or config for NixOS system
- outputs = { self, pre-commit-hooks, ... }@inputs:
+ outputs = inputs@{ self, ... }:
let
- inherit (inputs.futils.lib) eachSystem system;
- mySystems = [ system.x86_64-linux ];
- eachMySystem = eachSystem mySystems;
- lib = import ./nix { inherit inputs; };
+ myLib = import ./nix inputs;
+ lib = inputs.nixpkgs.lib // builtins;
+ supportedSystems = [ "x86_64-linux" ];
+ forAllSystems = lib.genAttrs supportedSystems;
+
+ # Nixpkgs instantiated for supported system types.
+ nixpkgsFor = forAllSystems (system:
+ import inputs.nixpkgs {
+ inherit system;
+ config = { allowUnfree = true; };
+ });
in
- eachMySystem
- (system:
- let
- pkgs = import inputs.nixpkgs { inherit system; };
- home-manager = inputs.home-manager.defaultPackage."${system}";
+ {
+ checks = forAllSystems (system:
+ let pkgs = nixpkgsFor.${system};
in
- rec {
- packages = pkgs // {
- inherit home-manager;
+ {
+ pre-commit-check = inputs.pre-commit-hooks.lib."${system}".run {
+ src = ./.;
+ hooks = {
+ nixpkgs-fmt.enable = true;
+ terraform-format.enable = true;
+ trailing-whitespace = {
+ enable = true;
+ entry =
+ "${pkgs.python3Packages.pre-commit-hooks}/bin/trailing-whitespace-fixer";
+ types = [ "text" ];
+ };
- tools = import ./tools { inherit pkgs; };
- ops = import ./ops { inherit pkgs; };
- users.fcuny = import ./users/fcuny { inherit pkgs; };
- };
+ end-of-file-fixer = {
+ enable = true;
+ entry =
+ "${pkgs.python3Packages.pre-commit-hooks}/bin/end-of-file-fixer";
+ types = [ "text" ];
+ };
+
+ check-executables-have-shebangs = {
+ entry =
+ "${pkgs.python3Packages.pre-commit-hooks}/check-executables-have-shebangs";
+ types = [ "text" "executable" ];
+ };
+
+ check-json = {
+ enable = true;
+ entry = "${pkgs.python3Packages.pre-commit-hooks}/check-json";
+ types = [ "json" ];
+ };
+
+ check-toml = {
+ enable = true;
+ entry = "${pkgs.python3Packages.pre-commit-hooks}/check-toml";
+ types = [ "toml" ];
+ };
- checks = import ./nix/checks.nix { inherit pkgs pre-commit-hooks; };
-
- devShells = {
- default = pkgs.mkShell {
- name = "NixOS-config";
- buildInputs = with pkgs; [
- gitAndTools.pre-commit
- nixUnstable
- nixfmt
- nixpkgs-fmt
- rnix-lsp
- home-manager
- git
- go
- gopls
- ];
- inherit (self.checks.${system}.pre-commit-check) shellHook;
+ check-yaml = {
+ enable = true;
+ entry = "${pkgs.python3Packages.pre-commit-hooks}/check-yaml";
+ types = [ "yaml" ];
+ };
+
+ shellcheck = {
+ enable = true;
+ files = "\\.sh$";
+ types_or = [ "file" ];
+ };
};
};
- }) // {
+ });
+
+ devShells = forAllSystems (system: {
+ default = inputs.nixpkgs.legacyPackages.${system}.mkShell {
+ name = "fcuny-configuration-on-${system}-system";
+ buildInputs = with inputs.nixpkgs.legacyPackages.${system}.pkgs; [
+ gitAndTools.pre-commit
+ nixfmt
+ nixpkgs-fmt
+ rnix-lsp
+ home-manager
+ git
+ nixos-rebuild
+ ];
+ inherit (self.checks.${system}.pre-commit-check) shellHook;
+ };
+ });
+
nixosConfigurations = {
- carmel = lib.mkSystem { hostname = "carmel"; };
- aptos = lib.mkSystem { hostname = "aptos"; };
- tahoe = lib.mkSystem { hostname = "tahoe"; };
+ aptos = myLib.mkSystem { hostname = "aptos"; };
+ carmel = myLib.mkSystem { hostname = "carmel"; };
+ tahoe = myLib.mkSystem { hostname = "tahoe"; };
+ };
+
+ homeConfigurations = {
+ useGlobalPkgs = true;
+ useUserPackages = true;
+
+ "fcuny@aptos" =
+ myLib.mkHomeManagerConfiguration { hostname = "aptos"; };
+
+ "fcuny@tahoe" =
+ myLib.mkHomeManagerConfiguration { hostname = "tahoe"; };
};
};
+ # in eachMySystem (system:
+ # let
+ # pkgs = import inputs.nixpkgs { inherit system; };
+ # home-manager = inputs.home-manager.defaultPackage."${system}";
+ # in rec {
+ # packages = pkgs // {
+ # inherit home-manager;
+
+ # tools = import ./tools { inherit pkgs; };
+ # ops = import ./ops { inherit pkgs; };
+ # users.fcuny = import ./users/fcuny { inherit pkgs; };
+ # };
}