From ea5ba53e3c77f2a29c61c8c96eb5d95caa90c535 Mon Sep 17 00:00:00 2001 From: James Walker Date: Fri, 6 May 2022 20:01:04 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20nixpkgs-fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- flake.nix | 47 +++++++---- hosts/aristotle/rpi-poe.nix | 164 ++++++++++++++++++------------------ hosts/epicurus/homebrew.nix | 2 +- modules/coredns/default.nix | 3 +- modules/gitea/default.nix | 3 +- modules/ipfs/gateway.nix | 3 +- modules/matrix/nginx.nix | 23 ++--- nix/sources.nix | 97 ++++++++++----------- services/ipfs-cluster.nix | 9 +- 9 files changed, 187 insertions(+), 164 deletions(-) diff --git a/flake.nix b/flake.nix index f60fc1c..ce48b9f 100644 --- a/flake.nix +++ b/flake.nix @@ -14,9 +14,18 @@ }; }; - outputs = { self, nixpkgs, deploy-rs, flake-utils, home-manager, dotfiles, ... }@attrs: + outputs = + { self + , nixpkgs + , deploy-rs + , flake-utils + , home-manager + , dotfiles + , ... + }@attrs: let mkSystem = hostName: system: modules: + nixpkgs.lib.nixosSystem { system = system; modules = [ @@ -26,29 +35,33 @@ home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; }) - ] - ++ modules; + ] ++ modules; }; in flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShells.default = pkgs.mkShell { - buildInputs = [ deploy-rs.packages.${system}.deploy-rs pkgs.sops ]; - }; - }) // { + let pkgs = nixpkgs.legacyPackages.${system}; + in + { + devShells.default = pkgs.mkShell { + buildInputs = [ deploy-rs.packages.${system}.deploy-rs pkgs.sops ]; + }; + }) // { nixosConfigurations = { # Aristotle - agent = mkSystem "agent" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; - form = mkSystem "form" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; - matter = mkSystem "matter" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; - purpose = mkSystem "purpose" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; + agent = mkSystem "agent" "aarch64-linux" + [ ./hosts/aristotle/configuration.nix ]; + form = mkSystem "form" "aarch64-linux" + [ ./hosts/aristotle/configuration.nix ]; + matter = mkSystem "matter" "aarch64-linux" + [ ./hosts/aristotle/configuration.nix ]; + purpose = mkSystem "purpose" "aarch64-linux" + [ ./hosts/aristotle/configuration.nix ]; - plato = mkSystem "plato" "x86_64-linux" [ ./hosts/plato/configuration.nix ]; - socrates = mkSystem "socrates" "x86_64-linux" [ ./hosts/socrates/configuration.nix ]; + plato = + mkSystem "plato" "x86_64-linux" [ ./hosts/plato/configuration.nix ]; + socrates = mkSystem "socrates" "x86_64-linux" + [ ./hosts/socrates/configuration.nix ]; }; deploy.nodes = { diff --git a/hosts/aristotle/rpi-poe.nix b/hosts/aristotle/rpi-poe.nix index 116b6b0..63572a9 100644 --- a/hosts/aristotle/rpi-poe.nix +++ b/hosts/aristotle/rpi-poe.nix @@ -16,91 +16,91 @@ / { compatible = "brcm,bcm2711"; - fragment@0 { - target-path = "/"; - __overlay__ { - fan0: rpi-poe-fan@0 { - compatible = "raspberrypi,rpi-poe-fan"; - firmware = <&firmware>; - cooling-min-state = <0>; - cooling-max-state = <4>; - #cooling-cells = <2>; - cooling-levels = <0 1 10 100 255>; - status = "okay"; - }; - }; - }; + fragment@0 { + target-path = "/"; + __overlay__ { + fan0: rpi-poe-fan@0 { + compatible = "raspberrypi,rpi-poe-fan"; + firmware = <&firmware>; + cooling-min-state = <0>; + cooling-max-state = <4>; + #cooling-cells = <2>; + cooling-levels = <0 1 10 100 255>; + status = "okay"; + }; + }; + }; - fragment@1 { - target = <&cpu_thermal>; - __overlay__ { - trips { - trip0: trip0 { - temperature = <40000>; - hysteresis = <2000>; - type = "active"; - }; - trip1: trip1 { - temperature = <45000>; - hysteresis = <2000>; - type = "active"; - }; - trip2: trip2 { - temperature = <50000>; - hysteresis = <2000>; - type = "active"; - }; - trip3: trip3 { - temperature = <55000>; - hysteresis = <5000>; - type = "active"; - }; - }; - cooling-maps { - map0 { - trip = <&trip0>; - cooling-device = <&fan0 0 1>; - }; - map1 { - trip = <&trip1>; - cooling-device = <&fan0 1 2>; - }; - map2 { - trip = <&trip2>; - cooling-device = <&fan0 2 3>; - }; - map3 { - trip = <&trip3>; - cooling-device = <&fan0 3 4>; - }; - }; - }; - }; + fragment@1 { + target = <&cpu_thermal>; + __overlay__ { + trips { + trip0: trip0 { + temperature = <40000>; + hysteresis = <2000>; + type = "active"; + }; + trip1: trip1 { + temperature = <45000>; + hysteresis = <2000>; + type = "active"; + }; + trip2: trip2 { + temperature = <50000>; + hysteresis = <2000>; + type = "active"; + }; + trip3: trip3 { + temperature = <55000>; + hysteresis = <5000>; + type = "active"; + }; + }; + cooling-maps { + map0 { + trip = <&trip0>; + cooling-device = <&fan0 0 1>; + }; + map1 { + trip = <&trip1>; + cooling-device = <&fan0 1 2>; + }; + map2 { + trip = <&trip2>; + cooling-device = <&fan0 2 3>; + }; + map3 { + trip = <&trip3>; + cooling-device = <&fan0 3 4>; + }; + }; + }; + }; - fragment@2 { - target-path = "/__overrides__"; - __overlay__ { - poe_fan_temp0 = <&trip0>,"temperature:0"; - poe_fan_temp0_hyst = <&trip0>,"hysteresis:0"; - poe_fan_temp1 = <&trip1>,"temperature:0"; - poe_fan_temp1_hyst = <&trip1>,"hysteresis:0"; - poe_fan_temp2 = <&trip2>,"temperature:0"; - poe_fan_temp2_hyst = <&trip2>,"hysteresis:0"; - poe_fan_temp3 = <&trip3>,"temperature:0"; - poe_fan_temp3_hyst = <&trip3>,"hysteresis:0"; - }; - }; + fragment@2 { + target-path = "/__overrides__"; + __overlay__ { + poe_fan_temp0 = <&trip0>,"temperature:0"; + poe_fan_temp0_hyst = <&trip0>,"hysteresis:0"; + poe_fan_temp1 = <&trip1>,"temperature:0"; + poe_fan_temp1_hyst = <&trip1>,"hysteresis:0"; + poe_fan_temp2 = <&trip2>,"temperature:0"; + poe_fan_temp2_hyst = <&trip2>,"hysteresis:0"; + poe_fan_temp3 = <&trip3>,"temperature:0"; + poe_fan_temp3_hyst = <&trip3>,"hysteresis:0"; + }; + }; - __overrides__ { - poe_fan_temp0 = <&trip0>,"temperature:0"; - poe_fan_temp0_hyst = <&trip0>,"hysteresis:0"; - poe_fan_temp1 = <&trip1>,"temperature:0"; - poe_fan_temp1_hyst = <&trip1>,"hysteresis:0"; - poe_fan_temp2 = <&trip2>,"temperature:0"; - poe_fan_temp2_hyst = <&trip2>,"hysteresis:0"; - poe_fan_temp3 = <&trip3>,"temperature:0"; - poe_fan_temp3_hyst = <&trip3>,"hysteresis:0"; - }; + __overrides__ { + poe_fan_temp0 = <&trip0>,"temperature:0"; + poe_fan_temp0_hyst = <&trip0>,"hysteresis:0"; + poe_fan_temp1 = <&trip1>,"temperature:0"; + poe_fan_temp1_hyst = <&trip1>,"hysteresis:0"; + poe_fan_temp2 = <&trip2>,"temperature:0"; + poe_fan_temp2_hyst = <&trip2>,"hysteresis:0"; + poe_fan_temp3 = <&trip3>,"temperature:0"; + poe_fan_temp3_hyst = <&trip3>,"hysteresis:0"; + }; }; ''; }]; diff --git a/hosts/epicurus/homebrew.nix b/hosts/epicurus/homebrew.nix index 5270580..ed732ca 100644 --- a/hosts/epicurus/homebrew.nix +++ b/hosts/epicurus/homebrew.nix @@ -42,4 +42,4 @@ Xcode = 497799835; }; }; -} \ No newline at end of file +} diff --git a/modules/coredns/default.nix b/modules/coredns/default.nix index 2f2de21..cf8e640 100644 --- a/modules/coredns/default.nix +++ b/modules/coredns/default.nix @@ -2,7 +2,8 @@ with lib; let cfg = config.walkah.coredns; -in { +in +{ options.walkah.coredns = { enable = mkEnableOption ""; addr = mkOption { diff --git a/modules/gitea/default.nix b/modules/gitea/default.nix index 4f7955e..d4adafb 100644 --- a/modules/gitea/default.nix +++ b/modules/gitea/default.nix @@ -1,7 +1,8 @@ { config, lib, pkgs, ... }: let cfg = config.services.gitea; -in { +in +{ users.users.git = { description = "Gitea Service"; home = cfg.stateDir; diff --git a/modules/ipfs/gateway.nix b/modules/ipfs/gateway.nix index 750aed6..12f97cb 100644 --- a/modules/ipfs/gateway.nix +++ b/modules/ipfs/gateway.nix @@ -22,7 +22,8 @@ let } ]; -in { +in +{ imports = [ ./default.nix ]; environment.systemPackages = with pkgs; [ ipfs-migrator ]; diff --git a/modules/matrix/nginx.nix b/modules/matrix/nginx.nix index 9fafab1..2cb5036 100644 --- a/modules/matrix/nginx.nix +++ b/modules/matrix/nginx.nix @@ -15,20 +15,23 @@ enableACME = true; locations."= /.well-known/matrix/server".extraConfig = let server = { "m.server" = "matrix.walkah.chat:443"; }; - in '' + in + '' default_type application/json; add_header Access-Control-Allow-Origin *; return 200 '${builtins.toJSON server}'; ''; - locations."= /.well-known/matrix/client".extraConfig = let - client = { - "m.homeserver" = { "base_url" = "https://matrix.walkah.chat"; }; - }; - in '' - default_type application/json; - add_header Access-Control-Allow-Origin *; - return 200 '${builtins.toJSON client}'; - ''; + locations."= /.well-known/matrix/client".extraConfig = + let + client = { + "m.homeserver" = { "base_url" = "https://matrix.walkah.chat"; }; + }; + in + '' + default_type application/json; + add_header Access-Control-Allow-Origin *; + return 200 '${builtins.toJSON client}'; + ''; locations."/" = { root = pkgs.element-web; }; }; }; diff --git a/nix/sources.nix b/nix/sources.nix index 41af0c6..7c6186d 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -10,31 +10,31 @@ let let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; + if spec.builtin or true then + builtins_fetchurl { inherit (spec) url sha256; name = name'; } + else + pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; fetch_tarball = pkgs: name: spec: let name' = sanitizeName name + "-src"; in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; + if spec.builtin or true then + builtins_fetchTarball { name = name'; inherit (spec) url sha256; } + else + pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; fetch_git = name: spec: let ref = if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; + if spec ? branch then "refs/heads/${spec.branch}" else + if spec ? tag then "refs/tags/${spec.tag}" else + abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; submodules = if spec ? submodules then spec.submodules else false; in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; } - // (if builtins.compareVersions builtins.nixVersion "2.4" >= 0 then { inherit submodules; } else {}); + builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; } + // (if builtins.compareVersions builtins.nixVersion "2.4" >= 0 then { inherit submodules; } else { }); fetch_local = spec: spec.path; @@ -68,16 +68,16 @@ let hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasThisAsNixpkgsPath = == ./.; in - if builtins.hasAttr "nixpkgs" sources - then sourcesNixpkgs - else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then - import {} - else - abort - '' - Please specify either (through -I or NIX_PATH=nixpkgs=...) or - add a package called "nixpkgs" to your sources.json. - ''; + if builtins.hasAttr "nixpkgs" sources + then sourcesNixpkgs + else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then + import { } + else + abort + '' + Please specify either (through -I or NIX_PATH=nixpkgs=...) or + add a package called "nixpkgs" to your sources.json. + ''; # The actual fetching function. fetch = pkgs: name: spec: @@ -100,10 +100,10 @@ let saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; + if ersatz == "" then drv else + # this turns the string into an actual Nix path (for both absolute and + # relative paths) + if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; # Ports of functions for older nix versions @@ -114,7 +114,7 @@ let ); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [] else builtins.genList (n: first + n) (last - first + 1); + range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); @@ -125,43 +125,46 @@ let concatStrings = builtins.concatStringsSep ""; # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else {}; + optionalAttrs = cond: as: if cond then as else { }; # fetchTarball version that is compatible between all the versions of Nix builtins_fetchTarball = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchTarball; in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; + if lessThan nixVersion "1.12" then + fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchTarball attrs; # fetchurl version that is compatible between all the versions of Nix builtins_fetchurl = { url, name ? null, sha256 }@attrs: let inherit (builtins) lessThan nixVersion fetchurl; in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; + if lessThan nixVersion "1.12" then + fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) + else + fetchurl attrs; # Create the final "sources" from the config mkSources = config: - mapAttrs ( - name: spec: - if builtins.hasAttr "outPath" spec - then abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) config.sources; + mapAttrs + ( + name: spec: + if builtins.hasAttr "outPath" spec + then + abort + "The values in sources.json should not have an 'outPath' attribute" + else + spec // { outPath = replace name (fetch config.pkgs name spec); } + ) + config.sources; # The "config" used by the fetchers mkConfig = { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile) + , sources ? if isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile) , system ? builtins.currentSystem , pkgs ? mkPkgs sources system }: rec { @@ -173,4 +176,4 @@ let }; in -mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } +mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } diff --git a/services/ipfs-cluster.nix b/services/ipfs-cluster.nix index 28c28e2..9c08eb2 100644 --- a/services/ipfs-cluster.nix +++ b/services/ipfs-cluster.nix @@ -10,7 +10,8 @@ let (optionalString (cfg.initPeers != [ ]) "--peers") (lib.strings.concatStringsSep "," cfg.initPeers) ]; -in { +in +{ ###### interface @@ -97,9 +98,9 @@ in { RemainAfterExit = true; User = cfg.user; Group = cfg.group; - } // optionalAttrs (cfg.secretFile != null) { - EnvironmentFile = cfg.secretFile; - }; + } // optionalAttrs (cfg.secretFile != null) { + EnvironmentFile = cfg.secretFile; + }; unitConfig.ConditionDirectoryNotEmpty = "!${cfg.dataDir}"; };