From 34ba3638fbbac7a01ed1b3af86083b7365ec524d Mon Sep 17 00:00:00 2001 From: toastal Date: Thu, 24 Aug 2023 09:51:41 +0700 Subject: [PATCH] flake: rm flake-utils dependency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pulling in an entire dependency to call a for-loop is wasteful & largely useless. When user adds this module to their config, flake-utils & all of its subdependencies will be pulled into the user’s flake.lock file. This for-loop was only being used for the developer shell to which a lot of folks probably aren’t doing active developments in this project as the module itself doesn’t require it. Potentially damagingly is that this project lacks its own flake.lock so the latest flake-utils will always be downloaded regardless of if it that version is compatible or not. Additionally, flake-utils’ default system list doesn’t include i686-linux which upstream Python3 in Nixpkgs does. The alternative solution to these problems is to remove the dependency & just write a for-loop in this project. This solution could be more or less robust, but it is an extensible version of that loop that could handle overlays or config changes if needed in the future. --- flake.nix | 87 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/flake.nix b/flake.nix index f658948b28d..c1b1bcb1723 100644 --- a/flake.nix +++ b/flake.nix @@ -1,45 +1,50 @@ { description = "Unified hosts file with base extensions."; - inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { self, nixpkgs, flake-utils }: { - nixosModule = { config, ... }: - with nixpkgs.lib; - let - cfg = config.networking.stevenBlackHosts; - alternatesList = (if cfg.blockFakenews then [ "fakenews" ] else []) ++ - (if cfg.blockGambling then [ "gambling" ] else []) ++ - (if cfg.blockPorn then [ "porn" ] else []) ++ - (if cfg.blockSocial then [ "social" ] else []); - alternatesPath = "alternates/" + builtins.concatStringsSep "-" alternatesList + "/"; - in - { - options.networking.stevenBlackHosts = { - enable = mkEnableOption "Use Steven Black's hosts file as extra hosts."; - blockFakenews = mkEnableOption "Additionally block fakenews hosts."; - blockGambling = mkEnableOption "Additionally block gambling hosts."; - blockPorn = mkEnableOption "Additionally block porn hosts."; - blockSocial = mkEnableOption "Additionally block social hosts."; + outputs = { self, nixpkgs, ... }@inputs: + let + forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.platforms.unix; + + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + }); + in + { + nixosModule = { config, ... }: + with nixpkgs.lib; + let + cfg = config.networking.stevenBlackHosts; + alternatesList = (if cfg.blockFakenews then [ "fakenews" ] else []) ++ + (if cfg.blockGambling then [ "gambling" ] else []) ++ + (if cfg.blockPorn then [ "porn" ] else []) ++ + (if cfg.blockSocial then [ "social" ] else []); + alternatesPath = "alternates/" + builtins.concatStringsSep "-" alternatesList + "/"; + in + { + options.networking.stevenBlackHosts = { + enable = mkEnableOption "Use Steven Black's hosts file as extra hosts."; + blockFakenews = mkEnableOption "Additionally block fakenews hosts."; + blockGambling = mkEnableOption "Additionally block gambling hosts."; + blockPorn = mkEnableOption "Additionally block porn hosts."; + blockSocial = mkEnableOption "Additionally block social hosts."; + }; + config = mkIf cfg.enable { + networking.extraHosts = + builtins.readFile ( + "${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts" + ); + }; }; - config = mkIf cfg.enable { - networking.extraHosts = - builtins.readFile ( - "${self}/" + (if alternatesList != [] then alternatesPath else "") + "hosts" - ); - }; - }; - } // flake-utils.lib.eachDefaultSystem - (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShell = pkgs.mkShell { - buildInputs = with pkgs; [ - python3 - python3Packages.flake8 - python3Packages.requests - ]; - }; - } - ); + + devShells = forAllSystems (system: + let pkgs = nixpkgsFor.${system}; in + { + default = pkgs.mkShell { + buildInputs = with pkgs; [ + python3 + python3Packages.flake8 + python3Packages.requests + ]; + }; + }); + }; }