lix-installer/flake.nix
Ana Hobden d69f335703
init-less install (#188)
* wip

* Add dockerfile

* Add readme bits

* Fix logic inversion

* Relax init detection error

* Tidying heuristics

* Fix doc tests

* Mac supports start-daemon false

* Get VM tests working

* Add instructions

* Some target_os flagging

* More target flagging

* Fix lints

* Fixup more mac-only stuff

* cfg flag examples too

* Fix planner wording

* More os specific lint fixing

* More refinement on mac and the README

* Add new CI jobs to test no-daemon

* Use nix-installer-pr to point at branch

* Tests with no-init

* init/no-daemon are linux only

* nix tests support a per-distro all attribute

* Add working podman test

* Expand docker tests

* Add contributing notes

* format

* Support both podman and docker

* Update contributing

* Add Windows WSL test script for Ubuntu

* format nix tests

* More ignores to check-spelling

* Add systemd based wsl test

* We don't have root-only darwin

* Reflect review nits

* Reenable tests

* Restore mac plan

* Flag off os specific tests

* Better cfg flagging

* Remove dead comments

* Rework readme to look better with new sections

* Correct codeblock language

* Remove some warnings
2023-02-01 12:35:52 -08:00

192 lines
6.1 KiB
Nix

{
description = "A Nix Installer";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-22.05";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
nix = {
url = "github:nixos/nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{ self
, nixpkgs
, fenix
, naersk
, nix
, ...
} @ inputs:
let
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forAllSystems = f: nixpkgs.lib.genAttrs supportedSystems (system: (forSystem system f));
forSystem = system: f: f rec {
inherit system;
pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
lib = pkgs.lib;
};
fenixToolchain = system: with fenix.packages.${system};
combine ([
stable.clippy
stable.rustc
stable.cargo
stable.rustfmt
stable.rust-src
] ++ nixpkgs.lib.optionals (system == "x86_64-linux") [
targets.x86_64-unknown-linux-musl.stable.rust-std
] ++ nixpkgs.lib.optionals (system == "aarch64-linux") [
targets.aarch64-unknown-linux-musl.stable.rust-std
]);
in
{
overlays.default = final: prev:
let
toolchain = fenixToolchain final.hostPlatform.system;
naerskLib = final.callPackage naersk {
cargo = toolchain;
rustc = toolchain;
};
sharedAttrs = {
pname = "nix-installer";
version = "0.1.0-unreleased";
src = builtins.path {
name = "nix-installer-source";
path = self;
filter = (path: type: baseNameOf path != "nix" || baseNameOf path != ".github");
};
nativeBuildInputs = with final; [ ];
buildInputs = with final; [ ] ++ lib.optionals (final.stdenv.isDarwin) (with final.darwin.apple_sdk.frameworks; [
SystemConfiguration
]);
doCheck = true;
doDoc = true;
doDocFail = true;
RUSTFLAGS = "--cfg tokio_unstable";
cargoTestOptions = f: f ++ [ "--all" ];
override = { preBuild ? "", ... }: {
preBuild = preBuild + ''
# logRun "cargo clippy --all-targets --all-features -- -D warnings"
'';
};
postInstall = ''
cp nix-installer.sh $out/bin/nix-installer.sh
'';
};
in
rec {
nix-installer = naerskLib.buildPackage sharedAttrs;
} // nixpkgs.lib.optionalAttrs (prev.hostPlatform.system == "x86_64-linux") rec {
default = nix-installer-static;
nix-installer-static = naerskLib.buildPackage
(sharedAttrs // {
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
});
} // nixpkgs.lib.optionalAttrs (prev.hostPlatform.system == "aarch64-linux") rec {
default = nix-installer-static;
nix-installer-static = naerskLib.buildPackage
(sharedAttrs // {
CARGO_BUILD_TARGET = "aarch64-unknown-linux-musl";
});
};
devShells = forAllSystems ({ system, pkgs, ... }:
let
toolchain = fenixToolchain system;
eclint = import ./nix/eclint.nix { inherit pkgs; };
check = import ./nix/check.nix { inherit pkgs eclint toolchain; };
in
{
default = pkgs.mkShell {
name = "nix-install-shell";
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
nativeBuildInputs = with pkgs; [ ];
buildInputs = with pkgs; [
toolchain
rust-analyzer
cargo-outdated
nixpkgs-fmt
check.check-rustfmt
check.check-spelling
check.check-nixpkgs-fmt
check.check-editorconfig
]
++ lib.optionals (pkgs.stdenv.isDarwin) (with pkgs; [ libiconv ]);
};
});
checks = forAllSystems ({ system, pkgs, ... }:
let
toolchain = fenixToolchain system;
eclint = import ./nix/eclint.nix { inherit pkgs; };
check = import ./nix/check.nix { inherit pkgs eclint toolchain; };
in
{
check-rustfmt = pkgs.runCommand "check-rustfmt" { buildInputs = [ check.check-rustfmt ]; } ''
cd ${./.}
check-rustfmt
touch $out
'';
check-spelling = pkgs.runCommand "check-spelling" { buildInputs = [ check.check-spelling ]; } ''
cd ${./.}
check-spelling
touch $out
'';
check-nixpkgs-fmt = pkgs.runCommand "check-nixpkgs-fmt" { buildInputs = [ check.check-nixpkgs-fmt ]; } ''
cd ${./.}
check-nixpkgs-fmt
touch $out
'';
check-editorconfig = pkgs.runCommand "check-editorconfig" { buildInputs = [ pkgs.git check.check-editorconfig ]; } ''
cd ${./.}
check-editorconfig
touch $out
'';
});
packages = forAllSystems ({ system, pkgs, ... }:
{
inherit (pkgs) nix-installer;
} // nixpkgs.lib.optionalAttrs (system == "x86_64-linux") {
inherit (pkgs) nix-installer-static;
default = pkgs.nix-installer-static;
} // nixpkgs.lib.optionalAttrs (system == "aarch64-linux") {
inherit (pkgs) nix-installer-static;
default = pkgs.nix-installer-static;
} // nixpkgs.lib.optionalAttrs (pkgs.stdenv.isDarwin) {
default = pkgs.nix-installer;
});
hydraJobs = {
vm-test = import ./nix/tests/vm-test {
inherit forSystem;
inherit (nix.hydraJobs) binaryTarball;
};
container-test = import ./nix/tests/container-test {
inherit forSystem;
inherit (nix.hydraJobs) binaryTarball;
};
};
};
}