From 93006f816cb33a5c820b5d1745f07413afe48259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charlotte=20=F0=9F=A6=9D=20Delenk?= Date: Mon, 28 Oct 2024 14:58:23 +0100 Subject: [PATCH] add riscv64 support --- flake.lock | 23 ++++++++++++++++- flake.nix | 45 ++++++++++++++++++++++++---------- modules/containers/default.nix | 7 +++++- modules/default.nix | 6 +++++ modules/riscv.nix | 12 +++++++++ tests/containers-default.nix | 2 +- 6 files changed, 79 insertions(+), 16 deletions(-) create mode 100644 modules/default.nix create mode 100644 modules/riscv.nix diff --git a/flake.lock b/flake.lock index 2b587ed4..2831246a 100644 --- a/flake.lock +++ b/flake.lock @@ -31,10 +31,31 @@ "type": "github" } }, + "riscv-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1728672381, + "narHash": "sha256-7zs+Kb4FaClPojFHIv7Wg4YH6B9/PpP2f0o9+5QIA7U=", + "owner": "DarkKirb", + "repo": "riscv-overlay", + "rev": "47b3b0e989ff06046004be0c76d24af9a46a0c29", + "type": "github" + }, + "original": { + "owner": "DarkKirb", + "repo": "riscv-overlay", + "type": "github" + } + }, "root": { "inputs": { "flake-compat": "flake-compat", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "riscv-overlay": "riscv-overlay" } } }, diff --git a/flake.nix b/flake.nix index 435e4661..e1051375 100644 --- a/flake.nix +++ b/flake.nix @@ -6,8 +6,11 @@ url = "github:edolstra/flake-compat"; flake = false; }; - nixpkgs.url = "github:nixos/nixpkgs"; + riscv-overlay = { + url = "github:DarkKirb/riscv-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; outputs = { @@ -21,16 +24,30 @@ nixos-config = self; inherit inputs; }; - pkgsFor = system: + pkgsFor = system: let + inputs' = + inputs + // { + inherit system; + }; + in import nixpkgs { inherit system; - overlays = [ - (_: _: - inputs - // { - inherit inputs; - }) - ]; + overlays = + [ + (_: _: + inputs' + // { + inputs = inputs'; + }) + ] + ++ ( + if system == "riscv64-linux" + then [ + inputs.riscv-overlay.overlays.default + ] + else [] + ); }; in { checks.x86_64-linux = nixpkgs.lib.listToAttrs (map (testName: { @@ -39,13 +56,13 @@ }) ["containers-default"]); nixosModules = { containers = import ./modules/containers/default.nix; - containers-autoconfig = import ./modules/containers/autoconfig.nix; + default = import ./modules/default.nix; }; nixosContainers = with nixpkgs.lib; let containerNames = [ "default" ]; - containerArches = ["x86_64-linux" "aarch64-linux"]; + containerArches = ["x86_64-linux" "aarch64-linux" "riscv64-linux"]; containers = listToAttrs (flatten (map (system: let pkgs = pkgsFor system; in @@ -58,13 +75,15 @@ in containers; nixosConfigurations = with nixpkgs.lib; let - mkSystem = args: + mkSystem = args: let + inputs' = inputs // {inherit (args) system;}; + in nixosSystem (args // { specialArgs = args.specialArgs or {} - // inputs; + // inputs'; }); containers = mapAttrs (_: container: mkSystem { diff --git a/modules/containers/default.nix b/modules/containers/default.nix index 5d7f61ca..520a072f 100644 --- a/modules/containers/default.nix +++ b/modules/containers/default.nix @@ -1,5 +1,10 @@ -{lib, ...}: { +{ + nixos-config, + lib, + ... +}: { imports = [ + nixos-config.nixosModules.default ./hostName.nix ]; diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 00000000..481f77d5 --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,6 @@ +{...}: { + imports = [ + ./riscv.nix + ./containers/autoconfig.nix + ]; +} diff --git a/modules/riscv.nix b/modules/riscv.nix new file mode 100644 index 00000000..1921b384 --- /dev/null +++ b/modules/riscv.nix @@ -0,0 +1,12 @@ +{ + system, + riscv-overlay, + ... +}: { + nixpkgs.overlays = + if system == "riscv64-linux" + then [ + riscv-overlay.overlays.default + ] + else []; +} diff --git a/tests/containers-default.nix b/tests/containers-default.nix index bf83fe89..52339d98 100644 --- a/tests/containers-default.nix +++ b/tests/containers-default.nix @@ -13,7 +13,7 @@ testers.runNixOSTest { ... }: { imports = [ - nixos-config.nixosModules.containers-autoconfig + nixos-config.nixosModules.default ]; autoContainers = ["default"]; };