Skip to content

Commit

Permalink
add nix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
viperML committed Nov 27, 2024
1 parent 51020a2 commit ffce875
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 117 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ jobs:

- run: |
eval "$(nix print-dev-env)"
cargo fix --allow-dirty
cargo clippy --fix --allow-dirty
cargo fmt
./fix.sh
git diff-index --quiet HEAD
name: Check clippy and formatting
name: Check formatting
1 change: 1 addition & 0 deletions fix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ set -eux
cargo fix --allow-dirty
cargo clippy --fix --allow-dirty
cargo fmt
nix fmt
55 changes: 26 additions & 29 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,33 @@
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
};

outputs = {
self,
nixpkgs,
}: let
forAllSystems = function:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
# experimental
"x86_64-darwin"
"aarch64-darwin"
] (system: function nixpkgs.legacyPackages.${system});
outputs =
{ self, nixpkgs }:
let
forAllSystems =
function:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
# experimental
"x86_64-darwin"
"aarch64-darwin"
] (system: function nixpkgs.legacyPackages.${system});

rev = self.shortRev or self.dirtyShortRev or "dirty";
in {
overlays.default = final: prev: {
nh = final.callPackage ./package.nix {
inherit rev;
};
};
rev = self.shortRev or self.dirtyShortRev or "dirty";
in
{
overlays.default = final: prev: { nh = final.callPackage ./package.nix { inherit rev; }; };

packages = forAllSystems (pkgs: rec {
nh = pkgs.callPackage ./package.nix {
inherit rev;
};
default = nh;
});
packages = forAllSystems (pkgs: rec {
nh = pkgs.callPackage ./package.nix { inherit rev; };
default = nh;
});

devShells = forAllSystems (pkgs: {
default = import ./shell.nix {inherit pkgs;};
});
};
devShells = forAllSystems (pkgs: {
default = import ./shell.nix { inherit pkgs; };
});

formatter = forAllSystems (pkgs: pkgs.nixfmt-rfc-style);
};
}
87 changes: 45 additions & 42 deletions package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,56 +10,59 @@
nix-output-monitor ? null,
rev ? "dirty",
}:
assert use-nom -> nix-output-monitor != null; let
runtimeDeps = [nvd] ++ lib.optionals use-nom [nix-output-monitor];
assert use-nom -> nix-output-monitor != null;
let
runtimeDeps = [ nvd ] ++ lib.optionals use-nom [ nix-output-monitor ];
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in
rustPlatform.buildRustPackage {
pname = "nh";
version = "${cargoToml.package.version}-${rev}";
rustPlatform.buildRustPackage {
pname = "nh";
version = "${cargoToml.package.version}-${rev}";

src = lib.fileset.toSource {
root = ./.;
fileset =
lib.fileset.intersection
(lib.fileset.fromSource (lib.sources.cleanSource ./.))
(lib.fileset.unions [
./src
./Cargo.toml
./Cargo.lock
]);
};
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.intersection (lib.fileset.fromSource (lib.sources.cleanSource ./.)) (
lib.fileset.unions [
./src
./Cargo.toml
./Cargo.lock
]
);
};

strictDeps = true;
strictDeps = true;

nativeBuildInputs = [
installShellFiles
makeBinaryWrapper
];
nativeBuildInputs = [
installShellFiles
makeBinaryWrapper
];

buildInputs = lib.optionals stdenv.isDarwin [darwin.apple_sdk.frameworks.SystemConfiguration];
buildInputs = lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.SystemConfiguration ];

preFixup = ''
mkdir completions
$out/bin/nh completions bash > completions/nh.bash
$out/bin/nh completions zsh > completions/nh.zsh
$out/bin/nh completions fish > completions/nh.fish
preFixup = ''
mkdir completions
$out/bin/nh completions bash > completions/nh.bash
$out/bin/nh completions zsh > completions/nh.zsh
$out/bin/nh completions fish > completions/nh.fish
installShellCompletion completions/*
'';
installShellCompletion completions/*
'';

postFixup = ''
wrapProgram $out/bin/nh \
--prefix PATH : ${lib.makeBinPath runtimeDeps}
'';
postFixup = ''
wrapProgram $out/bin/nh \
--prefix PATH : ${lib.makeBinPath runtimeDeps}
'';

cargoLock.lockFile = ./Cargo.lock;
cargoLock.lockFile = ./Cargo.lock;

meta = {
description = "Yet another nix cli helper";
homepage = "https://github.com/viperML/nh";
license = lib.licenses.eupl12;
mainProgram = "nh";
maintainers = with lib.maintainers; [drupol viperML];
};
}
meta = {
description = "Yet another nix cli helper";
homepage = "https://github.com/viperML/nh";
license = lib.licenses.eupl12;
mainProgram = "nh";
maintainers = with lib.maintainers; [
drupol
viperML
];
};
}
44 changes: 23 additions & 21 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{pkgs ? import <nixpkgs> {}}:
{
pkgs ? import <nixpkgs> { },
}:
with pkgs;
mkShell {
strictDeps = true;
mkShell {
strictDeps = true;

nativeBuildInputs = [
cargo
rustc
nativeBuildInputs = [
cargo
rustc

rust-analyzer-unwrapped
(rustfmt.override {asNightly = true;})
clippy
nvd
nix-output-monitor
taplo
yaml-language-server
];
rust-analyzer-unwrapped
(rustfmt.override { asNightly = true; })
clippy
nvd
nix-output-monitor
taplo
yaml-language-server
];

buildInputs = [];
buildInputs = [ ];

env = {
NH_NOM = "1";
NH_LOG = "nh=trace";
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
};
}
env = {
NH_NOM = "1";
NH_LOG = "nh=trace";
RUST_SRC_PATH = "${rustPlatform.rustLibSrc}";
};
}
6 changes: 1 addition & 5 deletions src/installable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ where
}
}
'"' => {
if !in_quote {
in_quote = true;
} else {
in_quote = false;
}
in_quote = !in_quote;
}
_ => elem.push(char),
}
Expand Down
20 changes: 10 additions & 10 deletions test/home.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
let
hm = builtins.getFlake "github:nix-community/home-manager";
pkgs = import <nixpkgs> {};
pkgs = import <nixpkgs> { };
in
import "${hm}/modules" {
inherit pkgs;
configuration = {
home.stateVersion = "24.05";
home.packages = [pkgs.hello];
home.username = "anon";
home.homeDirectory = "/anonfiles";
};
}
import "${hm}/modules" {
inherit pkgs;
configuration = {
home.stateVersion = "24.05";
home.packages = [ pkgs.hello ];
home.username = "anon";
home.homeDirectory = "/anonfiles";
};
}
5 changes: 1 addition & 4 deletions test/nixos.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
import <nixpkgs/nixos> {
configuration = {};
}

import <nixpkgs/nixos> { configuration = { }; }

0 comments on commit ffce875

Please sign in to comment.