🎨 nixpkgs-fmt

This commit is contained in:
James Walker 2022-05-06 20:01:04 -04:00
parent be14e0698c
commit ea5ba53e3c
Signed by: walkah
GPG Key ID: 3C127179D6086E93
9 changed files with 187 additions and 164 deletions

View File

@ -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 let
mkSystem = hostName: system: modules: mkSystem = hostName: system: modules:
nixpkgs.lib.nixosSystem { nixpkgs.lib.nixosSystem {
system = system; system = system;
modules = [ modules = [
@ -26,29 +35,33 @@
home-manager.useGlobalPkgs = true; home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true; home-manager.useUserPackages = true;
}) })
] ] ++ modules;
++ modules;
}; };
in in
flake-utils.lib.eachDefaultSystem flake-utils.lib.eachDefaultSystem
(system: (system:
let let pkgs = nixpkgs.legacyPackages.${system};
pkgs = nixpkgs.legacyPackages.${system}; in
in {
{ devShells.default = pkgs.mkShell {
devShells.default = pkgs.mkShell { buildInputs = [ deploy-rs.packages.${system}.deploy-rs pkgs.sops ];
buildInputs = [ deploy-rs.packages.${system}.deploy-rs pkgs.sops ]; };
}; }) // {
}) // {
nixosConfigurations = { nixosConfigurations = {
# Aristotle # Aristotle
agent = mkSystem "agent" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; agent = mkSystem "agent" "aarch64-linux"
form = mkSystem "form" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; [ ./hosts/aristotle/configuration.nix ];
matter = mkSystem "matter" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; form = mkSystem "form" "aarch64-linux"
purpose = mkSystem "purpose" "aarch64-linux" [ ./hosts/aristotle/configuration.nix ]; [ ./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 ]; plato =
socrates = mkSystem "socrates" "x86_64-linux" [ ./hosts/socrates/configuration.nix ]; mkSystem "plato" "x86_64-linux" [ ./hosts/plato/configuration.nix ];
socrates = mkSystem "socrates" "x86_64-linux"
[ ./hosts/socrates/configuration.nix ];
}; };
deploy.nodes = { deploy.nodes = {

View File

@ -16,91 +16,91 @@
/ { / {
compatible = "brcm,bcm2711"; compatible = "brcm,bcm2711";
fragment@0 { fragment@0 {
target-path = "/"; target-path = "/";
__overlay__ { __overlay__ {
fan0: rpi-poe-fan@0 { fan0: rpi-poe-fan@0 {
compatible = "raspberrypi,rpi-poe-fan"; compatible = "raspberrypi,rpi-poe-fan";
firmware = <&firmware>; firmware = <&firmware>;
cooling-min-state = <0>; cooling-min-state = <0>;
cooling-max-state = <4>; cooling-max-state = <4>;
#cooling-cells = <2>; #cooling-cells = <2>;
cooling-levels = <0 1 10 100 255>; cooling-levels = <0 1 10 100 255>;
status = "okay"; status = "okay";
}; };
}; };
}; };
fragment@1 { fragment@1 {
target = <&cpu_thermal>; target = <&cpu_thermal>;
__overlay__ { __overlay__ {
trips { trips {
trip0: trip0 { trip0: trip0 {
temperature = <40000>; temperature = <40000>;
hysteresis = <2000>; hysteresis = <2000>;
type = "active"; type = "active";
}; };
trip1: trip1 { trip1: trip1 {
temperature = <45000>; temperature = <45000>;
hysteresis = <2000>; hysteresis = <2000>;
type = "active"; type = "active";
}; };
trip2: trip2 { trip2: trip2 {
temperature = <50000>; temperature = <50000>;
hysteresis = <2000>; hysteresis = <2000>;
type = "active"; type = "active";
}; };
trip3: trip3 { trip3: trip3 {
temperature = <55000>; temperature = <55000>;
hysteresis = <5000>; hysteresis = <5000>;
type = "active"; type = "active";
}; };
}; };
cooling-maps { cooling-maps {
map0 { map0 {
trip = <&trip0>; trip = <&trip0>;
cooling-device = <&fan0 0 1>; cooling-device = <&fan0 0 1>;
}; };
map1 { map1 {
trip = <&trip1>; trip = <&trip1>;
cooling-device = <&fan0 1 2>; cooling-device = <&fan0 1 2>;
}; };
map2 { map2 {
trip = <&trip2>; trip = <&trip2>;
cooling-device = <&fan0 2 3>; cooling-device = <&fan0 2 3>;
}; };
map3 { map3 {
trip = <&trip3>; trip = <&trip3>;
cooling-device = <&fan0 3 4>; cooling-device = <&fan0 3 4>;
}; };
}; };
}; };
}; };
fragment@2 { fragment@2 {
target-path = "/__overrides__"; target-path = "/__overrides__";
__overlay__ { __overlay__ {
poe_fan_temp0 = <&trip0>,"temperature:0"; poe_fan_temp0 = <&trip0>,"temperature:0";
poe_fan_temp0_hyst = <&trip0>,"hysteresis:0"; poe_fan_temp0_hyst = <&trip0>,"hysteresis:0";
poe_fan_temp1 = <&trip1>,"temperature:0"; poe_fan_temp1 = <&trip1>,"temperature:0";
poe_fan_temp1_hyst = <&trip1>,"hysteresis:0"; poe_fan_temp1_hyst = <&trip1>,"hysteresis:0";
poe_fan_temp2 = <&trip2>,"temperature:0"; poe_fan_temp2 = <&trip2>,"temperature:0";
poe_fan_temp2_hyst = <&trip2>,"hysteresis:0"; poe_fan_temp2_hyst = <&trip2>,"hysteresis:0";
poe_fan_temp3 = <&trip3>,"temperature:0"; poe_fan_temp3 = <&trip3>,"temperature:0";
poe_fan_temp3_hyst = <&trip3>,"hysteresis:0"; poe_fan_temp3_hyst = <&trip3>,"hysteresis:0";
}; };
}; };
__overrides__ { __overrides__ {
poe_fan_temp0 = <&trip0>,"temperature:0"; poe_fan_temp0 = <&trip0>,"temperature:0";
poe_fan_temp0_hyst = <&trip0>,"hysteresis:0"; poe_fan_temp0_hyst = <&trip0>,"hysteresis:0";
poe_fan_temp1 = <&trip1>,"temperature:0"; poe_fan_temp1 = <&trip1>,"temperature:0";
poe_fan_temp1_hyst = <&trip1>,"hysteresis:0"; poe_fan_temp1_hyst = <&trip1>,"hysteresis:0";
poe_fan_temp2 = <&trip2>,"temperature:0"; poe_fan_temp2 = <&trip2>,"temperature:0";
poe_fan_temp2_hyst = <&trip2>,"hysteresis:0"; poe_fan_temp2_hyst = <&trip2>,"hysteresis:0";
poe_fan_temp3 = <&trip3>,"temperature:0"; poe_fan_temp3 = <&trip3>,"temperature:0";
poe_fan_temp3_hyst = <&trip3>,"hysteresis:0"; poe_fan_temp3_hyst = <&trip3>,"hysteresis:0";
}; };
}; };
''; '';
}]; }];

View File

@ -42,4 +42,4 @@
Xcode = 497799835; Xcode = 497799835;
}; };
}; };
} }

View File

@ -2,7 +2,8 @@
with lib; with lib;
let cfg = config.walkah.coredns; let cfg = config.walkah.coredns;
in { in
{
options.walkah.coredns = { options.walkah.coredns = {
enable = mkEnableOption ""; enable = mkEnableOption "";
addr = mkOption { addr = mkOption {

View File

@ -1,7 +1,8 @@
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
let cfg = config.services.gitea; let cfg = config.services.gitea;
in { in
{
users.users.git = { users.users.git = {
description = "Gitea Service"; description = "Gitea Service";
home = cfg.stateDir; home = cfg.stateDir;

View File

@ -22,7 +22,8 @@ let
} }
]; ];
in { in
{
imports = [ ./default.nix ]; imports = [ ./default.nix ];
environment.systemPackages = with pkgs; [ ipfs-migrator ]; environment.systemPackages = with pkgs; [ ipfs-migrator ];

View File

@ -15,20 +15,23 @@
enableACME = true; enableACME = true;
locations."= /.well-known/matrix/server".extraConfig = locations."= /.well-known/matrix/server".extraConfig =
let server = { "m.server" = "matrix.walkah.chat:443"; }; let server = { "m.server" = "matrix.walkah.chat:443"; };
in '' in
''
default_type application/json; default_type application/json;
add_header Access-Control-Allow-Origin *; add_header Access-Control-Allow-Origin *;
return 200 '${builtins.toJSON server}'; return 200 '${builtins.toJSON server}';
''; '';
locations."= /.well-known/matrix/client".extraConfig = let locations."= /.well-known/matrix/client".extraConfig =
client = { let
"m.homeserver" = { "base_url" = "https://matrix.walkah.chat"; }; client = {
}; "m.homeserver" = { "base_url" = "https://matrix.walkah.chat"; };
in '' };
default_type application/json; in
add_header Access-Control-Allow-Origin *; ''
return 200 '${builtins.toJSON client}'; default_type application/json;
''; add_header Access-Control-Allow-Origin *;
return 200 '${builtins.toJSON client}';
'';
locations."/" = { root = pkgs.element-web; }; locations."/" = { root = pkgs.element-web; };
}; };
}; };

View File

@ -10,31 +10,31 @@ let
let let
name' = sanitizeName name + "-src"; name' = sanitizeName name + "-src";
in in
if spec.builtin or true then if spec.builtin or true then
builtins_fetchurl { inherit (spec) url sha256; name = name'; } builtins_fetchurl { inherit (spec) url sha256; name = name'; }
else else
pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; pkgs.fetchurl { inherit (spec) url sha256; name = name'; };
fetch_tarball = pkgs: name: spec: fetch_tarball = pkgs: name: spec:
let let
name' = sanitizeName name + "-src"; name' = sanitizeName name + "-src";
in in
if spec.builtin or true then if spec.builtin or true then
builtins_fetchTarball { name = name'; inherit (spec) url sha256; } builtins_fetchTarball { name = name'; inherit (spec) url sha256; }
else else
pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; pkgs.fetchzip { name = name'; inherit (spec) url sha256; };
fetch_git = name: spec: fetch_git = name: spec:
let let
ref = ref =
if spec ? ref then spec.ref else if spec ? ref then spec.ref else
if spec ? branch then "refs/heads/${spec.branch}" else if spec ? branch then "refs/heads/${spec.branch}" else
if spec ? tag then "refs/tags/${spec.tag}" else if spec ? tag then "refs/tags/${spec.tag}" else
abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!";
submodules = if spec ? submodules then spec.submodules else false; submodules = if spec ? submodules then spec.submodules else false;
in in
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; } builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }
// (if builtins.compareVersions builtins.nixVersion "2.4" >= 0 then { inherit submodules; } else {}); // (if builtins.compareVersions builtins.nixVersion "2.4" >= 0 then { inherit submodules; } else { });
fetch_local = spec: spec.path; fetch_local = spec: spec.path;
@ -68,16 +68,16 @@ let
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath; hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.; hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in in
if builtins.hasAttr "nixpkgs" sources if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {} import <nixpkgs> { }
else else
abort abort
'' ''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json. add a package called "nixpkgs" to your sources.json.
''; '';
# The actual fetching function. # The actual fetching function.
fetch = pkgs: name: spec: 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; saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name;
ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}";
in in
if ersatz == "" then drv else if ersatz == "" then drv else
# this turns the string into an actual Nix path (for both absolute and # this turns the string into an actual Nix path (for both absolute and
# relative paths) # relative paths)
if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}";
# Ports of functions for older nix versions # Ports of functions for older nix versions
@ -114,7 +114,7 @@ let
); );
# https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 # 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 # 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)); stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1));
@ -125,43 +125,46 @@ let
concatStrings = builtins.concatStringsSep ""; concatStrings = builtins.concatStringsSep "";
# https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 # 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 # fetchTarball version that is compatible between all the versions of Nix
builtins_fetchTarball = { url, name ? null, sha256 }@attrs: builtins_fetchTarball = { url, name ? null, sha256 }@attrs:
let let
inherit (builtins) lessThan nixVersion fetchTarball; inherit (builtins) lessThan nixVersion fetchTarball;
in in
if lessThan nixVersion "1.12" then if lessThan nixVersion "1.12" then
fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else else
fetchTarball attrs; fetchTarball attrs;
# fetchurl version that is compatible between all the versions of Nix # fetchurl version that is compatible between all the versions of Nix
builtins_fetchurl = { url, name ? null, sha256 }@attrs: builtins_fetchurl = { url, name ? null, sha256 }@attrs:
let let
inherit (builtins) lessThan nixVersion fetchurl; inherit (builtins) lessThan nixVersion fetchurl;
in in
if lessThan nixVersion "1.12" then if lessThan nixVersion "1.12" then
fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; }))
else else
fetchurl attrs; fetchurl attrs;
# Create the final "sources" from the config # Create the final "sources" from the config
mkSources = config: mkSources = config:
mapAttrs ( mapAttrs
name: spec: (
if builtins.hasAttr "outPath" spec name: spec:
then abort if builtins.hasAttr "outPath" spec
"The values in sources.json should not have an 'outPath' attribute" then
else abort
spec // { outPath = replace name (fetch config.pkgs name spec); } "The values in sources.json should not have an 'outPath' attribute"
) config.sources; else
spec // { outPath = replace name (fetch config.pkgs name spec); }
)
config.sources;
# The "config" used by the fetchers # The "config" used by the fetchers
mkConfig = mkConfig =
{ sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null { 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 , system ? builtins.currentSystem
, pkgs ? mkPkgs sources system , pkgs ? mkPkgs sources system
}: rec { }: rec {
@ -173,4 +176,4 @@ let
}; };
in in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); } mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }

View File

@ -10,7 +10,8 @@ let
(optionalString (cfg.initPeers != [ ]) "--peers") (optionalString (cfg.initPeers != [ ]) "--peers")
(lib.strings.concatStringsSep "," cfg.initPeers) (lib.strings.concatStringsSep "," cfg.initPeers)
]; ];
in { in
{
###### interface ###### interface
@ -97,9 +98,9 @@ in {
RemainAfterExit = true; RemainAfterExit = true;
User = cfg.user; User = cfg.user;
Group = cfg.group; Group = cfg.group;
} // optionalAttrs (cfg.secretFile != null) { } // optionalAttrs (cfg.secretFile != null) {
EnvironmentFile = cfg.secretFile; EnvironmentFile = cfg.secretFile;
}; };
unitConfig.ConditionDirectoryNotEmpty = "!${cfg.dataDir}"; unitConfig.ConditionDirectoryNotEmpty = "!${cfg.dataDir}";
}; };