From d1d286e89fb8add54cee1bb4002670a178f67a90 Mon Sep 17 00:00:00 2001
From: Julien Moutinho <julm+julm-nix@sourcephile.fr>
Date: Sat, 20 Apr 2024 02:33:02 +0200
Subject: [PATCH] nix: use lib.fileset

---
 flake.nix                               | 63 ++++++++++++++++++++-----
 homes/julm.nix                          |  2 +-
 homes/julm/irssi/{config => irssi.conf} |  0
 3 files changed, 51 insertions(+), 14 deletions(-)
 rename homes/julm/irssi/{config => irssi.conf} (100%)

diff --git a/flake.nix b/flake.nix
index e673021..015fe12 100644
--- a/flake.nix
+++ b/flake.nix
@@ -52,17 +52,50 @@
           overlays = import nixpkgs/overlays.nix;
         };
       });
+      self = with lib.fileset; toSource {
+        root = ./.;
+        fileset =
+          intersection
+            (unions [
+              ./home-manager
+              ./homes
+              ./hosts
+              ./nixos
+              ./nixpkgs
+              ./share
+              ./users
+              ./shell.nix
+            ])
+            (fileFilter
+              (file: lib.any file.hasExt [
+                "clear"
+                "conf"
+                "cred"
+                "crt"
+                "css"
+                "el"
+                "hs"
+                "json"
+                "nix"
+                "patch"
+                "pem"
+                "pub"
+                "sh"
+                "theme"
+                "vim"
+              ]) ./.);
+      };
     in
-    {
+    rec {
       # nix -L build .#hello
       packages = forAllSystems ({ pkgs, ... }: pkgs);
 
       # nix -L build .#nixosConfigurations.oignon.config.system.build.toplevel
       # nix -L build .#nixosConfigurations.oignon.config.boot.kernelPackages.kernel.configfile
       # nix -L build .#nixosConfigurations.oignon.pkgs.hello
-      # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.rulese
+      # nix eval --raw .#nixosConfigurations.oignon.config.networking.nftables.ruleset
       nixosConfigurations = lib.genAttrs
-        (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (inputs.self + "/hosts"))))
+        (builtins.attrNames (lib.filterAttrs (_n: v: v == "directory") (builtins.readDir (self + "/hosts"))))
         (hostName: nixosSystem {
           system = null;
           specialArgs = {
@@ -72,14 +105,14 @@
           };
           modules = [
             nixos/default.nix
-            (import (./hosts + "/${hostName}.nix"))
+            (import (self + "/hosts/${hostName}.nix"))
             {
               _module.args = {
                 inherit hostName;
-                hosts = inputs.self.nixosConfigurations;
-                host = inputs.self.nixosConfigurations.${hostName}._module.args;
+                hosts = nixosConfigurations;
+                host = nixosConfigurations.${hostName}._module.args;
               };
-              nixpkgs.overlays = import nixpkgs/overlays.nix;
+              nixpkgs.overlays = import (self + "/nixpkgs/overlays.nix");
               nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [
                 "anydesk"
                 "cudatoolkit"
@@ -104,11 +137,15 @@
         });
 
       # nix -L develop  or  direnv allow
-      devShell = forAllSystems ({ pkgs, system, ... }: pkgs.callPackage ./shell.nix
+      devShells = forAllSystems ({ pkgs, system, ... }:
         {
-          inherit pkgs inputs system nixpkgsPath;
-          inherit (inputs.self.checks.${system}.pre-commit-check) shellHook;
-        });
+          default = pkgs.callPackage (self + "/shell.nix")
+            {
+              inherit pkgs inputs system nixpkgsPath;
+              inherit (checks.${system}.pre-commit-check) shellHook;
+            };
+        }
+      );
 
       # nix -L run .#oignon.switch
       apps = forAllSystems ({ pkgs, system, ... }:
@@ -166,12 +203,12 @@
                 fi
               '';
             })
-          inputs.self.nixosConfigurations);
+          nixosConfigurations);
 
       # nix flake check
       checks = forAllSystems (args: with args; {
         pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
-          src = inputs.self;
+          src = self;
           hooks = {
             nixpkgs-fmt.enable = true;
           };
diff --git a/homes/julm.nix b/homes/julm.nix
index 0fd7475..b45ba9c 100644
--- a/homes/julm.nix
+++ b/homes/julm.nix
@@ -82,7 +82,7 @@
     #                SHA256:bCfwfC8MQTjm6c1HcMLtzvGpnWRdqLwe/bvbh2jsNaA
     "F6CCA60CF05FADAE911CFBEC0BCDED22F40A19FD"
   ];
-  programs.irssi.extraConfig = lib.readFile julm/irssi/config;
+  programs.irssi.extraConfig = lib.readFile julm/irssi/irssi.conf;
   xdg.configFile."doom/config.el".text = lib.readFile julm/emacs/config.el;
   home.file.".irssi/passwd" = lib.mkIf config.programs.irssi.enable {
     text = ''
diff --git a/homes/julm/irssi/config b/homes/julm/irssi/irssi.conf
similarity index 100%
rename from homes/julm/irssi/config
rename to homes/julm/irssi/irssi.conf
-- 
2.47.0