Set up flake using the old overlay.nix

This commit is contained in:
Wolfgang Thaller 2023-12-17 19:04:35 +01:00
parent c57f0d98db
commit 551c7588ca
5 changed files with 153 additions and 82 deletions

View File

@ -1,16 +1,16 @@
let sources = import ./nix/sources.nix; let sources = import ./nix/sources.nix;
in { system ? builtins.currentSystem, nixpkgs ? sources.nixpkgs, ... }: in { system ? builtins.currentSystem, nixpkgs ? sources.nixpkgs,
multiversal_src ? if builtins.pathExists ./multiversal/make-multiverse.rb then
./multiversal
else
sources.multiversal,
... }:
let let
retroPlatforms = import nix/platforms.nix; retroPlatforms = import nix/platforms.nix;
lib = ((import nixpkgs) { inherit system; }).lib; lib = ((import nixpkgs) { inherit system; }).lib;
multiversal_src = if builtins.pathExists ./multiversal/make-multiverse.rb then
./multiversal
else
sources.multiversal;
# A Nixpkgs overlay. # A Nixpkgs overlay.
overlay = lib.composeManyExtensions [ overlay = lib.composeManyExtensions [
((import nix/overlay.nix) { inherit multiversal_src; }) ((import nix/overlay.nix) { inherit multiversal_src; })
@ -30,6 +30,8 @@ let
crossSystem = plat; crossSystem = plat;
config = { allowUnsupportedSystem = true; }; config = { allowUnsupportedSystem = true; };
}) retroPlatforms; }) retroPlatforms;
targetPkgs = lib.mapAttrs (name: cross:
cross.buildPackages) crossPkgs;
shell = lib.mapAttrs (name: cross: shell = lib.mapAttrs (name: cross:
cross.mkShell { cross.mkShell {
@ -45,4 +47,5 @@ let
in shell.m68k // shell // { in shell.m68k // shell // {
inherit overlay; inherit overlay;
inherit (overlaidPkgs) retro68; inherit (overlaidPkgs) retro68;
targetPkg = targetPkgs;
} }

View File

@ -17,6 +17,22 @@
"type": "indirect" "type": "indirect"
} }
}, },
"multiversal": {
"flake": false,
"locked": {
"lastModified": 1682955462,
"narHash": "sha256-fOLYuSJOWh/iE7JelpeuT4NgZ/5bZivqV+o9LtiJGxA=",
"owner": "autc04",
"repo": "multiversal",
"rev": "1170bce4c98f1956ad73ca335479d510cd6e8620",
"type": "github"
},
"original": {
"owner": "autc04",
"repo": "multiversal",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1702312524, "lastModified": 1702312524,
@ -54,6 +70,7 @@
"root": { "root": {
"inputs": { "inputs": {
"flake-parts": "flake-parts", "flake-parts": "flake-parts",
"multiversal": "multiversal",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
} }

View File

@ -3,31 +3,58 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
multiversal.url = "github:autc04/multiversal";
multiversal.flake = false;
}; };
outputs = inputs@{ flake-parts, ... }: outputs = inputs@{ flake-parts, nixpkgs, multiversal, ... }:
flake-parts.lib.mkFlake { inherit inputs; } { flake-parts.lib.mkFlake { inherit inputs; } ({ self, lib, retroPlatforms, ... }: {
imports = [ _module.args.lib = import (nixpkgs + "/lib");
# To import a flake module _module.args.retroPlatforms = import ./nix/platforms.nix;
# 1. Add foo to inputs
# 2. Add foo as a parameter to the outputs function
# 3. Add here: foo.flakeModule
];
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
perSystem = { config, self', inputs', pkgs, system, ... }: { perSystem = { config, self', inputs', pkgs, system, ... }:
# Per-system attributes can be defined here. The self' and inputs' {
# module parameters provide easy access to attributes of the same _module.args.pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
# system.
legacyPackages.crossPkgs = lib.mapAttrs
(name: plat:
import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
crossSystem = plat;
config = { allowUnsupportedSystem = true; };
})
retroPlatforms;
devShells = {
default = pkgs.mkShell {
inputsFrom = [ pkgs.retro68.monolithic ];
nativeBuildInputs = [ pkgs.nixpkgs-fmt ];
};
} // lib.mapAttrs
(name: cross:
cross.mkShell
{
nativeBuildInputs = with pkgs; [
retro68.hfsutils
retro68.tools
cmake
gnumake
];
buildInputs = [ cross.retro68.console ];
} // cross)
self'.legacyPackages.crossPkgs;
# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
packages.default = pkgs.hello;
}; };
flake = { flake = {
# The usual flake attributes can be defined here, including system- overlays.default =
# agnostic ones like nixosModule and system-enumerating ones, although lib.composeManyExtensions [
# those are more easily expressed in perSystem. ((import nix/overlay.nix) { multiversal_src = multiversal; })
(import nix/universal.nix)
}; (import nix/samples.nix)
];
}; };
});
} }

View File

@ -5,10 +5,10 @@
"homepage": null, "homepage": null,
"owner": "autc04", "owner": "autc04",
"repo": "multiversal", "repo": "multiversal",
"rev": "ce33b1bada9b0acb14021c21ac916927c757d525", "rev": "1170bce4c98f1956ad73ca335479d510cd6e8620",
"sha256": "1fsyjad4kwsqgr2mlx9dfl7z8z42cf2sgw1arqmci47zhaj8is1f", "sha256": "040vi7c2wggaazm2nrjvzrkn10sgmsbrcpmj2gi1ynjf4awxiqkw",
"type": "tarball", "type": "tarball",
"url": "https://github.com/autc04/multiversal/archive/ce33b1bada9b0acb14021c21ac916927c757d525.tar.gz", "url": "https://github.com/autc04/multiversal/archive/1170bce4c98f1956ad73ca335479d510cd6e8620.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}, },
"niv": { "niv": {
@ -17,10 +17,10 @@
"homepage": "https://github.com/nmattia/niv", "homepage": "https://github.com/nmattia/niv",
"owner": "nmattia", "owner": "nmattia",
"repo": "niv", "repo": "niv",
"rev": "5830a4dd348d77e39a0f3c4c762ff2663b602d4c", "rev": "6bd7cd686220bf3db0e212481faf9578e8c8ff0f",
"sha256": "1d3lsrqvci4qz2hwjrcnd8h5vfkg8aypq3sjd4g3izbc8frwz5sm", "sha256": "15claxlj6y15db67qc7kb4vzyn6sv7r13z4q502vq7a4z2488z94",
"type": "tarball", "type": "tarball",
"url": "https://github.com/nmattia/niv/archive/5830a4dd348d77e39a0f3c4c762ff2663b602d4c.tar.gz", "url": "https://github.com/nmattia/niv/archive/6bd7cd686220bf3db0e212481faf9578e8c8ff0f.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}, },
"nixpkgs": { "nixpkgs": {
@ -29,10 +29,10 @@
"homepage": "", "homepage": "",
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d1e59cfc49961e121583abe32e2f3db1550fbcff", "rev": "2766f77c32e171a04d59b636a91083bae862274e",
"sha256": "03ldf1dlxqf3g8qh9x5vp6vd9zvvr481fyjds111imll69y60wpm", "sha256": "1xk1f62n00z7q5i3pf4c8c4rlv5k4jwpgh0pqgzw1l40vhdkixk9",
"type": "tarball", "type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/d1e59cfc49961e121583abe32e2f3db1550fbcff.tar.gz", "url": "https://github.com/NixOS/nixpkgs/archive/2766f77c32e171a04d59b636a91083bae862274e.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
} }
} }

View File

@ -27,12 +27,33 @@ let
fetch_git = name: spec: fetch_git = name: spec:
let let
ref = ref =
if spec ? ref then spec.ref else spec.ref or (
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 = spec.submodules or false;
submoduleArg =
let
nixSupportsSubmodules = builtins.compareVersions builtins.nixVersion "2.4" >= 0;
emptyArgWithWarning =
if submodules
then
builtins.trace
(
"The niv input \"${name}\" uses submodules "
+ "but your nix's (${builtins.nixVersion}) builtins.fetchGit "
+ "does not support them"
)
{ }
else { };
in in
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; if nixSupportsSubmodules
then { inherit submodules; }
else emptyArgWithWarning;
in
builtins.fetchGit
({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
fetch_local = spec: spec.path; fetch_local = spec: spec.path;
@ -95,7 +116,7 @@ let
# the path directly as opposed to the fetched source. # the path directly as opposed to the fetched source.
replace = name: drv: replace = name: drv:
let let
saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; saneName = stringAsChars (c: if (builtins.match "[a-zA-Z0-9]" c) == null 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
@ -131,7 +152,7 @@ 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 (name != null) { inherit name; }))
else else
fetchTarball attrs; fetchTarball attrs;
@ -141,25 +162,28 @@ 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 (name != null) { 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: name: spec:
if builtins.hasAttr "outPath" spec if builtins.hasAttr "outPath" spec
then abort then
abort
"The values in sources.json should not have an 'outPath' attribute" "The values in sources.json should not have an 'outPath' attribute"
else else
spec // { outPath = replace name (fetch config.pkgs name spec); } spec // { outPath = replace name (fetch config.pkgs name spec); }
) config.sources; )
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 sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile)
, system ? builtins.currentSystem , system ? builtins.currentSystem
, pkgs ? mkPkgs sources system , pkgs ? mkPkgs sources system
}: rec { }: rec {