mirror of
https://github.com/autc04/Retro68.git
synced 2024-12-27 23:31:44 +00:00
Set up flake using the old overlay.nix
This commit is contained in:
parent
c57f0d98db
commit
551c7588ca
15
default.nix
15
default.nix
@ -1,16 +1,16 @@
|
||||
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
|
||||
retroPlatforms = import nix/platforms.nix;
|
||||
|
||||
lib = ((import nixpkgs) { inherit system; }).lib;
|
||||
|
||||
multiversal_src = if builtins.pathExists ./multiversal/make-multiverse.rb then
|
||||
./multiversal
|
||||
else
|
||||
sources.multiversal;
|
||||
|
||||
# A Nixpkgs overlay.
|
||||
overlay = lib.composeManyExtensions [
|
||||
((import nix/overlay.nix) { inherit multiversal_src; })
|
||||
@ -30,6 +30,8 @@ let
|
||||
crossSystem = plat;
|
||||
config = { allowUnsupportedSystem = true; };
|
||||
}) retroPlatforms;
|
||||
targetPkgs = lib.mapAttrs (name: cross:
|
||||
cross.buildPackages) crossPkgs;
|
||||
|
||||
shell = lib.mapAttrs (name: cross:
|
||||
cross.mkShell {
|
||||
@ -45,4 +47,5 @@ let
|
||||
in shell.m68k // shell // {
|
||||
inherit overlay;
|
||||
inherit (overlaidPkgs) retro68;
|
||||
targetPkg = targetPkgs;
|
||||
}
|
||||
|
17
flake.lock
generated
17
flake.lock
generated
@ -17,6 +17,22 @@
|
||||
"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": {
|
||||
"locked": {
|
||||
"lastModified": 1702312524,
|
||||
@ -54,6 +70,7 @@
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-parts": "flake-parts",
|
||||
"multiversal": "multiversal",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
|
67
flake.nix
67
flake.nix
@ -3,31 +3,58 @@
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
multiversal.url = "github:autc04/multiversal";
|
||||
multiversal.flake = false;
|
||||
};
|
||||
|
||||
outputs = inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [
|
||||
# To import a flake module
|
||||
# 1. Add foo to inputs
|
||||
# 2. Add foo as a parameter to the outputs function
|
||||
# 3. Add here: foo.flakeModule
|
||||
outputs = inputs@{ flake-parts, nixpkgs, multiversal, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } ({ self, lib, retroPlatforms, ... }: {
|
||||
_module.args.lib = import (nixpkgs + "/lib");
|
||||
_module.args.retroPlatforms = import ./nix/platforms.nix;
|
||||
|
||||
];
|
||||
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ];
|
||||
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
|
||||
# system.
|
||||
perSystem = { config, self', inputs', pkgs, system, ... }:
|
||||
{
|
||||
_module.args.pkgs = import nixpkgs { inherit system; overlays = [ self.overlays.default ]; };
|
||||
|
||||
# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
|
||||
packages.default = pkgs.hello;
|
||||
};
|
||||
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;
|
||||
|
||||
|
||||
};
|
||||
flake = {
|
||||
# The usual flake attributes can be defined here, including system-
|
||||
# agnostic ones like nixosModule and system-enumerating ones, although
|
||||
# those are more easily expressed in perSystem.
|
||||
|
||||
overlays.default =
|
||||
lib.composeManyExtensions [
|
||||
((import nix/overlay.nix) { multiversal_src = multiversal; })
|
||||
(import nix/universal.nix)
|
||||
(import nix/samples.nix)
|
||||
];
|
||||
};
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -5,10 +5,10 @@
|
||||
"homepage": null,
|
||||
"owner": "autc04",
|
||||
"repo": "multiversal",
|
||||
"rev": "ce33b1bada9b0acb14021c21ac916927c757d525",
|
||||
"sha256": "1fsyjad4kwsqgr2mlx9dfl7z8z42cf2sgw1arqmci47zhaj8is1f",
|
||||
"rev": "1170bce4c98f1956ad73ca335479d510cd6e8620",
|
||||
"sha256": "040vi7c2wggaazm2nrjvzrkn10sgmsbrcpmj2gi1ynjf4awxiqkw",
|
||||
"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"
|
||||
},
|
||||
"niv": {
|
||||
@ -17,10 +17,10 @@
|
||||
"homepage": "https://github.com/nmattia/niv",
|
||||
"owner": "nmattia",
|
||||
"repo": "niv",
|
||||
"rev": "5830a4dd348d77e39a0f3c4c762ff2663b602d4c",
|
||||
"sha256": "1d3lsrqvci4qz2hwjrcnd8h5vfkg8aypq3sjd4g3izbc8frwz5sm",
|
||||
"rev": "6bd7cd686220bf3db0e212481faf9578e8c8ff0f",
|
||||
"sha256": "15claxlj6y15db67qc7kb4vzyn6sv7r13z4q502vq7a4z2488z94",
|
||||
"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"
|
||||
},
|
||||
"nixpkgs": {
|
||||
@ -29,10 +29,10 @@
|
||||
"homepage": "",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "d1e59cfc49961e121583abe32e2f3db1550fbcff",
|
||||
"sha256": "03ldf1dlxqf3g8qh9x5vp6vd9zvvr481fyjds111imll69y60wpm",
|
||||
"rev": "2766f77c32e171a04d59b636a91083bae862274e",
|
||||
"sha256": "1xk1f62n00z7q5i3pf4c8c4rlv5k4jwpgh0pqgzw1l40vhdkixk9",
|
||||
"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"
|
||||
}
|
||||
}
|
||||
|
118
nix/sources.nix
118
nix/sources.nix
@ -10,29 +10,50 @@ 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
|
||||
spec.ref or (
|
||||
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 ? tag then "refs/tags/${spec.tag}" else
|
||||
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
|
||||
if nixSupportsSubmodules
|
||||
then { inherit submodules; }
|
||||
else emptyArgWithWarning;
|
||||
in
|
||||
builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; };
|
||||
builtins.fetchGit
|
||||
({ url = spec.repo; inherit (spec) rev; inherit ref; } // submoduleArg);
|
||||
|
||||
fetch_local = spec: spec.path;
|
||||
|
||||
@ -66,16 +87,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:
|
||||
@ -95,13 +116,13 @@ let
|
||||
# the path directly as opposed to the fetched source.
|
||||
replace = name: drv:
|
||||
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}";
|
||||
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
|
||||
|
||||
@ -112,7 +133,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));
|
||||
@ -123,43 +144,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 (name != null) { 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 (name != null) { 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 sourcesFile == null then { } else builtins.fromJSON (builtins.readFile sourcesFile)
|
||||
, system ? builtins.currentSystem
|
||||
, pkgs ? mkPkgs sources system
|
||||
}: rec {
|
||||
@ -171,4 +195,4 @@ let
|
||||
};
|
||||
|
||||
in
|
||||
mkSources (mkConfig {}) // { __functor = _: settings: mkSources (mkConfig settings); }
|
||||
mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); }
|
||||
|
Loading…
Reference in New Issue
Block a user