Skip to content

Commit

Permalink
chore: lint & fmt with nixpkgs-fmt
Browse files Browse the repository at this point in the history
Signed-off-by: Aaron Pham <[email protected]>
  • Loading branch information
aarnphm authored and yetone committed May 12, 2022
1 parent 136bcb4 commit d496d94
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 108 deletions.
24 changes: 12 additions & 12 deletions nix/go.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ with pkgs; let
toGoKernel = platform:
if platform.isDarwin then "darwin"
else platform.parsed.kernel.name;
hashes = {
# Use `./shells/print-hashes.sh ${version}` to generate the list below
# https://raw.githubusercontent.com/NixOS/nixpkgs/master/pkgs/development/compilers/go/print-hashes.sh
darwin-amd64 = "765c021e372a87ce0bc58d3670ab143008dae9305a79e9fa83440425529bb636";
darwin-arm64 = "ffe45ef267271b9681ca96ca9b0eb9b8598dd82f7bb95b27af3eef2461dc3d2c";
linux-386 = "982487a0264626950c635c5e185df68ecaadcca1361956207578d661a7b03bee";
linux-amd64 = "550f9845451c0c94be679faf116291e7807a8d78b43149f9506c1b15eb89008c";
linux-arm64 = "06f505c8d27203f78706ad04e47050b49092f1b06dc9ac4fbee4f0e4d015c8d4";
linux-armv6l = "aa0d5516c8bd61654990916274d27491cfa229d322475502b247a8dc885adec5";
linux-ppc64le = "b821ff58d088c61adc5d7376179a342f325d8715a06abdeb6974f6450663ee60";
linux-s390x = "7d1727e08fef295f48aed2b8124a07e3752e77aea747fcc7aeb8892b8e2f2ad2";
hashes = {
# Use `./shells/print-hashes.sh ${version}` to generate the list below
# https://raw.githubusercontent.com/NixOS/nixpkgs/master/pkgs/development/compilers/go/print-hashes.sh
darwin-amd64 = "765c021e372a87ce0bc58d3670ab143008dae9305a79e9fa83440425529bb636";
darwin-arm64 = "ffe45ef267271b9681ca96ca9b0eb9b8598dd82f7bb95b27af3eef2461dc3d2c";
linux-386 = "982487a0264626950c635c5e185df68ecaadcca1361956207578d661a7b03bee";
linux-amd64 = "550f9845451c0c94be679faf116291e7807a8d78b43149f9506c1b15eb89008c";
linux-arm64 = "06f505c8d27203f78706ad04e47050b49092f1b06dc9ac4fbee4f0e4d015c8d4";
linux-armv6l = "aa0d5516c8bd61654990916274d27491cfa229d322475502b247a8dc885adec5";
linux-ppc64le = "b821ff58d088c61adc5d7376179a342f325d8715a06abdeb6974f6450663ee60";
linux-s390x = "7d1727e08fef295f48aed2b8124a07e3752e77aea747fcc7aeb8892b8e2f2ad2";

};
};

toGoCPU = platform: {
"i686" = "386";
Expand Down
95 changes: 49 additions & 46 deletions nix/sources.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ 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`!";
in
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };

fetch_local = spec: spec.path;

Expand Down Expand Up @@ -66,16 +66,16 @@ let
hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;
hasThisAsNixpkgsPath = <nixpkgs> == ./.;
in
if builtins.hasAttr "nixpkgs" sources
then sourcesNixpkgs
else if hasNixpkgsPath && ! hasThisAsNixpkgsPath then
import <nixpkgs> {}
else
abort
''
Please specify either <nixpkgs> (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 <nixpkgs> { }
else
abort
''
Please specify either <nixpkgs> (through -I or NIX_PATH=nixpkgs=...) or
add a package called "nixpkgs" to your sources.json.
'';

# The actual fetching function.
fetch = pkgs: name: spec:
Expand All @@ -98,10 +98,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

Expand All @@ -112,7 +112,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));
Expand All @@ -123,43 +123,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 {
Expand All @@ -171,4 +174,4 @@ let
};

in
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }
100 changes: 50 additions & 50 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{ sources ? import nix/sources.nix
, pkgs ? import sources.nixpkgs { overlays = [] ; config = {}; }
, pkgs ? import sources.nixpkgs { overlays = [ ]; config = { }; }
}:

with pkgs;
Expand All @@ -8,7 +8,7 @@ let
inherit (lib) optional optionals;

# custom defined packages in nixpkgs
go = callPackage ./nix/go.nix { pkgs=pkgs; };
go = callPackage ./nix/go.nix { pkgs = pkgs; };
nodejs = nodejs-14_x;
postgresql = postgresql_14;

Expand Down Expand Up @@ -40,59 +40,59 @@ let
requiredPackages = basePackages
++ lib.optional stdenv.isLinux inotify-tools
++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [
CoreFoundation
CoreServices
]);
CoreFoundation
CoreServices
]);

env = buildEnv {
name = "build-env";
paths = requiredPackages;
};

in
stdenv.mkDerivation rec {
name = "yatai-dev";

phases = ["nobuild"];
buildInputs = [env];

shellHook = ''
# "nix-shell --pure" resets LANG to POSIX, this breaks "make TAGS".
export LANG="en_US.UTF-8"
# /bin/ps cannot be found in the build environment.
export PATH="/bin:/usr/bin:/usr/local/bin:/usr/sbin:$PATH"
# setup for dashboard
alias scripts='jq ".scripts" dashboard/package.json'
make fe-deps be-deps
export PGDATA=${pg_root}
export SOCKET_DIRECTORIES="$PWD/sockets"
mkdir $SOCKET_DIRECTORIES
if [ ! -d "$PGDATA" ]; then
initdb --auth=trust --auth-host=trust >/dev/null
echo "unix_socket_directories = '$SOCKET_DIRECTORIES'" >> $PGDATA/postgresql.conf
createuser ${pg_user} --createdb -h ${pg_host}
createdb ${pg_db} -h ${pg_host} k-O ${pg_user}
fi
pg_ctl -l $PGDATA/logfile start
function end {
echo "Shutting down the database..."
pg_ctl stop
echo "Removing directories..."
rm -rf $SOCKET_DIRECTORIES
}
trap end EXIT
'';
enableParallelBuilding = true;

LOCALE_ARCHIVE = if stdenv.isLinux then "${glibcLocales}/lib/locale/locale-archive" else "";

nobuild = ''
echo Do not run this derivation with nix-build, it can only be used with nix-shell
'';
stdenv.mkDerivation rec {
name = "yatai-dev";

phases = [ "nobuild" ];
buildInputs = [ env ];

shellHook = ''
# "nix-shell --pure" resets LANG to POSIX, this breaks "make TAGS".
export LANG="en_US.UTF-8"
# /bin/ps cannot be found in the build environment.
export PATH="/bin:/usr/bin:/usr/local/bin:/usr/sbin:$PATH"
# setup for dashboard
alias scripts='jq ".scripts" dashboard/package.json'
make fe-deps be-deps
export PGDATA=${pg_root}
export SOCKET_DIRECTORIES="$PWD/sockets"
mkdir $SOCKET_DIRECTORIES
if [ ! -d "$PGDATA" ]; then
initdb --auth=trust --auth-host=trust >/dev/null
echo "unix_socket_directories = '$SOCKET_DIRECTORIES'" >> $PGDATA/postgresql.conf
createuser ${pg_user} --createdb -h ${pg_host}
createdb ${pg_db} -h ${pg_host} k-O ${pg_user}
fi
pg_ctl -l $PGDATA/logfile start
function end {
echo "Shutting down the database..."
pg_ctl stop
echo "Removing directories..."
rm -rf $SOCKET_DIRECTORIES
}
trap end EXIT
'';
enableParallelBuilding = true;

LOCALE_ARCHIVE = if stdenv.isLinux then "${glibcLocales}/lib/locale/locale-archive" else "";

nobuild = ''
echo Do not run this derivation with nix-build, it can only be used with nix-shell
'';
}

0 comments on commit d496d94

Please sign in to comment.