diff --git a/doc/default.nix b/doc/default.nix index af51265d..39ee9e6c 100644 --- a/doc/default.nix +++ b/doc/default.nix @@ -13,6 +13,9 @@ }: let + # Prefix to remove from option declaration file paths. + rootPrefix = toString ../. + "/"; + nixosConfiguration = nixosSystem { inherit system; modules = [ @@ -50,7 +53,7 @@ let }; }; - metadata = callPackage "${inputs.self}/stylix/meta.nix" { inherit inputs; }; + metadata = callPackage ../stylix/meta.nix { }; # We construct an index of all Stylix options, using the following format: # @@ -119,15 +122,10 @@ let option, }: # Only include options which are declared by a module within Stylix. - if lib.hasPrefix "${inputs.self}/" declaration then + if lib.hasPrefix rootPrefix declaration then let - # Part of this string may become an attribute name in the index, and - # attribute names aren't allowed to have string context. The context - # comes from `${inputs.self}`, which is removed by `removePrefix`. - # Therefore, this use of `unsafeDiscardStringContext` is safe. - pathWithContext = lib.removePrefix "${inputs.self}/" declaration; - path = builtins.unsafeDiscardStringContext pathWithContext; - pathComponents = lib.splitString "/" path; + subPath = lib.removePrefix rootPrefix (toString declaration); + pathComponents = lib.splitString "/" subPath; in # Options declared in the modules directory go to the Modules section, # otherwise they're assumed to be shared between modules, and go to the @@ -236,29 +234,30 @@ let }; } else - insert { - inherit index platform option; + let page = "src/options/platforms/${platform}.md"; + path = ./. + "/${page}"; + in + insert { + inherit + index + platform + page + option + ; emptyPage = { referenceSection = "Platforms"; readme = - let - path = "${inputs.self}/doc/src/options/platforms/${platform}.md"; - - # This doesn't count as IFD because ${inputs.self} is a flake input - mainText = - if builtins.pathExists path then - builtins.readFile path - else - '' - # ${platform.name} - > [!NOTE] - > Documentation is not available for this platform. Its - > main options are listed below, and you may find more - > specific options in the documentation for each module. - ''; - in - mainText; + if builtins.pathExists path then + builtins.readFile path + else + '' + # ${platform.name} + > [!NOTE] + > Documentation is not available for this platform. Its + > main options are listed below, and you may find more + > specific options in the documentation for each module. + ''; # Platform pages only initialise that platform, since showing other # platforms here would be nonsensical. @@ -339,9 +338,6 @@ let else throw "unexpected value type: ${builtins.typeOf value}"; - # Prefix to remove from file paths when listing where an option is declared. - declarationPrefix = "${inputs.self}"; - # Permalink to view a source file on GitHub. If the commit isn't known, # then fall back to the latest commit. declarationCommit = inputs.self.rev or "master"; @@ -354,12 +350,11 @@ let declaration: let declarationString = toString declaration; - filePath = lib.removePrefix "${declarationPrefix}/" declarationString; + subPath = lib.removePrefix rootPrefix declarationString; in - if lib.hasPrefix declarationPrefix declarationString then - "- [${filePath}](${declarationPermalink}/${filePath})" - else - throw "declaration not in ${declarationPrefix}: ${declarationString}"; + lib.throwIfNot (lib.hasPrefix rootPrefix declarationString) + "declaration not in ${rootPrefix}: ${declarationString}" + "- [${subPath}](${declarationPermalink}/${subPath})"; # You can embed HTML inside a Markdown document, but to render further # Markdown between the HTML tags, it must be surrounded by blank lines: diff --git a/flake/modules.nix b/flake/modules.nix index f1f16d72..adf315a6 100644 --- a/flake/modules.nix +++ b/flake/modules.nix @@ -10,7 +10,7 @@ { pkgs, ... }@args: { imports = [ - (lib.modules.importApply "${self}/stylix/nixos" inputs) + ../stylix/nixos { stylix = { inherit inputs; @@ -27,7 +27,7 @@ { pkgs, ... }@args: { imports = [ - (lib.modules.importApply "${self}/stylix/hm" inputs) + ../stylix/hm { stylix = { inherit inputs; @@ -43,7 +43,7 @@ { pkgs, ... }@args: { imports = [ - (lib.modules.importApply "${self}/stylix/darwin" inputs) + ../stylix/darwin { stylix = { inherit inputs; @@ -60,7 +60,7 @@ { pkgs, ... }@args: { imports = [ - (lib.modules.importApply "${self}/stylix/droid" inputs) + ../stylix/droid { stylix = { paletteGenerator = diff --git a/flake/packages.nix b/flake/packages.nix index 53f57637..6b371cf6 100644 --- a/flake/packages.nix +++ b/flake/packages.nix @@ -1,9 +1,4 @@ -{ - lib, - inputs, - self, - ... -}: +{ lib, inputs, ... }: { perSystem = @@ -17,17 +12,17 @@ # Testbeds are virtual machines based on NixOS, therefore they are # only available for Linux systems. (lib.mkIf pkgs.stdenv.hostPlatform.isLinux ( - import "${self}/stylix/testbed/default.nix" { + import ../stylix/testbed/default.nix { inherit pkgs inputs lib; } )) { - docs = pkgs.callPackage "${self}/doc" { + docs = pkgs.callPackage ../doc { inherit inputs; inherit (inputs.nixpkgs.lib) nixosSystem; inherit (inputs.home-manager.lib) homeManagerConfiguration; }; - palette-generator = pkgs.callPackage "${self}/palette-generator" { }; + palette-generator = pkgs.callPackage ../palette-generator { }; } ]; }; diff --git a/stylix/autoload.nix b/stylix/autoload.nix index 5d952e05..34782fbd 100644 --- a/stylix/autoload.nix +++ b/stylix/autoload.nix @@ -1,13 +1,13 @@ -{ lib, inputs }: +{ lib }: # string -> [ path ] # List include path for either nixos modules or hm modules -for: +platform: builtins.concatLists ( lib.mapAttrsToList ( - path: kind: + target: kind: let - file = "${inputs.self}/modules/${path}/${for}.nix"; + file = ../modules/${target}/${platform}.nix; module = import file; # Detect whether the file's value has an argument named `mkTarget` @@ -47,5 +47,5 @@ builtins.concatLists ( else file ) - ) (builtins.readDir "${inputs.self}/modules") + ) (builtins.readDir ../modules) ) diff --git a/stylix/darwin/default.nix b/stylix/darwin/default.nix index fc9e3e1c..499ff7bf 100644 --- a/stylix/darwin/default.nix +++ b/stylix/darwin/default.nix @@ -1,29 +1,24 @@ -inputs: { lib, config, ... }: -# Imported modules which define new options must use an absolute path based -# on ${inputs.self}, otherwise those options will not appear in the generated -# documentation. - let - autoload = import ../autoload.nix { inherit lib inputs; } "darwin"; + autoload = import ../autoload.nix { inherit lib; } "darwin"; in { imports = [ - "${inputs.self}/stylix/darwin/fonts.nix" - "${inputs.self}/stylix/darwin/palette.nix" - "${inputs.self}/stylix/fonts.nix" - "${inputs.self}/stylix/home-manager-integration.nix" - "${inputs.self}/stylix/opacity.nix" - "${inputs.self}/stylix/palette.nix" - "${inputs.self}/stylix/pixel.nix" - "${inputs.self}/stylix/target.nix" - "${inputs.self}/stylix/release.nix" - (lib.modules.importApply "${inputs.self}/stylix/overlays.nix" inputs) + ./fonts.nix + ./palette.nix + ../fonts.nix + ../home-manager-integration.nix + ../opacity.nix + ../palette.nix + ../pixel.nix + ../target.nix + ../release.nix + ../overlays.nix ] ++ autoload; config.warnings = lib.mkIf diff --git a/stylix/droid/default.nix b/stylix/droid/default.nix index 80cdeba9..1f21cebe 100644 --- a/stylix/droid/default.nix +++ b/stylix/droid/default.nix @@ -1,18 +1,17 @@ -inputs: { lib, ... }: let - autoload = import ../autoload.nix { inherit lib inputs; } "droid"; + autoload = import ../autoload.nix { inherit lib; } "droid"; in { imports = [ - "${inputs.self}/stylix/fonts.nix" - "${inputs.self}/stylix/home-manager-integration.nix" - "${inputs.self}/stylix/opacity.nix" - "${inputs.self}/stylix/palette.nix" - "${inputs.self}/stylix/pixel.nix" - "${inputs.self}/stylix/target.nix" - (lib.modules.importApply "${inputs.self}/stylix/overlays.nix" inputs) + ../fonts.nix + ../home-manager-integration.nix + ../opacity.nix + ../palette.nix + ../pixel.nix + ../target.nix + ../overlays.nix ] ++ autoload; # See https://github.com/nix-community/nix-on-droid/issues/436 diff --git a/stylix/hm/default.nix b/stylix/hm/default.nix index 0c7e5ae8..773881ce 100644 --- a/stylix/hm/default.nix +++ b/stylix/hm/default.nix @@ -1,32 +1,27 @@ -inputs: { lib, config, ... }: -# Imported modules which define new options must use an absolute path based -# on ${inputs.self}, otherwise those options will not appear in the generated -# documentation. - let - autoload = import ../autoload.nix { inherit lib inputs; } "hm"; + autoload = import ../autoload.nix { inherit lib; } "hm"; in { imports = [ - "${inputs.self}/stylix/cursor.nix" - "${inputs.self}/stylix/fonts.nix" - "${inputs.self}/stylix/hm/cursor.nix" - "${inputs.self}/stylix/hm/fonts.nix" - "${inputs.self}/stylix/hm/icon.nix" - "${inputs.self}/stylix/hm/palette.nix" - "${inputs.self}/stylix/icon.nix" - "${inputs.self}/stylix/opacity.nix" - "${inputs.self}/stylix/palette.nix" - "${inputs.self}/stylix/pixel.nix" - "${inputs.self}/stylix/target.nix" - "${inputs.self}/stylix/release.nix" - (lib.modules.importApply "${inputs.self}/stylix/overlays.nix" inputs) + ./cursor.nix + ./fonts.nix + ./icon.nix + ./palette.nix + ../cursor.nix + ../fonts.nix + ../icon.nix + ../opacity.nix + ../palette.nix + ../pixel.nix + ../target.nix + ../release.nix + ../overlays.nix ] ++ autoload; config.warnings = lib.mkIf diff --git a/stylix/meta.nix b/stylix/meta.nix index 4bedd1b2..9a6763a6 100644 --- a/stylix/meta.nix +++ b/stylix/meta.nix @@ -1,16 +1,14 @@ { pkgs, lib, - inputs, - ... }: builtins.mapAttrs ( _: value: - if (builtins.typeOf value == "lambda") then + if builtins.isFunction value then (value { inherit pkgs; - lib = pkgs.lib.extend ( + lib = lib.extend ( _: prev: { maintainers = lib.attrsets.unionOfDisjoint prev.maintainers (import ./maintainers.nix); } @@ -21,9 +19,9 @@ builtins.mapAttrs ) ( lib.concatMapAttrs ( - path: kind: + target: kind: lib.optionalAttrs (kind == "directory") { - ${path} = import "${inputs.self}/modules/${path}/meta.nix"; + ${target} = import ../modules/${target}/meta.nix; } - ) (builtins.readDir "${inputs.self}/modules") + ) (builtins.readDir ../modules) ) diff --git a/stylix/nixos/default.nix b/stylix/nixos/default.nix index d08b5314..d5988bce 100644 --- a/stylix/nixos/default.nix +++ b/stylix/nixos/default.nix @@ -1,31 +1,26 @@ -inputs: { lib, config, ... }: -# Imported modules which define new options must use an absolute path based -# on ${inputs.self}, otherwise those options will not appear in the generated -# documentation. - let - autoload = import ../autoload.nix { inherit lib inputs; } "nixos"; + autoload = import ../autoload.nix { inherit lib; } "nixos"; in { imports = [ - "${inputs.self}/stylix/cursor.nix" - "${inputs.self}/stylix/fonts.nix" - "${inputs.self}/stylix/home-manager-integration.nix" - "${inputs.self}/stylix/nixos/cursor.nix" - "${inputs.self}/stylix/nixos/fonts.nix" - "${inputs.self}/stylix/nixos/palette.nix" - "${inputs.self}/stylix/opacity.nix" - "${inputs.self}/stylix/palette.nix" - "${inputs.self}/stylix/pixel.nix" - "${inputs.self}/stylix/target.nix" - "${inputs.self}/stylix/release.nix" - (lib.modules.importApply "${inputs.self}/stylix/overlays.nix" inputs) + ./cursor.nix + ./fonts.nix + ./palette.nix + ../cursor.nix + ../fonts.nix + ../home-manager-integration.nix + ../opacity.nix + ../palette.nix + ../pixel.nix + ../target.nix + ../release.nix + ../overlays.nix ] ++ autoload; config.warnings = lib.mkIf diff --git a/stylix/overlays.nix b/stylix/overlays.nix index aefb45e4..3285c2f5 100644 --- a/stylix/overlays.nix +++ b/stylix/overlays.nix @@ -1,4 +1,3 @@ -inputs: { lib, pkgs, @@ -33,5 +32,5 @@ inputs: attrs.overlay ]; } - ) (import ./autoload.nix { inherit lib inputs; } "overlay"); + ) (import ./autoload.nix { inherit lib; } "overlay"); } diff --git a/stylix/testbed/default.nix b/stylix/testbed/default.nix index 12ba1727..bcb61484 100644 --- a/stylix/testbed/default.nix +++ b/stylix/testbed/default.nix @@ -8,43 +8,40 @@ let isEnabled = pkgs.callPackage ./is-enabled.nix { }; - autoload = - let - directory = "testbeds"; - modules = "${inputs.self}/modules"; - in - lib.pipe modules [ - builtins.readDir - builtins.attrNames - (builtins.concatMap ( - module: + autoload = lib.pipe ../../modules [ + builtins.readDir + builtins.attrNames + (builtins.concatMap ( + module: + let + testbeds = ../../modules/${module}/testbeds; + files = lib.optionalAttrs (builtins.pathExists testbeds) ( + builtins.readDir testbeds + ); + in + lib.mapAttrsToList ( + testbed: type: let - testbeds = "${modules}/${module}/${directory}"; - files = lib.optionalAttrs (builtins.pathExists testbeds) ( - builtins.readDir testbeds - ); + path = testbeds + "/${testbed}"; + pathStr = toString path; in - lib.mapAttrsToList ( - testbed: type: - if type != "regular" then - throw "${testbed} must be regular: ${type}" + if type != "regular" then + throw "${pathStr} must be regular: ${type}" - else if !lib.hasSuffix ".nix" testbed then - throw "testbed must be a Nix file: ${testbeds}/${testbed}" + else if !lib.hasSuffix ".nix" testbed then + throw "testbed must be a Nix file: ${pathStr}" - else if testbed == ".nix" then - throw "testbed must have a name: ${testbed}" + else if testbed == ".nix" then + throw "testbed must have a name: ${pathStr}" - else - { - inherit module; - - name = lib.removeSuffix ".nix" testbed; - path = "${testbeds}/${testbed}"; - } - ) files - )) - ]; + else + { + inherit module path; + name = lib.removeSuffix ".nix" testbed; + } + ) files + )) + ]; makeTestbed = testbed: themeName: themeModule: