From d4a8025d0649dc98addaac611621d7886175ea60 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Wed, 31 Jul 2024 21:51:40 +0800 Subject: [PATCH] wrapper-manager-fds: reformat codebase --- docs/default.nix | 113 ++-- docs/gemset.nix | 300 ++++++---- docs/hugo-build-module.nix | 545 ++++++++++-------- docs/website/shell.nix | 4 +- flake.nix | 98 ++-- lib/default.nix | 15 +- lib/env.nix | 32 +- lib/utils.nix | 18 +- modules/env/common.nix | 16 +- modules/env/home-manager/default.nix | 31 +- modules/env/nixos/default.nix | 29 +- modules/wrapper-manager/base.nix | 123 ++-- modules/wrapper-manager/build.nix | 40 +- modules/wrapper-manager/locale.nix | 84 +-- .../wrapper-manager/xdg-desktop-entries.nix | 189 +++--- modules/wrapper-manager/xdg-dirs.nix | 42 +- shell.nix | 6 +- tests/configs/default.nix | 8 +- tests/configs/wrapper-fastfetch.nix | 24 +- tests/configs/wrapper-neofetch.nix | 29 +- tests/default.nix | 23 +- tests/lib/default.nix | 11 +- tests/lib/env/default.nix | 14 +- tests/lib/utils.nix | 6 +- 24 files changed, 1083 insertions(+), 717 deletions(-) diff --git a/docs/default.nix b/docs/default.nix index 4190bf1..e3bc866 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,26 +1,42 @@ let sources = import ../npins; in -{ pkgs ? import sources.nixos-unstable { } }: +{ + pkgs ? import sources.nixos-unstable { }, +}: let inherit (pkgs) nixosOptionsDoc lib; # Pretty much inspired from home-manager's documentation build process. - evalDoc = args@{ modules, includeModuleSystemOptions ? false, ... }: + evalDoc = + args@{ + modules, + includeModuleSystemOptions ? false, + ... + }: let - options = (pkgs.lib.evalModules { - modules = modules ++ [ { _module.check = false; _module.args.pkgs = pkgs; } ]; - class = "wrapperManager"; - }).options; - in - nixosOptionsDoc ({ options = - if includeModuleSystemOptions - then options - else builtins.removeAttrs options [ "_module" ]; + (pkgs.lib.evalModules { + modules = modules ++ [ + { + _module.check = false; + _module.args.pkgs = pkgs; + } + ]; + class = "wrapperManager"; + }).options; + in + nixosOptionsDoc ( + { + options = + if includeModuleSystemOptions then options else builtins.removeAttrs options [ "_module" ]; } - // builtins.removeAttrs args [ "modules" "includeModuleSystemOptions" ]); + // builtins.removeAttrs args [ + "modules" + "includeModuleSystemOptions" + ] + ); releaseConfig = lib.importJSON ../release.json; wrapperManagerLib = (import ../. { }).lib; @@ -48,20 +64,28 @@ in buildHugoSite = pkgs.callPackage ./hugo-build-module.nix { }; # Now this is some dogfooding. - asciidoctorWrapped = - wrapperManagerLib.build { - inherit pkgs; - modules = [ - ({ config, lib, pkgs, ... }: { + asciidoctorWrapped = wrapperManagerLib.build { + inherit pkgs; + modules = [ + ( + { + config, + lib, + pkgs, + ... + }: + { wrappers.asciidoctor = { arg0 = lib.getExe' gems "asciidoctor"; appendArgs = [ - "-T" "${sources.website}/templates" + "-T" + "${sources.website}/templates" ]; }; - }) - ]; - }; + } + ) + ]; + }; in buildHugoSite { pname = "wrapper-manager-docs"; @@ -101,27 +125,40 @@ in }; inherit wmOptionsDoc; - wmNixosDoc = evalDoc { modules = [ ../modules/env/nixos ]; }; + wmNixosDoc = evalDoc { modules = [ ../modules/env/nixos ]; }; wmHmDoc = evalDoc { modules = [ ../modules/env/home-manager ]; }; inherit releaseConfig; outputs = { - manpage = pkgs.runCommand "wrapper-manager-reference-manpage" { - nativeBuildInputs = with pkgs; [ nixos-render-docs gems gems.wrappedRuby ]; - } '' - mkdir -p $out/share/man/man5 - asciidoctor --backend manpage ${./manpages/header.adoc} --out-file header.5 - nixos-render-docs options manpage --revision ${releaseConfig.version} \ - --header ./header.5 --footer ${./manpages/footer.5} \ - ${wmOptionsDoc.optionsJSON}/share/doc/nixos/options.json \ - $out/share/man/man5/wrapper-manager.nix.5 - ''; + manpage = + pkgs.runCommand "wrapper-manager-reference-manpage" + { + nativeBuildInputs = with pkgs; [ + nixos-render-docs + gems + gems.wrappedRuby + ]; + } + '' + mkdir -p $out/share/man/man5 + asciidoctor --backend manpage ${./manpages/header.adoc} --out-file header.5 + nixos-render-docs options manpage --revision ${releaseConfig.version} \ + --header ./header.5 --footer ${./manpages/footer.5} \ + ${wmOptionsDoc.optionsJSON}/share/doc/nixos/options.json \ + $out/share/man/man5/wrapper-manager.nix.5 + ''; - html = pkgs.runCommand "wrapper-manager-reference-html" { - nativeBuildInputs = [ gems gems.wrappedRuby ]; - } '' - mkdir -p $out/share/wrapper-manager - asciidoctor --backend html ${wmOptionsDoc.optionsAsciiDoc} --out-file $out/share/wrapper-manager/options-reference.html - ''; + html = + pkgs.runCommand "wrapper-manager-reference-html" + { + nativeBuildInputs = [ + gems + gems.wrappedRuby + ]; + } + '' + mkdir -p $out/share/wrapper-manager + asciidoctor --backend html ${wmOptionsDoc.optionsAsciiDoc} --out-file $out/share/wrapper-manager/options-reference.html + ''; }; } diff --git a/docs/gemset.nix b/docs/gemset.nix index 1b5f391..11fe6e8 100644 --- a/docs/gemset.nix +++ b/docs/gemset.nix @@ -1,339 +1,421 @@ { asciidoctor = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1wyxgwmnz9bw377r3lba26b090hbsq9qnbw8575a1prpy83qh82j"; type = "gem"; }; version = "2.0.23"; }; asciidoctor-diagram = { - dependencies = ["asciidoctor" "asciidoctor-diagram-ditaamini" "asciidoctor-diagram-plantuml" "rexml"]; - groups = ["default"]; - platforms = []; + dependencies = [ + "asciidoctor" + "asciidoctor-diagram-ditaamini" + "asciidoctor-diagram-plantuml" + "rexml" + ]; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1214scxm36k409gfy3wilfqx3akrm52r530zmra6cmmf6d22c5q4"; type = "gem"; }; version = "2.3.1"; }; asciidoctor-diagram-batik = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0220xqxmkmimxmhsqhlbr0hslijvnhzdds3s6h6fxbxqrrmm0jrl"; type = "gem"; }; version = "1.17"; }; asciidoctor-diagram-ditaamini = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "13h65bfbq7hc7z3kqn0m28w9c6ap7fikpjcvsdga6jg01slb4c56"; type = "gem"; }; version = "1.0.3"; }; asciidoctor-diagram-plantuml = { - dependencies = ["asciidoctor-diagram-batik"]; - groups = ["default"]; - platforms = []; + dependencies = [ "asciidoctor-diagram-batik" ]; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1ppl5nsq40x11731ciahi89k5yvszlm12pml1pqaj0lwbi7ww6x0"; type = "gem"; }; version = "1.2024.5"; }; asciidoctor-foodogsquared-extensions = { - dependencies = ["asciidoctor" "rugged"]; - groups = ["default"]; - platforms = []; + dependencies = [ + "asciidoctor" + "rugged" + ]; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0fm6shyysj51wi4s7nnb643j2mphp68fh44gmr83x8n613hg9a4l"; type = "gem"; }; version = "1.2.1"; }; ast = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "04nc8x27hlzlrr5c2gn7mar4vdr0apw5xg22wp6m8dx3wqr04a0y"; type = "gem"; }; version = "2.4.2"; }; concurrent-ruby = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0skwdasxq7mnlcccn6aqabl7n9r3jd7k19ryzlzzip64cn4x572g"; type = "gem"; }; version = "1.3.3"; }; json = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0b4qsi8gay7ncmigr0pnbxyb17y3h8kavdyhsh7nrlqwr35vb60q"; type = "gem"; }; version = "2.7.2"; }; language_server-protocol = { - groups = ["default" "development" "lint"]; - platforms = []; + groups = [ + "default" + "development" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0gvb1j8xsqxms9mww01rmdl78zkd72zgxaap56bhv8j45z05hp1x"; type = "gem"; }; version = "3.17.0.3"; }; logger = { - groups = ["default" "development"]; - platforms = []; + groups = [ + "default" + "development" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0gpg8gzi0xwymw4aaq2iafcbx31i3xzkg3fb30mdxn1d4qhc3dqa"; type = "gem"; }; version = "1.6.0"; }; open-uri-cached = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "03v0if3jlvbclnd6jgjk94fbhf0h2fq1wxr0mbx7018sxzm0biwr"; type = "gem"; }; version = "1.0.0"; }; parallel = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "145bn5q7ysnjj02jdf1x4nc1f0xxrv7ihgz9yr1j7sinmawqkq0j"; type = "gem"; }; version = "1.25.1"; }; parser = { - dependencies = ["ast" "racc"]; - groups = ["default" "lint"]; - platforms = []; + dependencies = [ + "ast" + "racc" + ]; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "10ly2wind06nylyqa5724ld2l0l46d3ag4fm04ifjgw7qdlpf94d"; type = "gem"; }; version = "3.3.4.0"; }; prism = { - groups = ["default" "development"]; - platforms = []; + groups = [ + "default" + "development" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "05j9bcxdz6wfnrjn32zvdwj1qsbp88mwx3rv7g256gziya6avc2r"; type = "gem"; }; version = "0.30.0"; }; racc = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "021s7maw0c4d9a6s07vbmllrzqsj2sgmrwimlh8ffkvwqdjrld09"; type = "gem"; }; version = "1.8.0"; }; rainbow = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0smwg4mii0fm38pyb5fddbmrdpifwv22zv3d3px2xx497am93503"; type = "gem"; }; version = "3.1.1"; }; rake = { - groups = ["development"]; - platforms = []; + groups = [ "development" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "17850wcwkgi30p7yqh60960ypn7yibacjjha0av78zaxwvd3ijs6"; type = "gem"; }; version = "13.2.1"; }; rbs = { - dependencies = ["logger"]; - groups = ["default" "development"]; - platforms = []; + dependencies = [ "logger" ]; + groups = [ + "default" + "development" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1fzk0a3d68fglnkwpaz07npi929y1kh2hh1j63y04943vvshyjmc"; type = "gem"; }; version = "3.5.2"; }; regexp_parser = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0ik40vcv7mqigsfpqpca36hpmnx0536xa825ai5qlkv3mmkyf9ss"; type = "gem"; }; version = "2.9.2"; }; rexml = { - dependencies = ["strscan"]; - groups = ["default" "lint"]; - platforms = []; + dependencies = [ "strscan" ]; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "09f3sw7f846fpcpwdm362ylqldwqxpym6z0qpld4av7zisrrzbrl"; type = "gem"; }; version = "3.3.1"; }; rouge = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "072qvvrcqj0yfr3b0j932mlhvn41i38bq37z7z07i3ikagndkqwy"; type = "gem"; }; version = "4.3.0"; }; rubocop = { - dependencies = ["json" "language_server-protocol" "parallel" "parser" "rainbow" "regexp_parser" "rexml" "rubocop-ast" "ruby-progressbar" "unicode-display_width"]; - groups = ["lint"]; - platforms = []; + dependencies = [ + "json" + "language_server-protocol" + "parallel" + "parser" + "rainbow" + "regexp_parser" + "rexml" + "rubocop-ast" + "ruby-progressbar" + "unicode-display_width" + ]; + groups = [ "lint" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "18g462bccr0rvszc7kirr89laggdf6254p7pqsckk3izg901chv2"; type = "gem"; }; version = "1.65.0"; }; rubocop-ast = { - dependencies = ["parser"]; - groups = ["default" "lint"]; - platforms = []; + dependencies = [ "parser" ]; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "063qgvqbyv354icl2sgx758z22wzq38hd9skc3n96sbpv0cdc1qv"; type = "gem"; }; version = "1.31.3"; }; ruby-lsp = { - dependencies = ["language_server-protocol" "prism" "rbs" "sorbet-runtime"]; - groups = ["development"]; - platforms = []; + dependencies = [ + "language_server-protocol" + "prism" + "rbs" + "sorbet-runtime" + ]; + groups = [ "development" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1kvyk0cald1cw6fqxy5w68la1gnc1nv2mqx8myijjsbcf9npjbp8"; type = "gem"; }; version = "0.17.7"; }; ruby-progressbar = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0cwvyb7j47m7wihpfaq7rc47zwwx9k4v7iqd9s1xch5nm53rrz40"; type = "gem"; }; version = "1.13.0"; }; rugged = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1sccng15h8h3mcjxfgvxy85lfpswbj0nhmzwwsqdffbzqgsb2jch"; type = "gem"; }; version = "1.7.2"; }; slim = { - dependencies = ["temple" "tilt"]; - groups = ["default"]; - platforms = []; + dependencies = [ + "temple" + "tilt" + ]; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1rqk7jn66wgx50b18ndhbppjq55rbcwgqg1rbhnhxwiggvzisdbj"; type = "gem"; }; version = "5.2.1"; }; sorbet-runtime = { - groups = ["default" "development"]; - platforms = []; + groups = [ + "default" + "development" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "122702d5cmrbaydcqfjksh1d78g0mq69h77zd4yljwjrc50jz70b"; type = "gem"; }; version = "0.5.11481"; }; strscan = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0mamrl7pxacbc79ny5hzmakc9grbjysm3yy6119ppgsg44fsif01"; type = "gem"; }; version = "3.1.0"; }; temple = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0fwia5hvc1xz9w7vprzjnsym3v9j5l9ggdvy70jixbvpcpz4acfz"; type = "gem"; }; version = "0.10.3"; }; tilt = { - groups = ["default"]; - platforms = []; + groups = [ "default" ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "0kds7wkxmb038cwp6ravnwn8k65ixc68wpm8j5jx5bhx8ndg4x6z"; type = "gem"; }; version = "2.4.0"; }; unicode-display_width = { - groups = ["default" "lint"]; - platforms = []; + groups = [ + "default" + "lint" + ]; + platforms = [ ]; source = { - remotes = ["https://rubygems.org"]; + remotes = [ "https://rubygems.org" ]; sha256 = "1d0azx233nags5jx3fqyr23qa2rhgzbhv8pxp46dgbg1mpf82xky"; type = "gem"; }; diff --git a/docs/hugo-build-module.nix b/docs/hugo-build-module.nix index 1226d2a..551b705 100644 --- a/docs/hugo-build-module.nix +++ b/docs/hugo-build-module.nix @@ -1,318 +1,397 @@ -{ hugo, go, cacert, git, lib, stdenv }: +{ + hugo, + go, + cacert, + git, + lib, + stdenv, +}: -{ name ? "${args'.pname}-${args'.version}" -, src -, nativeBuildInputs ? [ ] -, passthru ? { } -, patches ? [ ] +{ + name ? "${args'.pname}-${args'.version}", + src, + nativeBuildInputs ? [ ], + passthru ? { }, + patches ? [ ], # A function to override the goModules derivation -, overrideModAttrs ? (_oldAttrs: { }) + overrideModAttrs ? (_oldAttrs: { }), # path to go.mod and go.sum directory -, modRoot ? "./" + modRoot ? "./", # vendorHash is the SRI hash of the vendored dependencies # # if vendorHash is null, then we won't fetch any dependencies and # rely on the vendor folder within the source. -, vendorHash ? throw ( - if args'?vendorSha256 then + vendorHash ? throw ( + if args' ? vendorSha256 then "buildGoModule: Expect vendorHash instead of vendorSha256" else "buildGoModule: vendorHash is missing" - ) + ), # Whether to delete the vendor folder supplied with the source. -, deleteVendor ? false + deleteVendor ? false, # Whether to fetch (go mod download) and proxy the vendor directory. # This is useful if your code depends on c code and go mod tidy does not # include the needed sources to build or if any dependency has case-insensitive # conflicts which will produce platform dependant `vendorHash` checksums. -, proxyVendor ? false + proxyVendor ? false, # We want parallel builds by default -, enableParallelBuilding ? true + enableParallelBuilding ? true, # Do not enable this without good reason # IE: programs coupled with the compiler -, allowGoReference ? false + allowGoReference ? false, -, CGO_ENABLED ? go.CGO_ENABLED + CGO_ENABLED ? go.CGO_ENABLED, -, meta ? { } + meta ? { }, # Not needed with buildGoModule -, goPackagePath ? "" + goPackagePath ? "", -, ldflags ? [ ] + ldflags ? [ ], -, GOFLAGS ? [ ] + GOFLAGS ? [ ], # needed for buildFlags{,Array} warning -, buildFlags ? "" -, buildFlagsArray ? "" + buildFlags ? "", + buildFlagsArray ? "", -, ... + ... }@args': assert goPackagePath != "" -> throw "`goPackagePath` is not needed with `buildGoModule`"; let - args = removeAttrs args' [ "overrideModAttrs" "vendorSha256" "vendorHash" ]; + args = removeAttrs args' [ + "overrideModAttrs" + "vendorSha256" + "vendorHash" + ]; GO111MODULE = "on"; GOTOOLCHAIN = "local"; - hugoModules = if (vendorHash == null) then "" else - (stdenv.mkDerivation { - name = "${name}-hugo-modules"; + hugoModules = + if (vendorHash == null) then + "" + else + (stdenv.mkDerivation { + name = "${name}-hugo-modules"; - nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ hugo go git cacert ]; + nativeBuildInputs = (args.nativeBuildInputs or [ ]) ++ [ + hugo + go + git + cacert + ]; - inherit (args) src; - inherit (go) GOOS GOARCH; - inherit GO111MODULE GOTOOLCHAIN; + inherit (args) src; + inherit (go) GOOS GOARCH; + inherit GO111MODULE GOTOOLCHAIN; - # The following inheritence behavior is not trivial to expect, and some may - # argue it's not ideal. Changing it may break vendor hashes in Nixpkgs and - # out in the wild. In anycase, it's documented in: - # doc/languages-frameworks/go.section.md - prePatch = args.prePatch or ""; - patches = args.patches or [ ]; - patchFlags = args.patchFlags or [ ]; - postPatch = args.postPatch or ""; - preBuild = args.preBuild or ""; - postBuild = args.modPostBuild or ""; - sourceRoot = args.sourceRoot or ""; - setSourceRoot = args.setSourceRoot or ""; - env = args.env or { }; + # The following inheritence behavior is not trivial to expect, and some may + # argue it's not ideal. Changing it may break vendor hashes in Nixpkgs and + # out in the wild. In anycase, it's documented in: + # doc/languages-frameworks/go.section.md + prePatch = args.prePatch or ""; + patches = args.patches or [ ]; + patchFlags = args.patchFlags or [ ]; + postPatch = args.postPatch or ""; + preBuild = args.preBuild or ""; + postBuild = args.modPostBuild or ""; + sourceRoot = args.sourceRoot or ""; + setSourceRoot = args.setSourceRoot or ""; + env = args.env or { }; - impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ - "GIT_PROXY_COMMAND" - "SOCKS_SERVER" - "GOPROXY" - ]; + impureEnvVars = lib.fetchers.proxyImpureEnvVars ++ [ + "GIT_PROXY_COMMAND" + "SOCKS_SERVER" + "GOPROXY" + ]; - configurePhase = args.modConfigurePhase or '' - runHook preConfigure - export GOCACHE=$TMPDIR/go-cache - export GOPATH="$TMPDIR/go" - cd "${modRoot}" - runHook postConfigure - ''; + configurePhase = + args.modConfigurePhase or '' + runHook preConfigure + export GOCACHE=$TMPDIR/go-cache + export GOPATH="$TMPDIR/go" + cd "${modRoot}" + runHook postConfigure + ''; - buildPhase = args.modBuildPhase or ('' - runHook preBuild - '' + lib.optionalString deleteVendor '' - if [ ! -d _vendor ]; then - echo "_vendor folder does not exist, 'deleteVendor' is not needed" - exit 10 - else - rm -rf _vendor - fi - '' + '' - if [ -d _vendor ]; then - echo "_vendor folder exists, please set 'vendorHash = null;' in your expression" - exit 10 - fi + buildPhase = + args.modBuildPhase or ( + '' + runHook preBuild + '' + + lib.optionalString deleteVendor '' + if [ ! -d _vendor ]; then + echo "_vendor folder does not exist, 'deleteVendor' is not needed" + exit 10 + else + rm -rf _vendor + fi + '' + + '' + if [ -d _vendor ]; then + echo "_vendor folder exists, please set 'vendorHash = null;' in your expression" + exit 10 + fi - ${if proxyVendor then '' - mkdir -p "''${GOPATH}/pkg/mod/cache/download" - hugo mod vendor - '' else '' - if (( "''${NIX_DEBUG:-0}" >= 1 )); then - hugoModVendorFlags+=(-v) - fi - hugo mod vendor "''${hugoModVendorFlags[@]}" - ''} + ${ + if proxyVendor then + '' + mkdir -p "''${GOPATH}/pkg/mod/cache/download" + hugo mod vendor + '' + else + '' + if (( "''${NIX_DEBUG:-0}" >= 1 )); then + hugoModVendorFlags+=(-v) + fi + hugo mod vendor "''${hugoModVendorFlags[@]}" + '' + } - mkdir -p _vendor + mkdir -p _vendor - runHook postBuild - ''); + runHook postBuild + '' + ); - installPhase = args.modInstallPhase or '' - runHook preInstall + installPhase = + args.modInstallPhase or '' + runHook preInstall - ${if proxyVendor then '' - rm -rf "''${GOPATH}/pkg/mod/cache/download/sumdb" - cp -r --reflink=auto "''${GOPATH}/pkg/mod/cache/download" $out - '' else '' - cp -r --reflink=auto _vendor $out - ''} + ${ + if proxyVendor then + '' + rm -rf "''${GOPATH}/pkg/mod/cache/download/sumdb" + cp -r --reflink=auto "''${GOPATH}/pkg/mod/cache/download" $out + '' + else + '' + cp -r --reflink=auto _vendor $out + '' + } - if ! [ "$(ls -A $out)" ]; then - echo "_vendor folder is empty, please set 'vendorHash = null;' in your expression" - exit 10 - fi + if ! [ "$(ls -A $out)" ]; then + echo "_vendor folder is empty, please set 'vendorHash = null;' in your expression" + exit 10 + fi - runHook postInstall - ''; + runHook postInstall + ''; - dontFixup = true; + dontFixup = true; - outputHashMode = "recursive"; - outputHash = vendorHash; - # Handle empty vendorHash; avoid - # error: empty hash requires explicit hash algorithm - outputHashAlgo = if vendorHash == "" then "sha256" else null; - }).overrideAttrs overrideModAttrs; + outputHashMode = "recursive"; + outputHash = vendorHash; + # Handle empty vendorHash; avoid + # error: empty hash requires explicit hash algorithm + outputHashAlgo = if vendorHash == "" then "sha256" else null; + }).overrideAttrs + overrideModAttrs; - package = stdenv.mkDerivation (args // { - nativeBuildInputs = [ hugo git go ] ++ nativeBuildInputs; + package = stdenv.mkDerivation ( + args + // { + nativeBuildInputs = [ + hugo + git + go + ] ++ nativeBuildInputs; - inherit (go) GOOS GOARCH; + inherit (go) GOOS GOARCH; - GOFLAGS = GOFLAGS - ++ lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" - (lib.optional (!proxyVendor) "-mod=vendor") - ++ lib.warnIf (builtins.elem "-trimpath" GOFLAGS) "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" - (lib.optional (!allowGoReference) "-trimpath"); - inherit CGO_ENABLED enableParallelBuilding GO111MODULE GOTOOLCHAIN; + GOFLAGS = + GOFLAGS + ++ + lib.warnIf (lib.any (lib.hasPrefix "-mod=") GOFLAGS) + "use `proxyVendor` to control Go module/vendor behavior instead of setting `-mod=` in GOFLAGS" + (lib.optional (!proxyVendor) "-mod=vendor") + ++ + lib.warnIf (builtins.elem "-trimpath" GOFLAGS) + "`-trimpath` is added by default to GOFLAGS by buildGoModule when allowGoReference isn't set to true" + (lib.optional (!allowGoReference) "-trimpath"); + inherit + CGO_ENABLED + enableParallelBuilding + GO111MODULE + GOTOOLCHAIN + ; - # If not set to an explicit value, set the buildid empty for reproducibility. - ldflags = ldflags ++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags) "-buildid="; + # If not set to an explicit value, set the buildid empty for reproducibility. + ldflags = ldflags ++ lib.optional (!lib.any (lib.hasPrefix "-buildid=") ldflags) "-buildid="; - configurePhase = args.configurePhase or ('' - runHook preConfigure + configurePhase = + args.configurePhase or ( + '' + runHook preConfigure - export GOCACHE=$TMPDIR/go-cache - export GOPATH="$TMPDIR/go" - export GOPROXY=off - export GOSUMDB=off - cd "$modRoot" - '' + lib.optionalString (vendorHash != null) '' - ${if proxyVendor then '' - export GOPROXY=file://${hugoModules} - '' else '' - rm -rf _vendor - cp -r --reflink=auto ${hugoModules} _vendor - ''} - '' + '' + export GOCACHE=$TMPDIR/go-cache + export GOPATH="$TMPDIR/go" + export GOPROXY=off + export GOSUMDB=off + cd "$modRoot" + '' + + lib.optionalString (vendorHash != null) '' + ${ + if proxyVendor then + '' + export GOPROXY=file://${hugoModules} + '' + else + '' + rm -rf _vendor + cp -r --reflink=auto ${hugoModules} _vendor + '' + } + '' + + '' - # currently pie is only enabled by default in pkgsMusl - # this will respect the `hardening{Disable,Enable}` flags if set - if [[ $NIX_HARDENING_ENABLE =~ "pie" ]]; then - export GOFLAGS="-buildmode=pie $GOFLAGS" - fi + # currently pie is only enabled by default in pkgsMusl + # this will respect the `hardening{Disable,Enable}` flags if set + if [[ $NIX_HARDENING_ENABLE =~ "pie" ]]; then + export GOFLAGS="-buildmode=pie $GOFLAGS" + fi - runHook postConfigure - ''); + runHook postConfigure + '' + ); - buildPhase = args.buildPhase or ( - lib.warnIf (buildFlags != "" || buildFlagsArray != "") - "`buildFlags`/`buildFlagsArray` are deprecated and will be removed in the 24.11 release. Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" - lib.warnIf (builtins.elem "-buildid=" ldflags) - "`-buildid=` is set by default as ldflag by buildGoModule" - '' - runHook preBuild + buildPhase = + args.buildPhase or ( + lib.warnIf (buildFlags != "" || buildFlagsArray != "") + "`buildFlags`/`buildFlagsArray` are deprecated and will be removed in the 24.11 release. Use the `ldflags` and/or `tags` attributes instead of `buildFlags`/`buildFlagsArray`" + lib.warnIf + (builtins.elem "-buildid=" ldflags) + "`-buildid=` is set by default as ldflag by buildGoModule" + '' + runHook preBuild - exclude='\(/_\|examples\|Godeps\|testdata' - if [[ -n "$excludedPackages" ]]; then - IFS=' ' read -r -a excludedArr <<<$excludedPackages - printf -v excludedAlternates '%s\\|' "''${excludedArr[@]}" - excludedAlternates=''${excludedAlternates%\\|} # drop final \| added by printf - exclude+='\|'"$excludedAlternates" - fi - exclude+='\)' + exclude='\(/_\|examples\|Godeps\|testdata' + if [[ -n "$excludedPackages" ]]; then + IFS=' ' read -r -a excludedArr <<<$excludedPackages + printf -v excludedAlternates '%s\\|' "''${excludedArr[@]}" + excludedAlternates=''${excludedAlternates%\\|} # drop final \| added by printf + exclude+='\|'"$excludedAlternates" + fi + exclude+='\)' - buildGoDir() { - local cmd="$1" dir="$2" + buildGoDir() { + local cmd="$1" dir="$2" - declare -ga buildFlagsArray - declare -a flags - flags+=($buildFlags "''${buildFlagsArray[@]}") - flags+=(''${tags:+-tags=''${tags// /,}}) - flags+=(''${ldflags:+-ldflags="$ldflags"}) - flags+=("-p" "$NIX_BUILD_CORES") + declare -ga buildFlagsArray + declare -a flags + flags+=($buildFlags "''${buildFlagsArray[@]}") + flags+=(''${tags:+-tags=''${tags// /,}}) + flags+=(''${ldflags:+-ldflags="$ldflags"}) + flags+=("-p" "$NIX_BUILD_CORES") - if [ "$cmd" = "test" ]; then - flags+=(-vet=off) - flags+=($checkFlags) - fi + if [ "$cmd" = "test" ]; then + flags+=(-vet=off) + flags+=($checkFlags) + fi - local OUT - if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then - if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then - echo "$OUT" >&2 - return 1 - fi - fi - if [ -n "$OUT" ]; then - echo "$OUT" >&2 - fi - return 0 - } + local OUT + if ! OUT="$(go $cmd "''${flags[@]}" $dir 2>&1)"; then + if ! echo "$OUT" | grep -qE '(no( buildable| non-test)?|build constraints exclude all) Go (source )?files'; then + echo "$OUT" >&2 + return 1 + fi + fi + if [ -n "$OUT" ]; then + echo "$OUT" >&2 + fi + return 0 + } - getGoDirs() { - local type; - type="$1" - if [ -n "$subPackages" ]; then - echo "$subPackages" | sed "s,\(^\| \),\1./,g" - else - find . -type f -name \*$type.go -exec dirname {} \; | grep -v "/_vendor/" | sort --unique | grep -v "$exclude" - fi - } + getGoDirs() { + local type; + type="$1" + if [ -n "$subPackages" ]; then + echo "$subPackages" | sed "s,\(^\| \),\1./,g" + else + find . -type f -name \*$type.go -exec dirname {} \; | grep -v "/_vendor/" | sort --unique | grep -v "$exclude" + fi + } - if (( "''${NIX_DEBUG:-0}" >= 1 )); then - buildFlagsArray+=(-x) - fi + if (( "''${NIX_DEBUG:-0}" >= 1 )); then + buildFlagsArray+=(-x) + fi - if [ -z "$enableParallelBuilding" ]; then - export NIX_BUILD_CORES=1 - fi - for pkg in $(getGoDirs ""); do - echo "Building subPackage $pkg" - buildGoDir install "$pkg" - done - '' + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' - # normalize cross-compiled builds w.r.t. native builds - ( - dir=$GOPATH/bin/${go.GOOS}_${go.GOARCH} - if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]]; then - mv $dir/* $dir/.. - fi - if [[ -d $dir ]]; then - rmdir $dir - fi - ) - '' + '' - runHook postBuild - ''); + if [ -z "$enableParallelBuilding" ]; then + export NIX_BUILD_CORES=1 + fi + for pkg in $(getGoDirs ""); do + echo "Building subPackage $pkg" + buildGoDir install "$pkg" + done + '' + + lib.optionalString (stdenv.hostPlatform != stdenv.buildPlatform) '' + # normalize cross-compiled builds w.r.t. native builds + ( + dir=$GOPATH/bin/${go.GOOS}_${go.GOARCH} + if [[ -n "$(shopt -s nullglob; echo $dir/*)" ]]; then + mv $dir/* $dir/.. + fi + if [[ -d $dir ]]; then + rmdir $dir + fi + ) + '' + + '' + runHook postBuild + '' + ); - doCheck = args.doCheck or true; - checkPhase = args.checkPhase or '' - runHook preCheck - # We do not set trimpath for tests, in case they reference test assets - export GOFLAGS=''${GOFLAGS//-trimpath/} + doCheck = args.doCheck or true; + checkPhase = + args.checkPhase or '' + runHook preCheck + # We do not set trimpath for tests, in case they reference test assets + export GOFLAGS=''${GOFLAGS//-trimpath/} - for pkg in $(getGoDirs test); do - buildGoDir test "$pkg" - done + for pkg in $(getGoDirs test); do + buildGoDir test "$pkg" + done - runHook postCheck - ''; + runHook postCheck + ''; - installPhase = args.installPhase or '' - runHook preInstall + installPhase = + args.installPhase or '' + runHook preInstall - mkdir -p $out - dir="$GOPATH/bin" - [ -e "$dir" ] && cp -r $dir $out + mkdir -p $out + dir="$GOPATH/bin" + [ -e "$dir" ] && cp -r $dir $out - runHook postInstall - ''; + runHook postInstall + ''; - strictDeps = true; + strictDeps = true; - disallowedReferences = lib.optional (!allowGoReference) go; + disallowedReferences = lib.optional (!allowGoReference) go; - passthru = passthru // { inherit go hugo hugoModules vendorHash; }; + passthru = passthru // { + inherit + go + hugo + hugoModules + vendorHash + ; + }; - meta = { - # Add default meta information - platforms = go.meta.platforms or lib.platforms.all; - } // meta; - }); + meta = { + # Add default meta information + platforms = go.meta.platforms or lib.platforms.all; + } // meta; + } + ); in package diff --git a/docs/website/shell.nix b/docs/website/shell.nix index 3a37702..05aa3ee 100644 --- a/docs/website/shell.nix +++ b/docs/website/shell.nix @@ -1,7 +1,9 @@ let sources = import ../../npins; in -{ pkgs ? import sources.nixos-unstable { } }: +{ + pkgs ? import sources.nixos-unstable { }, +}: let docs = import ../. { inherit pkgs; }; diff --git a/flake.nix b/flake.nix index e4ba179..97d6753 100644 --- a/flake.nix +++ b/flake.nix @@ -2,49 +2,65 @@ # We're already using the Nix projects through pinning with npins. { description = "wrapper-manager-fds flake"; - outputs = { ... }: let - sources = import ./npins; - systems = [ "x86_64-linux" "aarch64-linux" ]; - eachSystem = systems: f: + outputs = + { ... }: + let + sources = import ./npins; + systems = [ + "x86_64-linux" + "aarch64-linux" + ]; + eachSystem = + systems: f: + let + # Merge together the outputs for all systems. + op = + attrs: system: + let + ret = f system; + op = + attrs: key: + attrs + // { + ${key} = (attrs.${key} or { }) // { + ${system} = ret.${key}; + }; + }; + in + builtins.foldl' op attrs (builtins.attrNames ret); + in + builtins.foldl' op { } ( + systems + # add the current system if --impure is used + ++ ( + if builtins ? currentSystem then + if builtins.elem builtins.currentSystem systems then [ ] else [ builtins.currentSystem ] + else + [ ] + ) + ); + in + import ./. { } + // (eachSystem systems ( + system: let - # Merge together the outputs for all systems. - op = attrs: system: - let - ret = f system; - op = attrs: key: attrs // - { - ${key} = (attrs.${key} or { }) - // { ${system} = ret.${key}; }; - } - ; - in - builtins.foldl' op attrs (builtins.attrNames ret); + pkgs = import sources.nixos-unstable { inherit system; }; + tests = import ./tests { inherit pkgs; }; + docs = import ./docs { inherit pkgs; }; in - builtins.foldl' op { } - (systems - ++ # add the current system if --impure is used - (if builtins?currentSystem then - if builtins.elem builtins.currentSystem systems - then [] - else [ builtins.currentSystem ] - else - [])); - in import ./. { } // (eachSystem systems (system: let - pkgs = import sources.nixos-unstable { inherit system; }; - tests = import ./tests { inherit pkgs; }; - docs = import ./docs { inherit pkgs; }; - in { - devShells = { - default = import ./shell.nix { inherit pkgs; }; - website = import ./docs/website/shell.nix { inherit pkgs; }; - }; + { + devShells = { + default = import ./shell.nix { inherit pkgs; }; + website = import ./docs/website/shell.nix { inherit pkgs; }; + }; - packages = { - manpage-reference = docs.outputs.manpage; - html-reference = docs.outputs.html; - website = docs.website; - }; + packages = { + manpage-reference = docs.outputs.manpage; + html-reference = docs.outputs.html; + website = docs.website; + }; - checks.wrapperManagerLibrarySetPkg = tests.libTestPkg; - })); + checks.wrapperManagerLibrarySetPkg = tests.libTestPkg; + } + )); } diff --git a/lib/default.nix b/lib/default.nix index 1ebb1b6..689dc23 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -9,10 +9,15 @@ # module. { pkgs }: -pkgs.lib.makeExtensible - (self: +pkgs.lib.makeExtensible ( + self: let - callLibs = file: import file { inherit (pkgs) lib; inherit pkgs self; }; + callLibs = + file: + import file { + inherit (pkgs) lib; + inherit pkgs self; + }; in { env = import ./env.nix; @@ -20,5 +25,5 @@ pkgs.lib.makeExtensible inherit (self.env) build eval; inherit (self.utils) getBin getLibexec; - }) - + } +) diff --git a/lib/env.nix b/lib/env.nix index 74242e4..900f895 100644 --- a/lib/env.nix +++ b/lib/env.nix @@ -1,17 +1,18 @@ rec { - /* Given the attrset for evaluating a wrapper-manager module, return a - derivation containing the wrapper. + /* + Given the attrset for evaluating a wrapper-manager module, return a + derivation containing the wrapper. */ - build = args: - (eval args).config.build.toplevel; + build = args: (eval args).config.build.toplevel; - /* Evaluate a wrapper-manager configuration. */ - eval = { - pkgs, - lib ? pkgs.lib, - modules ? [ ], - specialArgs ? { }, - }: + # Evaluate a wrapper-manager configuration. + eval = + { + pkgs, + lib ? pkgs.lib, + modules ? [ ], + specialArgs ? { }, + }: lib.evalModules { inherit specialArgs; modules = [ @@ -20,9 +21,12 @@ rec { # Setting pkgs modularly. This would make setting up wrapper-manager # with different nixpkgs instances possible but it isn't something that # is explicitly supported. - ({ lib, ... }: { - config._module.args.pkgs = lib.mkDefault pkgs; - }) + ( + { lib, ... }: + { + config._module.args.pkgs = lib.mkDefault pkgs; + } + ) ] ++ modules; }; } diff --git a/lib/utils.nix b/lib/utils.nix index edf5a95..d749913 100644 --- a/lib/utils.nix +++ b/lib/utils.nix @@ -1,31 +1,31 @@ -{ pkgs, lib, self }: +{ + pkgs, + lib, + self, +}: rec { /* Given a list of derivations, return a list of the store path with the `bin` output (or at least with "/bin" in each of the paths). */ - getBin = drvs: - builtins.map (v: lib.getBin v) drvs; + getBin = drvs: builtins.map (v: lib.getBin v) drvs; /* Given a list of derivations, return a list of the store paths with the `libexec` appended. */ - getLibexec = drvs: - builtins.map (v: "${v}/libexec") drvs; + getLibexec = drvs: builtins.map (v: "${v}/libexec") drvs; /* Given a list of derivations, return a list of the store paths appended with `/etc/xdg` suitable as part of the XDG_CONFIG_DIRS environment variable. */ - getXdgConfigDirs = drvs: - builtins.map (v: "${v}/etc/xdg") drvs; + getXdgConfigDirs = drvs: builtins.map (v: "${v}/etc/xdg") drvs; /* Given a list of derivations, return a list of store paths appended with `/share` suitable as part of the XDG_DATA_DIRS environment variable. */ - getXdgDataDirs = drvs: - builtins.map (v: "${v}/share") drvs; + getXdgDataDirs = drvs: builtins.map (v: "${v}/share") drvs; } diff --git a/modules/env/common.nix b/modules/env/common.nix index a116d61..f93f986 100644 --- a/modules/env/common.nix +++ b/modules/env/common.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.wrapper-manager; @@ -10,9 +15,12 @@ let modules = [ ../wrapper-manager - ({ lib, ... }: { - config._module.args.pkgs = lib.mkDefault pkgs; - }) + ( + { lib, ... }: + { + config._module.args.pkgs = lib.mkDefault pkgs; + } + ) ] ++ cfg.sharedModules; }; in diff --git a/modules/env/home-manager/default.nix b/modules/env/home-manager/default.nix index 2fa1df3..ab821f8 100644 --- a/modules/env/home-manager/default.nix +++ b/modules/env/home-manager/default.nix @@ -1,13 +1,16 @@ -{ config, lib, pkgs, ... }@moduleArgs: +{ + config, + lib, + pkgs, + ... +}@moduleArgs: let cfg = config.wrapper-manager; wmDocs = import ../../../docs { inherit pkgs; }; in { - imports = [ - ../common.nix - ]; + imports = [ ../common.nix ]; config = lib.mkMerge [ { @@ -20,17 +23,19 @@ in (lib.mkIf (moduleArgs ? nixosConfig) { wrapper-manager.sharedModules = [ - ({ lib, ... }: { - # NixOS already has the option to set the locale so we don't need to - # have this. - config.locale.enable = lib.mkDefault false; - }) + ( + { lib, ... }: + { + # NixOS already has the option to set the locale so we don't need to + # have this. + config.locale.enable = lib.mkDefault false; + } + ) ]; }) - (lib.mkIf (cfg.packages != {}) { - home.packages = - lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.packages; + (lib.mkIf (cfg.packages != { }) { + home.packages = lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.packages; }) - ] ; + ]; } diff --git a/modules/env/nixos/default.nix b/modules/env/nixos/default.nix index 943834a..e6090c5 100644 --- a/modules/env/nixos/default.nix +++ b/modules/env/nixos/default.nix @@ -1,13 +1,16 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.wrapper-manager; wmDocs = import ../../../docs { inherit pkgs; }; in { - imports = [ - ../common.nix - ]; + imports = [ ../common.nix ]; config = lib.mkMerge [ { @@ -18,17 +21,19 @@ in wrapper-manager.extraSpecialArgs.nixosConfig = config; wrapper-manager.sharedModules = [ - ({ lib, ... }: { - # NixOS already has the option to set the locale so we don't need to - # have this. - config.locale.enable = lib.mkDefault false; - }) + ( + { lib, ... }: + { + # NixOS already has the option to set the locale so we don't need to + # have this. + config.locale.enable = lib.mkDefault false; + } + ) ]; } - (lib.mkIf (cfg.packages != {}) { - environment.systemPackages = - lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.packages; + (lib.mkIf (cfg.packages != { }) { + environment.systemPackages = lib.mapAttrsToList (_: wrapper: wrapper.build.toplevel) cfg.packages; }) ]; } diff --git a/modules/wrapper-manager/base.nix b/modules/wrapper-manager/base.nix index 1a7cfbb..a06ef3e 100644 --- a/modules/wrapper-manager/base.nix +++ b/modules/wrapper-manager/base.nix @@ -1,40 +1,63 @@ -{ config, lib, options, ... }: +{ + config, + lib, + options, + ... +}: let envConfig = config; toStringType = with lib.types; coercedTo anything (x: builtins.toString x) str; - envSubmodule = { config, lib, name, ... }: { - options = { - action = lib.mkOption { - type = lib.types.enum [ "unset" "set" "set-default" ]; - description = '' - Sets the appropriate action for the environment variable. + envSubmodule = + { + config, + lib, + name, + ... + }: + { + options = { + action = lib.mkOption { + type = lib.types.enum [ + "unset" + "set" + "set-default" + ]; + description = '' + Sets the appropriate action for the environment variable. - * `unset`... unsets the given variable. - * `set-default` only sets the variable with the given value if - not already set. - * `set` forcibly sets the variable with given value. - ''; - default = "set"; - example = "unset"; - }; + * `unset`... unsets the given variable. + * `set-default` only sets the variable with the given value if + not already set. + * `set` forcibly sets the variable with given value. + ''; + default = "set"; + example = "unset"; + }; - value = lib.mkOption { - type = toStringType; - description = '' - The value of the variable that is holding. - ''; - example = "HELLO THERE"; - }; + value = lib.mkOption { + type = toStringType; + description = '' + The value of the variable that is holding. + ''; + example = "HELLO THERE"; + }; - isEscaped = lib.mkEnableOption "escaping of the value" // { - default = true; + isEscaped = lib.mkEnableOption "escaping of the value" // { + default = true; + }; }; }; - }; - wrapperType = { name, lib, config, pkgs, ... }: + wrapperType = + { + name, + lib, + config, + pkgs, + ... + }: let flagType = with lib.types; listOf toStringType; in @@ -118,28 +141,36 @@ let env = envConfig.environment.variables; pathAdd = envConfig.environment.pathAdd; - makeWrapperArgs = [ - "--argv0" config.arg0 - ] - ++ (lib.mapAttrsToList - (n: v: - if v.action == "unset" - then "--${v.action} ${lib.escapeShellArg n}" - else "--${v.action} ${lib.escapeShellArg n} ${if v.isEscaped then lib.escapeShellArg v.value else v.value}") - config.env) - ++ (builtins.map (v: "--add-flags ${lib.escapeShellArg v}") config.prependArgs) - ++ (builtins.map (v: "--append-flags ${lib.escapeShellArg v}") config.appendArgs) - ++ (lib.optionals (!envConfig.build.isBinary && config.preScript != "") ( - let - preScript = - pkgs.runCommand "wrapper-script-prescript-${config.executableName}" { } config.preScript; - in - [ "--run" preScript ])); + makeWrapperArgs = + [ + "--argv0" + config.arg0 + ] + ++ (lib.mapAttrsToList ( + n: v: + if v.action == "unset" then + "--${v.action} ${lib.escapeShellArg n}" + else + "--${v.action} ${lib.escapeShellArg n} ${ + if v.isEscaped then lib.escapeShellArg v.value else v.value + }" + ) config.env) + ++ (builtins.map (v: "--add-flags ${lib.escapeShellArg v}") config.prependArgs) + ++ (builtins.map (v: "--append-flags ${lib.escapeShellArg v}") config.appendArgs) + ++ (lib.optionals (!envConfig.build.isBinary && config.preScript != "") ( + let + preScript = + pkgs.runCommand "wrapper-script-prescript-${config.executableName}" { } + config.preScript; + in + [ + "--run" + preScript + ] + )); } - (lib.mkIf (config.pathAdd != [ ]) { - env.PATH.value = lib.concatStringsSep ":" config.pathAdd; - }) + (lib.mkIf (config.pathAdd != [ ]) { env.PATH.value = lib.concatStringsSep ":" config.pathAdd; }) ]; }; in diff --git a/modules/wrapper-manager/build.nix b/modules/wrapper-manager/build.nix index f181119..788ce9f 100644 --- a/modules/wrapper-manager/build.nix +++ b/modules/wrapper-manager/build.nix @@ -1,4 +1,9 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: { options.build = { @@ -48,30 +53,27 @@ build = { toplevel = let - mkWrapBuild = wrappers: + mkWrapBuild = + wrappers: lib.concatMapStrings (v: '' makeWrapper "${v.arg0}" "${builtins.placeholder "out"}/bin/${v.executableName}" ${lib.concatStringsSep " " v.makeWrapperArgs} '') wrappers; - mkDesktopEntries = desktopEntries: - builtins.map (entry: pkgs.makeDesktopItem entry) desktopEntries; + mkDesktopEntries = desktopEntries: builtins.map (entry: pkgs.makeDesktopItem entry) desktopEntries; - desktopEntries = - mkDesktopEntries (lib.attrValues config.xdg.desktopEntries); + desktopEntries = mkDesktopEntries (lib.attrValues config.xdg.desktopEntries); in - pkgs.symlinkJoin { - passthru = config.build.extraPassthru; - name = "wrapper-manager-fds-wrapped-package"; - paths = desktopEntries ++ config.basePackages; - nativeBuildInputs = - if config.build.isBinary - then [ pkgs.makeBinaryWrapper ] - else [ pkgs.makeWrapper ]; - postBuild = '' - ${config.build.extraSetup} - ${mkWrapBuild (lib.attrValues config.wrappers)} - ''; - }; + pkgs.symlinkJoin { + passthru = config.build.extraPassthru; + name = "wrapper-manager-fds-wrapped-package"; + paths = desktopEntries ++ config.basePackages; + nativeBuildInputs = + if config.build.isBinary then [ pkgs.makeBinaryWrapper ] else [ pkgs.makeWrapper ]; + postBuild = '' + ${config.build.extraSetup} + ${mkWrapBuild (lib.attrValues config.wrappers)} + ''; + }; }; }; } diff --git a/modules/wrapper-manager/locale.nix b/modules/wrapper-manager/locale.nix index 454fb45..4c7a1c4 100644 --- a/modules/wrapper-manager/locale.nix +++ b/modules/wrapper-manager/locale.nix @@ -1,50 +1,66 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let cfg = config.locale; - localeModuleFactory = { isGlobal ? false }: { - enable = lib.mkOption { - type = lib.types.bool; - default = if isGlobal then true else cfg.enable; - example = false; - description = if isGlobal then '' - Whether to enable explicit glibc locale support. This is recommended - for Nix-built applications. - '' else '' - Whether to enable locale support for this wrapper. Recommended for - Nix-built applications. - ''; - }; + localeModuleFactory = + { + isGlobal ? false, + }: + { + enable = lib.mkOption { + type = lib.types.bool; + default = if isGlobal then true else cfg.enable; + example = false; + description = + if isGlobal then + '' + Whether to enable explicit glibc locale support. This is recommended + for Nix-built applications. + '' + else + '' + Whether to enable locale support for this wrapper. Recommended for + Nix-built applications. + ''; + }; - package = lib.mkOption { - type = lib.types.package; - default = - if isGlobal - then (pkgs.glibcLocales.override { allLocales = true; }) - else cfg.package; - description = '' - The package containing glibc locales. - ''; + package = lib.mkOption { + type = lib.types.package; + default = if isGlobal then (pkgs.glibcLocales.override { allLocales = true; }) else cfg.package; + description = '' + The package containing glibc locales. + ''; + }; }; - }; in { options.locale = localeModuleFactory { isGlobal = true; }; options.wrappers = let - localeSubmodule = { config, lib, name, ... }: let - submoduleCfg = config.locale; - in { - options.locale = localeModuleFactory { isGlobal = false; }; + localeSubmodule = + { + config, + lib, + name, + ... + }: + let + submoduleCfg = config.locale; + in + { + options.locale = localeModuleFactory { isGlobal = false; }; - config = lib.mkIf submoduleCfg.enable { - env.LOCALE_ARCHIVE.value = "${submoduleCfg.package}/lib/locale/locale-archive"; + config = lib.mkIf submoduleCfg.enable { + env.LOCALE_ARCHIVE.value = "${submoduleCfg.package}/lib/locale/locale-archive"; + }; }; - }; in - lib.mkOption { - type = with lib.types; attrsOf (submodule localeSubmodule); - }; + lib.mkOption { type = with lib.types; attrsOf (submodule localeSubmodule); }; } diff --git a/modules/wrapper-manager/xdg-desktop-entries.nix b/modules/wrapper-manager/xdg-desktop-entries.nix index 2d42462..d343c5a 100644 --- a/modules/wrapper-manager/xdg-desktop-entries.nix +++ b/modules/wrapper-manager/xdg-desktop-entries.nix @@ -1,63 +1,81 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: let # We're only setting up options for the most common keys typically used to # set up a desktop entry. Everything else is acceptable under a freeform # module anyways. - xdgDesktopEntry = { name, lib, pkgs, ... }: { - freeformType = with lib.types; attrsOf anything; + xdgDesktopEntry = + { + name, + lib, + pkgs, + ... + }: + { + freeformType = with lib.types; attrsOf anything; - options = { - name = lib.mkOption { - type = lib.types.nonEmptyStr; - description = "The name of the desktop file."; - default = name; - example = "firefox"; - }; + options = { + name = lib.mkOption { + type = lib.types.nonEmptyStr; + description = "The name of the desktop file."; + default = name; + example = "firefox"; + }; - desktopName = lib.mkOption { - type = lib.types.nonEmptyStr; - description = "Specific name of the application."; - default = name; - example = "Firefox"; - }; + desktopName = lib.mkOption { + type = lib.types.nonEmptyStr; + description = "Specific name of the application."; + default = name; + example = "Firefox"; + }; - exec = lib.mkOption { - type = with lib.types; nullOr nonEmptyStr; - description = "Program with execute along with its arguments."; - default = null; - example = "firefox %U"; - }; + exec = lib.mkOption { + type = with lib.types; nullOr nonEmptyStr; + description = "Program with execute along with its arguments."; + default = null; + example = "firefox %U"; + }; - genericName = lib.mkOption { - type = with lib.types; nullOr nonEmptyStr; - description = "Generic name of the application."; - default = null; - example = "Web browser"; - }; + genericName = lib.mkOption { + type = with lib.types; nullOr nonEmptyStr; + description = "Generic name of the application."; + default = null; + example = "Web browser"; + }; - terminal = lib.mkOption { - type = lib.types.bool; - description = "Whether the program runs in a terminal window."; - default = false; - example = true; - }; + terminal = lib.mkOption { + type = lib.types.bool; + description = "Whether the program runs in a terminal window."; + default = false; + example = true; + }; - categories = lib.mkOption { - type = with lib.types; listOf nonEmptyStr; - description = "List of categories should the application be shown in a menu."; - default = [ ]; - example = [ "Applications" "Network" ]; - }; + categories = lib.mkOption { + type = with lib.types; listOf nonEmptyStr; + description = "List of categories should the application be shown in a menu."; + default = [ ]; + example = [ + "Applications" + "Network" + ]; + }; - mimeTypes = lib.mkOption { - type = with lib.types; listOf nonEmptyStr; - description = "The MIME types supported by the application."; - default = [ ]; - example = [ "text/html" "text/xml" ]; + mimeTypes = lib.mkOption { + type = with lib.types; listOf nonEmptyStr; + description = "The MIME types supported by the application."; + default = [ ]; + example = [ + "text/html" + "text/xml" + ]; + }; }; }; - }; in { options.xdg.desktopEntries = lib.mkOption { @@ -89,44 +107,51 @@ in options.wrappers = lib.mkOption { type = let - xdgDesktopEntryWrapperSubmodule = { name, config, lib, ... }: { - options.xdg.desktopEntry = { - enable = - lib.mkEnableOption "automatic creation of a desktop entry for the wrapper"; - settings = lib.mkOption { - type = lib.types.submodule xdgDesktopEntry; - description = '' - Settings to be passed to the `makeDesktopItem` builder. - ''; - example = lib.literalExpression '' - { - mimeTypes = [ "text/html" "text/xml" ]; - categories = [ "Applications" "Network" ]; - } - ''; + xdgDesktopEntryWrapperSubmodule = + { + name, + config, + lib, + ... + }: + { + options.xdg.desktopEntry = { + enable = lib.mkEnableOption "automatic creation of a desktop entry for the wrapper"; + settings = lib.mkOption { + type = lib.types.submodule xdgDesktopEntry; + description = '' + Settings to be passed to the `makeDesktopItem` builder. + ''; + example = lib.literalExpression '' + { + mimeTypes = [ "text/html" "text/xml" ]; + categories = [ "Applications" "Network" ]; + } + ''; + }; + }; + + config.xdg.desktopEntry.settings = lib.mkIf config.xdg.desktopEntry.enable { + name = lib.mkDefault config.executableName; + desktopName = lib.mkDefault name; + type = lib.mkDefault "Application"; + + # Welp, we could set it to the absolute location of the wrapper + # executable in the final output but it's a big pain the ass to do + # so we're opting to the executable name instead. This current + # way of doing it is simply the next best (and the simplest) thing. + # We just have to make sure the build step for the wrapper script + # is consistent throughout the entire module environment. + # + # Besides, if the user wants a desktop entry along with the wrapper + # script, it will be included alongside in whatever environment + # they are using it for anyways. + exec = config.executableName; }; }; - - config.xdg.desktopEntry.settings = lib.mkIf config.xdg.desktopEntry.enable { - name = lib.mkDefault config.executableName; - desktopName = lib.mkDefault name; - type = lib.mkDefault "Application"; - - # Welp, we could set it to the absolute location of the wrapper - # executable in the final output but it's a big pain the ass to do - # so we're opting to the executable name instead. This current - # way of doing it is simply the next best (and the simplest) thing. - # We just have to make sure the build step for the wrapper script - # is consistent throughout the entire module environment. - # - # Besides, if the user wants a desktop entry along with the wrapper - # script, it will be included alongside in whatever environment - # they are using it for anyways. - exec = config.executableName; - }; - }; in - with lib.types; attrsOf (submodule xdgDesktopEntryWrapperSubmodule); + with lib.types; + attrsOf (submodule xdgDesktopEntryWrapperSubmodule); }; config = { @@ -134,6 +159,6 @@ in let wrappersWithDesktopEntries = lib.filterAttrs (_: v: v.xdg.desktopEntry.enable) config.wrappers; in - lib.mapAttrs (_: v: v.xdg.desktopEntry.settings) wrappersWithDesktopEntries; + lib.mapAttrs (_: v: v.xdg.desktopEntry.settings) wrappersWithDesktopEntries; }; } diff --git a/modules/wrapper-manager/xdg-dirs.nix b/modules/wrapper-manager/xdg-dirs.nix index 5209273..3557533 100644 --- a/modules/wrapper-manager/xdg-dirs.nix +++ b/modules/wrapper-manager/xdg-dirs.nix @@ -41,26 +41,34 @@ in options.wrappers = lib.mkOption { type = let - xdgDirsType = { name, lib, config, ... }: { - options.xdg = xdgDirsOption; + xdgDirsType = + { + name, + lib, + config, + ... + }: + { + options.xdg = xdgDirsOption; - config = lib.mkMerge [ - { - # When set this way, we could allow the user to override everything. - xdg.configDirs = cfg.configDirs; - xdg.dataDirs = cfg.dataDirs; - } + config = lib.mkMerge [ + { + # When set this way, we could allow the user to override everything. + xdg.configDirs = cfg.configDirs; + xdg.dataDirs = cfg.dataDirs; + } - (lib.mkIf (config.xdg.configDirs != [ ]) { - env.XDG_CONFIG_DIRS.value = lib.concatStringsSep ":" config.xdg.configDirs; - }) + (lib.mkIf (config.xdg.configDirs != [ ]) { + env.XDG_CONFIG_DIRS.value = lib.concatStringsSep ":" config.xdg.configDirs; + }) - (lib.mkIf (config.xdg.dataDirs != [ ]) { - env.XDG_DATA_DIRS.value = lib.concatStringsSep ":" config.xdg.dataDirs; - }) - ]; - }; + (lib.mkIf (config.xdg.dataDirs != [ ]) { + env.XDG_DATA_DIRS.value = lib.concatStringsSep ":" config.xdg.dataDirs; + }) + ]; + }; in - with lib.types; attrsOf (submodule xdgDirsType); + with lib.types; + attrsOf (submodule xdgDirsType); }; } diff --git a/shell.nix b/shell.nix index 25d150d..f338268 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,9 @@ let sources = import ./npins; in -{ pkgs ? import sources.nixos-unstable { } }: +{ + pkgs ? import sources.nixos-unstable { }, +}: let docs = import ./docs { inherit pkgs; }; @@ -12,7 +14,7 @@ pkgs.mkShell { packages = with pkgs; [ npins treefmt - nixpkgs-fmt + nixfmt-rfc-style # For easy validation of the test suite. yajsv diff --git a/tests/configs/default.nix b/tests/configs/default.nix index 5cdc45b..b8b90c6 100644 --- a/tests/configs/default.nix +++ b/tests/configs/default.nix @@ -1,13 +1,13 @@ let sources = import ../../npins; in -{ pkgs ? import sources.nixos-unstable { } }: +{ + pkgs ? import sources.nixos-unstable { }, +}: let wmLib = (import ../../. { }).lib; - build = modules: wmLib.build { - inherit pkgs modules; - }; + build = modules: wmLib.build { inherit pkgs modules; }; in { fastfetch = build [ ./wrapper-fastfetch.nix ]; diff --git a/tests/configs/wrapper-fastfetch.nix b/tests/configs/wrapper-fastfetch.nix index 239e979..98fbee2 100644 --- a/tests/configs/wrapper-fastfetch.nix +++ b/tests/configs/wrapper-fastfetch.nix @@ -1,18 +1,28 @@ -{ config, lib, pkgs, ... }: +{ + config, + lib, + pkgs, + ... +}: { wrappers.fastfetch = { arg0 = lib.getExe' pkgs.fastfetch "fastfetch"; - appendArgs = [ "--logo" "Guix" ]; + appendArgs = [ + "--logo" + "Guix" + ]; env.NO_COLOR.value = "1"; xdg.desktopEntry.enable = true; }; build.extraPassthru.tests = { - actuallyBuilt = let - wrapper = config.build.toplevel; - in pkgs.runCommand "wrapper-manager-fastfetch-actually-built" { } '' - [ -e "${wrapper}/share/applications/fastfetch.desktop" ] && [ -x "${wrapper}/bin/${config.wrappers.fastfetch.executableName}" ] && touch $out - ''; + actuallyBuilt = + let + wrapper = config.build.toplevel; + in + pkgs.runCommand "wrapper-manager-fastfetch-actually-built" { } '' + [ -e "${wrapper}/share/applications/fastfetch.desktop" ] && [ -x "${wrapper}/bin/${config.wrappers.fastfetch.executableName}" ] && touch $out + ''; }; } diff --git a/tests/configs/wrapper-neofetch.nix b/tests/configs/wrapper-neofetch.nix index 6db34f8..d012fad 100644 --- a/tests/configs/wrapper-neofetch.nix +++ b/tests/configs/wrapper-neofetch.nix @@ -1,21 +1,32 @@ -{ config, lib, pkgs, yourMomName, ... }: +{ + config, + lib, + pkgs, + yourMomName, + ... +}: { wrappers.neofetch = { arg0 = lib.getExe' pkgs.neofetch "neofetch"; executableName = yourMomName; appendArgs = [ - "--ascii_distro" "guix" - "--title_fqdn" "off" - "--os_arch" "off" + "--ascii_distro" + "guix" + "--title_fqdn" + "off" + "--os_arch" + "off" ]; }; build.extraPassthru.tests = { - actuallyBuilt = let - wrapper = config.build.toplevel; - in pkgs.runCommand "wrapper-manager-neofetch-actually-built" { } '' - [ -x "${wrapper}/bin/${config.wrappers.fastfetch.executableName}" ] && touch $out - ''; + actuallyBuilt = + let + wrapper = config.build.toplevel; + in + pkgs.runCommand "wrapper-manager-neofetch-actually-built" { } '' + [ -x "${wrapper}/bin/${config.wrappers.fastfetch.executableName}" ] && touch $out + ''; }; } diff --git a/tests/default.nix b/tests/default.nix index bea8479..1593b9d 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,7 +1,9 @@ let sources = import ../npins; in -{ pkgs ? import sources.nixos-unstable { } }: +{ + pkgs ? import sources.nixos-unstable { }, +}: let lib = import ./lib { inherit pkgs; }; @@ -9,11 +11,16 @@ in { inherit lib; libTestPkg = - pkgs.runCommand "wrapper-manager-fds-lib-test" { - testData = builtins.toJSON lib; - passAsFile = [ "testData" ]; - nativeBuildInputs = with pkgs; [ yajsv jq ]; - } '' - yajsv -s "${./lib/tests.schema.json}" "$testDataPath" && touch $out || jq . "$testDataPath" - ''; + pkgs.runCommand "wrapper-manager-fds-lib-test" + { + testData = builtins.toJSON lib; + passAsFile = [ "testData" ]; + nativeBuildInputs = with pkgs; [ + yajsv + jq + ]; + } + '' + yajsv -s "${./lib/tests.schema.json}" "$testDataPath" && touch $out || jq . "$testDataPath" + ''; } diff --git a/tests/lib/default.nix b/tests/lib/default.nix index 1079b29..ce4f6c8 100644 --- a/tests/lib/default.nix +++ b/tests/lib/default.nix @@ -2,10 +2,13 @@ let lib = import ../../lib { inherit pkgs; }; - callLib = file: import file { - inherit (pkgs) lib; inherit pkgs; - self = lib; - }; + callLib = + file: + import file { + inherit (pkgs) lib; + inherit pkgs; + self = lib; + }; in { env = callLib ./env; diff --git a/tests/lib/env/default.nix b/tests/lib/env/default.nix index 44dfb19..c3cef52 100644 --- a/tests/lib/env/default.nix +++ b/tests/lib/env/default.nix @@ -1,4 +1,8 @@ -{ pkgs, lib, self }: +{ + pkgs, + lib, + self, +}: let neofetchWrapper = ../../configs/wrapper-neofetch.nix; @@ -14,7 +18,7 @@ lib.runTests { specialArgs.yourMomName = "Joe Mama"; }; in - lib.isDerivation sampleConf.config.build.toplevel; + lib.isDerivation sampleConf.config.build.toplevel; expected = true; }; @@ -27,7 +31,7 @@ lib.runTests { specialArgs.yourMomName = "Joe Mama"; }; in - lib.isDerivation sampleConf.config.build.toplevel; + lib.isDerivation sampleConf.config.build.toplevel; expected = true; }; @@ -40,7 +44,7 @@ lib.runTests { specialArgs.yourMomName = "Joe Mama"; }; in - lib.isDerivation sampleConf; + lib.isDerivation sampleConf; expected = true; }; @@ -53,7 +57,7 @@ lib.runTests { specialArgs.yourMomName = "Joe Mama"; }; in - lib.isDerivation sampleConf; + lib.isDerivation sampleConf; expected = true; }; } diff --git a/tests/lib/utils.nix b/tests/lib/utils.nix index 735fc03..08bd69f 100644 --- a/tests/lib/utils.nix +++ b/tests/lib/utils.nix @@ -1,4 +1,8 @@ -{ pkgs, lib, self }: +{ + pkgs, + lib, + self, +}: lib.runTests { testsUtilsGetBin = {